diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ba1029d..41b2c90 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -41,3 +41,7 @@ jobs: - name: Check Enclave Compile run: | yarn enclave:ci + + - name: Check Mock-Enclave VM Compile + run: | + yarn mock-enclave:test diff --git a/Cargo.toml b/Cargo.toml index bd1cd4f..61686bf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ exclude = [ 'mock-enclave/src/skw-vm-host', 'mock-enclave/src/skw-vm-engine', 'mock-enclave/src/skw-vm-engine-cli', + 'mock-enclave/src/near-test-contracts', ] [profile.release] panic = 'unwind' diff --git a/mock-enclave/result.json b/mock-enclave/result.json index c0c4e66..e69de29 100644 --- a/mock-enclave/result.json +++ b/mock-enclave/result.json @@ -1,5 +0,0 @@ -{ -"outcome": "None", -"state": "{\"YgkAAABzeXN0ZW0uc2s=\":\"DAAAAHN5c3RlbV9oZWxsbw==\",\"U1RBVEU=\":\"AQAAAGI=\"}", -"error": "None" -} diff --git a/mock-enclave/scripts/test.ts b/mock-enclave/scripts/test.ts index de72a63..01c8f7d 100644 --- a/mock-enclave/scripts/test.ts +++ b/mock-enclave/scripts/test.ts @@ -12,9 +12,9 @@ function build() { const srcPath = path.join(__dirname, '../src'); // compile the runner - execute(`cd ${srcPath}/near-vm-logic && cargo test --release`); - execute(`cd ${srcPath}/near-vm-runner && cargo test --release`); - execute(`cd ${srcPath}/near-vm-errors && cargo test --release`); + execute(`cd ${srcPath}/skw-vm-host && cargo check --release && cargo test --release`); + execute(`cd ${srcPath}/skw-vm-engine && cargo check --release && cargo test --release`); + execute(`cd ${srcPath}/skw-vm-engine-cli && cargo check --release && cargo test --release`); } build(); diff --git a/mock-enclave/scripts/vm.ts b/mock-enclave/scripts/vm.ts index 0928b61..95ebff9 100644 --- a/mock-enclave/scripts/vm.ts +++ b/mock-enclave/scripts/vm.ts @@ -11,7 +11,7 @@ console.log('$ yarn vm', process.argv.slice(2).join(' ')); function compile() { // compile the runner - execute('cd src/near-vm-runner-standalone && cargo build --release') + execute('cd src/skw-vm-engine-cli && cargo build --release') } @@ -48,7 +48,7 @@ function runVM({ wasmFile = "./wasm/greeting.wasm", profiling = false }) { - const runnerPath = "./src/near-vm-runner-standalone/target/release/near-vm-runner-standalone"; + const runnerPath = "./src/skw-vm-engine-cli/target/release/skw-vm-engine-cli"; execute(`${runnerPath} --context '${injectOrigin(origin)}' --wasm-file ${wasmFile} --method-name ${methodName} --input \'${input}\' --state \'${stateInput}\' ${profiling ? "--timings" : ""} > result.json`) // parse the output diff --git a/mock-enclave/src/near-test-contracts/Cargo.lock b/mock-enclave/src/near-test-contracts/Cargo.lock new file mode 100644 index 0000000..197db42 --- /dev/null +++ b/mock-enclave/src/near-test-contracts/Cargo.lock @@ -0,0 +1,55 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "leb128" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "near-test-contracts" +version = "0.0.0" +dependencies = [ + "once_cell", + "wat", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + +[[package]] +name = "wast" +version = "39.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e9bbbd53432b267421186feee3e52436531fa69a7cfee9403f5204352df3dd05" +dependencies = [ + "leb128", + "memchr", + "unicode-width", +] + +[[package]] +name = "wat" +version = "1.0.41" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab98ed25494f97c69f28758617f27c3e92e5336040b5c3a14634f2dd3fe61830" +dependencies = [ + "wast", +] diff --git a/mock-enclave/src/near-test-contracts/build.rs b/mock-enclave/src/near-test-contracts/build.rs index 43c43bc..3de9099 100644 --- a/mock-enclave/src/near-test-contracts/build.rs +++ b/mock-enclave/src/near-test-contracts/build.rs @@ -12,17 +12,17 @@ fn main() { fn try_main() -> io::Result<()> { build_contract("./test-contract-rs", &[], "test_contract_rs")?; - build_contract( - "./test-contract-rs", - &["--features", "nightly_protocol_features"], - "nightly_test_contract_rs", - )?; - build_contract("./contract-for-fuzzing-rs", &[], "contract_for_fuzzing_rs")?; - build_contract( - "./test-contract-rs", - &["--features", "base_protocol"], - "test_contract_rs_base_protocol", - )?; + // build_contract( + // "./test-contract-rs", + // &["--features", "nightly_protocol_features"], + // "nightly_test_contract_rs", + // )?; + // build_contract("./contract-for-fuzzing-rs", &[], "contract_for_fuzzing_rs")?; + // build_contract( + // "./test-contract-rs", + // &["--features", "base_protocol"], + // "test_contract_rs_base_protocol", + // )?; Ok(()) } diff --git a/mock-enclave/src/near-test-contracts/src/lib.rs b/mock-enclave/src/near-test-contracts/src/lib.rs index 0fd0804..7a937b9 100644 --- a/mock-enclave/src/near-test-contracts/src/lib.rs +++ b/mock-enclave/src/near-test-contracts/src/lib.rs @@ -21,25 +21,25 @@ pub fn rs_contract() -> &'static [u8] { CONTRACT.get_or_init(|| read_contract("test_contract_rs.wasm")).as_slice() } -pub fn rs_contract_base_protocol() -> &'static [u8] { - static CONTRACT: OnceCell> = OnceCell::new(); - CONTRACT.get_or_init(|| read_contract("test_contract_rs_base_protocol.wasm")).as_slice() -} +// pub fn rs_contract_base_protocol() -> &'static [u8] { +// static CONTRACT: OnceCell> = OnceCell::new(); +// CONTRACT.get_or_init(|| read_contract("test_contract_rs_base_protocol.wasm")).as_slice() +// } -pub fn nightly_rs_contract() -> &'static [u8] { - static CONTRACT: OnceCell> = OnceCell::new(); - CONTRACT.get_or_init(|| read_contract("nightly_test_contract_rs.wasm")).as_slice() -} +// pub fn nightly_rs_contract() -> &'static [u8] { +// static CONTRACT: OnceCell> = OnceCell::new(); +// CONTRACT.get_or_init(|| read_contract("nightly_test_contract_rs.wasm")).as_slice() +// } pub fn ts_contract() -> &'static [u8] { static CONTRACT: OnceCell> = OnceCell::new(); CONTRACT.get_or_init(|| read_contract("test_contract_ts.wasm")).as_slice() } -pub fn fuzzing_contract() -> &'static [u8] { - static CONTRACT: OnceCell> = OnceCell::new(); - CONTRACT.get_or_init(|| read_contract("contract_for_fuzzing_rs.wasm")).as_slice() -} +// pub fn fuzzing_contract() -> &'static [u8] { +// static CONTRACT: OnceCell> = OnceCell::new(); +// CONTRACT.get_or_init(|| read_contract("contract_for_fuzzing_rs.wasm")).as_slice() +// } /// Read given wasm file or panic if unable to. fn read_contract(file_name: &str) -> Vec { @@ -54,11 +54,11 @@ fn read_contract(file_name: &str) -> Vec { #[test] fn smoke_test() { assert!(!rs_contract().is_empty()); - assert!(!nightly_rs_contract().is_empty()); + // assert!(!nightly_rs_contract().is_empty()); assert!(!ts_contract().is_empty()); assert!(!trivial_contract().is_empty()); - assert!(!fuzzing_contract().is_empty()); - assert!(!rs_contract_base_protocol().is_empty()); + // assert!(!fuzzing_contract().is_empty()); + // assert!(!rs_contract_base_protocol().is_empty()); } pub fn many_functions_contract(function_count: u32) -> Vec { diff --git a/mock-enclave/src/near-test-contracts/test-contract-rs/Cargo.toml b/mock-enclave/src/near-test-contracts/test-contract-rs/Cargo.toml index e2ceac0..755f491 100644 --- a/mock-enclave/src/near-test-contracts/test-contract-rs/Cargo.toml +++ b/mock-enclave/src/near-test-contracts/test-contract-rs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "test-contract-rs" version = "0.1.0" -authors = ["Near Inc "] +authors = ["SkyeKiwi ", "Near Inc "] publish = false # Please update rust-toolchain.toml as well when changing version here: rust-version = "1.56.0" @@ -30,6 +30,3 @@ incremental = false members = [] [features] -nightly_protocol_features = ["protocol_feature_alt_bn128"] -protocol_feature_alt_bn128 = [] -base_protocol = [] diff --git a/mock-enclave/src/near-test-contracts/test-contract-rs/src/lib.rs b/mock-enclave/src/near-test-contracts/test-contract-rs/src/lib.rs index 8647e19..c8eb16e 100644 --- a/mock-enclave/src/near-test-contracts/test-contract-rs/src/lib.rs +++ b/mock-enclave/src/near-test-contracts/test-contract-rs/src/lib.rs @@ -19,7 +19,7 @@ extern "C" { fn predecessor_account_id(register_id: u64); fn input(register_id: u64); // TODO #1903 fn block_height() -> u64; - fn block_index() -> u64; + fn block_number() -> u64; fn block_timestamp() -> u64; fn epoch_height() -> u64; fn storage_usage() -> u64; @@ -86,34 +86,6 @@ extern "C" { gas: u64, ); fn promise_batch_action_transfer(promise_index: u64, amount_ptr: u64); - fn promise_batch_action_stake( - promise_index: u64, - amount_ptr: u64, - public_key_len: u64, - public_key_ptr: u64, - ); - fn promise_batch_action_add_key_with_full_access( - promise_index: u64, - public_key_len: u64, - public_key_ptr: u64, - nonce: u64, - ); - fn promise_batch_action_add_key_with_function_call( - promise_index: u64, - public_key_len: u64, - public_key_ptr: u64, - nonce: u64, - allowance_ptr: u64, - receiver_id_len: u64, - receiver_id_ptr: u64, - method_names_len: u64, - method_names_ptr: u64, - ); - fn promise_batch_action_delete_key( - promise_index: u64, - public_key_len: u64, - public_key_ptr: u64, - ); fn promise_batch_action_delete_account( promise_index: u64, beneficiary_id_len: u64, @@ -138,28 +110,10 @@ extern "C" { fn storage_read(key_len: u64, key_ptr: u64, register_id: u64) -> u64; fn storage_remove(key_len: u64, key_ptr: u64, register_id: u64) -> u64; fn storage_has_key(key_len: u64, key_ptr: u64) -> u64; - fn storage_iter_prefix(prefix_len: u64, prefix_ptr: u64) -> u64; - fn storage_iter_range(start_len: u64, start_ptr: u64, end_len: u64, end_ptr: u64) -> u64; - fn storage_iter_next(iterator_id: u64, key_register_id: u64, value_register_id: u64) -> u64; - // ################# - // # Validator API # - // ################# - fn validator_stake(account_id_len: u64, account_id_ptr: u64, stake_ptr: u64); - fn validator_total_stake(stake_ptr: u64); // ################### // # Math Extensions # // ################### - #[cfg(not(feature = "base_protocol"))] fn ripemd160(value_len: u64, value_ptr: u64, register_id: u64); - // ################# - // # alt_bn128 API # - // ################# - #[cfg(feature = "protocol_feature_alt_bn128")] - fn alt_bn128_g1_multiexp(value_len: u64, value_ptr: u64, register_id: u64); - #[cfg(feature = "protocol_feature_alt_bn128")] - fn alt_bn128_g1_sum(value_len: u64, value_ptr: u64, register_id: u64); - #[cfg(feature = "protocol_feature_alt_bn128")] - fn alt_bn128_pairing_check(value_len: u64, value_ptr: u64) -> u64; } macro_rules! ext_test { @@ -197,7 +151,7 @@ macro_rules! ext_test_u128 { } ext_test_u64!(ext_storage_usage, storage_usage); -ext_test_u64!(ext_block_index, block_index); +ext_test_u64!(ext_block_number, block_number); ext_test_u64!(ext_block_timestamp, block_timestamp); ext_test_u64!(ext_prepaid_gas, prepaid_gas); @@ -210,8 +164,6 @@ ext_test!(ext_account_id, current_account_id); ext_test_u128!(ext_account_balance, account_balance); ext_test_u128!(ext_attached_deposit, attached_deposit); -ext_test_u128!(ext_validator_total_stake, validator_total_stake); - #[no_mangle] pub unsafe fn ext_sha256() { input(0); @@ -239,45 +191,6 @@ pub unsafe fn ext_used_gas() { value_return(result.len() as u64, result.as_ptr() as *const u64 as u64); } -#[cfg(feature = "protocol_feature_alt_bn128")] -#[no_mangle] -pub unsafe fn ext_alt_bn128_g1_multiexp() { - input(0); - alt_bn128_g1_multiexp(u64::MAX, 0, 1); - value_return(u64::MAX, 1); -} - -#[cfg(feature = "protocol_feature_alt_bn128")] -#[no_mangle] -pub unsafe fn ext_alt_bn128_g1_sum() { - input(0); - alt_bn128_g1_sum(u64::MAX, 0, 1); - value_return(u64::MAX, 1); -} - -#[cfg(feature = "protocol_feature_alt_bn128")] -#[no_mangle] -pub unsafe fn ext_alt_bn128_pairing_check() { - input(0); - let res = alt_bn128_pairing_check(u64::MAX, 0); - let byte = [res as u8; 1]; - value_return(1, byte.as_ptr() as _); -} - -#[no_mangle] -pub unsafe fn ext_validator_stake() { - input(0); - let account_id = vec![0; register_len(0) as usize]; - read_register(0, account_id.as_ptr() as *const u64 as u64); - let result = [0u8; size_of::()]; - validator_stake( - account_id.len() as u64, - account_id.as_ptr() as *const u64 as u64, - result.as_ptr() as *const u64 as u64, - ); - value_return(result.len() as u64, result.as_ptr() as *const u64 as u64); -} - #[no_mangle] pub unsafe fn write_key_value() { input(0); @@ -300,10 +213,10 @@ pub unsafe fn write_key_value() { } #[no_mangle] -pub unsafe fn write_block_height() { - let block_height = block_index(); +pub unsafe fn write_block_number() { + let block_number = block_number(); let mut key = [0u8; size_of::()]; - key.copy_from_slice(&block_height.to_le_bytes()); + key.copy_from_slice(&block_number.to_le_bytes()); let value = b"hello"; storage_write(key.len() as _, key.as_ptr() as _, value.len() as _, value.as_ptr() as _, 0); } @@ -721,56 +634,6 @@ fn call_promise() { &amount as *const u128 as *const u64 as u64, ); promise_index - } else if let Some(action) = arg.get("action_stake") { - let promise_index = action["promise_index"].as_i64().unwrap() as u64; - let amount = action["amount"].as_str().unwrap().parse::().unwrap(); - let public_key = from_base64(action["public_key"].as_str().unwrap()); - promise_batch_action_stake( - promise_index, - &amount as *const u128 as *const u64 as u64, - public_key.len() as u64, - public_key.as_ptr() as u64, - ); - promise_index - } else if let Some(action) = arg.get("action_add_key_with_full_access") { - let promise_index = action["promise_index"].as_i64().unwrap() as u64; - let public_key = from_base64(action["public_key"].as_str().unwrap()); - let nonce = action["nonce"].as_i64().unwrap() as u64; - promise_batch_action_add_key_with_full_access( - promise_index, - public_key.len() as u64, - public_key.as_ptr() as u64, - nonce, - ); - promise_index - } else if let Some(action) = arg.get("action_add_key_with_function_call") { - let promise_index = action["promise_index"].as_i64().unwrap() as u64; - let public_key = from_base64(action["public_key"].as_str().unwrap()); - let nonce = action["nonce"].as_i64().unwrap() as u64; - let allowance = action["allowance"].as_str().unwrap().parse::().unwrap(); - let receiver_id = action["receiver_id"].as_str().unwrap().as_bytes(); - let method_names = action["method_names"].as_str().unwrap().as_bytes(); - promise_batch_action_add_key_with_function_call( - promise_index, - public_key.len() as u64, - public_key.as_ptr() as u64, - nonce, - &allowance as *const u128 as *const u64 as u64, - receiver_id.len() as u64, - receiver_id.as_ptr() as u64, - method_names.len() as u64, - method_names.as_ptr() as u64, - ); - promise_index - } else if let Some(action) = arg.get("action_delete_key") { - let promise_index = action["promise_index"].as_i64().unwrap() as u64; - let public_key = from_base64(action["public_key"].as_str().unwrap()); - promise_batch_action_delete_key( - promise_index, - public_key.len() as u64, - public_key.as_ptr() as u64, - ); - promise_index } else if let Some(action) = arg.get("action_delete_account") { let promise_index = action["promise_index"].as_i64().unwrap() as u64; let beneficiary_id = action["beneficiary_id"].as_str().unwrap().as_bytes(); @@ -793,8 +656,6 @@ fn call_promise() { } } } - -#[cfg(not(feature = "base_protocol"))] #[no_mangle] fn do_ripemd() { let data = b"tesdsst"; diff --git a/mock-enclave/src/skw-vm-engine-cli/Cargo.lock b/mock-enclave/src/skw-vm-engine-cli/Cargo.lock index 45aa419..db82d95 100644 --- a/mock-enclave/src/skw-vm-engine-cli/Cargo.lock +++ b/mock-enclave/src/skw-vm-engine-cli/Cargo.lock @@ -46,26 +46,6 @@ version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" -[[package]] -name = "async-mutex" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-trait" -version = "0.1.52" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "061a7acccaa286c011ddc30970520b98fa40e00c9d644633fb26b5fc63a265e3" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "atty" version = "0.2.14" @@ -83,12 +63,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" - [[package]] name = "base64" version = "0.13.0" @@ -203,12 +177,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytesize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" - [[package]] name = "c2-chacha" version = "0.3.3" @@ -219,39 +187,6 @@ dependencies = [ "ppv-lite86", ] -[[package]] -name = "cached" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e2afe73808fbaac302e39c9754bfc3c4b4d0f99c9c240b9f4e4efc841ad1b74" -dependencies = [ - "async-mutex", - "async-trait", - "cached_proc_macro", - "cached_proc_macro_types", - "futures", - "hashbrown 0.9.1", - "once_cell", -] - -[[package]] -name = "cached_proc_macro" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4230b8d9f5db741004bfaef172c5b2dbf0eb94f105204cc6147a220080daaa85" -dependencies = [ - "cached_proc_macro_types", - "darling", - "quote", - "syn", -] - -[[package]] -name = "cached_proc_macro_types" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" - [[package]] name = "cc" version = "1.0.72" @@ -279,8 +214,6 @@ dependencies = [ "libc", "num-integer", "num-traits", - "serde", - "time", "winapi", ] @@ -369,41 +302,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "darling" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b" -dependencies = [ - "darling_core", - "quote", - "syn", -] - [[package]] name = "derive_more" version = "0.99.17" @@ -432,12 +330,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "easy-ext" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53aff6fdc1b181225acdcb5b14c47106726fd8e486707315b1b138baed68ee31" - [[package]] name = "ed25519" version = "1.3.0" @@ -461,12 +353,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - [[package]] name = "fixed-hash" version = "0.7.0" @@ -479,107 +365,12 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "funty" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" -[[package]] -name = "futures" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28560757fe2bb34e79f907794bb6b22ae8b0e5c669b638a1132f2592b19035b4" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba3dda0b6588335f360afc675d0564c17a77a2bda81ca178a4b6081bd86c7f0b" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0c8ff0461b82559810cdccfde3215c3f373807f5e5232b71479bff7bb2583d7" - -[[package]] -name = "futures-executor" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d6d2ff5bb10fb95c85b8ce46538a2e5f5e7fdc755623a7d4529ab8a4ed9d2a" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f9d34af5a1aac6fb380f735fe510746c38067c5bf16c7fd250280503c971b2" - -[[package]] -name = "futures-macro" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dbd947adfffb0efc70599b3ddcf7b5597bb5fa9e245eb99f62b3a5f7bb8bd3c" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3055baccb68d74ff6480350f8d6eb8fcfa3aa11bdc1a1ae3afdd0514617d508" - -[[package]] -name = "futures-task" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ee7c6485c30167ce4dfb83ac568a849fe53274c831081476ee13e0dce1aad72" - -[[package]] -name = "futures-util" -version = "0.3.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b5cf40b47a271f77a8b1bec03ca09044d99d2372c0de244e66430761127164" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "generic-array" version = "0.14.5" @@ -654,12 +445,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "impl-codec" version = "0.5.1" @@ -759,29 +544,11 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memoffset" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" -dependencies = [ - "autocfg", -] - [[package]] name = "memory_units" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" - -[[package]] -name = "near-account-id" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "borsh", - "serde", -] +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "near-account-id" @@ -792,32 +559,6 @@ dependencies = [ "serde", ] -[[package]] -name = "near-crypto" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "arrayref", - "blake2", - "borsh", - "bs58", - "c2-chacha", - "curve25519-dalek", - "derive_more", - "ed25519-dalek", - "libc", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "once_cell", - "parity-secp256k1", - "primitive-types", - "rand 0.7.3", - "rand_core 0.5.1", - "serde", - "serde_json", - "subtle", - "thiserror", -] - [[package]] name = "near-crypto" version = "0.0.0" @@ -832,7 +573,7 @@ dependencies = [ "derive_more", "ed25519-dalek", "libc", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore)", + "near-account-id", "once_cell", "parity-secp256k1", "primitive-types", @@ -844,93 +585,14 @@ dependencies = [ "thiserror", ] -[[package]] -name = "near-primitives" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "borsh", - "byteorder", - "bytesize", - "chrono", - "derive_more", - "easy-ext", - "hex", - "near-crypto 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "near-primitives-core", - "near-rpc-error-macro", - "near-vm-errors", - "num-rational 0.3.2", - "primitive-types", - "rand 0.7.3", - "reed-solomon-erasure", - "serde", - "serde_json", - "sha2", - "smart-default", -] - -[[package]] -name = "near-primitives-core" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "base64 0.11.0", - "borsh", - "bs58", - "derive_more", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "num-rational 0.3.2", - "serde", - "serde_json", - "sha2", -] - -[[package]] -name = "near-rpc-error-core" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "syn", -] - -[[package]] -name = "near-rpc-error-macro" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "near-rpc-error-core", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn", -] - [[package]] name = "near-test-contracts" version = "0.0.0" -source = "git+https://github.com/near/nearcore#14f249db13765108a01cf5ba5f5d0ba26378aaa7" dependencies = [ "once_cell", "wat", ] -[[package]] -name = "near-vm-errors" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "borsh", - "hex", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "near-rpc-error-macro", - "serde", -] - [[package]] name = "num-bigint" version = "0.3.3" @@ -973,7 +635,6 @@ dependencies = [ "num-bigint 0.3.3", "num-integer", "num-traits", - "serde", ] [[package]] @@ -997,16 +658,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "19e64526ebdee182341572e50e9ad03965aa510cd94427a4549448f285e957a1" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" version = "1.9.0" @@ -1063,12 +714,6 @@ dependencies = [ "rand 0.7.3", ] -[[package]] -name = "parity-wasm" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" - [[package]] name = "parity-wasm" version = "0.42.2" @@ -1081,12 +726,6 @@ version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" -[[package]] -name = "pin-utils" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" - [[package]] name = "ppv-lite86" version = "0.2.16" @@ -1158,13 +797,13 @@ dependencies = [ [[package]] name = "pwasm-utils" -version = "0.12.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" +checksum = "880b3384fb00b8f6ecccd5d358b93bd2201900ae3daad213791d1864f6441f5c" dependencies = [ "byteorder", "log", - "parity-wasm 0.41.0", + "parity-wasm", ] [[package]] @@ -1253,15 +892,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "reed-solomon-erasure" -version = "4.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d" -dependencies = [ - "smallvec", -] - [[package]] name = "regex" version = "1.5.4" @@ -1350,7 +980,6 @@ version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "indexmap", "itoa", "ryu", "serde", @@ -1400,18 +1029,13 @@ checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" name = "skw-vm-engine" version = "0.0.0" dependencies = [ - "borsh", - "cached", "lazy_static", "lru", - "memoffset", - "near-primitives", - "parity-wasm 0.41.0", + "parity-wasm", "pwasm-utils", "serde", "skw-vm-host", "skw-vm-primitives", - "threadpool", "tracing", "wasmi", "wasmparser", @@ -1421,7 +1045,7 @@ dependencies = [ name = "skw-vm-engine-cli" version = "0.0.0" dependencies = [ - "base64 0.13.0", + "base64", "clap", "clap_derive", "hex", @@ -1440,17 +1064,16 @@ dependencies = [ name = "skw-vm-host" version = "0.0.0" dependencies = [ - "base64 0.13.0", - "borsh", + "base64", "bs58", "byteorder", - "near-crypto 0.0.0 (git+https://github.com/near/nearcore)", - "parity-secp256k1", + "near-crypto", "ripemd160", "serde", "sha2", "sha3", "skw-vm-primitives", + "wasmi", ] [[package]] @@ -1463,12 +1086,6 @@ dependencies = [ "wasmi", ] -[[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - [[package]] name = "smallvec" version = "1.8.0" @@ -1476,15 +1093,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2dd574626839106c320a323308629dcb1acfc96e32a8cba364ddc61ac23ee83" [[package]] -name = "smart-default" -version = "0.6.0" +name = "spin" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" [[package]] name = "static_assertions" @@ -1586,25 +1198,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "toml" version = "0.5.8" @@ -1761,26 +1354,46 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasmi" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03919fcab96ed058e0c411c47b370883d6393c40307f3140876f68a9256cadb1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", + "wasmi_v1", +] + +[[package]] +name = "wasmi-validation" +version = "0.4.1" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", +] + +[[package]] +name = "wasmi_core" +version = "0.1.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ "downcast-rs", "libm", "memory_units", "num-rational 0.4.0", "num-traits", - "parity-wasm 0.42.2", - "wasmi-validation", + "parity-wasm", ] [[package]] -name = "wasmi-validation" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +name = "wasmi_v1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ - "parity-wasm 0.42.2", + "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", ] [[package]] diff --git a/mock-enclave/src/skw-vm-engine-cli/Cargo.toml b/mock-enclave/src/skw-vm-engine-cli/Cargo.toml index 6ce6918..078c3fb 100644 --- a/mock-enclave/src/skw-vm-engine-cli/Cargo.toml +++ b/mock-enclave/src/skw-vm-engine-cli/Cargo.toml @@ -27,7 +27,7 @@ skw-vm-primitives = { path = "../skw-vm-primitives" } [dev-dependencies] hex = "0.4" -near-test-contracts = { git = "https://github.com/near/nearcore" } +near-test-contracts = { path = "../near-test-contracts" } [features] default = [] diff --git a/mock-enclave/src/skw-vm-engine-cli/src/main.rs b/mock-enclave/src/skw-vm-engine-cli/src/main.rs index e5fe98d..ff36ea1 100644 --- a/mock-enclave/src/skw-vm-engine-cli/src/main.rs +++ b/mock-enclave/src/skw-vm-engine-cli/src/main.rs @@ -1,11 +1,9 @@ -#![doc = include_str!("../README.md")] - mod script; use crate::script::Script; use clap::Clap; use skw_vm_host::VMOutcome; -use skw_vm_host::{mocks::mock_external::Receipt, ProtocolVersion}; +use skw_vm_host::{mocks::mock_external::Receipt}; use serde::{ de::{MapAccess, Visitor}, ser::SerializeMap, diff --git a/mock-enclave/src/skw-vm-engine/Cargo.lock b/mock-enclave/src/skw-vm-engine/Cargo.lock index 52dd68e..3c7f85d 100644 --- a/mock-enclave/src/skw-vm-engine/Cargo.lock +++ b/mock-enclave/src/skw-vm-engine/Cargo.lock @@ -14,17 +14,11 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.4", "once_cell", "version_check", ] -[[package]] -name = "anyhow" -version = "1.0.49" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a03e93e97a28fbc9f42fbc5ba0886a3c67eb637b476dbee711f80a6ffe8223d" - [[package]] name = "arrayref" version = "0.3.6" @@ -49,38 +43,12 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" -[[package]] -name = "async-mutex" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479db852db25d9dbf6204e6cb6253698f175c15726470f78af0d918e99d6156e" -dependencies = [ - "event-listener", -] - -[[package]] -name = "async-trait" -version = "0.1.51" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44318e776df68115a881de9a8fd1b9e53368d7a4a5ce4cc48517da3393233a5e" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "autocfg" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" -[[package]] -name = "base64" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7" - [[package]] name = "base64" version = "0.13.0" @@ -189,12 +157,6 @@ version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" -[[package]] -name = "bytesize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70" - [[package]] name = "c2-chacha" version = "0.3.3" @@ -205,39 +167,6 @@ dependencies = [ "ppv-lite86", ] -[[package]] -name = "cached" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e2afe73808fbaac302e39c9754bfc3c4b4d0f99c9c240b9f4e4efc841ad1b74" -dependencies = [ - "async-mutex", - "async-trait", - "cached_proc_macro", - "cached_proc_macro_types", - "futures", - "hashbrown 0.9.1", - "once_cell", -] - -[[package]] -name = "cached_proc_macro" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4230b8d9f5db741004bfaef172c5b2dbf0eb94f105204cc6147a220080daaa85" -dependencies = [ - "cached_proc_macro_types", - "darling", - "quote", - "syn", -] - -[[package]] -name = "cached_proc_macro_types" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" - [[package]] name = "cc" version = "1.0.72" @@ -256,20 +185,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" -dependencies = [ - "libc", - "num-integer", - "num-traits", - "serde", - "time", - "winapi", -] - [[package]] name = "cipher" version = "0.2.5" @@ -323,46 +238,11 @@ dependencies = [ "zeroize", ] -[[package]] -name = "darling" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" -dependencies = [ - "darling_core", - "darling_macro", -] - -[[package]] -name = "darling_core" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" -dependencies = [ - "fnv", - "ident_case", - "proc-macro2", - "quote", - "strsim", - "syn", -] - -[[package]] -name = "darling_macro" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" -dependencies = [ - "darling_core", - "quote", - "syn", -] - [[package]] name = "derive_more" -version = "0.99.16" +version = "0.99.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40eebddd2156ce1bb37b20bbe5151340a31828b1f2d22ba4141f3531710e38df" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", "proc-macro2", @@ -386,12 +266,6 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" -[[package]] -name = "easy-ext" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53aff6fdc1b181225acdcb5b14c47106726fd8e486707315b1b138baed68ee31" - [[package]] name = "ed25519" version = "1.3.0" @@ -415,12 +289,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "event-listener" -version = "2.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" - [[package]] name = "fixed-hash" version = "0.7.0" @@ -433,112 +301,17 @@ dependencies = [ "static_assertions", ] -[[package]] -name = "fnv" -version = "1.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" - [[package]] name = "funty" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" -[[package]] -name = "futures" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd0210d8c325c245ff06fd95a3b13689a1a276ac8cfa8e8720cb840bfb84b9e" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-channel" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27" -dependencies = [ - "futures-core", - "futures-sink", -] - -[[package]] -name = "futures-core" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445" - -[[package]] -name = "futures-executor" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b808bf53348a36cab739d7e04755909b9fcaaa69b7d7e588b37b6ec62704c97" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11" - -[[package]] -name = "futures-macro" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a89f17b21645bc4ed773c69af9c9a0effd4a3f1a3876eadd453469f8854e7fdd" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "futures-sink" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af" - -[[package]] -name = "futures-task" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12" - -[[package]] -name = "futures-util" -version = "0.3.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e" -dependencies = [ - "futures-channel", - "futures-core", - "futures-io", - "futures-macro", - "futures-sink", - "futures-task", - "memchr", - "pin-project-lite", - "pin-utils", - "slab", -] - [[package]] name = "generic-array" -version = "0.14.4" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501466ecc8a30d1d3b7fc9229b122b2ce8ed6e9d9223f1138d4babb253e51817" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" dependencies = [ "typenum", "version_check", @@ -557,9 +330,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +checksum = "418d37c8b1d42553c93648be529cb70f920d3baf8ef469b74b9638df426e0b4c" dependencies = [ "cfg-if 1.0.0", "libc", @@ -584,27 +357,12 @@ dependencies = [ "ahash 0.7.6", ] -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -[[package]] -name = "ident_case" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" - [[package]] name = "impl-codec" version = "0.5.1" @@ -625,21 +383,11 @@ dependencies = [ "syn", ] -[[package]] -name = "indexmap" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" -dependencies = [ - "autocfg", - "hashbrown 0.11.2", -] - [[package]] name = "itoa" -version = "0.4.8" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" [[package]] name = "keccak" @@ -661,9 +409,9 @@ checksum = "884e2677b40cc8c339eaefcb701c32ef1fd2493d71118dc0ca4b6a736c93bd67" [[package]] name = "libc" -version = "0.2.108" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "libm" @@ -695,69 +443,25 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memoffset" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" -dependencies = [ - "autocfg", -] - [[package]] name = "memory_units" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "near-account-id" version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" +source = "git+https://github.com/near/nearcore#14f249db13765108a01cf5ba5f5d0ba26378aaa7" dependencies = [ "borsh", "serde", ] -[[package]] -name = "near-account-id" -version = "0.0.0" -source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" -dependencies = [ - "borsh", - "serde", -] - -[[package]] -name = "near-crypto" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "arrayref", - "blake2", - "borsh", - "bs58", - "c2-chacha", - "curve25519-dalek", - "derive_more", - "ed25519-dalek", - "libc", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "once_cell", - "parity-secp256k1", - "primitive-types", - "rand 0.7.3", - "rand_core 0.5.1", - "serde", - "serde_json", - "subtle", - "thiserror", -] - [[package]] name = "near-crypto" version = "0.0.0" -source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" +source = "git+https://github.com/near/nearcore#14f249db13765108a01cf5ba5f5d0ba26378aaa7" dependencies = [ "arrayref", "blake2", @@ -768,7 +472,7 @@ dependencies = [ "derive_more", "ed25519-dalek", "libc", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore)", + "near-account-id", "once_cell", "parity-secp256k1", "primitive-types", @@ -780,72 +484,6 @@ dependencies = [ "thiserror", ] -[[package]] -name = "near-primitives" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "borsh", - "byteorder", - "bytesize", - "chrono", - "derive_more", - "easy-ext", - "hex", - "near-crypto 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "near-primitives-core", - "near-rpc-error-macro", - "near-vm-errors", - "num-rational 0.3.2", - "primitive-types", - "rand 0.7.3", - "reed-solomon-erasure", - "serde", - "serde_json", - "sha2", - "smart-default", -] - -[[package]] -name = "near-primitives-core" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "base64 0.11.0", - "borsh", - "bs58", - "derive_more", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "num-rational 0.3.2", - "serde", - "serde_json", - "sha2", -] - -[[package]] -name = "near-rpc-error-core" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "proc-macro2", - "quote", - "serde", - "syn", -] - -[[package]] -name = "near-rpc-error-macro" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "near-rpc-error-core", - "proc-macro2", - "quote", - "serde", - "serde_json", - "syn", -] - [[package]] name = "near-test-contracts" version = "0.0.0" @@ -854,29 +492,6 @@ dependencies = [ "wat", ] -[[package]] -name = "near-vm-errors" -version = "0.0.0" -source = "git+https://github.com/near/nearcore?tag=crates-0.11.0#8d04fa95d4cb8191e636bd24517ea7744b78ec5f" -dependencies = [ - "borsh", - "hex", - "near-account-id 0.0.0 (git+https://github.com/near/nearcore?tag=crates-0.11.0)", - "near-rpc-error-macro", - "serde", -] - -[[package]] -name = "num-bigint" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - [[package]] name = "num-bigint" version = "0.4.3" @@ -905,10 +520,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ "autocfg", - "num-bigint 0.3.3", "num-integer", "num-traits", - "serde", ] [[package]] @@ -918,7 +531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" dependencies = [ "autocfg", - "num-bigint 0.4.3", + "num-bigint", "num-integer", "num-traits", ] @@ -932,21 +545,11 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "opaque-debug" @@ -992,44 +595,23 @@ dependencies = [ "rand 0.7.3", ] -[[package]] -name = "parity-wasm" -version = "0.41.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" - [[package]] name = "parity-wasm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" -[[package]] -name = "pest" -version = "2.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" -dependencies = [ - "ucd-trie", -] - [[package]] name = "pin-project-lite" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d31d11c69a6b52a174b42bdc0c30e5e11670f90788b2c471c31c1d17d449443" - -[[package]] -name = "pin-utils" -version = "0.1.0" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +checksum = "e280fbe77cc62c91527259e9442153f4688736748d24660126286329742b4c6c" [[package]] name = "ppv-lite86" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed0cfbc8191465bed66e1718596ee0b0b35d5ee1f41c5df2189d0fe8bde535ba" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "primitive-types" @@ -1063,29 +645,29 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] name = "pwasm-utils" -version = "0.12.0" +version = "0.18.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" +checksum = "880b3384fb00b8f6ecccd5d358b93bd2201900ae3daad213791d1864f6441f5c" dependencies = [ "byteorder", "log", - "parity-wasm 0.41.0", + "parity-wasm", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -1155,7 +737,7 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" dependencies = [ - "getrandom 0.2.3", + "getrandom 0.2.4", ] [[package]] @@ -1167,15 +749,6 @@ dependencies = [ "rand_core 0.5.1", ] -[[package]] -name = "reed-solomon-erasure" -version = "4.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a415a013dd7c5d4221382329a5a3482566da675737494935cbbbcdec04662f9d" -dependencies = [ - "smallvec", -] - [[package]] name = "ripemd160" version = "0.9.1" @@ -1195,51 +768,39 @@ checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" [[package]] name = "rustc_version" -version = "0.3.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" dependencies = [ "semver", ] [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "semver" -version = "0.11.0" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" -dependencies = [ - "semver-parser", -] - -[[package]] -name = "semver-parser" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00b0bef5b7f9e0df16536d3961cfb6e84331c065b4066afb39768d0e319411f7" -dependencies = [ - "pest", -] +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" [[package]] name = "serde" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.130" +version = "1.0.133" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" dependencies = [ "proc-macro2", "quote", @@ -1248,11 +809,10 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.72" +version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "indexmap", "itoa", "ryu", "serde", @@ -1260,9 +820,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b69f9a4c9740d74c5baa3fd2e547f9525fa8088a8a958e0ca2409a514e33f5fa" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" dependencies = [ "block-buffer", "cfg-if 1.0.0", @@ -1285,30 +845,23 @@ dependencies = [ [[package]] name = "signature" -version = "1.4.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02658e48d89f2bec991f9a78e69cfa4c316f8d6a6c4ec12fae1aeb263d486788" +checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" [[package]] name = "skw-vm-engine" version = "0.0.0" dependencies = [ - "anyhow", "assert_matches", - "base64 0.13.0", - "borsh", - "cached", "lazy_static", "lru", - "memoffset", - "near-primitives", "near-test-contracts", - "parity-wasm 0.41.0", + "parity-wasm", "pwasm-utils", "serde", "skw-vm-host", "skw-vm-primitives", - "threadpool", "tracing", "wasmi", "wasmparser", @@ -1319,17 +872,16 @@ dependencies = [ name = "skw-vm-host" version = "0.0.0" dependencies = [ - "base64 0.13.0", - "borsh", + "base64", "bs58", "byteorder", - "near-crypto 0.0.0 (git+https://github.com/near/nearcore)", - "parity-secp256k1", + "near-crypto", "ripemd160", "serde", "sha2", "sha3", "skw-vm-primitives", + "wasmi", ] [[package]] @@ -1343,27 +895,10 @@ dependencies = [ ] [[package]] -name = "slab" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5" - -[[package]] -name = "smallvec" -version = "1.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ecab6c735a6bb4139c0caafd0cc3635748bbb3acf4550e8138122099251f309" - -[[package]] -name = "smart-default" -version = "0.6.0" +name = "spin" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" [[package]] name = "static_assertions" @@ -1371,12 +906,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - [[package]] name = "subtle" version = "2.4.1" @@ -1385,9 +914,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -1432,25 +961,6 @@ dependencies = [ "syn", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - -[[package]] -name = "time" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "toml" version = "0.5.8" @@ -1479,15 +989,9 @@ checksum = "1f4ed65637b8390770814083d20756f87bfa2c21bf2f110babdc5438351746e4" [[package]] name = "typenum" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" - -[[package]] -name = "ucd-trie" -version = "0.1.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56dee185309b50d1f11bfedef0fe6d036842e3fb77413abef29f8f8d1c5d4c1c" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "uint" @@ -1501,6 +1005,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "unicode-width" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" + [[package]] name = "unicode-xid" version = "0.2.2" @@ -1509,9 +1019,9 @@ checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "wasi" @@ -1527,26 +1037,46 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasmi" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03919fcab96ed058e0c411c47b370883d6393c40307f3140876f68a9256cadb1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", + "wasmi_v1", +] + +[[package]] +name = "wasmi-validation" +version = "0.4.1" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", +] + +[[package]] +name = "wasmi_core" +version = "0.1.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ "downcast-rs", "libm", "memory_units", "num-rational 0.4.0", "num-traits", - "parity-wasm 0.42.2", - "wasmi-validation", + "parity-wasm", ] [[package]] -name = "wasmi-validation" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +name = "wasmi_v1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ - "parity-wasm 0.42.2", + "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", ] [[package]] @@ -1557,44 +1087,24 @@ checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" [[package]] name = "wast" -version = "38.0.1" +version = "39.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae0d7b256bef26c898fa7344a2d627e8499f5a749432ce0a05eae1a64ff0c271" +checksum = "e9bbbd53432b267421186feee3e52436531fa69a7cfee9403f5204352df3dd05" dependencies = [ "leb128", + "memchr", + "unicode-width", ] [[package]] name = "wat" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adcfaeb27e2578d2c6271a45609f4a055e6d7ba3a12eff35b1fd5ba147bdf046" +checksum = "ab98ed25494f97c69f28758617f27c3e92e5336040b5c3a14634f2dd3fe61830" dependencies = [ "wast", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "wyz" version = "0.2.0" @@ -1603,18 +1113,18 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "zeroize" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" +checksum = "cc222aec311c323c717f56060324f32b82da1ce1dd81d9a09aa6a9030bfe08db" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.2.2" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" +checksum = "81e8f13fef10b63c06356d65d416b070798ddabcadc10d3ece0c5be9b3c7eddb" dependencies = [ "proc-macro2", "quote", diff --git a/mock-enclave/src/skw-vm-engine/Cargo.toml b/mock-enclave/src/skw-vm-engine/Cargo.toml index 2c173bb..8e2fa2e 100644 --- a/mock-enclave/src/skw-vm-engine/Cargo.toml +++ b/mock-enclave/src/skw-vm-engine/Cargo.toml @@ -14,32 +14,25 @@ This crate implements the specification of the interface that SkyeKiwi Network s """ [dependencies] -borsh = "0.9" serde = { version = "1", features = ["derive"] } wasmparser = "0.78" -memoffset = "0.6" -pwasm-utils = "0.12" -parity-wasm = "0.41" -wasmi = "0.10.0" +pwasm-utils = "0.18.2" +parity-wasm = "0.42.2" lru = "0.7.2" -anyhow = { version = "1.0.19", optional = true } +wasmi = { git = "https://github.com/paritytech/wasmi", features = ['v1'] } skw-vm-host = { path = "../skw-vm-host", default-features = false, features = [] } skw-vm-primitives = { path = "../skw-vm-primitives" } - lazy_static = "1.4.0" -near-primitives = { git = "https://github.com/near/nearcore", tag = "crates-0.11.0" } -cached = "0.23.0" tracing = { version = "0.1", default-features = false } -threadpool = "1.8.1" [dev-dependencies] near-test-contracts = { path = "../near-test-contracts" } assert_matches = "1.3" wat = "1.0.40" -base64 = "0.13" + [features] default = [] diff --git a/mock-enclave/src/skw-vm-engine/src/cache.rs b/mock-enclave/src/skw-vm-engine/src/cache.rs index 8637c2a..e10d453 100644 --- a/mock-enclave/src/skw-vm-engine/src/cache.rs +++ b/mock-enclave/src/skw-vm-engine/src/cache.rs @@ -1,9 +1,9 @@ use crate::prepare; -use crate::imports::{WasmiImportResolver, create_builder}; -use wasmi::{ModuleInstance, ModuleRef}; +use skw_vm_host::{WasmiImportResolver, create_builder}; +use wasmi::{ModuleInstance, ModuleRef, MemoryRef}; use skw_vm_primitives::contract_runtime::{ContractCode, CryptoHash}; -use skw_vm_primitives::errors::{CacheError, CompilationError}; +use skw_vm_primitives::errors::{CompilationError}; use skw_vm_primitives::config::{VMConfig}; use lazy_static::lazy_static; @@ -16,200 +16,49 @@ lazy_static! { RwLock::new(LruCache::new(0)); } -pub fn create_module_instance(contract_code: &ContractCode, config: &VMConfig) -> Result { +pub fn create_module_instance(contract_code: &ContractCode, config: &VMConfig, memory: MemoryRef) -> Result { let code_hash = contract_code.hash; MODULE_CACHE.write().unwrap().get(&code_hash); let mut cache = MODULE_CACHE.write().unwrap(); - match cache.get(&code_hash).map(create_instance) { - Some(Ok(module_ref)) => return Ok(module_ref), - None => {} - - // we should not ever get here - // toxic cache - removing - Some(Err(_)) => { - cache.pop(&code_hash); + match cache.get(&code_hash) { + Some(m) => { + create_instance(&m, memory) + .map_err(|e| { + cache.pop(&code_hash); + e + }) + }, + None => { + let prepared_module = prepare::prepare_contract(&contract_code.code, config).map_err(|e| CompilationError::PrepareError(e))?; + let module = wasmi::Module::from_parity_wasm_module(prepared_module).map_err(|e| { + println!("create_module {:?}", e); + CompilationError::WasmCompileError + })?; + + // TODO: this is a major issue - need to redo a shit lots of config on fees + // module.deny_floating_point() + // .map_err(|_| CompilationError::FloatingPointError)?; + + let result = create_instance(&module, memory); + cache.put(code_hash, module); + + result } } - - // no hit in cache - compiling - let prepared_module = prepare::prepare_contract(&contract_code.code, config).map_err(|e| CompilationError::PrepareError(e))?; - let module = wasmi::Module::from_buffer(prepared_module).map_err(|_| CompilationError::WasmCompileError)?; - - module.deny_floating_point() - .map_err(|_| CompilationError::FloatingPointError)?; - - let result = create_instance(&module); - cache.put(code_hash, module); - - result } -pub fn get_module_instance(code_hash: &CryptoHash) -> Option> { - MODULE_CACHE - .read() - .unwrap() - .peek(code_hash) - .map(create_instance) -} - -pub fn create_instance(module: &wasmi::Module) -> Result { - let resolver = WasmiImportResolver {}; +pub fn create_instance(module: &wasmi::Module, memory: MemoryRef) -> Result { + let resolver = WasmiImportResolver::new(memory); let imports_builder = create_builder(&resolver); - let module_instance = ModuleInstance::new(module, &imports_builder).map_err(|_| CompilationError::WasmCompileError)?; + let module_instance = ModuleInstance::new(module, &imports_builder).map_err(|e| { + println!("create_instance {:?}", e); + CompilationError::WasmCompileError + })?; if module_instance.has_start() { return Err(CompilationError::StartFunctionError); } Ok(module_instance.not_started_instance().clone()) } - -// #[cfg(not(feature = "no_cache"))] -// const CACHE_SIZE: usize = 128; - -// pub mod wasmi_cache { -// use near_primitives::contract::ContractCode; - -// use super::*; - -// fn compile_module_wasmi( -// code: &[u8], -// config: &VMConfig, -// ) -> Result { -// let _span = tracing::debug_span!(target: "vm", "compile_module_wasmi").entered(); - -// let prepared_code = -// prepare::prepare_contract(code, config).map_err(CompilationError::PrepareError)?; -// Module::from_bytes(prepared_code).map_err(|err| match err { -// wasmi::Error::Instantiation(_) => { -// CompilationError::WasmerCompileError { msg: err.to_string() } -// } -// }) -// } - -// pub(crate) fn compile_and_serialize_wasmi( -// wasm_code: &[u8], -// key: &CryptoHash, -// config: &VMConfig, -// cache: &dyn CompiledContractCache, -// ) -> Result, CacheError> { -// let _span = tracing::debug_span!(target: "vm", "compile_and_serialize_wasmi").entered(); - -// let module = match compile_module_wasmi(wasm_code, config) { -// Ok(module) => module, -// Err(err) => { -// cache_error(&err, key, cache)?; -// return Ok(Err(err)); -// } -// }; - -// let code = -// module.to_bytes().map_err(|_e| CacheError::SerializationError { hash: key.0 })?; -// let serialized = CacheRecord::Code(code).try_to_vec().unwrap(); -// cache.put(key.as_ref(), &serialized).map_err(|_io_err| CacheError::WriteError)?; -// Ok(Ok(module)) -// } - -// fn deserialize_wasmi( -// serialized: &[u8], -// ) -> Result, CacheError> { -// let _span = tracing::debug_span!(target: "vm", "deserialize_wasmer2").entered(); - -// let record = CacheRecord::try_from_slice(serialized) -// .map_err(|_e| CacheError::DeserializationError)?; -// let serialized_module = match record { -// CacheRecord::CompileModuleError(err) => return Ok(Err(err)), -// CacheRecord::Code(code) => code, -// }; - -// //TODO: seems pretty safe to me :( -// // unsafe { -// Ok(Ok(Module::fron_bytes(serialized_module.as_slice().map_err(|_e| CacheError::DeserializationError)?))) -// // } -// } - -// fn compile_module_cached_wasmi_impl( -// key: CryptoHash, -// wasm_code: &[u8], -// config: &VMConfig, -// cache: Option<&dyn CompiledContractCache>, -// ) -> Result, CacheError> { -// match cache { -// None => Ok(compile_module_wasmi(wasm_code, config)), -// Some(cache) => { -// let serialized = cache.get(&key.0).map_err(|_io_err| CacheError::WriteError)?; -// match serialized { -// Some(serialized) => deserialize_wasmi(serialized.as_slice()), -// None => compile_and_serialize_wasmi(wasm_code, &key, config, cache), -// } -// } -// } -// } - - -// // TODO: not sure what to do with this feature flag -// #[cfg(not(feature = "no_cache"))] -// cached_key! { -// MODULES: SizedCache, CacheError>> -// = SizedCache::with_size(CACHE_SIZE); -// Key = { -// key -// }; - -// fn memcache_compile_module_cached_wasmi( -// key: CryptoHash, -// wasm_code: &[u8], -// config: &VMConfig, -// cache: Option<&dyn CompiledContractCache>, -// ) -> Result, CacheError> = { -// compile_module_cached_wasmi_impl(key, wasm_code, config, cache) -// } -// } - -// pub(crate) fn compile_module_cached_wasmi( -// code: &ContractCode, -// config: &VMConfig, -// cache: Option<&dyn CompiledContractCache>, -// ) -> Result, CacheError> { -// let key = get_contract_cache_key(code, config); -// #[cfg(not(feature = "no_cache"))] -// return memcache_compile_module_cached_wasmi(key, &code.code(), config, cache); -// #[cfg(feature = "no_cache")] -// return compile_module_cached_wasmi_impl(key, &code.code(), config, cache); -// } -// } - -// /// Precompiles contract for the current default VM, and stores result to the cache. -// /// Returns `Ok(true)` if compiled code was added to the cache, and `Ok(false)` if element -// /// is already in the cache, or if cache is `None`. -// pub fn precompile_contract( -// wasm_code: &ContractCode, -// config: &VMConfig, -// cache: Option<&dyn CompiledContractCache>, -// ) -> Result, CacheError> { -// let cache = match cache { -// None => return Ok(Ok(ContractPrecompilatonResult::CacheNotAvailable)), -// Some(it) => it, -// }; - -// let key = get_contract_cache_key(wasm_code, config); -// // Check if we already cached with such a key. -// match cache.get(&key.0).map_err(|_io_error| CacheError::ReadError)? { -// // If so - do not override. -// Some(_) => return Ok(Ok(ContractPrecompilatonResult::ContractAlreadyInCache)), -// None => {} -// }; -// let res = { -// wasmi_cache::compile_and_serialize_wasmi( -// wasm_code.code(), -// &key, -// config, -// cache, -// )? -// .map(|_module| ()) -// }; -// Ok(res.map(|()| ContractPrecompilatonResult::ContractCompiled)) -// } - - diff --git a/mock-enclave/src/skw-vm-engine/src/imports.rs b/mock-enclave/src/skw-vm-engine/src/imports.rs deleted file mode 100644 index 5dd8430..0000000 --- a/mock-enclave/src/skw-vm-engine/src/imports.rs +++ /dev/null @@ -1,209 +0,0 @@ -use wasmi::{ - Error as InterpeterError, FuncInstance, FuncRef, ImportsBuilder, ModuleImportResolver, - Signature, ValueType, -}; - -use crate::externals::HostFunctions; - -pub fn create_builder(resolver: &dyn ModuleImportResolver) -> ImportsBuilder { - ImportsBuilder::new().with_resolver("env", resolver) -} - -#[derive(Debug, Clone)] -pub struct WasmiImportResolver {} - -impl ModuleImportResolver for WasmiImportResolver { - fn resolve_func( - &self, - func_name: &str, - _signature: &Signature, - ) -> Result { - match func_name { - "read_register" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::ReadRegister.into(), - )), - "register_len" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::RegisterLen.into(), - )), - "write_register" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..] , None), - HostFunctions::WriteRegister.into(), - )), - "current_account_id" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::CurrentAccountId.into(), - )), - "signer_account_id" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::SignerAccountId.into(), - )), - "signer_account_pk" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..] , None), - HostFunctions::SignerAccountPublicKey.into(), - )), - "predecessor_account_id" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::PredecessorAccountId.into(), - )), - "input" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::Input.into(), - )), - "block_number" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::BlockNumber.into(), - )), - "block_timestamp" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::BlockTimestamp.into(), - )), - "epoch_height" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::EpochHeight.into(), - )), - "storage_usage" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::StorageUsage.into(), - )), - "account_balance" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::AccountBalance.into(), - )), - "attached_deposit" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::AttachedDeposit.into(), - )), - "prepaid_gas" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::PrepaidGas.into(), - )), - "used_gas" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::UsedGas.into(), - )), - "random_seed" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::RandomSeed.into(), - )), - "sha256" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::Sha256.into(), - )), - "keccak256" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::Keccak256.into(), - )), - "keccak512" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::Keccak512.into(), - )), - "ripemd160" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::Ripemd160.into(), - )), - "ecrecover" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType:: I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::Ecrecover.into(), - )), - "value_return" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::ValueReturn.into(), - )), - "panic" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], None), - HostFunctions::Panic.into(), - )), - "panic_utf8" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::PanicUtf8.into(), - )), - "log_utf8" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::LogUtf8.into(), - )), - "log_utf16" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::LogUtf16.into(), - )), - "abort" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32][..], None), - HostFunctions::Abort.into(), - )), - "promise_create" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseCreate.into(), - )), - "promise_then" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseThen.into(), - )), - "promise_and" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseAnd.into(), - )), - "promise_batch_create" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseBatchCreate.into(), - )), - "promise_batch_then" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseBatchThen.into(), - )), - "promise_batch_action_create_account" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::PromiseBatchActionCreateAccount.into(), - )), - "promise_batch_action_deploy_contract" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::PromiseBatchActionDeployContract.into(), - )), - "promise_batch_action_function_call" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::PromiseBatchActionFunctionCall.into(), - )), - "promise_batch_action_transfer" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], None), - HostFunctions::PromiseBatchActionTransfer.into(), - )), - "promise_batch_action_delete_account" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), - HostFunctions::PromiseBatchActionDeleteAccount.into(), - )), - "promise_results_count" => Ok(FuncInstance::alloc_host( - Signature::new(&[][..], Some(ValueType::I64)), - HostFunctions::PromiseResultsCount.into(), - )), - "promise_result" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::PromiseResult.into(), - )), - "promise_return" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64][..], None), - HostFunctions::PromiseReturn.into(), - )), - "storage_write" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::StorageWrite.into(), - )), - "storage_read" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::StorageRead.into(), - )), - "storage_remove" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::StorageRemove.into(), - )), - "storage_has_key" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), - HostFunctions::StorageHasKey.into(), - )), - "gas" => Ok(FuncInstance::alloc_host( - Signature::new(&[ValueType::I32][..], None), - HostFunctions::Gas.into(), - )), - _ => Err(InterpeterError::Function("invalid function".to_string())) - } - } -} diff --git a/mock-enclave/src/skw-vm-engine/src/lib.rs b/mock-enclave/src/skw-vm-engine/src/lib.rs index a48bcdb..a38544c 100644 --- a/mock-enclave/src/skw-vm-engine/src/lib.rs +++ b/mock-enclave/src/skw-vm-engine/src/lib.rs @@ -1,8 +1,6 @@ mod cache; pub mod prepare; mod runner; -mod externals; -mod imports; #[cfg(test)] mod tests; diff --git a/mock-enclave/src/skw-vm-engine/src/prepare.rs b/mock-enclave/src/skw-vm-engine/src/prepare.rs index 8f85cb2..6f20e41 100644 --- a/mock-enclave/src/skw-vm-engine/src/prepare.rs +++ b/mock-enclave/src/skw-vm-engine/src/prepare.rs @@ -2,8 +2,7 @@ //! wasm module before execution. use parity_wasm::builder; -use parity_wasm::elements::{self, External, MemorySection, Type}; -use wasmi::Module; +use parity_wasm::elements::{self, External, MemorySection, Type, Module}; use pwasm_utils::{self, rules}; use skw_vm_primitives::errors::PrepareError; @@ -82,7 +81,7 @@ impl<'a> ContractModule<'a> { return Ok(Self { module, config }); } let gas_rules = rules::Set::new(1, Default::default()).with_grow_cost(config.grow_mem_cost); - let module = pwasm_utils::inject_gas_counter(module, &gas_rules) + let module = pwasm_utils::inject_gas_counter(module, &gas_rules, "env") .map_err(|_| PrepareError::GasInstrumentation)?; Ok(Self { module, config }) } @@ -168,8 +167,8 @@ impl<'a> ContractModule<'a> { Ok(self) } - fn into_wasm_code(self) -> Result, PrepareError> { - elements::serialize(self.module).map_err(|_| PrepareError::Serialization) + fn get_module(self) -> Result { + Ok(self.module) } } @@ -184,7 +183,7 @@ impl<'a> ContractModule<'a> { /// - functions number does not exceed limit specified in VMConfig, /// /// The preprocessing includes injecting code for gas metering and metering the height of stack. -pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result, PrepareError> { +pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result { ContractModule::init(original_code, config)? .validate_functions_number()? .standardize_mem() @@ -192,7 +191,8 @@ pub fn prepare_contract(original_code: &[u8], config: &VMConfig) -> Result Result, PrepareError> { + fn parse_and_prepare_wat(wat: &str) -> Result { let wasm = wat::parse_str(wat).unwrap(); let config = VMConfig::test(); prepare_contract(wasm.as_ref(), &config) diff --git a/mock-enclave/src/skw-vm-engine/src/runner.rs b/mock-enclave/src/skw-vm-engine/src/runner.rs index de9e6aa..eb276aa 100644 --- a/mock-enclave/src/skw-vm-engine/src/runner.rs +++ b/mock-enclave/src/skw-vm-engine/src/runner.rs @@ -2,20 +2,23 @@ use crate::{cache}; use skw_vm_primitives::contract_runtime::{ContractCode}; use skw_vm_primitives::fees::RuntimeFeesConfig; -use crate::externals::VMHost; use skw_vm_primitives::errors::{ - FunctionCallError, MethodResolveError, VMError, WasmTrap, + FunctionCallError, MethodResolveError, VMError, WasmTrap, HostError, }; use skw_vm_host::types::{PromiseResult}; use skw_vm_host::{MemoryLike, VMConfig, VMContext, VMLogic, VMOutcome, RuntimeExternal}; use wasmi::{ MemoryInstance, MemoryRef, ModuleInstance, - memory_units::{Pages, Bytes, size_of} + memory_units::{Pages, Bytes, size_of}, + Trap, TrapCode, }; -pub struct WasmiMemory(MemoryRef); +// impl WasmiHostError for HostError {} + +#[derive(Clone)] +pub struct WasmiMemory(pub MemoryRef); impl WasmiMemory { pub fn new( @@ -29,6 +32,10 @@ impl WasmiMemory { .expect("TODO creating memory cannot fail"), )) } + + pub fn clone(&self) -> MemoryRef { + self.0.clone() + } } impl MemoryLike for WasmiMemory { @@ -82,6 +89,36 @@ fn check_method(module: &ModuleInstance, method_name: &str) -> Result<(), VMErro } } +fn map_invoke_err(err: wasmi::Error) -> VMError { + + println!("Real {:?}", err); + + // Real Trap(Host(HostError(GasExceeded))) + let result = match err { + wasmi::Error::Trap(Trap::Code(e)) => { + match e { + TrapCode::Unreachable => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable)), + TrapCode::MemoryAccessOutOfBounds => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds)), + TrapCode::TableAccessOutOfBounds => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds)), + TrapCode::ElemUninitialized => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::IndirectCallToNull)), + TrapCode::DivisionByZero => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::IllegalArithmetic)), + TrapCode::IntegerOverflow => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::IllegalArithmetic)), + TrapCode::InvalidConversionToInt => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::IllegalArithmetic)), + TrapCode::StackOverflow => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::StackOverflow)), + TrapCode::UnexpectedSignature => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::IncorrectCallIndirectSignature)), + } + }, + wasmi::Error::Trap(Trap::Host(e)) => { + println!("{:?}", e.downcast_ref::()); + println!("before {:?}", e); + VMError::FunctionCallError(FunctionCallError::HostError(e.downcast_ref::().unwrap().clone())) + }, + _ => VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable)) + }; + println!("Fake {:?}", result.clone()); + result +} + pub struct WasmiVM; impl WasmiVM { pub fn run( @@ -101,7 +138,42 @@ impl WasmiVM { ) .entered(); - let module = cache::create_module_instance(&code, wasm_config); + if method_name.is_empty() { + return ( + None, + Some(VMError::FunctionCallError(FunctionCallError::MethodResolveError( + MethodResolveError::MethodEmptyName, + ))), + ); + } + + let mut memory = WasmiMemory::new( + wasm_config.limit_config.initial_memory_pages, + wasm_config.limit_config.max_memory_pages, + ).expect("Cannot create memory for a contract call"); + let memory_copy = memory.clone(); + + let mut logic = VMLogic::new( + ext, + context, + wasm_config, + fees_config, + promise_results, + &mut memory + ); + + if logic.add_contract_compile_fee(code.code.len() as u64).is_err() { + return ( + Some(logic.outcome()), + Some(VMError::FunctionCallError(FunctionCallError::HostError( + HostError::GasExceeded + ))) + ) + } + + println!("{:?}", logic.clone_outcome()); + + let module = cache::create_module_instance(&code, wasm_config, memory_copy); let module = match module { Ok(m) => m, @@ -109,28 +181,18 @@ impl WasmiVM { return (None, Some(VMError::FunctionCallError(FunctionCallError::CompilationError(e)))); } }; - + if let Err(e) = check_method(&module, method_name) { return (None, Some(e)); } - - let mut memory = WasmiMemory::new( - wasm_config.limit_config.initial_memory_pages, - wasm_config.limit_config.max_memory_pages, - ) - .expect("Cannot create memory for a contract call"); - - let logic = VMLogic::new(ext, context, wasm_config, fees_config, promise_results, &mut memory); - let mut host = VMHost(logic); - let result = module - .invoke_export(&method_name, &[], &mut host) - .map_err(|_| FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds)); + .invoke_export(&method_name, &[], &mut logic) + .map_err(map_invoke_err); - (Some(host.0.outcome()), match result { + (Some(logic.outcome()), match result { Ok(_) => None, - Err(_) => Some(VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds))) + Err(e) => Some(e) }) } } diff --git a/mock-enclave/src/skw-vm-engine/src/tests.rs b/mock-enclave/src/skw-vm-engine/src/tests.rs index 5f38e23..c11a4eb 100644 --- a/mock-enclave/src/skw-vm-engine/src/tests.rs +++ b/mock-enclave/src/skw-vm-engine/src/tests.rs @@ -1,10 +1,10 @@ mod compile_errors; -// mod contract_preload; mod rs_contract; mod runtime_errors; mod ts_contract; mod wasm_validation; +// mod contract_preload; use crate::runner::WasmiVM; use skw_vm_primitives::contract_runtime::ContractCode; @@ -71,3 +71,21 @@ fn make_simple_contract_call_vm( make_simple_contract_call_with_gas_vm(code, method_name, 10u64.pow(14)) } +#[track_caller] +fn gas_and_error_match( + outcome_and_error: (Option, Option), + expected_gas: Option, + expected_error: Option, +) { + match expected_gas { + Some(gas) => { + println!("outcome_and_error {:?}",outcome_and_error.0); + let outcome = outcome_and_error.0.unwrap(); + assert_eq!(outcome.used_gas, gas, "used gas differs"); + assert_eq!(outcome.burnt_gas, gas, "burnt gas differs"); + } + None => assert!(outcome_and_error.0.is_none()), + } + + assert_eq!(outcome_and_error.1, expected_error); +} diff --git a/mock-enclave/src/skw-vm-engine/src/tests/compile_errors.rs b/mock-enclave/src/skw-vm-engine/src/tests/compile_errors.rs index ebb63e2..bb16e41 100644 --- a/mock-enclave/src/skw-vm-engine/src/tests/compile_errors.rs +++ b/mock-enclave/src/skw-vm-engine/src/tests/compile_errors.rs @@ -1,7 +1,9 @@ -use skw_vm_primitives::errors::{CompilationError, FunctionCallError, PrepareError, VMError}; +use skw_vm_primitives::errors::{ + CompilationError, FunctionCallError, PrepareError, VMError, WasmTrap +}; use assert_matches::assert_matches; -use crate::tests::{make_simple_contract_call_vm}; +use crate::tests::{make_simple_contract_call_vm, gas_and_error_match}; fn initializer_wrong_signature_contract() -> Vec { wat::parse_str( @@ -139,11 +141,12 @@ fn test_limit_contract_functions_number() { let code = near_test_contracts::many_functions_contract(functions_number_limit); let (_, err) = make_simple_contract_call_vm(&code, method_name); + assert_eq!(err, None); let code = near_test_contracts::many_functions_contract(functions_number_limit + 1); let (_, err) = make_simple_contract_call_vm(&code, method_name); - + assert_matches!( err, Some(VMError::FunctionCallError(FunctionCallError::CompilationError( @@ -151,3 +154,43 @@ fn test_limit_contract_functions_number() { ))) ); } + +fn many_locals(n_locals: usize) -> Vec { + wat::parse_str(&format!( + r#" + (module + (func $main (export "main") + (local {}) + (call $main)) + )"#, + "i32 ".repeat(n_locals) + )) + .unwrap() +} + +#[test] +fn test_limit_locals() { + let wasm_err = many_locals(50_001); + let res = make_simple_contract_call_vm(&wasm_err, "main"); + gas_and_error_match( + res, + None, + Some( + VMError::FunctionCallError( + FunctionCallError::CompilationError( + CompilationError::PrepareError(PrepareError::Deserialization), + ) + ) + ), + ); + + let wasm_ok = many_locals(50_000); + let res = make_simple_contract_call_vm(&wasm_ok, "main"); + + // behavior in the original near vm + gas_and_error_match( + res, + Some(47583963), + Some(VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable))), + ); +} diff --git a/mock-enclave/src/skw-vm-engine/src/tests/rs_contract.rs b/mock-enclave/src/skw-vm-engine/src/tests/rs_contract.rs index a37f6bb..5c2a399 100644 --- a/mock-enclave/src/skw-vm-engine/src/tests/rs_contract.rs +++ b/mock-enclave/src/skw-vm-engine/src/tests/rs_contract.rs @@ -1,4 +1,4 @@ -use skw_vm_primitives::contract_runtime::{ContractCode, Balance}; +use skw_vm_primitives::contract_runtime::{ContractCode}; use skw_vm_primitives::fees::RuntimeFeesConfig; use skw_vm_primitives::errors::{FunctionCallError, VMError, WasmTrap}; @@ -19,6 +19,8 @@ fn test_contract() -> ContractCode { } fn assert_run_result((outcome, err): (Option, Option), expected_value: u64) { + println!("{:?}", err); + if let Some(_) = err { panic!("Failed execution"); } @@ -80,7 +82,7 @@ pub fn test_read_write() { } #[test] -pub fn test_stablized_host_function() { +pub fn test_do_ripemd() { let code = test_contract(); let mut fake_external = MockedExternal::new(); @@ -99,20 +101,6 @@ pub fn test_stablized_host_function() { &promise_results, ); assert_eq!(result.1, None); - - let result = WasmiVM::run( - &code, - "do_ripemd", - &mut fake_external, - context, - &config, - &fees, - &promise_results, - ); - match result.1 { - Some(VMError::FunctionCallError(FunctionCallError::LinkError { msg: _ })) => {} - _ => panic!("should return a link error due to missing import"), - } } macro_rules! def_test_ext { @@ -184,11 +172,10 @@ def_test_ext!(ext_signer_pk, "ext_signer_pk", &SIGNER_ACCOUNT_PK); def_test_ext!(ext_random_seed, "ext_random_seed", &[0, 1, 2]); def_test_ext!(ext_prepaid_gas, "ext_prepaid_gas", &(10_u64.pow(14)).to_le_bytes()); - -// TODO: change block_index to block_number -def_test_ext!(ext_block_index, "ext_block_index", &10u64.to_le_bytes()); +def_test_ext!(ext_block_number, "ext_block_number", &10u64.to_le_bytes()); def_test_ext!(ext_block_timestamp, "ext_block_timestamp", &42u64.to_le_bytes()); def_test_ext!(ext_storage_usage, "ext_storage_usage", &12u64.to_le_bytes()); + // Note, the used_gas is not a global used_gas at the beginning of method, but instead a diff // in used_gas for computing fib(30) in a loop def_test_ext!(ext_used_gas, "ext_used_gas", &[111, 10, 200, 15, 0, 0, 0, 0]); diff --git a/mock-enclave/src/skw-vm-engine/src/tests/runtime_errors.rs b/mock-enclave/src/skw-vm-engine/src/tests/runtime_errors.rs index fc7e5d9..b43b3be 100644 --- a/mock-enclave/src/skw-vm-engine/src/tests/runtime_errors.rs +++ b/mock-enclave/src/skw-vm-engine/src/tests/runtime_errors.rs @@ -2,30 +2,9 @@ use skw_vm_primitives::errors::{ CompilationError, FunctionCallError, HostError, MethodResolveError, PrepareError, VMError, WasmTrap, }; -use skw_vm_host::VMOutcome; - -use crate::runner::WasmiVM; -use crate::tests::{make_simple_contract_call_vm, make_simple_contract_call_with_gas_vm}; - -#[track_caller] -fn gas_and_error_match( - outcome_and_error: (Option, Option), - expected_gas: Option, - expected_error: Option, -) { - match expected_gas { - Some(gas) => { - let outcome = outcome_and_error.0.unwrap(); - assert_eq!(outcome.used_gas, gas, "used gas differs"); - assert_eq!(outcome.burnt_gas, gas, "burnt gas differs"); - } - None => assert!(outcome_and_error.0.is_none()), - } - - assert_eq!(outcome_and_error.1, expected_error); -} - +use crate::tests::{make_simple_contract_call_vm, make_simple_contract_call_with_gas_vm, gas_and_error_match}; +// DIFF: these functions won't past compile in SkyeKiwi VM // fn infinite_initializer_contract() -> Vec { // wat::parse_str( // r#" @@ -167,10 +146,16 @@ fn trap_initializer() -> Vec { #[test] fn test_trap_initializer() { + // DIFF: behavior of the origianl NEAR VM + // gas_and_error_match( + // make_simple_contract_call_vm(&trap_initializer(), "hello"), + // Some(47755584), + // Some(VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable))), + // ); gas_and_error_match( make_simple_contract_call_vm(&trap_initializer(), "hello"), - Some(47755584), - Some(VMError::FunctionCallError(FunctionCallError::WasmTrap(WasmTrap::Unreachable))), + None, + Some(VMError::FunctionCallError(FunctionCallError::CompilationError(CompilationError::StartFunctionError))), ); } @@ -450,6 +435,8 @@ fn bad_import_func(env: &str) -> Vec { // Weird behavior: // Invalid import not from "env" -> PrepareError::Instantiate // Invalid import from "env" -> LinkError + +// DIFF: these tests won't pass compile in SkyeKiwi VM fn test_bad_import_1() { gas_and_error_match( make_simple_contract_call_vm(&bad_import_global("wtf"), "hello"), @@ -551,15 +538,22 @@ fn bad_many_imports() -> Vec { #[test] fn test_bad_many_imports() { let result = make_simple_contract_call_vm(&bad_many_imports(), "hello"); - let outcome = result.0.unwrap(); - assert_eq!(outcome.used_gas, 299664213); - assert_eq!(outcome.burnt_gas, 299664213); - if let Some(VMError::FunctionCallError(FunctionCallError::LinkError { msg })) = result.1 { - eprintln!("{}", msg); - assert!(msg.len() < 1000, "Huge error message: {}", msg.len()); - } else { - panic!("{:?}", result.1); - } + assert_eq!(result.1 + ,Some(VMError::FunctionCallError(FunctionCallError::CompilationError( + CompilationError::WasmCompileError, + ))) + ); + + // DIFF: Original Behavior of NEAR VM + // let outcome = result.0.unwrap(); + // assert_eq!(outcome.used_gas, 299664213); + // assert_eq!(outcome.burnt_gas, 299664213); + // if let Some(VMError::FunctionCallError(FunctionCallError::LinkError { msg })) = result.1 { + // eprintln!("{}", msg); + // assert!(msg.len() < 1000, "Huge error message: {}", msg.len()); + // } else { + // panic!("{:?}", result.1); + // } } fn external_call_contract() -> Vec { @@ -619,6 +613,7 @@ fn test_external_call_indirect() { gas_and_error_match((outcome, err), Some(334541937), None); } +// DIFF: included with the original NEAR VM tests // #[test] // fn test_contract_error_caching() { // let code = [42; 1000]; diff --git a/mock-enclave/src/skw-vm-host/Cargo.lock b/mock-enclave/src/skw-vm-host/Cargo.lock index d13c388..8cfadda 100644 --- a/mock-enclave/src/skw-vm-host/Cargo.lock +++ b/mock-enclave/src/skw-vm-host/Cargo.lock @@ -342,9 +342,6 @@ name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] [[package]] name = "impl-codec" @@ -388,15 +385,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] - [[package]] name = "libc" version = "0.2.112" @@ -411,14 +399,14 @@ checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "memory_units" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "near-account-id" version = "0.0.0" -source = "git+https://github.com/near/nearcore#1338d817efeb30721d56ca776aa5bae83706e1d8" +source = "git+https://github.com/near/nearcore#14f249db13765108a01cf5ba5f5d0ba26378aaa7" dependencies = [ "borsh", "serde", @@ -427,7 +415,7 @@ dependencies = [ [[package]] name = "near-crypto" version = "0.0.0" -source = "git+https://github.com/near/nearcore#1338d817efeb30721d56ca776aa5bae83706e1d8" +source = "git+https://github.com/near/nearcore#14f249db13765108a01cf5ba5f5d0ba26378aaa7" dependencies = [ "arrayref", "blake2", @@ -796,12 +784,9 @@ name = "skw-vm-host" version = "0.0.0" dependencies = [ "base64", - "borsh", "bs58", "byteorder", - "hex", "near-crypto", - "parity-secp256k1", "ripemd160", "serde", "serde_json", @@ -809,7 +794,6 @@ dependencies = [ "sha3", "skw-vm-primitives", "wasmi", - "zeropool-bn", ] [[package]] @@ -819,13 +803,14 @@ dependencies = [ "num-rational 0.3.2", "serde", "sha2", + "wasmi", ] [[package]] name = "spin" -version = "0.5.2" +version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" +checksum = "511254be0c5bcf062b019a6c89c01a664aa359ded62f78aa72c6fc137c0590e5" [[package]] name = "static_assertions" @@ -941,9 +926,28 @@ checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" [[package]] name = "wasmi" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03919fcab96ed058e0c411c47b370883d6393c40307f3140876f68a9256cadb1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", + "wasmi_v1", +] + +[[package]] +name = "wasmi-validation" +version = "0.4.1" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" +dependencies = [ + "parity-wasm", +] + +[[package]] +name = "wasmi_core" +version = "0.1.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ "downcast-rs", "libm", @@ -951,16 +955,17 @@ dependencies = [ "num-rational 0.4.0", "num-traits", "parity-wasm", - "wasmi-validation", ] [[package]] -name = "wasmi-validation" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" +name = "wasmi_v1" +version = "0.11.0" +source = "git+https://github.com/paritytech/wasmi#88b38b7702a5830b00669ef7c622db5fbfd6b335" dependencies = [ "parity-wasm", + "spin", + "wasmi-validation", + "wasmi_core", ] [[package]] @@ -971,35 +976,21 @@ checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" [[package]] name = "zeroize" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" +checksum = "cc222aec311c323c717f56060324f32b82da1ce1dd81d9a09aa6a9030bfe08db" dependencies = [ "zeroize_derive", ] [[package]] name = "zeroize_derive" -version = "1.2.2" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" +checksum = "81e8f13fef10b63c06356d65d416b070798ddabcadc10d3ece0c5be9b3c7eddb" dependencies = [ "proc-macro2", "quote", "syn", "synstructure", ] - -[[package]] -name = "zeropool-bn" -version = "0.5.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a25023b8f5e576f5d81f000e6262ab873987a913f3399256e23f7038031f1c" -dependencies = [ - "borsh", - "byteorder", - "crunchy", - "lazy_static", - "rand 0.8.4", - "rustc-hex", -] diff --git a/mock-enclave/src/skw-vm-host/Cargo.toml b/mock-enclave/src/skw-vm-host/Cargo.toml index 76c1220..e80dabf 100644 --- a/mock-enclave/src/skw-vm-host/Cargo.toml +++ b/mock-enclave/src/skw-vm-host/Cargo.toml @@ -14,22 +14,18 @@ This crate implements the specification of the interface that Near blockchain ex [dependencies] base64 = "0.13" -borsh = "0.9" bs58 = "0.4" byteorder = "1.2" ripemd160 = "0.9.0" serde = { version = "1", features = ["derive"] } sha2 = ">=0.8,<0.10" sha3 = ">=0.8,<0.10" -parity-secp256k1 = "0.7" +wasmi = { git = "https://github.com/paritytech/wasmi", features = ['v1'] } near-crypto = { git = "https://github.com/near/nearcore" } skw-vm-primitives = { path = "../skw-vm-primitives" } -bn = { package = "zeropool-bn", version = "0.5.9", features = [], optional = true } - [dev-dependencies] -hex = { version = "0.4", features = ["serde"] } serde_json = { version = "1", features = ["preserve_order"] } [features] diff --git a/mock-enclave/src/skw-vm-engine/src/externals.rs b/mock-enclave/src/skw-vm-host/src/externals.rs similarity index 52% rename from mock-enclave/src/skw-vm-engine/src/externals.rs rename to mock-enclave/src/skw-vm-host/src/externals.rs index 77ee51b..f209f30 100644 --- a/mock-enclave/src/skw-vm-engine/src/externals.rs +++ b/mock-enclave/src/skw-vm-host/src/externals.rs @@ -1,10 +1,10 @@ use wasmi::{ - Externals, RuntimeArgs, Trap, TrapKind, HostError, + Externals, RuntimeArgs, Trap, TrapCode, RuntimeValue, }; -use skw_vm_host::{VMLogic}; -use skw_vm_primitives::errors::{VMLogicError}; +use crate::{VMLogic}; +use skw_vm_primitives::errors::{VMLogicError, HostError}; #[derive(PartialEq, Eq)] pub enum HostFunctions { @@ -117,9 +117,15 @@ impl Into for HostFunctions { } } -pub struct VMHost<'a>(pub VMLogic<'a>); +pub fn vmlogicerr_to_trap(err: VMLogicError) -> Trap { + match err { + VMLogicError::HostError(e) => e.into(), + VMLogicError::ExternalError(v) => HostError::ExternalError(v).into(), + VMLogicError::InconsistentStateError(e) => HostError::InconsistentStateError(e).into(), + } +} -impl<'a> Externals for VMHost<'a> { +impl<'a> Externals for VMLogic<'a> { fn invoke_index( &mut self, index: usize, @@ -127,340 +133,340 @@ impl<'a> Externals for VMHost<'a> { ) -> Result, Trap> { match HostFunctions::from(index) { HostFunctions::ReadRegister => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.read_register(register_id, ptr) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.read_register(register_id, ptr) .map(|_| None) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::RegisterLen => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.register_len(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.register_len(register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::WriteRegister => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let data_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let data_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.write_register(register_id, data_len, data_ptr) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let data_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let data_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.write_register(register_id, data_len, data_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::CurrentAccountId => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.current_account_id(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.current_account_id(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::SignerAccountId => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.signer_account_id(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.signer_account_id(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::SignerAccountPublicKey => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.signer_account_pk(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.signer_account_pk(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PredecessorAccountId => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.predecessor_account_id(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.predecessor_account_id(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Input => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.input(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.input(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::BlockNumber => { - self.0.block_number() + self.block_number() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::BlockTimestamp => { - self.0.block_timestamp() + self.block_timestamp() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::EpochHeight => { - self.0.epoch_height() + self.epoch_height() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::StorageUsage => { - self.0.storage_usage() + self.storage_usage() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::AccountBalance => { - let balance_ptr: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.account_balance(balance_ptr) + let balance_ptr: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.account_balance(balance_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::AttachedDeposit => { - let balance_ptr: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.attached_deposit(balance_ptr) + let balance_ptr: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.attached_deposit(balance_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PrepaidGas => { - self.0.prepaid_gas() + self.prepaid_gas() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::UsedGas => { - self.0.used_gas() + self.used_gas() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::RandomSeed => { - let register_id: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.random_seed(register_id) + let register_id: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.random_seed(register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Sha256 => { - let value_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.sha256(value_len, value_ptr, register_id) + let value_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.sha256(value_len, value_ptr, register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Keccak256 => { - let value_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.keccak256(value_len, value_ptr, register_id) + let value_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.keccak256(value_len, value_ptr, register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Keccak512 => { - let value_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.keccak512(value_len, value_ptr, register_id) + let value_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.keccak512(value_len, value_ptr, register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Ripemd160 => { - let value_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.ripemd160(value_len, value_ptr, register_id) + let value_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.ripemd160(value_len, value_ptr, register_id) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Ecrecover => { - let hash_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let hash_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let sign_len: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let sig_ptr: u64 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - let v: u64 = args.nth_checked(4).map_err(|_| TrapKind::UnexpectedSignature)?; - let malleability_flag: u64 = args.nth_checked(5).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(6).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.ecrecover(hash_len, hash_ptr, sign_len, sig_ptr, v, malleability_flag, register_id) + let hash_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let hash_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let sign_len: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let sig_ptr: u64 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + let v: u64 = args.nth_checked(4).map_err(|_| TrapCode::UnexpectedSignature)?; + let malleability_flag: u64 = args.nth_checked(5).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(6).map_err(|_| TrapCode::UnexpectedSignature)?; + self.ecrecover(hash_len, hash_ptr, sign_len, sig_ptr, v, malleability_flag, register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::ValueReturn => { - let value_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.value_return(value_len, value_ptr) + let value_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.value_return(value_len, value_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Panic => { - self.0.panic() + self.panic() .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PanicUtf8 => { - let len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.panic_utf8(len, ptr) + let len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.panic_utf8(len, ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::LogUtf8 => { - let len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.log_utf8(len, ptr) + let len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.log_utf8(len, ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::LogUtf16 => { - let len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.log_utf16(len, ptr) + let len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.log_utf16(len, ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Abort => { - let msg_ptr: u32 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let filename_ptr: u32 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let line: u32 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let col: u32 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.abort(msg_ptr, filename_ptr, line, col) + let msg_ptr: u32 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let filename_ptr: u32 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let line: u32 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let col: u32 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + self.abort(msg_ptr, filename_ptr, line, col) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseCreate => { - let account_id_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_len: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_ptr: u64 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_len: u64 = args.nth_checked(4).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_ptr: u64 = args.nth_checked(5).map_err(|_| TrapKind::UnexpectedSignature)?; - let amount_ptr: u64 = args.nth_checked(6).map_err(|_| TrapKind::UnexpectedSignature)?; - let gas: u64 = args.nth_checked(7).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_create(account_id_len, account_id_ptr, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) + let account_id_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_len: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_ptr: u64 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_len: u64 = args.nth_checked(4).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_ptr: u64 = args.nth_checked(5).map_err(|_| TrapCode::UnexpectedSignature)?; + let amount_ptr: u64 = args.nth_checked(6).map_err(|_| TrapCode::UnexpectedSignature)?; + let gas: u64 = args.nth_checked(7).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_create(account_id_len, account_id_ptr, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseThen => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_len: u64 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_ptr: u64 = args.nth_checked(4).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_len: u64 = args.nth_checked(5).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_ptr: u64 = args.nth_checked(6).map_err(|_| TrapKind::UnexpectedSignature)?; - let amount_ptr: u64 = args.nth_checked(7).map_err(|_| TrapKind::UnexpectedSignature)?; - let gas: u64 = args.nth_checked(8).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_then(promise_index, account_id_len, account_id_ptr, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_len: u64 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_ptr: u64 = args.nth_checked(4).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_len: u64 = args.nth_checked(5).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_ptr: u64 = args.nth_checked(6).map_err(|_| TrapCode::UnexpectedSignature)?; + let amount_ptr: u64 = args.nth_checked(7).map_err(|_| TrapCode::UnexpectedSignature)?; + let gas: u64 = args.nth_checked(8).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_then(promise_index, account_id_len, account_id_ptr, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseAnd => { - let promise_idx_ptr: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let promise_idx_count: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_and(promise_idx_ptr, promise_idx_count) + let promise_idx_ptr: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let promise_idx_count: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_and(promise_idx_ptr, promise_idx_count) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchCreate => { - let account_id_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_create(account_id_len, account_id_ptr) + let account_id_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_create(account_id_len, account_id_ptr) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchThen => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let account_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_then(promise_index, account_id_len, account_id_ptr) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let account_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_then(promise_index, account_id_len, account_id_ptr) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchActionCreateAccount => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_action_create_account(promise_index) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_action_create_account(promise_index) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchActionDeployContract => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let code_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let code_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_action_deploy_contract(promise_index, code_len, code_ptr) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let code_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let code_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_action_deploy_contract(promise_index, code_len, code_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchActionFunctionCall => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let method_name_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_len: u64 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - let arguments_ptr: u64 = args.nth_checked(4).map_err(|_| TrapKind::UnexpectedSignature)?; - let amount_ptr: u64 = args.nth_checked(5).map_err(|_| TrapKind::UnexpectedSignature)?; - let gas: u64 = args.nth_checked(6).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_action_function_call(promise_index, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let method_name_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_len: u64 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + let arguments_ptr: u64 = args.nth_checked(4).map_err(|_| TrapCode::UnexpectedSignature)?; + let amount_ptr: u64 = args.nth_checked(5).map_err(|_| TrapCode::UnexpectedSignature)?; + let gas: u64 = args.nth_checked(6).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_action_function_call(promise_index, method_name_len, method_name_ptr, arguments_len, arguments_ptr, amount_ptr, gas) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchActionTransfer => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let amount_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_action_transfer(promise_index, amount_ptr) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let amount_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_action_transfer(promise_index, amount_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseBatchActionDeleteAccount => { - let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let beneficiary_id_len: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let beneficiary_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_batch_action_delete_account(promise_index, beneficiary_id_len, beneficiary_id_ptr) + let promise_index: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let beneficiary_id_len: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let beneficiary_id_ptr: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_batch_action_delete_account(promise_index, beneficiary_id_len, beneficiary_id_ptr) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseResultsCount => { - self.0.promise_results_count() + self.promise_results_count() .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseResult => { - let result_idx: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_result(result_idx, register_id) + let result_idx: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_result(result_idx, register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::PromiseReturn => { - let promise_idx: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.promise_return(promise_idx) + let promise_idx: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.promise_return(promise_idx) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::StorageWrite => { - let key_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_len: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - let value_ptr: u64 = args.nth_checked(3).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(4).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.storage_write(key_len, key_ptr, value_len, value_ptr, register_id) + let key_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_len: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + let value_ptr: u64 = args.nth_checked(3).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(4).map_err(|_| TrapCode::UnexpectedSignature)?; + self.storage_write(key_len, key_ptr, value_len, value_ptr, register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::StorageRead => { - let key_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.storage_read(key_len, key_ptr, register_id) + let key_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.storage_read(key_len, key_ptr, register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::StorageRemove => { - let key_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - let register_id: u64 = args.nth_checked(2).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.storage_remove(key_len, key_ptr, register_id) + let key_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + let register_id: u64 = args.nth_checked(2).map_err(|_| TrapCode::UnexpectedSignature)?; + self.storage_remove(key_len, key_ptr, register_id) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::StorageHasKey => { - let key_len: u64 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.storage_has_key(key_len, key_ptr) + let key_len: u64 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + let key_ptr: u64 = args.nth_checked(1).map_err(|_| TrapCode::UnexpectedSignature)?; + self.storage_has_key(key_len, key_ptr) .map(|ret| Some(ret.into()) ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, HostFunctions::Gas => { - let gas_amount: u32 = args.nth_checked(0).map_err(|_| TrapKind::UnexpectedSignature)?; - self.0.gas(gas_amount) + let gas_amount: u32 = args.nth_checked(0).map_err(|_| TrapCode::UnexpectedSignature)?; + self.gas(gas_amount) .map(|_| None ) - .map_err(|e| e.into()) + .map_err(vmlogicerr_to_trap) }, _ => { - Err(Trap::new(TrapKind::Unreachable)) + Err(Trap::Code(TrapCode::Unreachable)) } } } diff --git a/mock-enclave/src/skw-vm-host/src/imports.rs b/mock-enclave/src/skw-vm-host/src/imports.rs new file mode 100644 index 0000000..52d4217 --- /dev/null +++ b/mock-enclave/src/skw-vm-host/src/imports.rs @@ -0,0 +1,227 @@ +use wasmi::{ + Error as InterpeterError, FuncInstance, FuncRef, ImportsBuilder, ModuleImportResolver, + Signature, ValueType, MemoryRef, MemoryDescriptor, +}; + +use skw_vm_primitives::errors::HostError; +use crate::externals::HostFunctions; + +pub fn create_builder(resolver: &dyn ModuleImportResolver) -> ImportsBuilder { + ImportsBuilder::new().with_resolver("env", resolver) +} + +#[derive(Debug, Clone)] +pub struct WasmiImportResolver(Option); + +impl WasmiImportResolver { + pub fn new(memory: MemoryRef) -> Self { + WasmiImportResolver(Some(memory)) + } +} + +impl ModuleImportResolver for WasmiImportResolver { + fn resolve_func( + &self, + func_name: &str, + _signature: &Signature, + ) -> Result { + match func_name { + "read_register" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::ReadRegister.into(), + )), + "register_len" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::RegisterLen.into(), + )), + "write_register" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..] , None), + HostFunctions::WriteRegister.into(), + )), + "current_account_id" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::CurrentAccountId.into(), + )), + "signer_account_id" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::SignerAccountId.into(), + )), + "signer_account_pk" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..] , None), + HostFunctions::SignerAccountPublicKey.into(), + )), + "predecessor_account_id" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::PredecessorAccountId.into(), + )), + "input" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::Input.into(), + )), + "block_number" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::BlockNumber.into(), + )), + "block_timestamp" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::BlockTimestamp.into(), + )), + "epoch_height" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::EpochHeight.into(), + )), + "storage_usage" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::StorageUsage.into(), + )), + "account_balance" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::AccountBalance.into(), + )), + "attached_deposit" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::AttachedDeposit.into(), + )), + "prepaid_gas" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::PrepaidGas.into(), + )), + "used_gas" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::UsedGas.into(), + )), + "random_seed" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::RandomSeed.into(), + )), + "sha256" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::Sha256.into(), + )), + "keccak256" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::Keccak256.into(), + )), + "keccak512" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::Keccak512.into(), + )), + "ripemd160" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::Ripemd160.into(), + )), + "ecrecover" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType:: I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::Ecrecover.into(), + )), + "value_return" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::ValueReturn.into(), + )), + "panic" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], None), + HostFunctions::Panic.into(), + )), + "panic_utf8" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::PanicUtf8.into(), + )), + "log_utf8" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::LogUtf8.into(), + )), + "log_utf16" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::LogUtf16.into(), + )), + "abort" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I32, ValueType::I32, ValueType::I32, ValueType::I32][..], None), + HostFunctions::Abort.into(), + )), + "promise_create" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseCreate.into(), + )), + "promise_then" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseThen.into(), + )), + "promise_and" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseAnd.into(), + )), + "promise_batch_create" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseBatchCreate.into(), + )), + "promise_batch_then" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseBatchThen.into(), + )), + "promise_batch_action_create_account" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::PromiseBatchActionCreateAccount.into(), + )), + "promise_batch_action_deploy_contract" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::PromiseBatchActionDeployContract.into(), + )), + "promise_batch_action_function_call" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::PromiseBatchActionFunctionCall.into(), + )), + "promise_batch_action_transfer" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], None), + HostFunctions::PromiseBatchActionTransfer.into(), + )), + "promise_batch_action_delete_account" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], None), + HostFunctions::PromiseBatchActionDeleteAccount.into(), + )), + "promise_results_count" => Ok(FuncInstance::alloc_host( + Signature::new(&[][..], Some(ValueType::I64)), + HostFunctions::PromiseResultsCount.into(), + )), + "promise_result" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::PromiseResult.into(), + )), + "promise_return" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64][..], None), + HostFunctions::PromiseReturn.into(), + )), + "storage_write" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::StorageWrite.into(), + )), + "storage_read" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::StorageRead.into(), + )), + "storage_remove" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::StorageRemove.into(), + )), + "storage_has_key" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I64, ValueType::I64][..], Some(ValueType::I64)), + HostFunctions::StorageHasKey.into(), + )), + "gas" => Ok(FuncInstance::alloc_host( + Signature::new(&[ValueType::I32][..], None), + HostFunctions::Gas.into(), + )), + _ => Err(InterpeterError::Trap(HostError::InvalidMethodName.into())) + } + } + + fn resolve_memory( + &self, + _field_name: &str, + _memory_type: &MemoryDescriptor, + ) -> Result { + match self.0.clone() { + None => Err(InterpeterError::Instantiation("memory missing".to_string())), + Some(m) => Ok(m), + } + } +} diff --git a/mock-enclave/src/skw-vm-host/src/lib.rs b/mock-enclave/src/skw-vm-host/src/lib.rs index 42aac24..f9bd073 100644 --- a/mock-enclave/src/skw-vm-host/src/lib.rs +++ b/mock-enclave/src/skw-vm-host/src/lib.rs @@ -1,6 +1,8 @@ mod context; mod dependencies; mod logic; +mod externals; +mod imports; pub mod mocks; pub mod serde_with; pub mod types; @@ -8,11 +10,11 @@ pub mod gas_counter; pub use context::VMContext; pub use dependencies::{RuntimeExternal, MemoryLike, ValuePtr}; pub use logic::{VMLogic, VMOutcome}; +pub use imports::{WasmiImportResolver, create_builder}; pub use skw_vm_primitives::config::*; pub use skw_vm_primitives::profile; pub use skw_vm_primitives::contract_runtime::ProtocolVersion; - pub use skw_vm_primitives::errors::{HostError, VMLogicError}; pub use types::ReturnData; diff --git a/mock-enclave/src/skw-vm-host/src/logic.rs b/mock-enclave/src/skw-vm-host/src/logic.rs index 617a446..2154a25 100644 --- a/mock-enclave/src/skw-vm-host/src/logic.rs +++ b/mock-enclave/src/skw-vm-host/src/logic.rs @@ -2103,13 +2103,13 @@ impl std::fmt::Debug for VMOutcome { ReturnData::ReceiptIndex(_) => "Receipt".to_string(), ReturnData::Value(v) => format!("{:?}", v), }; - write!( - f, "{}", return_data_str - ) // write!( - // f, - // "VMOutcome: balance {} storage_usage {} return data {} burnt gas {} used gas {}", - // self.balance, self.storage_usage, return_data_str, self.burnt_gas, self.used_gas + // f, "{}", return_data_str // ) + write!( + f, + "VMOutcome: balance {} storage_usage {} return data {} burnt gas {} used gas {}", + self.balance, self.storage_usage, return_data_str, self.burnt_gas, self.used_gas + ) } } diff --git a/mock-enclave/src/skw-vm-primitives/Cargo.toml b/mock-enclave/src/skw-vm-primitives/Cargo.toml index 400f8ff..734e667 100644 --- a/mock-enclave/src/skw-vm-primitives/Cargo.toml +++ b/mock-enclave/src/skw-vm-primitives/Cargo.toml @@ -16,7 +16,7 @@ Primitives types for the SkyeKiwi Network Secret Contracts sha2 = "0.9" serde = { version = "1", optional = true } num-rational = { version = "0.3.1", default-features = false } -wasmi = "0.10.0" +wasmi = { git = "https://github.com/paritytech/wasmi", features = ['v1'] } [features] default = ["std"] diff --git a/mock-enclave/src/skw-vm-primitives/src/errors.rs b/mock-enclave/src/skw-vm-primitives/src/errors.rs index cddc0ec..580eb52 100644 --- a/mock-enclave/src/skw-vm-primitives/src/errors.rs +++ b/mock-enclave/src/skw-vm-primitives/src/errors.rs @@ -211,8 +211,16 @@ pub enum HostError { Deprecated { method_name: String }, /// General errors for ECDSA recover. ECRecoverError { msg: String }, + + /// work-around for Traps + ExternalError(Vec), + InconsistentStateError(InconsistentStateError), + Unknown, } +// impl wasmi::HostError for VMLogicError {} +impl wasmi::HostError for HostError {} + #[derive(Debug, Clone, PartialEq)] pub enum VMLogicError { /// Errors coming from native Wasm VM. @@ -223,7 +231,6 @@ pub enum VMLogicError { InconsistentStateError(InconsistentStateError), } -impl wasmi::HostError for VMLogicError {} /// An error which can be returned when parsing a NEAR Account ID. #[derive(Eq, Clone, Debug, PartialEq)] @@ -461,6 +468,9 @@ impl std::fmt::Display for HostError { ContractSizeExceeded { size, limit } => write!(f, "The size of a contract code in DeployContract action {} exceeds the limit {}", size, limit), Deprecated {method_name}=> write!(f, "Attempted to call deprecated host function {}", method_name), ECRecoverError { msg } => write!(f, "ECDSA recover error: {}", msg), + ExternalError(_) => write!(f, "external error"), + InconsistentStateError(e) => write!(f, "InconsistentStateError: {}", e), + Unknown => write!(f, "unkonw error"), } } } diff --git a/mock-enclave/src/skw-vm-primitives/src/lib.rs b/mock-enclave/src/skw-vm-primitives/src/lib.rs index 9dd41fa..ab0c84c 100644 --- a/mock-enclave/src/skw-vm-primitives/src/lib.rs +++ b/mock-enclave/src/skw-vm-primitives/src/lib.rs @@ -607,7 +607,7 @@ pub mod config { max_promises_per_function_call_action: 1024, // Unlikely to hit it for normal development. max_number_input_data_dependencies: 128, - max_functions_number_per_contract: None, + max_functions_number_per_contract: Some(10_000), } } }