Skip to content

Commit

Permalink
Merge pull request #1 from klever-io/klever-remake
Browse files Browse the repository at this point in the history
[KLC-570] multiversx -> klever
  • Loading branch information
fbsobreira authored Mar 13, 2024
2 parents 852c923 + f4c6edb commit 4794613
Show file tree
Hide file tree
Showing 32 changed files with 386 additions and 631 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/libvmexeccapi-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,42 @@ on:
push:
branches:
- master
- klever
pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build:
name: Build dynamic library for ${{ matrix.os }}
name: Build dynamic library for ${{ matrix.os }} ${{ matrix.platform }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- os: ubuntu-20.04
platform: amd64
artifact_name: libvmexeccapi.so
make_target: capi-linux-amd64
- os: macos-11
platform: amd64
artifact_name: libvmexeccapi.dylib
make_target: capi-osx-amd64
- os: macos-11
platform: arm
artifact_name: libvmexeccapi_arm.dylib
make_target: capi-osx-arm
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Add tragets
run: |
rustup target add aarch64-unknown-linux-gnu
rustup target add aarch64-apple-darwin
- name: Make
run: make ${{ matrix.make_target }}
env:
PLATFORM: ${{ matrix.platform }}
- name: Save artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/rust-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- master
- klever
pull_request:

jobs:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ Cargo.lock

# Personal scripts
my-*

.idea
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

This file contains a centralizes a trace of all published crate versions, with their changes in short.

## [multiversx-chain-vm-executor 0.1.0] - 2023-06-15
## [klever-chain-vm-executor 0.2.0] - 2023-10-12
- New VM hook: `managedGetBackTransfers`.
- Memory fix.

## [klever-chain-vm-executor 0.1.0] - 2023-06-15
This is the initial official release of the VM executor interface. The purpose is for it to be used in the new smart contract debugger architecture.

It targets VM 1.5 and integrates the Wasmer 2.2 implementation.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ members = [
"vm-executor",
"vm-executor-wasmer",
]
resolver = "2"
30 changes: 23 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
.PHONY: clean

TARGET :=
TARGET_DIR := ./target
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
ifeq ($(PLATFORM),arm)
TARGET = --target aarch64-unknown-linux-gnu
TARGET_DIR = ./target/aarch64-unknown-linux-gnu
endif
endif
ifeq ($(UNAME_S),Darwin)
ifeq ($(PLATFORM),arm)
TARGET = --target aarch64-apple-darwin --target-dir ./target
TARGET_DIR = ./target/aarch64-apple-darwin
endif
endif

capi:
cargo build -p multiversx-chain-vm-executor-c-api --release
cargo build ${TARGET} -p klever-chain-vm-executor-c-api --release

capi-linux-amd64: capi
mv target/release/libmultiversx_chain_vm_executor_c_api.so target/release/libvmexeccapi.so
mv ${TARGET_DIR}/release/libklever_chain_vm_executor_c_api.so target/release/libvmexeccapi.so
patchelf --set-soname libvmexeccapi.so target/release/libvmexeccapi.so

capi-linux-arm: capi
mv target/release/libmultiversx_chain_vm_executor_c_api.so target/release/libvmexeccapi_arm.so
mv ${TARGET_DIR}/release/libklever_chain_vm_executor_c_api.so target/release/libvmexeccapi_arm.so
patchelf --set-soname libvmexeccapi_arm.so target/release/libvmexeccapi_arm.so

capi-osx-amd64: capi
mv target/release/libmultiversx_chain_vm_executor_c_api.dylib target/release/libvmexeccapi.dylib
install_name_tool -id @executable_path/libvmexeccapi.dylib target/release/libvmexeccapi.dylib
mv ${TARGET_DIR}/release/libklever_chain_vm_executor_c_api.dylib target/release/libvmexeccapi.dylib
install_name_tool -id @rpath/libvmexeccapi.dylib target/release/libvmexeccapi.dylib

capi-osx-arm: capi
mv target/release/libmultiversx_chain_vm_executor_c_api.dylib target/release/libvmexeccapi_arm.dylib
install_name_tool -id @executable_path/libvmexeccapi_arm.dylib target/release/libvmexeccapi_arm.dylib
mv ${TARGET_DIR}/release/libklever_chain_vm_executor_c_api.dylib target/release/libvmexeccapi_arm.dylib
install_name_tool -id @rpath/libvmexeccapi_arm.dylib target/release/libvmexeccapi_arm.dylib

clean:
cargo clean
Expand Down
6 changes: 3 additions & 3 deletions c-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "multiversx-chain-vm-executor-c-api"
name = "klever-chain-vm-executor-c-api"
version = "0.0.0"
edition = "2021"
publish = false
Expand All @@ -8,8 +8,8 @@ publish = false
crate-type = ["cdylib"]

[dependencies]
multiversx-chain-vm-executor = { path = "../vm-executor" }
multiversx-chain-vm-executor-wasmer = { path = "../vm-executor-wasmer" }
klever-chain-vm-executor = { path = "../vm-executor" }
klever-chain-vm-executor-wasmer = { path = "../vm-executor-wasmer" }

lazy_static = "1.4"
libc = { version = "^0.2", default-features = false }
Expand Down
69 changes: 27 additions & 42 deletions c-api/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,29 +41,18 @@ typedef struct {
int64_t (*get_gas_left_func_ptr)(void *context);
void (*get_sc_address_func_ptr)(void *context, int32_t result_offset);
void (*get_owner_address_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_shard_of_address_func_ptr)(void *context, int32_t address_offset);
int32_t (*is_smart_contract_func_ptr)(void *context, int32_t address_offset);
void (*signal_error_func_ptr)(void *context, int32_t message_offset, int32_t message_length);
void (*get_external_balance_func_ptr)(void *context, int32_t address_offset, int32_t result_offset);
int32_t (*get_block_hash_func_ptr)(void *context, int64_t nonce, int32_t result_offset);
int32_t (*get_esdt_balance_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t result_offset);
int32_t (*get_esdt_nft_name_length_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce);
int32_t (*get_esdt_nft_attribute_length_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce);
int32_t (*get_esdt_nft_uri_length_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce);
int32_t (*get_esdt_token_data_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t value_handle, int32_t properties_offset, int32_t hash_offset, int32_t name_offset, int32_t attributes_offset, int32_t creator_offset, int32_t royalties_handle, int32_t uris_offset);
int64_t (*get_esdt_local_roles_func_ptr)(void *context, int32_t token_id_handle);
int32_t (*get_kda_balance_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t result_offset);
int32_t (*get_kda_nft_name_length_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce);
int32_t (*get_kda_nft_uri_length_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce);
int32_t (*get_kda_token_data_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t precision_handle, int32_t id_offset, int32_t name_offset, int32_t creator_offset, int32_t logo_offset, int32_t initial_supply_offset, int32_t circulating_supply_offset, int32_t max_supply_offset, int32_t minted_offset, int32_t burned_offset, int32_t royalties_offset, int32_t properties_offset, int32_t attributes_offset, int32_t roles_offset);
int32_t (*validate_token_identifier_func_ptr)(void *context, int32_t token_id_handle);
int32_t (*transfer_value_func_ptr)(void *context, int32_t dest_offset, int32_t value_offset, int32_t data_offset, int32_t length);
int32_t (*transfer_value_execute_func_ptr)(void *context, int32_t dest_offset, int32_t value_offset, int64_t gas_limit, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
int32_t (*transfer_esdt_execute_func_ptr)(void *context, int32_t dest_offset, int32_t token_id_offset, int32_t token_id_len, int32_t value_offset, int64_t gas_limit, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
int32_t (*transfer_esdt_nft_execute_func_ptr)(void *context, int32_t dest_offset, int32_t token_id_offset, int32_t token_id_len, int32_t value_offset, int64_t nonce, int64_t gas_limit, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
int32_t (*multi_transfer_esdt_nft_execute_func_ptr)(void *context, int32_t dest_offset, int32_t num_token_transfers, int32_t token_transfers_args_length_offset, int32_t token_transfer_data_offset, int64_t gas_limit, int32_t function_offset, int32_t function_length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
int32_t (*create_async_call_func_ptr)(void *context, int32_t dest_offset, int32_t value_offset, int32_t data_offset, int32_t data_length, int32_t success_offset, int32_t success_length, int32_t error_offset, int32_t error_length, int64_t gas, int64_t extra_gas_for_callback);
int32_t (*set_async_context_callback_func_ptr)(void *context, int32_t callback, int32_t callback_length, int32_t data, int32_t data_length, int64_t gas);
void (*upgrade_contract_func_ptr)(void *context, int32_t dest_offset, int64_t gas_limit, int32_t value_offset, int32_t code_offset, int32_t code_metadata_offset, int32_t length, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
void (*upgrade_from_source_contract_func_ptr)(void *context, int32_t dest_offset, int64_t gas_limit, int32_t value_offset, int32_t source_contract_address_offset, int32_t code_metadata_offset, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
void (*delete_contract_func_ptr)(void *context, int32_t dest_offset, int64_t gas_limit, int32_t num_arguments, int32_t arguments_length_offset, int32_t data_offset);
void (*async_call_func_ptr)(void *context, int32_t dest_offset, int32_t value_offset, int32_t data_offset, int32_t length);
int32_t (*get_argument_length_func_ptr)(void *context, int32_t id);
int32_t (*get_argument_func_ptr)(void *context, int32_t id, int32_t arg_offset);
int32_t (*get_function_func_ptr)(void *context, int32_t function_offset);
Expand All @@ -79,16 +68,16 @@ typedef struct {
void (*get_caller_func_ptr)(void *context, int32_t result_offset);
void (*check_no_payment_func_ptr)(void *context);
int32_t (*get_call_value_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_esdt_value_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_esdt_value_by_index_func_ptr)(void *context, int32_t result_offset, int32_t index);
int32_t (*get_esdt_token_name_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_esdt_token_name_by_index_func_ptr)(void *context, int32_t result_offset, int32_t index);
int64_t (*get_esdt_token_nonce_func_ptr)(void *context);
int64_t (*get_esdt_token_nonce_by_index_func_ptr)(void *context, int32_t index);
int64_t (*get_current_esdt_nft_nonce_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len);
int32_t (*get_esdt_token_type_func_ptr)(void *context);
int32_t (*get_esdt_token_type_by_index_func_ptr)(void *context, int32_t index);
int32_t (*get_num_esdt_transfers_func_ptr)(void *context);
int32_t (*get_kda_value_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_kda_value_by_index_func_ptr)(void *context, int32_t result_offset, int32_t index);
int32_t (*get_kda_token_name_func_ptr)(void *context, int32_t result_offset);
int32_t (*get_kda_token_name_by_index_func_ptr)(void *context, int32_t result_offset, int32_t index);
int64_t (*get_kda_token_nonce_func_ptr)(void *context);
int64_t (*get_kda_token_nonce_by_index_func_ptr)(void *context, int32_t index);
int32_t (*get_kda_token_type_func_ptr)(void *context);
int32_t (*get_kda_token_type_by_index_func_ptr)(void *context, int32_t index);
int32_t (*get_num_kda_transfers_func_ptr)(void *context);
int32_t (*get_call_value_by_token_name_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset, int32_t token_name_length);
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);
void (*write_log_func_ptr)(void *context, int32_t data_pointer, int32_t data_length, int32_t topic_ptr, int32_t num_topics);
Expand Down Expand Up @@ -128,13 +117,13 @@ typedef struct {
void (*managed_get_block_random_seed_func_ptr)(void *context, int32_t result_handle);
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_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);
int32_t (*managed_create_async_call_func_ptr)(void *context, int32_t dest_handle, int32_t value_handle, int32_t function_handle, int32_t arguments_handle, int32_t success_offset, int32_t success_length, int32_t error_offset, int32_t error_length, int64_t gas, int64_t extra_gas_for_callback, int32_t callback_closure_handle);
void (*managed_get_callback_closure_func_ptr)(void *context, int32_t callback_closure_handle);
void (*managed_get_kda_call_value_func_ptr)(void *context, int32_t kda_call_value_handle, int32_t kda_handle);
void (*managed_get_multi_kda_call_value_func_ptr)(void *context, int32_t multi_call_value_handle);
void (*managed_get_back_transfers_func_ptr)(void *context, int32_t kda_transfers_value_handle, int32_t call_value_handle);
void (*managed_get_kda_balance_func_ptr)(void *context, int32_t address_handle, int32_t token_id_handle, int64_t nonce, int32_t value_handle);
void (*managed_get_user_kda_func_ptr)(void *context, int32_t address_handle, int32_t ticker_handle, int64_t nonce, int32_t balance_handle, int32_t frozen_handle, int32_t last_claim_handle, int32_t buckets_handle, int32_t mime_handle, int32_t metadata_handle);
void (*managed_get_kda_token_data_func_ptr)(void *context, int32_t address_handle, int32_t ticker_handle, int64_t nonce, int32_t precision_handle, int32_t id_handle, int32_t name_handle, int32_t creator_handle, int32_t logo_handle, int32_t uris_handle, int32_t initial_supply_handle, int32_t circulating_supply_handle, int32_t max_supply_handle, int32_t minted_handle, int32_t burned_handle, int32_t royalties_handle, int32_t properties_handle, int32_t attributes_handle, int32_t roles_handle, int32_t issue_date_handle);
void (*managed_get_kda_roles_func_ptr)(void *context, int32_t ticker_handle, int32_t roles_handle);
void (*managed_upgrade_from_source_contract_func_ptr)(void *context, int32_t dest_handle, int64_t gas, int32_t value_handle, int32_t address_handle, int32_t code_metadata_handle, int32_t arguments_handle, int32_t result_handle);
void (*managed_upgrade_contract_func_ptr)(void *context, int32_t dest_handle, int64_t gas, int32_t value_handle, int32_t code_handle, int32_t code_metadata_handle, int32_t arguments_handle, int32_t result_handle);
void (*managed_delete_contract_func_ptr)(void *context, int32_t dest_handle, int64_t gas_limit, int32_t arguments_handle);
Expand All @@ -143,11 +132,7 @@ typedef struct {
int32_t (*managed_execute_read_only_func_ptr)(void *context, int64_t gas, int32_t address_handle, int32_t function_handle, int32_t arguments_handle, int32_t result_handle);
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_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);
int32_t (*managed_is_esdt_paused_func_ptr)(void *context, int32_t token_id_handle);
int32_t (*managed_multi_transfer_kda_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);
void (*managed_buffer_to_hex_func_ptr)(void *context, int32_t source_handle, int32_t dest_handle);
void (*managed_get_code_metadata_func_ptr)(void *context, int32_t address_handle, int32_t response_handle);
int32_t (*managed_is_builtin_function_func_ptr)(void *context, int32_t function_name_handle);
Expand Down Expand Up @@ -178,10 +163,10 @@ typedef struct {
int32_t (*big_int_storage_store_unsigned_func_ptr)(void *context, int32_t key_offset, int32_t key_length, int32_t source_handle);
int32_t (*big_int_storage_load_unsigned_func_ptr)(void *context, int32_t key_offset, int32_t key_length, int32_t destination_handle);
void (*big_int_get_call_value_func_ptr)(void *context, int32_t destination_handle);
void (*big_int_get_esdt_call_value_func_ptr)(void *context, int32_t destination);
void (*big_int_get_esdt_call_value_by_index_func_ptr)(void *context, int32_t destination_handle, int32_t index);
void (*big_int_get_kda_call_value_func_ptr)(void *context, int32_t destination);
void (*big_int_get_kda_call_value_by_index_func_ptr)(void *context, int32_t destination_handle, int32_t index);
void (*big_int_get_external_balance_func_ptr)(void *context, int32_t address_offset, int32_t result);
void (*big_int_get_esdt_external_balance_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t result_handle);
void (*big_int_get_kda_external_balance_func_ptr)(void *context, int32_t address_offset, int32_t token_id_offset, int32_t token_id_len, int64_t nonce, int32_t result_handle);
int32_t (*big_int_new_func_ptr)(void *context, int64_t small_value);
int32_t (*big_int_unsigned_byte_length_func_ptr)(void *context, int32_t reference_handle);
int32_t (*big_int_signed_byte_length_func_ptr)(void *context, int32_t reference_handle);
Expand Down Expand Up @@ -317,7 +302,7 @@ vm_exec_result_t vm_check_signatures(vm_exec_instance_t *instance_ptr);
*
* C API function, works with raw object pointers.
*/
void vm_exec_executor_destroy(vm_exec_executor_t *executor);
void vm_exec_executor_destroy(vm_exec_executor_t *executor_ptr);

/**
* Sets the data that can be hold by an instance context.
Expand Down Expand Up @@ -380,7 +365,7 @@ vm_exec_result_t vm_exec_instance_call(vm_exec_instance_t *instance_ptr, const c
*
* C API function, works with raw object pointers.
*/
void vm_exec_instance_destroy(vm_exec_instance_t *instance);
void vm_exec_instance_destroy(vm_exec_instance_t *instance_ptr);

/**
* Creates a new VM executor instance from cache.
Expand Down
2 changes: 1 addition & 1 deletion c-api/src/capi_breakpoints.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use multiversx_chain_vm_executor::Instance;
use klever_chain_vm_executor::Instance;

use crate::capi_instance::{vm_exec_instance_t, CapiInstance};
use crate::service_singleton::with_service;
Expand Down
Loading

0 comments on commit 4794613

Please sign in to comment.