From 3d1eec3a2350551b7ded05831f3ed5bf155db7c0 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 12 Feb 2024 16:11:53 +0200 Subject: [PATCH 01/16] new crypto VM hooks --- Cargo.toml | 3 ++- c-api/libvmexeccapi.h | 5 ++++- c-api/src/capi_vm_hook_pointers.rs | 5 ++++- c-api/src/capi_vm_hooks.rs | 16 ++++++++++++++-- vm-executor-wasmer/src/wasmer_imports.rs | 22 ++++++++++++++++++++-- vm-executor/src/vm_hooks.rs | 22 ++++++++++++++++++++-- 6 files changed, 64 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 9a3678c..def40f7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,6 @@ - [workspace] +resolver = "2" + members = [ "c-api", "vm-executor", diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index c7b77ad..a5e6235 100644 --- a/c-api/libvmexeccapi.h +++ b/c-api/libvmexeccapi.h @@ -129,7 +129,7 @@ typedef struct { void (*managed_get_prev_block_random_seed_func_ptr)(void *context, int32_t result_handle); void (*managed_get_return_data_func_ptr)(void *context, int32_t result_id, int32_t result_handle); void (*managed_get_multi_esdt_call_value_func_ptr)(void *context, int32_t multi_call_value_handle); - void (*managed_get_back_transfers_func_ptr)(void *context, int32_t esdt_transfers_value_handle, int32_t call_value_handle); + void (*managed_get_back_transfers_func_ptr)(void *context, int32_t esdt_transfers_value_handle, int32_t egld_value_handle); void (*managed_get_esdt_balance_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t value_handle); void (*managed_get_esdt_token_data_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t value_handle, int32_t properties_handle, int32_t hash_handle, int32_t name_handle, int32_t attributes_handle, int32_t creator_handle, int32_t royalties_handle, int32_t uris_handle); void (*managed_async_call_func_ptr)(void *context, int32_t dest_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle); @@ -293,6 +293,9 @@ typedef struct { int32_t (*get_curve_length_ec_func_ptr)(void *context, int32_t ec_handle); int32_t (*get_priv_key_byte_length_ec_func_ptr)(void *context, int32_t ec_handle); int32_t (*elliptic_curve_get_values_func_ptr)(void *context, int32_t ec_handle, int32_t field_order_handle, int32_t base_point_order_handle, int32_t eq_constant_handle, int32_t x_base_point_handle, int32_t y_base_point_handle); + int32_t (*managed_verify_secp256r1_func_ptr)(void *context, int32_t key_handle, int32_t message_handle, int32_t sig_handle); + int32_t (*managed_verify_blssignature_share_func_ptr)(void *context, int32_t key_handle, int32_t message_handle, int32_t sig_handle); + int32_t (*managed_verify_blsaggregated_signature_func_ptr)(void *context, int32_t key_handle, int32_t message_handle, int32_t sig_handle); } vm_exec_vm_hook_c_func_pointers; typedef struct { diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index 77fc5ef..d62a251 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -101,7 +101,7 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub managed_get_prev_block_random_seed_func_ptr: extern "C" fn(context: *mut c_void, result_handle: i32), pub managed_get_return_data_func_ptr: extern "C" fn(context: *mut c_void, result_id: i32, result_handle: i32), pub managed_get_multi_esdt_call_value_func_ptr: extern "C" fn(context: *mut c_void, multi_call_value_handle: i32), - pub managed_get_back_transfers_func_ptr: extern "C" fn(context: *mut c_void, esdt_transfers_value_handle: i32, call_value_handle: i32), + pub managed_get_back_transfers_func_ptr: extern "C" fn(context: *mut c_void, esdt_transfers_value_handle: i32, egld_value_handle: i32), pub managed_get_esdt_balance_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32), pub managed_get_esdt_token_data_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32, properties_handle: i32, hash_handle: i32, name_handle: i32, attributes_handle: i32, creator_handle: i32, royalties_handle: i32, uris_handle: i32), pub managed_async_call_func_ptr: extern "C" fn(context: *mut c_void, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32), @@ -265,6 +265,9 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub get_curve_length_ec_func_ptr: extern "C" fn(context: *mut c_void, ec_handle: i32) -> i32, pub get_priv_key_byte_length_ec_func_ptr: extern "C" fn(context: *mut c_void, ec_handle: i32) -> i32, pub elliptic_curve_get_values_func_ptr: extern "C" fn(context: *mut c_void, ec_handle: i32, field_order_handle: i32, base_point_order_handle: i32, eq_constant_handle: i32, x_base_point_handle: i32, y_base_point_handle: i32) -> i32, + pub managed_verify_secp256r1_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32, + pub managed_verify_blssignature_share_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32, + pub managed_verify_blsaggregated_signature_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32, } impl std::fmt::Debug for vm_exec_vm_hook_c_func_pointers { diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index 687cdec..a6d2f2d 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -403,8 +403,8 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.managed_get_multi_esdt_call_value_func_ptr)(self.vm_hooks_ptr, multi_call_value_handle) } - fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, call_value_handle: i32) { - (self.c_func_pointers_ptr.managed_get_back_transfers_func_ptr)(self.vm_hooks_ptr, esdt_transfers_value_handle, call_value_handle) + fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, egld_value_handle: i32) { + (self.c_func_pointers_ptr.managed_get_back_transfers_func_ptr)(self.vm_hooks_ptr, esdt_transfers_value_handle, egld_value_handle) } fn managed_get_esdt_balance(&self, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32) { @@ -1058,4 +1058,16 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { fn elliptic_curve_get_values(&self, ec_handle: i32, field_order_handle: i32, base_point_order_handle: i32, eq_constant_handle: i32, x_base_point_handle: i32, y_base_point_handle: i32) -> i32 { (self.c_func_pointers_ptr.elliptic_curve_get_values_func_ptr)(self.vm_hooks_ptr, ec_handle, field_order_handle, base_point_order_handle, eq_constant_handle, x_base_point_handle, y_base_point_handle) } + + fn managed_verify_secp256r1(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + (self.c_func_pointers_ptr.managed_verify_secp256r1_func_ptr)(self.vm_hooks_ptr, key_handle, message_handle, sig_handle) + } + + fn managed_verify_blssignature_share(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + (self.c_func_pointers_ptr.managed_verify_blssignature_share_func_ptr)(self.vm_hooks_ptr, key_handle, message_handle, sig_handle) + } + + fn managed_verify_blsaggregated_signature(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + (self.c_func_pointers_ptr.managed_verify_blsaggregated_signature_func_ptr)(self.vm_hooks_ptr, key_handle, message_handle, sig_handle) + } } diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 63e07c9..be5ad0c 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -466,8 +466,8 @@ fn wasmer_import_managed_get_multi_esdt_call_value(env: &VMHooksWrapper, multi_c } #[rustfmt::skip] -fn wasmer_import_managed_get_back_transfers(env: &VMHooksWrapper, esdt_transfers_value_handle: i32, call_value_handle: i32) { - env.vm_hooks.managed_get_back_transfers(esdt_transfers_value_handle, call_value_handle) +fn wasmer_import_managed_get_back_transfers(env: &VMHooksWrapper, esdt_transfers_value_handle: i32, egld_value_handle: i32) { + env.vm_hooks.managed_get_back_transfers(esdt_transfers_value_handle, egld_value_handle) } #[rustfmt::skip] @@ -1285,6 +1285,21 @@ fn wasmer_import_elliptic_curve_get_values(env: &VMHooksWrapper, ec_handle: i32, env.vm_hooks.elliptic_curve_get_values(ec_handle, field_order_handle, base_point_order_handle, eq_constant_handle, x_base_point_handle, y_base_point_handle) } +#[rustfmt::skip] +fn wasmer_import_managed_verify_secp256r1(env: &VMHooksWrapper, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + env.vm_hooks.managed_verify_secp256r1(key_handle, message_handle, sig_handle) +} + +#[rustfmt::skip] +fn wasmer_import_managed_verify_blssignature_share(env: &VMHooksWrapper, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + env.vm_hooks.managed_verify_blssignature_share(key_handle, message_handle, sig_handle) +} + +#[rustfmt::skip] +fn wasmer_import_managed_verify_blsaggregated_signature(env: &VMHooksWrapper, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + env.vm_hooks.managed_verify_blsaggregated_signature(key_handle, message_handle, sig_handle) +} + pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObject { imports! { "env" => { @@ -1543,6 +1558,9 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "getCurveLengthEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_curve_length_ec), "getPrivKeyByteLengthEC" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_priv_key_byte_length_ec), "ellipticCurveGetValues" => Function::new_native_with_env(store, env.clone(), wasmer_import_elliptic_curve_get_values), + "managedVerifySecp256r1" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_secp256r1), + "managedVerifyBLSSignatureShare" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_blssignature_share), + "managedVerifyBLSAggregatedSignature" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_verify_blsaggregated_signature), } } diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 05685fd..eba5afd 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -104,7 +104,7 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn managed_get_prev_block_random_seed(&self, result_handle: i32); fn managed_get_return_data(&self, result_id: i32, result_handle: i32); fn managed_get_multi_esdt_call_value(&self, multi_call_value_handle: i32); - fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, call_value_handle: i32); + fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, egld_value_handle: i32); fn managed_get_esdt_balance(&self, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32); fn managed_get_esdt_token_data(&self, address_handle: i32, token_id_handle: i32, nonce: i64, value_handle: i32, properties_handle: i32, hash_handle: i32, name_handle: i32, attributes_handle: i32, creator_handle: i32, royalties_handle: i32, uris_handle: i32); fn managed_async_call(&self, dest_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32); @@ -268,6 +268,9 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn get_curve_length_ec(&self, ec_handle: i32) -> i32; fn get_priv_key_byte_length_ec(&self, ec_handle: i32) -> i32; fn elliptic_curve_get_values(&self, ec_handle: i32, field_order_handle: i32, base_point_order_handle: i32, eq_constant_handle: i32, x_base_point_handle: i32, y_base_point_handle: i32) -> i32; + fn managed_verify_secp256r1(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32; + fn managed_verify_blssignature_share(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32; + fn managed_verify_blsaggregated_signature(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32; } /// Dummy implementation for VMHooks. Can be used as placeholder, or in tests. @@ -703,7 +706,7 @@ impl VMHooks for VMHooksDefault { println!("Called: managed_get_multi_esdt_call_value"); } - fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, call_value_handle: i32) { + fn managed_get_back_transfers(&self, esdt_transfers_value_handle: i32, egld_value_handle: i32) { println!("Called: managed_get_back_transfers"); } @@ -1460,4 +1463,19 @@ impl VMHooks for VMHooksDefault { println!("Called: elliptic_curve_get_values"); 0 } + + fn managed_verify_secp256r1(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + println!("Called: managed_verify_secp256r1"); + 0 + } + + fn managed_verify_blssignature_share(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + println!("Called: managed_verify_blssignature_share"); + 0 + } + + fn managed_verify_blsaggregated_signature(&self, key_handle: i32, message_handle: i32, sig_handle: i32) -> i32 { + println!("Called: managed_verify_blsaggregated_signature"); + 0 + } } From 522c80e6d717394e8d2b8fab5c62f0d8c40bb640 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 12 Feb 2024 16:13:37 +0200 Subject: [PATCH 02/16] clippy fix --- vm-executor-wasmer/src/wasmer_instance.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vm-executor-wasmer/src/wasmer_instance.rs b/vm-executor-wasmer/src/wasmer_instance.rs index 385e947..764e4ac 100644 --- a/vm-executor-wasmer/src/wasmer_instance.rs +++ b/vm-executor-wasmer/src/wasmer_instance.rs @@ -137,7 +137,7 @@ fn get_memories(wasmer_instance: &wasmer::Instance) -> Vec<(&String, &wasmer::Me memories } -fn validate_memories(memories: &Vec<(&String, &wasmer::Memory)>) -> Result<(), ExecutorError> { +fn validate_memories(memories: &[(&String, &wasmer::Memory)]) -> Result<(), ExecutorError> { if memories.is_empty() { return Err(Box::new(ServiceError::new( "no memory declared in smart contract", From c805854ae1ca58197f34265cef96ed612a5e5bdd Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 12 Feb 2024 16:13:43 +0200 Subject: [PATCH 03/16] cargo fmt --- vm-executor-wasmer/src/wasmer_helpers.rs | 2 +- vm-executor-wasmer/src/wasmer_service.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/vm-executor-wasmer/src/wasmer_helpers.rs b/vm-executor-wasmer/src/wasmer_helpers.rs index 290c668..3e08d75 100644 --- a/vm-executor-wasmer/src/wasmer_helpers.rs +++ b/vm-executor-wasmer/src/wasmer_helpers.rs @@ -1,4 +1,4 @@ -use wasmer::{ExportIndex, GlobalInit, GlobalType, Mutability, Type, wasmparser::Operator}; +use wasmer::{wasmparser::Operator, ExportIndex, GlobalInit, GlobalType, Mutability, Type}; use wasmer_types::{GlobalIndex, ModuleInfo}; pub trait MiddlewareWithProtectedGlobals { diff --git a/vm-executor-wasmer/src/wasmer_service.rs b/vm-executor-wasmer/src/wasmer_service.rs index 9000c03..30cd25f 100644 --- a/vm-executor-wasmer/src/wasmer_service.rs +++ b/vm-executor-wasmer/src/wasmer_service.rs @@ -3,9 +3,9 @@ use multiversx_chain_vm_executor::{ Executor, ExecutorError, ExecutorLastError, ExecutorService, VMHooks, }; -use log::LevelFilter; use crate::wasmer_logger as WasmerLogger; use crate::WasmerExecutor; +use log::LevelFilter; #[derive(Default)] pub struct BasicExecutorService { From 450ed37d95df01ca69201e892b2b7081260ba138 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 28 Mar 2024 14:49:41 +0200 Subject: [PATCH 04/16] rust-toolchain.toml --- rust-toolchain.toml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..292fe49 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "stable" From 70e9ce97e29260485efb10eb2b91ad978a79fa0b Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Thu, 28 Mar 2024 14:51:43 +0200 Subject: [PATCH 05/16] new VM hooks - transfer execute by user --- c-api/src/capi_vm_hook_pointers.rs | 3 +++ c-api/src/capi_vm_hooks.rs | 12 ++++++++++++ vm-executor-wasmer/src/wasmer_imports.rs | 18 ++++++++++++++++++ vm-executor/src/vm_hooks.rs | 16 ++++++++++++++++ 4 files changed, 49 insertions(+) diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index d62a251..7280a14 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -93,6 +93,8 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub managed_sc_address_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32), pub managed_owner_address_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32), pub managed_caller_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32), + pub managed_get_original_caller_addr_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32), + pub managed_get_relayer_addr_func_ptr: extern "C" fn(context: *mut c_void, destination_handle: i32), pub managed_signal_error_func_ptr: extern "C" fn(context: *mut c_void, err_handle: i32), pub managed_write_log_func_ptr: extern "C" fn(context: *mut c_void, topics_handle: i32, data_handle: i32), pub managed_get_original_tx_hash_func_ptr: extern "C" fn(context: *mut c_void, result_handle: i32), @@ -116,6 +118,7 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub managed_execute_on_same_context_func_ptr: extern "C" fn(context: *mut c_void, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32, pub managed_execute_on_dest_context_func_ptr: extern "C" fn(context: *mut c_void, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32, pub managed_multi_transfer_esdt_nft_execute_func_ptr: extern "C" fn(context: *mut c_void, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32, + pub managed_multi_transfer_esdt_nft_execute_by_user_func_ptr: extern "C" fn(context: *mut c_void, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32, pub managed_transfer_value_execute_func_ptr: extern "C" fn(context: *mut c_void, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32, pub managed_is_esdt_frozen_func_ptr: extern "C" fn(context: *mut c_void, address_handle: i32, token_id_handle: i32, nonce: i64) -> i32, pub managed_is_esdt_limited_transfer_func_ptr: extern "C" fn(context: *mut c_void, token_id_handle: i32) -> i32, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index a6d2f2d..09fb97f 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -371,6 +371,14 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.managed_caller_func_ptr)(self.vm_hooks_ptr, destination_handle) } + fn managed_get_original_caller_addr(&self, destination_handle: i32) { + (self.c_func_pointers_ptr.managed_get_original_caller_addr_func_ptr)(self.vm_hooks_ptr, destination_handle) + } + + fn managed_get_relayer_addr(&self, destination_handle: i32) { + (self.c_func_pointers_ptr.managed_get_relayer_addr_func_ptr)(self.vm_hooks_ptr, destination_handle) + } + fn managed_signal_error(&self, err_handle: i32) { (self.c_func_pointers_ptr.managed_signal_error_func_ptr)(self.vm_hooks_ptr, err_handle) } @@ -463,6 +471,10 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.managed_multi_transfer_esdt_nft_execute_func_ptr)(self.vm_hooks_ptr, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle) } + fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { + (self.c_func_pointers_ptr.managed_multi_transfer_esdt_nft_execute_by_user_func_ptr)(self.vm_hooks_ptr, user_handle, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle) + } + fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { (self.c_func_pointers_ptr.managed_transfer_value_execute_func_ptr)(self.vm_hooks_ptr, dst_handle, value_handle, gas_limit, function_handle, arguments_handle) } diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index be5ad0c..345686f 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -425,6 +425,16 @@ fn wasmer_import_managed_caller(env: &VMHooksWrapper, destination_handle: i32) { env.vm_hooks.managed_caller(destination_handle) } +#[rustfmt::skip] +fn wasmer_import_managed_get_original_caller_addr(env: &VMHooksWrapper, destination_handle: i32) { + env.vm_hooks.managed_get_original_caller_addr(destination_handle) +} + +#[rustfmt::skip] +fn wasmer_import_managed_get_relayer_addr(env: &VMHooksWrapper, destination_handle: i32) { + env.vm_hooks.managed_get_relayer_addr(destination_handle) +} + #[rustfmt::skip] fn wasmer_import_managed_signal_error(env: &VMHooksWrapper, err_handle: i32) { env.vm_hooks.managed_signal_error(err_handle) @@ -540,6 +550,11 @@ fn wasmer_import_managed_multi_transfer_esdt_nft_execute(env: &VMHooksWrapper, d env.vm_hooks.managed_multi_transfer_esdt_nft_execute(dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle) } +#[rustfmt::skip] +fn wasmer_import_managed_multi_transfer_esdt_nft_execute_by_user(env: &VMHooksWrapper, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { + env.vm_hooks.managed_multi_transfer_esdt_nft_execute_by_user(user_handle, dst_handle, token_transfers_handle, gas_limit, function_handle, arguments_handle) +} + #[rustfmt::skip] fn wasmer_import_managed_transfer_value_execute(env: &VMHooksWrapper, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { env.vm_hooks.managed_transfer_value_execute(dst_handle, value_handle, gas_limit, function_handle, arguments_handle) @@ -1386,6 +1401,8 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "managedSCAddress" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_sc_address), "managedOwnerAddress" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_owner_address), "managedCaller" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_caller), + "managedGetOriginalCallerAddr" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_original_caller_addr), + "managedGetRelayerAddr" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_relayer_addr), "managedSignalError" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_signal_error), "managedWriteLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_write_log), "managedGetOriginalTxHash" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_get_original_tx_hash), @@ -1409,6 +1426,7 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "managedExecuteOnSameContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_execute_on_same_context), "managedExecuteOnDestContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_execute_on_dest_context), "managedMultiTransferESDTNFTExecute" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_multi_transfer_esdt_nft_execute), + "managedMultiTransferESDTNFTExecuteByUser" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_multi_transfer_esdt_nft_execute_by_user), "managedTransferValueExecute" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_transfer_value_execute), "managedIsESDTFrozen" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_is_esdt_frozen), "managedIsESDTLimitedTransfer" => Function::new_native_with_env(store, env.clone(), wasmer_import_managed_is_esdt_limited_transfer), diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index eba5afd..33bc97e 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -96,6 +96,8 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn managed_sc_address(&self, destination_handle: i32); fn managed_owner_address(&self, destination_handle: i32); fn managed_caller(&self, destination_handle: i32); + fn managed_get_original_caller_addr(&self, destination_handle: i32); + fn managed_get_relayer_addr(&self, destination_handle: i32); fn managed_signal_error(&self, err_handle: i32); fn managed_write_log(&self, topics_handle: i32, data_handle: i32); fn managed_get_original_tx_hash(&self, result_handle: i32); @@ -119,6 +121,7 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn managed_execute_on_same_context(&self, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32; fn managed_execute_on_dest_context(&self, gas: i64, address_handle: i32, value_handle: i32, function_handle: i32, arguments_handle: i32, result_handle: i32) -> i32; fn managed_multi_transfer_esdt_nft_execute(&self, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32; + fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32; fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32; fn managed_is_esdt_frozen(&self, address_handle: i32, token_id_handle: i32, nonce: i64) -> i32; fn managed_is_esdt_limited_transfer(&self, token_id_handle: i32) -> i32; @@ -674,6 +677,14 @@ impl VMHooks for VMHooksDefault { println!("Called: managed_caller"); } + fn managed_get_original_caller_addr(&self, destination_handle: i32) { + println!("Called: managed_get_original_caller_addr"); + } + + fn managed_get_relayer_addr(&self, destination_handle: i32) { + println!("Called: managed_get_relayer_addr"); + } + fn managed_signal_error(&self, err_handle: i32) { println!("Called: managed_signal_error"); } @@ -773,6 +784,11 @@ impl VMHooks for VMHooksDefault { 0 } + fn managed_multi_transfer_esdt_nft_execute_by_user(&self, user_handle: i32, dst_handle: i32, token_transfers_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { + println!("Called: managed_multi_transfer_esdt_nft_execute_by_user"); + 0 + } + fn managed_transfer_value_execute(&self, dst_handle: i32, value_handle: i32, gas_limit: i64, function_handle: i32, arguments_handle: i32) -> i32 { println!("Called: managed_transfer_value_execute"); 0 From cfdd5fb9eec08bb7f98d0b29f4786be7db2351ed Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:23:06 +0000 Subject: [PATCH 06/16] IsBuiltinFunctionName vmhook --- c-api/src/capi_vm_hook_pointers.rs | 1 + c-api/src/capi_vm_hooks.rs | 4 ++++ vm-executor-wasmer/src/wasmer_imports.rs | 6 ++++++ vm-executor/src/vm_hooks.rs | 6 ++++++ 4 files changed, 17 insertions(+) diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index 7280a14..8c58388 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -63,6 +63,7 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub get_num_esdt_transfers_func_ptr: extern "C" fn(context: *mut c_void) -> i32, pub get_call_value_token_name_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32) -> i32, pub get_call_value_token_name_by_index_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32, index: i32) -> i32, + pub is_builtin_function_name_func_ptr: extern "C" fn(context: *mut c_void, name_offset: i32, name_length: i32) -> i32, pub write_log_func_ptr: extern "C" fn(context: *mut c_void, data_pointer: i32, data_length: i32, topic_ptr: i32, num_topics: i32), pub write_event_log_func_ptr: extern "C" fn(context: *mut c_void, num_topics: i32, topic_lengths_offset: i32, topic_offset: i32, data_offset: i32, data_length: i32), pub get_block_timestamp_func_ptr: extern "C" fn(context: *mut c_void) -> i64, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index 09fb97f..a76bc77 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -251,6 +251,10 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.get_call_value_token_name_by_index_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(call_value_offset), self.convert_mem_ptr(token_name_offset), index) } + fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { + (self.c_func_pointers_ptr.is_builtin_function_name_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(name_offset), self.convert_mem_length(name_length)) + } + fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32) { (self.c_func_pointers_ptr.write_log_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(data_pointer), self.convert_mem_length(data_length), self.convert_mem_ptr(topic_ptr), num_topics) } diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 345686f..69b360d 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -275,6 +275,11 @@ fn wasmer_import_get_call_value_token_name_by_index(env: &VMHooksWrapper, call_v env.vm_hooks.get_call_value_token_name_by_index(env.convert_mem_ptr(call_value_offset), env.convert_mem_ptr(token_name_offset), index) } +#[rustfmt::skip] +fn wasmer_import_is_builtin_function_name(env: &VMHooksWrapper, name_offset: i32, name_length: i32) -> i32 { + env.vm_hooks.is_builtin_function_name(env.convert_mem_ptr(name_offset), env.convert_mem_length(name_length)) +} + #[rustfmt::skip] fn wasmer_import_write_log(env: &VMHooksWrapper, data_pointer: i32, data_length: i32, topic_ptr: i32, num_topics: i32) { env.vm_hooks.write_log(env.convert_mem_ptr(data_pointer), env.convert_mem_length(data_length), env.convert_mem_ptr(topic_ptr), num_topics) @@ -1371,6 +1376,7 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "getNumESDTTransfers" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_num_esdt_transfers), "getCallValueTokenName" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_call_value_token_name), "getCallValueTokenNameByIndex" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_call_value_token_name_by_index), + "isBuiltinFunctionName" => Function::new_native_with_env(store, env.clone(), wasmer_import_is_builtin_function_name), "writeLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_write_log), "writeEventLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_write_event_log), "getBlockTimestamp" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_block_timestamp), diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 33bc97e..6259205 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -66,6 +66,7 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn get_num_esdt_transfers(&self) -> i32; fn get_call_value_token_name(&self, call_value_offset: MemPtr, token_name_offset: MemPtr) -> i32; fn get_call_value_token_name_by_index(&self, call_value_offset: MemPtr, token_name_offset: MemPtr, index: i32) -> i32; + fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32; fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32); fn write_event_log(&self, num_topics: i32, topic_lengths_offset: MemPtr, topic_offset: MemPtr, data_offset: MemPtr, data_length: MemLength); fn get_block_timestamp(&self) -> i64; @@ -541,6 +542,11 @@ impl VMHooks for VMHooksDefault { 0 } + fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { + println!("Called: is_builtin_function_name"); + 0 + } + fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32) { println!("Called: write_log"); } From 378bf83c9511472a36a5427f67630f8f3c64ca37 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:35:47 +0000 Subject: [PATCH 07/16] install rust step in action --- .github/workflows/libvmexeccapi-build.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index 6e57182..3e99065 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -26,6 +26,11 @@ jobs: artifact_name: libvmexeccapi_arm make_target: capi-osx-arm steps: + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: stable + - name: Checkout uses: actions/checkout@v4 From 5ddd0f0ce10e7aba3572bd51ceda68695fdd66f9 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:49:52 +0000 Subject: [PATCH 08/16] IsBuiltinFunctionName vmhook --- c-api/libvmexeccapi.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index a5e6235..7c74024 100644 --- a/c-api/libvmexeccapi.h +++ b/c-api/libvmexeccapi.h @@ -91,6 +91,7 @@ typedef struct { int32_t (*get_num_esdt_transfers_func_ptr)(void *context); int32_t (*get_call_value_token_name_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset); int32_t (*get_call_value_token_name_by_index_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset, int32_t index); + int32_t (*is_builtin_function_name_func_ptr)(void *context, int32_t name_offset, int32_t name_length); void (*write_log_func_ptr)(void *context, int32_t data_pointer, int32_t data_length, int32_t topic_ptr, int32_t num_topics); void (*write_event_log_func_ptr)(void *context, int32_t num_topics, int32_t topic_lengths_offset, int32_t topic_offset, int32_t data_offset, int32_t data_length); int64_t (*get_block_timestamp_func_ptr)(void *context); @@ -121,6 +122,8 @@ typedef struct { void (*managed_sc_address_func_ptr)(void *context, int32_t destination_handle); void (*managed_owner_address_func_ptr)(void *context, int32_t destination_handle); void (*managed_caller_func_ptr)(void *context, int32_t destination_handle); + void (*managed_get_original_caller_addr_func_ptr)(void *context, int32_t destination_handle); + void (*managed_get_relayer_addr_func_ptr)(void *context, int32_t destination_handle); void (*managed_signal_error_func_ptr)(void *context, int32_t err_handle); void (*managed_write_log_func_ptr)(void *context, int32_t topics_handle, int32_t data_handle); void (*managed_get_original_tx_hash_func_ptr)(void *context, int32_t result_handle); @@ -144,6 +147,7 @@ typedef struct { int32_t (*managed_execute_on_same_context_func_ptr)(void *context, int64_t gas, int32_t address_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle, int32_t result_handle); int32_t (*managed_execute_on_dest_context_func_ptr)(void *context, int64_t gas, int32_t address_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle, int32_t result_handle); int32_t (*managed_multi_transfer_esdt_nft_execute_func_ptr)(void *context, int32_t dst_handle, int32_t token_transfers_handle, int64_t gas_limit, int32_t function_handle, int32_t arguments_handle); + int32_t (*managed_multi_transfer_esdt_nft_execute_by_user_func_ptr)(void *context, int32_t user_handle, int32_t dst_handle, int32_t token_transfers_handle, int64_t gas_limit, int32_t function_handle, int32_t arguments_handle); int32_t (*managed_transfer_value_execute_func_ptr)(void *context, int32_t dst_handle, int32_t value_handle, int64_t gas_limit, int32_t function_handle, int32_t arguments_handle); int32_t (*managed_is_esdt_frozen_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce); int32_t (*managed_is_esdt_limited_transfer_func_ptr)(void *context, int32_t token_id_handle); From f9a97ab9827eca6324c71547cfcd75819c366b45 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:51:28 +0000 Subject: [PATCH 09/16] update rust to 1.77 --- .github/workflows/libvmexeccapi-build.yml | 2 +- Docker/arm64.dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index 3e99065..d27e0e1 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -29,7 +29,7 @@ jobs: - name: Install rust uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: stable + toolchain: "1.77" - name: Checkout uses: actions/checkout@v4 diff --git a/Docker/arm64.dockerfile b/Docker/arm64.dockerfile index 316c730..0f2f776 100644 --- a/Docker/arm64.dockerfile +++ b/Docker/arm64.dockerfile @@ -1,4 +1,4 @@ -FROM arm64v8/rust:1.76.0 +FROM arm64v8/rust:1.77.0 RUN apt-get update && apt-get install -y \ wget \ From 864d7ec370037ee45edfd1a74b236b604ec0621c Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:53:24 +0000 Subject: [PATCH 10/16] update rust to 1.77 --- .github/workflows/rust-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index fa8a949..5a88d1d 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -15,7 +15,7 @@ jobs: - uses: actions-rs/toolchain@v1 with: default: true - toolchain: stable + toolchain: "1.77" - name: Run rust tests run: cargo test clippy_check: From d74a889aa0042e5a8efc8eb814760fd82e741eba Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Fri, 7 Jun 2024 10:56:07 +0000 Subject: [PATCH 11/16] update rust to 1.77 --- .github/workflows/rust-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index 5a88d1d..2210ed6 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -17,7 +17,7 @@ jobs: default: true toolchain: "1.77" - name: Run rust tests - run: cargo test + run: cargo +1.77 test clippy_check: permissions: write-all name: Clippy linter check From 816eb1fc1e3ef490500b3ad45bdda2fd1d4b0741 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Mon, 10 Jun 2024 06:55:23 +0000 Subject: [PATCH 12/16] rename to IsReservedFunctionName --- c-api/libvmexeccapi.h | 2 +- c-api/src/capi_vm_hook_pointers.rs | 2 +- c-api/src/capi_vm_hooks.rs | 4 ++-- vm-executor-wasmer/src/wasmer_imports.rs | 6 +++--- vm-executor/src/vm_hooks.rs | 6 +++--- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index 7c74024..de4f96a 100644 --- a/c-api/libvmexeccapi.h +++ b/c-api/libvmexeccapi.h @@ -91,7 +91,7 @@ typedef struct { int32_t (*get_num_esdt_transfers_func_ptr)(void *context); int32_t (*get_call_value_token_name_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset); int32_t (*get_call_value_token_name_by_index_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset, int32_t index); - int32_t (*is_builtin_function_name_func_ptr)(void *context, int32_t name_offset, int32_t name_length); + int32_t (*is_reserved_function_name_func_ptr)(void *context, int32_t name_offset, int32_t name_length); void (*write_log_func_ptr)(void *context, int32_t data_pointer, int32_t data_length, int32_t topic_ptr, int32_t num_topics); void (*write_event_log_func_ptr)(void *context, int32_t num_topics, int32_t topic_lengths_offset, int32_t topic_offset, int32_t data_offset, int32_t data_length); int64_t (*get_block_timestamp_func_ptr)(void *context); diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index 8c58388..b962c40 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -63,7 +63,7 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub get_num_esdt_transfers_func_ptr: extern "C" fn(context: *mut c_void) -> i32, pub get_call_value_token_name_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32) -> i32, pub get_call_value_token_name_by_index_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32, index: i32) -> i32, - pub is_builtin_function_name_func_ptr: extern "C" fn(context: *mut c_void, name_offset: i32, name_length: i32) -> i32, + pub is_reserved_function_name_func_ptr: extern "C" fn(context: *mut c_void, name_offset: i32, name_length: i32) -> i32, pub write_log_func_ptr: extern "C" fn(context: *mut c_void, data_pointer: i32, data_length: i32, topic_ptr: i32, num_topics: i32), pub write_event_log_func_ptr: extern "C" fn(context: *mut c_void, num_topics: i32, topic_lengths_offset: i32, topic_offset: i32, data_offset: i32, data_length: i32), pub get_block_timestamp_func_ptr: extern "C" fn(context: *mut c_void) -> i64, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index a76bc77..0a2f617 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -251,8 +251,8 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.get_call_value_token_name_by_index_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(call_value_offset), self.convert_mem_ptr(token_name_offset), index) } - fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { - (self.c_func_pointers_ptr.is_builtin_function_name_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(name_offset), self.convert_mem_length(name_length)) + fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { + (self.c_func_pointers_ptr.is_reserved_function_name_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(name_offset), self.convert_mem_length(name_length)) } fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32) { diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 69b360d..be92c90 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -276,8 +276,8 @@ fn wasmer_import_get_call_value_token_name_by_index(env: &VMHooksWrapper, call_v } #[rustfmt::skip] -fn wasmer_import_is_builtin_function_name(env: &VMHooksWrapper, name_offset: i32, name_length: i32) -> i32 { - env.vm_hooks.is_builtin_function_name(env.convert_mem_ptr(name_offset), env.convert_mem_length(name_length)) +fn wasmer_import_is_reserved_function_name(env: &VMHooksWrapper, name_offset: i32, name_length: i32) -> i32 { + env.vm_hooks.is_reserved_function_name(env.convert_mem_ptr(name_offset), env.convert_mem_length(name_length)) } #[rustfmt::skip] @@ -1376,7 +1376,7 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "getNumESDTTransfers" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_num_esdt_transfers), "getCallValueTokenName" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_call_value_token_name), "getCallValueTokenNameByIndex" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_call_value_token_name_by_index), - "isBuiltinFunctionName" => Function::new_native_with_env(store, env.clone(), wasmer_import_is_builtin_function_name), + "isReservedFunctionName" => Function::new_native_with_env(store, env.clone(), wasmer_import_is_reserved_function_name), "writeLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_write_log), "writeEventLog" => Function::new_native_with_env(store, env.clone(), wasmer_import_write_event_log), "getBlockTimestamp" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_block_timestamp), diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 6259205..5b9ac77 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -66,7 +66,7 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn get_num_esdt_transfers(&self) -> i32; fn get_call_value_token_name(&self, call_value_offset: MemPtr, token_name_offset: MemPtr) -> i32; fn get_call_value_token_name_by_index(&self, call_value_offset: MemPtr, token_name_offset: MemPtr, index: i32) -> i32; - fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32; + fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32; fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32); fn write_event_log(&self, num_topics: i32, topic_lengths_offset: MemPtr, topic_offset: MemPtr, data_offset: MemPtr, data_length: MemLength); fn get_block_timestamp(&self) -> i64; @@ -542,8 +542,8 @@ impl VMHooks for VMHooksDefault { 0 } - fn is_builtin_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { - println!("Called: is_builtin_function_name"); + fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { + println!("Called: is_reserved_function_name"); 0 } From 36cb3ffca653a6057a3d8790abd28cd5a54c984a Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Thu, 13 Jun 2024 09:57:50 +0000 Subject: [PATCH 13/16] accept managed buffer handle instead of memory range for IsReservedFunctionName --- c-api/libvmexeccapi.h | 2 +- c-api/src/capi_vm_hook_pointers.rs | 2 +- c-api/src/capi_vm_hooks.rs | 4 ++-- vm-executor-wasmer/src/wasmer_imports.rs | 4 ++-- vm-executor/src/vm_hooks.rs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index de4f96a..f4f989a 100644 --- a/c-api/libvmexeccapi.h +++ b/c-api/libvmexeccapi.h @@ -91,7 +91,7 @@ typedef struct { int32_t (*get_num_esdt_transfers_func_ptr)(void *context); int32_t (*get_call_value_token_name_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset); int32_t (*get_call_value_token_name_by_index_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset, int32_t index); - int32_t (*is_reserved_function_name_func_ptr)(void *context, int32_t name_offset, int32_t name_length); + int32_t (*is_reserved_function_name_func_ptr)(void *context, int32_t name_handle); void (*write_log_func_ptr)(void *context, int32_t data_pointer, int32_t data_length, int32_t topic_ptr, int32_t num_topics); void (*write_event_log_func_ptr)(void *context, int32_t num_topics, int32_t topic_lengths_offset, int32_t topic_offset, int32_t data_offset, int32_t data_length); int64_t (*get_block_timestamp_func_ptr)(void *context); diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index b962c40..4202ec0 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -63,7 +63,7 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub get_num_esdt_transfers_func_ptr: extern "C" fn(context: *mut c_void) -> i32, pub get_call_value_token_name_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32) -> i32, pub get_call_value_token_name_by_index_func_ptr: extern "C" fn(context: *mut c_void, call_value_offset: i32, token_name_offset: i32, index: i32) -> i32, - pub is_reserved_function_name_func_ptr: extern "C" fn(context: *mut c_void, name_offset: i32, name_length: i32) -> i32, + pub is_reserved_function_name_func_ptr: extern "C" fn(context: *mut c_void, name_handle: i32) -> i32, pub write_log_func_ptr: extern "C" fn(context: *mut c_void, data_pointer: i32, data_length: i32, topic_ptr: i32, num_topics: i32), pub write_event_log_func_ptr: extern "C" fn(context: *mut c_void, num_topics: i32, topic_lengths_offset: i32, topic_offset: i32, data_offset: i32, data_length: i32), pub get_block_timestamp_func_ptr: extern "C" fn(context: *mut c_void) -> i64, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index 0a2f617..53659c4 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -251,8 +251,8 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.get_call_value_token_name_by_index_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(call_value_offset), self.convert_mem_ptr(token_name_offset), index) } - fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { - (self.c_func_pointers_ptr.is_reserved_function_name_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(name_offset), self.convert_mem_length(name_length)) + fn is_reserved_function_name(&self, name_handle: i32) -> i32 { + (self.c_func_pointers_ptr.is_reserved_function_name_func_ptr)(self.vm_hooks_ptr, name_handle) } fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32) { diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index be92c90..484676e 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -276,8 +276,8 @@ fn wasmer_import_get_call_value_token_name_by_index(env: &VMHooksWrapper, call_v } #[rustfmt::skip] -fn wasmer_import_is_reserved_function_name(env: &VMHooksWrapper, name_offset: i32, name_length: i32) -> i32 { - env.vm_hooks.is_reserved_function_name(env.convert_mem_ptr(name_offset), env.convert_mem_length(name_length)) +fn wasmer_import_is_reserved_function_name(env: &VMHooksWrapper, name_handle: i32) -> i32 { + env.vm_hooks.is_reserved_function_name(name_handle) } #[rustfmt::skip] diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 5b9ac77..88a14eb 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -66,7 +66,7 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn get_num_esdt_transfers(&self) -> i32; fn get_call_value_token_name(&self, call_value_offset: MemPtr, token_name_offset: MemPtr) -> i32; fn get_call_value_token_name_by_index(&self, call_value_offset: MemPtr, token_name_offset: MemPtr, index: i32) -> i32; - fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32; + fn is_reserved_function_name(&self, name_handle: i32) -> i32; fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32); fn write_event_log(&self, num_topics: i32, topic_lengths_offset: MemPtr, topic_offset: MemPtr, data_offset: MemPtr, data_length: MemLength); fn get_block_timestamp(&self) -> i64; @@ -542,7 +542,7 @@ impl VMHooks for VMHooksDefault { 0 } - fn is_reserved_function_name(&self, name_offset: MemPtr, name_length: MemLength) -> i32 { + fn is_reserved_function_name(&self, name_handle: i32) -> i32 { println!("Called: is_reserved_function_name"); 0 } From 0fa7bbf42eb00e7b4bff4e694c39d93c126e1a00 Mon Sep 17 00:00:00 2001 From: Andrei Marinica Date: Mon, 17 Jun 2024 16:12:50 +0300 Subject: [PATCH 14/16] small int conversion hooks --- c-api/src/capi_vm_hook_pointers.rs | 4 ++++ c-api/src/capi_vm_hooks.rs | 16 ++++++++++++++++ vm-executor-wasmer/src/wasmer_imports.rs | 24 ++++++++++++++++++++++++ vm-executor/src/vm_hooks.rs | 22 ++++++++++++++++++++++ 4 files changed, 66 insertions(+) diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index 4202ec0..35e386e 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -206,6 +206,10 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub mbuffer_to_big_int_signed_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, big_int_handle: i32) -> i32, pub mbuffer_from_big_int_unsigned_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, big_int_handle: i32) -> i32, pub mbuffer_from_big_int_signed_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, big_int_handle: i32) -> i32, + pub mbuffer_to_small_int_unsigned_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32) -> i64, + pub mbuffer_to_small_int_signed_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32) -> i64, + pub mbuffer_from_small_int_unsigned_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, value: i64), + pub mbuffer_from_small_int_signed_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, value: i64), pub mbuffer_to_big_float_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, big_float_handle: i32) -> i32, pub mbuffer_from_big_float_func_ptr: extern "C" fn(context: *mut c_void, m_buffer_handle: i32, big_float_handle: i32) -> i32, pub mbuffer_storage_store_func_ptr: extern "C" fn(context: *mut c_void, key_handle: i32, source_handle: i32) -> i32, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index 53659c4..3da9310 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -823,6 +823,22 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.mbuffer_from_big_int_signed_func_ptr)(self.vm_hooks_ptr, m_buffer_handle, big_int_handle) } + fn mbuffer_to_small_int_unsigned(&self, m_buffer_handle: i32) -> i64 { + (self.c_func_pointers_ptr.mbuffer_to_small_int_unsigned_func_ptr)(self.vm_hooks_ptr, m_buffer_handle) + } + + fn mbuffer_to_small_int_signed(&self, m_buffer_handle: i32) -> i64 { + (self.c_func_pointers_ptr.mbuffer_to_small_int_signed_func_ptr)(self.vm_hooks_ptr, m_buffer_handle) + } + + fn mbuffer_from_small_int_unsigned(&self, m_buffer_handle: i32, value: i64) { + (self.c_func_pointers_ptr.mbuffer_from_small_int_unsigned_func_ptr)(self.vm_hooks_ptr, m_buffer_handle, value) + } + + fn mbuffer_from_small_int_signed(&self, m_buffer_handle: i32, value: i64) { + (self.c_func_pointers_ptr.mbuffer_from_small_int_signed_func_ptr)(self.vm_hooks_ptr, m_buffer_handle, value) + } + fn mbuffer_to_big_float(&self, m_buffer_handle: i32, big_float_handle: i32) -> i32 { (self.c_func_pointers_ptr.mbuffer_to_big_float_func_ptr)(self.vm_hooks_ptr, m_buffer_handle, big_float_handle) } diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 484676e..76bb81e 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -990,6 +990,26 @@ fn wasmer_import_mbuffer_from_big_int_signed(env: &VMHooksWrapper, m_buffer_hand env.vm_hooks.mbuffer_from_big_int_signed(m_buffer_handle, big_int_handle) } +#[rustfmt::skip] +fn wasmer_import_mbuffer_to_small_int_unsigned(env: &VMHooksWrapper, m_buffer_handle: i32) -> i64 { + env.vm_hooks.mbuffer_to_small_int_unsigned(m_buffer_handle) +} + +#[rustfmt::skip] +fn wasmer_import_mbuffer_to_small_int_signed(env: &VMHooksWrapper, m_buffer_handle: i32) -> i64 { + env.vm_hooks.mbuffer_to_small_int_signed(m_buffer_handle) +} + +#[rustfmt::skip] +fn wasmer_import_mbuffer_from_small_int_unsigned(env: &VMHooksWrapper, m_buffer_handle: i32, value: i64) { + env.vm_hooks.mbuffer_from_small_int_unsigned(m_buffer_handle, value) +} + +#[rustfmt::skip] +fn wasmer_import_mbuffer_from_small_int_signed(env: &VMHooksWrapper, m_buffer_handle: i32, value: i64) { + env.vm_hooks.mbuffer_from_small_int_signed(m_buffer_handle, value) +} + #[rustfmt::skip] fn wasmer_import_mbuffer_to_big_float(env: &VMHooksWrapper, m_buffer_handle: i32, big_float_handle: i32) -> i32 { env.vm_hooks.mbuffer_to_big_float(m_buffer_handle, big_float_handle) @@ -1519,6 +1539,10 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "mBufferToBigIntSigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_to_big_int_signed), "mBufferFromBigIntUnsigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_from_big_int_unsigned), "mBufferFromBigIntSigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_from_big_int_signed), + "mBufferToSmallIntUnsigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_to_small_int_unsigned), + "mBufferToSmallIntSigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_to_small_int_signed), + "mBufferFromSmallIntUnsigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_from_small_int_unsigned), + "mBufferFromSmallIntSigned" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_from_small_int_signed), "mBufferToBigFloat" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_to_big_float), "mBufferFromBigFloat" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_from_big_float), "mBufferStorageStore" => Function::new_native_with_env(store, env.clone(), wasmer_import_mbuffer_storage_store), diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 88a14eb..f12ddd6 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -209,6 +209,10 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn mbuffer_to_big_int_signed(&self, m_buffer_handle: i32, big_int_handle: i32) -> i32; fn mbuffer_from_big_int_unsigned(&self, m_buffer_handle: i32, big_int_handle: i32) -> i32; fn mbuffer_from_big_int_signed(&self, m_buffer_handle: i32, big_int_handle: i32) -> i32; + fn mbuffer_to_small_int_unsigned(&self, m_buffer_handle: i32) -> i64; + fn mbuffer_to_small_int_signed(&self, m_buffer_handle: i32) -> i64; + fn mbuffer_from_small_int_unsigned(&self, m_buffer_handle: i32, value: i64); + fn mbuffer_from_small_int_signed(&self, m_buffer_handle: i32, value: i64); fn mbuffer_to_big_float(&self, m_buffer_handle: i32, big_float_handle: i32) -> i32; fn mbuffer_from_big_float(&self, m_buffer_handle: i32, big_float_handle: i32) -> i32; fn mbuffer_storage_store(&self, key_handle: i32, source_handle: i32) -> i32; @@ -1177,6 +1181,24 @@ impl VMHooks for VMHooksDefault { 0 } + fn mbuffer_to_small_int_unsigned(&self, m_buffer_handle: i32) -> i64 { + println!("Called: mbuffer_to_small_int_unsigned"); + 0 + } + + fn mbuffer_to_small_int_signed(&self, m_buffer_handle: i32) -> i64 { + println!("Called: mbuffer_to_small_int_signed"); + 0 + } + + fn mbuffer_from_small_int_unsigned(&self, m_buffer_handle: i32, value: i64) { + println!("Called: mbuffer_from_small_int_unsigned"); + } + + fn mbuffer_from_small_int_signed(&self, m_buffer_handle: i32, value: i64) { + println!("Called: mbuffer_from_small_int_signed"); + } + fn mbuffer_to_big_float(&self, m_buffer_handle: i32, big_float_handle: i32) -> i32 { println!("Called: mbuffer_to_big_float"); 0 From 3459261051bd4cc1f7d084a503c4b601963964e2 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Mon, 17 Jun 2024 17:15:23 +0300 Subject: [PATCH 15/16] upgrade to macos 13 in build workflow --- .github/workflows/libvmexeccapi-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index d27e0e1..4f028ef 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -19,7 +19,7 @@ jobs: - os: ubuntu-20.04 artifact_name: libvmexeccapi.so make_target: capi-linux-amd64 - - os: macos-11 + - os: macos-13 artifact_name: libvmexeccapi.dylib make_target: capi-osx-amd64 - os: macos-13-xlarge From f49771b85ce53edf8b41928691a689d20a074306 Mon Sep 17 00:00:00 2001 From: Laurentiu Ciobanu Date: Thu, 27 Jun 2024 12:46:27 +0000 Subject: [PATCH 16/16] add new blockchain hooks --- c-api/libvmexeccapi.h | 4 ++++ c-api/src/capi_vm_hook_pointers.rs | 4 ++++ c-api/src/capi_vm_hooks.rs | 16 ++++++++++++++++ vm-executor-wasmer/src/wasmer_imports.rs | 24 ++++++++++++++++++++++++ vm-executor/src/vm_hooks.rs | 24 ++++++++++++++++++++++++ 5 files changed, 72 insertions(+) diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index f4f989a..f4a31f7 100644 --- a/c-api/libvmexeccapi.h +++ b/c-api/libvmexeccapi.h @@ -105,6 +105,10 @@ typedef struct { int64_t (*get_prev_block_round_func_ptr)(void *context); int64_t (*get_prev_block_epoch_func_ptr)(void *context); void (*get_prev_block_random_seed_func_ptr)(void *context, int32_t pointer); + int64_t (*get_round_time_func_ptr)(void *context); + int64_t (*epoch_start_block_time_stamp_func_ptr)(void *context); + int64_t (*epoch_start_block_nonce_func_ptr)(void *context); + int64_t (*epoch_start_block_round_func_ptr)(void *context); void (*finish_func_ptr)(void *context, int32_t pointer, int32_t length); int32_t (*execute_on_same_context_func_ptr)(void *context, int64_t gas_limit, int32_t address_offset, int32_t value_offset, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset); int32_t (*execute_on_dest_context_func_ptr)(void *context, int64_t gas_limit, int32_t address_offset, int32_t value_offset, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset); diff --git a/c-api/src/capi_vm_hook_pointers.rs b/c-api/src/capi_vm_hook_pointers.rs index 4202ec0..f89d5e0 100644 --- a/c-api/src/capi_vm_hook_pointers.rs +++ b/c-api/src/capi_vm_hook_pointers.rs @@ -77,6 +77,10 @@ pub struct vm_exec_vm_hook_c_func_pointers { pub get_prev_block_round_func_ptr: extern "C" fn(context: *mut c_void) -> i64, pub get_prev_block_epoch_func_ptr: extern "C" fn(context: *mut c_void) -> i64, pub get_prev_block_random_seed_func_ptr: extern "C" fn(context: *mut c_void, pointer: i32), + pub get_round_time_func_ptr: extern "C" fn(context: *mut c_void) -> i64, + pub epoch_start_block_time_stamp_func_ptr: extern "C" fn(context: *mut c_void) -> i64, + pub epoch_start_block_nonce_func_ptr: extern "C" fn(context: *mut c_void) -> i64, + pub epoch_start_block_round_func_ptr: extern "C" fn(context: *mut c_void) -> i64, pub finish_func_ptr: extern "C" fn(context: *mut c_void, pointer: i32, length: i32), pub execute_on_same_context_func_ptr: extern "C" fn(context: *mut c_void, gas_limit: i64, address_offset: i32, value_offset: i32, function_offset: i32, function_length: i32, num_arguments: i32, arguments_length_offset: i32, data_offset: i32) -> i32, pub execute_on_dest_context_func_ptr: extern "C" fn(context: *mut c_void, gas_limit: i64, address_offset: i32, value_offset: i32, function_offset: i32, function_length: i32, num_arguments: i32, arguments_length_offset: i32, data_offset: i32) -> i32, diff --git a/c-api/src/capi_vm_hooks.rs b/c-api/src/capi_vm_hooks.rs index 53659c4..c368987 100644 --- a/c-api/src/capi_vm_hooks.rs +++ b/c-api/src/capi_vm_hooks.rs @@ -307,6 +307,22 @@ impl multiversx_chain_vm_executor::VMHooks for CapiVMHooks { (self.c_func_pointers_ptr.get_prev_block_random_seed_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(pointer)) } + fn get_round_time(&self) -> i64 { + (self.c_func_pointers_ptr.get_round_time_func_ptr)(self.vm_hooks_ptr) + } + + fn epoch_start_block_time_stamp(&self) -> i64 { + (self.c_func_pointers_ptr.epoch_start_block_time_stamp_func_ptr)(self.vm_hooks_ptr) + } + + fn epoch_start_block_nonce(&self) -> i64 { + (self.c_func_pointers_ptr.epoch_start_block_nonce_func_ptr)(self.vm_hooks_ptr) + } + + fn epoch_start_block_round(&self) -> i64 { + (self.c_func_pointers_ptr.epoch_start_block_round_func_ptr)(self.vm_hooks_ptr) + } + fn finish(&self, pointer: MemPtr, length: MemLength) { (self.c_func_pointers_ptr.finish_func_ptr)(self.vm_hooks_ptr, self.convert_mem_ptr(pointer), self.convert_mem_length(length)) } diff --git a/vm-executor-wasmer/src/wasmer_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 484676e..0dcbdf2 100644 --- a/vm-executor-wasmer/src/wasmer_imports.rs +++ b/vm-executor-wasmer/src/wasmer_imports.rs @@ -345,6 +345,26 @@ fn wasmer_import_get_prev_block_random_seed(env: &VMHooksWrapper, pointer: i32) env.vm_hooks.get_prev_block_random_seed(env.convert_mem_ptr(pointer)) } +#[rustfmt::skip] +fn wasmer_import_get_round_time(env: &VMHooksWrapper) -> i64 { + env.vm_hooks.get_round_time() +} + +#[rustfmt::skip] +fn wasmer_import_epoch_start_block_time_stamp(env: &VMHooksWrapper) -> i64 { + env.vm_hooks.epoch_start_block_time_stamp() +} + +#[rustfmt::skip] +fn wasmer_import_epoch_start_block_nonce(env: &VMHooksWrapper) -> i64 { + env.vm_hooks.epoch_start_block_nonce() +} + +#[rustfmt::skip] +fn wasmer_import_epoch_start_block_round(env: &VMHooksWrapper) -> i64 { + env.vm_hooks.epoch_start_block_round() +} + #[rustfmt::skip] fn wasmer_import_finish(env: &VMHooksWrapper, pointer: i32, length: i32) { env.vm_hooks.finish(env.convert_mem_ptr(pointer), env.convert_mem_length(length)) @@ -1390,6 +1410,10 @@ pub fn generate_import_object(store: &Store, env: &VMHooksWrapper) -> ImportObje "getPrevBlockRound" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_prev_block_round), "getPrevBlockEpoch" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_prev_block_epoch), "getPrevBlockRandomSeed" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_prev_block_random_seed), + "getRoundTime" => Function::new_native_with_env(store, env.clone(), wasmer_import_get_round_time), + "epochStartBlockTimeStamp" => Function::new_native_with_env(store, env.clone(), wasmer_import_epoch_start_block_time_stamp), + "epochStartBlockNonce" => Function::new_native_with_env(store, env.clone(), wasmer_import_epoch_start_block_nonce), + "epochStartBlockRound" => Function::new_native_with_env(store, env.clone(), wasmer_import_epoch_start_block_round), "finish" => Function::new_native_with_env(store, env.clone(), wasmer_import_finish), "executeOnSameContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_execute_on_same_context), "executeOnDestContext" => Function::new_native_with_env(store, env.clone(), wasmer_import_execute_on_dest_context), diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 88a14eb..5757f43 100644 --- a/vm-executor/src/vm_hooks.rs +++ b/vm-executor/src/vm_hooks.rs @@ -80,6 +80,10 @@ pub trait VMHooks: core::fmt::Debug + 'static { fn get_prev_block_round(&self) -> i64; fn get_prev_block_epoch(&self) -> i64; fn get_prev_block_random_seed(&self, pointer: MemPtr); + fn get_round_time(&self) -> i64; + fn epoch_start_block_time_stamp(&self) -> i64; + fn epoch_start_block_nonce(&self) -> i64; + fn epoch_start_block_round(&self) -> i64; fn finish(&self, pointer: MemPtr, length: MemLength); fn execute_on_same_context(&self, gas_limit: i64, address_offset: MemPtr, value_offset: MemPtr, function_offset: MemPtr, function_length: MemLength, num_arguments: i32, arguments_length_offset: MemPtr, data_offset: MemPtr) -> i32; fn execute_on_dest_context(&self, gas_limit: i64, address_offset: MemPtr, value_offset: MemPtr, function_offset: MemPtr, function_length: MemLength, num_arguments: i32, arguments_length_offset: MemPtr, data_offset: MemPtr) -> i32; @@ -607,6 +611,26 @@ impl VMHooks for VMHooksDefault { println!("Called: get_prev_block_random_seed"); } + fn get_round_time(&self) -> i64 { + println!("Called: get_round_time"); + 0 + } + + fn epoch_start_block_time_stamp(&self) -> i64 { + println!("Called: epoch_start_block_time_stamp"); + 0 + } + + fn epoch_start_block_nonce(&self) -> i64 { + println!("Called: epoch_start_block_nonce"); + 0 + } + + fn epoch_start_block_round(&self) -> i64 { + println!("Called: epoch_start_block_round"); + 0 + } + fn finish(&self, pointer: MemPtr, length: MemLength) { println!("Called: finish"); }