diff --git a/.github/workflows/libvmexeccapi-build.yml b/.github/workflows/libvmexeccapi-build.yml index 6e57182..4f028ef 100644 --- a/.github/workflows/libvmexeccapi-build.yml +++ b/.github/workflows/libvmexeccapi-build.yml @@ -19,13 +19,18 @@ 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 artifact_name: libvmexeccapi_arm make_target: capi-osx-arm steps: + - name: Install rust + uses: actions-rust-lang/setup-rust-toolchain@v1 + with: + toolchain: "1.77" + - name: Checkout uses: actions/checkout@v4 diff --git a/.github/workflows/rust-ci.yml b/.github/workflows/rust-ci.yml index fa8a949..2210ed6 100644 --- a/.github/workflows/rust-ci.yml +++ b/.github/workflows/rust-ci.yml @@ -15,9 +15,9 @@ jobs: - uses: actions-rs/toolchain@v1 with: default: true - toolchain: stable + toolchain: "1.77" - name: Run rust tests - run: cargo test + run: cargo +1.77 test clippy_check: permissions: write-all name: Clippy linter check 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/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 \ diff --git a/c-api/libvmexeccapi.h b/c-api/libvmexeccapi.h index c7b77ad..1152bc3 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_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); @@ -104,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); @@ -121,6 +126,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); @@ -129,7 +136,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); @@ -144,6 +151,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); @@ -230,6 +238,10 @@ typedef struct { int32_t (*mbuffer_to_big_int_signed_func_ptr)(void *context, int32_t m_buffer_handle, int32_t big_int_handle); int32_t (*mbuffer_from_big_int_unsigned_func_ptr)(void *context, int32_t m_buffer_handle, int32_t big_int_handle); int32_t (*mbuffer_from_big_int_signed_func_ptr)(void *context, int32_t m_buffer_handle, int32_t big_int_handle); + int64_t (*mbuffer_to_small_int_unsigned_func_ptr)(void *context, int32_t m_buffer_handle); + int64_t (*mbuffer_to_small_int_signed_func_ptr)(void *context, int32_t m_buffer_handle); + void (*mbuffer_from_small_int_unsigned_func_ptr)(void *context, int32_t m_buffer_handle, int64_t value); + void (*mbuffer_from_small_int_signed_func_ptr)(void *context, int32_t m_buffer_handle, int64_t value); int32_t (*mbuffer_to_big_float_func_ptr)(void *context, int32_t m_buffer_handle, int32_t big_float_handle); int32_t (*mbuffer_from_big_float_func_ptr)(void *context, int32_t m_buffer_handle, int32_t big_float_handle); int32_t (*mbuffer_storage_store_func_ptr)(void *context, int32_t key_handle, int32_t source_handle); @@ -293,6 +305,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..2780ce7 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_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, @@ -76,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, @@ -93,6 +98,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), @@ -101,7 +108,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), @@ -116,6 +123,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, @@ -202,6 +210,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, @@ -265,6 +277,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..55db186 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_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) { (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) } @@ -303,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)) } @@ -371,6 +391,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) } @@ -403,8 +431,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) { @@ -463,6 +491,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) } @@ -807,6 +839,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) } @@ -1058,4 +1106,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/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" diff --git a/vm-executor-wasmer/Cargo.toml b/vm-executor-wasmer/Cargo.toml index b4ad51f..6b8815c 100644 --- a/vm-executor-wasmer/Cargo.toml +++ b/vm-executor-wasmer/Cargo.toml @@ -11,15 +11,15 @@ version = "0.2.0" path = "../vm-executor" [dependencies] -wasmer = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550", default-features = false, features = [ +wasmer = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df", default-features = false, features = [ "singlepass", "sys", "universal", "wat", ] } -wasmer-vm = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550" } -wasmer-types = { git = "https://github.com/multiversx/wasmer", rev = "cdd1550" } +wasmer-vm = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df" } +wasmer-types = { git = "https://github.com/multiversx/wasmer", rev = "090ad17927fd1cbecb253a7b123d21e453fa13df" } chrono = "0.4.23" log = "0.4.17" 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_imports.rs b/vm-executor-wasmer/src/wasmer_imports.rs index 63e07c9..8aee016 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_reserved_function_name(env: &VMHooksWrapper, name_handle: i32) -> i32 { + env.vm_hooks.is_reserved_function_name(name_handle) +} + #[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) @@ -340,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)) @@ -425,6 +450,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) @@ -466,8 +501,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] @@ -540,6 +575,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) @@ -970,6 +1010,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) @@ -1285,6 +1345,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" => { @@ -1341,6 +1416,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), + "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), @@ -1354,6 +1430,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), @@ -1371,6 +1451,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), @@ -1394,6 +1476,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), @@ -1480,6 +1563,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), @@ -1543,6 +1630,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-wasmer/src/wasmer_instance.rs b/vm-executor-wasmer/src/wasmer_instance.rs index 385e947..49acbbb 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", @@ -180,6 +180,7 @@ fn push_middlewares( // Create opcode_control middleware let opcode_control_middleware = Arc::new(OpcodeControl::new( + 100, // TODO: should be compilation_options.max_memory_grow_count, compilation_options.max_memory_grow, compilation_options.max_memory_grow_delta, breakpoints_middleware.clone(), diff --git a/vm-executor-wasmer/src/wasmer_opcode_control.rs b/vm-executor-wasmer/src/wasmer_opcode_control.rs index 195bca4..7c1cbe8 100644 --- a/vm-executor-wasmer/src/wasmer_opcode_control.rs +++ b/vm-executor-wasmer/src/wasmer_opcode_control.rs @@ -26,6 +26,8 @@ struct OpcodeControlGlobalIndexes { #[derive(Debug)] pub(crate) struct OpcodeControl { + total_memory_grow_count: Arc>, + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, @@ -34,11 +36,14 @@ pub(crate) struct OpcodeControl { impl OpcodeControl { pub(crate) fn new( + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, ) -> Self { Self { + total_memory_grow_count: Arc::new(Mutex::new(0)), + max_memory_grow_count, max_memory_grow, max_memory_grow_delta, breakpoints_middleware, @@ -81,6 +86,8 @@ impl ModuleMiddleware for OpcodeControl { _local_function_index: LocalFunctionIndex, ) -> Box { Box::new(FunctionOpcodeControl { + total_memory_grow_count: self.total_memory_grow_count.clone(), + max_memory_grow_count: self.max_memory_grow_count, max_memory_grow: self.max_memory_grow, max_memory_grow_delta: self.max_memory_grow_delta, breakpoints_middleware: self.breakpoints_middleware.clone(), @@ -117,6 +124,8 @@ impl MiddlewareWithProtectedGlobals for OpcodeControl { #[derive(Debug)] struct FunctionOpcodeControl { + total_memory_grow_count: Arc>, + max_memory_grow_count: usize, max_memory_grow: usize, max_memory_grow_delta: usize, breakpoints_middleware: Arc, @@ -193,6 +202,12 @@ impl FunctionMiddleware for FunctionOpcodeControl { state: &mut MiddlewareReaderState<'b>, ) -> Result<(), MiddlewareError> { if matches!(operator, Operator::MemoryGrow { .. }) { + let mut grow_count = self.total_memory_grow_count.lock().map_err(|_| MiddlewareError::new("MemoryGrowLimit", "failed to lock counter"))?; + *grow_count += 1; + if *grow_count > self.max_memory_grow_count { + return Err(MiddlewareError::new("MemoryGrowLimit", "memory.grow limit exceeded")); + } + self.inject_memory_grow_check(state); } 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 { diff --git a/vm-executor/src/vm_hooks.rs b/vm-executor/src/vm_hooks.rs index 05685fd..2703868 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_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; @@ -79,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; @@ -96,6 +101,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); @@ -104,7 +111,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); @@ -119,6 +126,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; @@ -205,6 +213,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; @@ -268,6 +280,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. @@ -535,6 +550,11 @@ impl VMHooks for VMHooksDefault { 0 } + fn is_reserved_function_name(&self, name_handle: i32) -> i32 { + println!("Called: is_reserved_function_name"); + 0 + } + fn write_log(&self, data_pointer: MemPtr, data_length: MemLength, topic_ptr: MemPtr, num_topics: i32) { println!("Called: write_log"); } @@ -595,6 +615,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"); } @@ -671,6 +711,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"); } @@ -703,7 +751,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"); } @@ -770,6 +818,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 @@ -1152,6 +1205,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 @@ -1460,4 +1531,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 + } }