Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsBuiltinFunctionName vmhook #39

Merged
merged 8 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/libvmexeccapi-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: "1.77"

- name: Checkout
uses: actions/checkout@v4

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Docker/arm64.dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
4 changes: 4 additions & 0 deletions c-api/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions c-api/src/capi_vm_hook_pointers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions c-api/src/capi_vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
6 changes: 6 additions & 0 deletions vm-executor-wasmer/src/wasmer_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
"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),
Expand Down
6 changes: 6 additions & 0 deletions vm-executor/src/vm_hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -541,6 +542,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");
}
Expand Down
Loading