From e86de5fa2548842beaba42a631f19c8aef142243 Mon Sep 17 00:00:00 2001 From: Song Zhou Date: Thu, 13 Jan 2022 08:13:30 +0000 Subject: [PATCH] [CI Skip] wasmer -> wasmi --- .github/workflows/check.yml | 1 + Cargo.toml | 4 + mock-enclave/host/blockchain.ts | 29 + mock-enclave/package.json | 5 +- mock-enclave/result.json | 5 + mock-enclave/scripts/contract-build.ts | 18 + mock-enclave/scripts/execSync.ts | 16 + mock-enclave/scripts/test.ts | 20 + mock-enclave/scripts/vm.ts | 110 ++ mock-enclave/src/near-vm-logic/Cargo.lock | 1117 +++++++++++++++++ mock-enclave/src/near-vm-logic/src/logic.rs | 2 +- .../rust-toolchain.toml | 5 +- .../src/near-vm-runner-standalone/src/main.rs | 13 +- .../near-vm-runner-standalone/src/script.rs | 43 +- mock-enclave/src/near-vm-runner/Cargo.lock | 1090 +++------------- mock-enclave/src/near-vm-runner/Cargo.toml | 22 +- mock-enclave/src/near-vm-runner/src/cache.rs | 144 +-- .../src/near-vm-runner/src/imports.rs | 563 ++++++--- mock-enclave/src/near-vm-runner/src/lib.rs | 11 +- mock-enclave/src/near-vm-runner/src/runner.rs | 48 +- .../src/near-vm-runner/src/vm_kind.rs | 33 - .../src/near-vm-runner/src/wasmi_runner.rs | 311 +++++ package.json | 2 + 23 files changed, 2316 insertions(+), 1296 deletions(-) create mode 100644 mock-enclave/result.json create mode 100644 mock-enclave/scripts/contract-build.ts create mode 100644 mock-enclave/scripts/execSync.ts create mode 100644 mock-enclave/scripts/test.ts create mode 100644 mock-enclave/scripts/vm.ts create mode 100644 mock-enclave/src/near-vm-logic/Cargo.lock delete mode 100644 mock-enclave/src/near-vm-runner/src/vm_kind.rs create mode 100644 mock-enclave/src/near-vm-runner/src/wasmi_runner.rs diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 373b751..ba1029d 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -8,6 +8,7 @@ on: workflow_dispatch: jobs: check: + if: "! startsWith(github.event.head_commit.message, '[CI Skip]')" runs-on: ubuntu-20.04 steps: diff --git a/Cargo.toml b/Cargo.toml index 747203b..36f8b54 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,10 @@ exclude = [ 'enclave/crates/skw-types', 'enclave/crates/skw-unit-test', 'enclave/crates/skw-utils', + 'mock-enclave/src/near-vm-errors', + 'mock-enclave/src/near-vm-logic', + 'mock-enclave/src/near-vm-runner', + 'mock-enclave/src/near-vm-runner-standalone', ] [profile.release] panic = 'unwind' diff --git a/mock-enclave/host/blockchain.ts b/mock-enclave/host/blockchain.ts index 869ea14..9d2170e 100644 --- a/mock-enclave/host/blockchain.ts +++ b/mock-enclave/host/blockchain.ts @@ -99,3 +99,32 @@ export class MockBlockchainEnv { }, 6000); } } + + +export class BlockchainSubscriber { + + // Map contractId -> nextCallIndex(as number) + #nextCallIndex: { [key: string]: number } + #callHistory: {[key: string]: any} + #keyring: KeyringPair + #api: ApiPromise + #provider: WsProvider + + public async init() { + await waitReady(); + this.#keyring = new Keyring({ type: 'sr25519' }).addFromUri(`//Alice`) + this.#provider = new WsProvider('wss://sgdev.skye.kiwi'); + this.#api = await ApiPromise.create({ provider: this.#provider }); + } + + public async registerSecretKeeper() { + const key = randomBytes(32); + const sealer = new DefaultSealer(); + sealer.unlock(key); + + console.log(`keypair - private ${u8aToHex(key)}; public ${u8aToHex(sealer.getAuthorKey())}`); + + + } + +} diff --git a/mock-enclave/package.json b/mock-enclave/package.json index 16259de..d46e2e9 100644 --- a/mock-enclave/package.json +++ b/mock-enclave/package.json @@ -6,8 +6,9 @@ "license": "GPL-3.0-or-later", "scripts": { "vm": "npx ts-node ./scripts/vm.ts", - "build": "npx ts-node ./scripts/build.ts", - "start": "yarn build && yarn vm", + "test": "npx ts-node ./scripts/test.ts", + "contract:build": "npx ts-node ./scripts/contract-build.ts", + "start": "yarn contract:build && yarn vm", "serve": "npx ts-node ./host/index.ts" }, "devDependencies": { diff --git a/mock-enclave/result.json b/mock-enclave/result.json new file mode 100644 index 0000000..c0c4e66 --- /dev/null +++ b/mock-enclave/result.json @@ -0,0 +1,5 @@ +{ +"outcome": "None", +"state": "{\"YgkAAABzeXN0ZW0uc2s=\":\"DAAAAHN5c3RlbV9oZWxsbw==\",\"U1RBVEU=\":\"AQAAAGI=\"}", +"error": "None" +} diff --git a/mock-enclave/scripts/contract-build.ts b/mock-enclave/scripts/contract-build.ts new file mode 100644 index 0000000..6338841 --- /dev/null +++ b/mock-enclave/scripts/contract-build.ts @@ -0,0 +1,18 @@ +// Copyright 2021 @skyekiwi authors & contributors +// SPDX-License-Identifier: GPL-3.0-or-later + +import fs from 'fs'; +import { fromByteArray, toByteArray } from 'base64-js'; +import { u8aToString } from '@skyekiwi/util'; + +const { execute } = require('./execSync'); + +console.log('$ yarn build', process.argv.slice(2).join(' ')); + +function build() { + // compile the runner + execute('cd contract && cargo build --target wasm32-unknown-unknown --release'); + execute('cp contract/target/wasm32-unknown-unknown/release/greeting.wasm wasm/'); +} + +build(); diff --git a/mock-enclave/scripts/execSync.ts b/mock-enclave/scripts/execSync.ts new file mode 100644 index 0000000..712323e --- /dev/null +++ b/mock-enclave/scripts/execSync.ts @@ -0,0 +1,16 @@ +// Copyright 2021 @skyekiwi authors & contributors +// SPDX-License-Identifier: GPL-3.0-or-later + +const { execSync } = require('child_process'); + +const execute = (cmd: string, noLog: boolean) => { + !noLog && console.log(`$ ${cmd}`); + + try { + execSync(cmd, { stdio: 'inherit' }); + } catch (error) { + process.exit(-1); + } +}; + +export {execute}; diff --git a/mock-enclave/scripts/test.ts b/mock-enclave/scripts/test.ts new file mode 100644 index 0000000..de72a63 --- /dev/null +++ b/mock-enclave/scripts/test.ts @@ -0,0 +1,20 @@ +// Copyright 2021 @skyekiwi authors & contributors +// SPDX-License-Identifier: GPL-3.0-or-later + +import fs from 'fs'; +import path from 'path'; + +const { execute } = require('./execSync'); + +console.log('$ yarn test', process.argv.slice(2).join(' ')); + +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`); +} + +build(); diff --git a/mock-enclave/scripts/vm.ts b/mock-enclave/scripts/vm.ts new file mode 100644 index 0000000..0928b61 --- /dev/null +++ b/mock-enclave/scripts/vm.ts @@ -0,0 +1,110 @@ +// Copyright 2021 @skyekiwi authors & contributors +// SPDX-License-Identifier: GPL-3.0-or-later + +import fs from 'fs'; +import { fromByteArray, toByteArray } from 'base64-js'; +import { u8aToString } from '@skyekiwi/util'; + +const { execute } = require('./execSync'); + +console.log('$ yarn vm', process.argv.slice(2).join(' ')); + +function compile() { + // compile the runner + execute('cd src/near-vm-runner-standalone && cargo build --release') +} + + +const defaultContext = { + current_account_id: 'contract.sk', + signer_account_id: 'system.sk', + signer_account_pk: '15T', + predecessor_account_id: 'system.sk', + input: '', + block_index: 1, + block_timestamp: '1586796191203000000', + epoch_height: 1, + account_balance: '10000000000000000000000000', + account_locked_balance: '0', + storage_usage: 100, + attached_deposit: '0', + prepaid_gas: 1000000000000000000, + random_seed: '15T', + view_config: null, + output_data_receivers: [] +} + +const injectOrigin = (origin: string) => { + let thisContext = defaultContext; + thisContext['signer_account_id'] = origin; + return JSON.stringify(thisContext); +} + +function runVM({ + methodName = "", + stateInput = "{}", + input = "", + origin = "system.sk", + wasmFile = "./wasm/greeting.wasm", + profiling = false +}) { + const runnerPath = "./src/near-vm-runner-standalone/target/release/near-vm-runner-standalone"; + execute(`${runnerPath} --context '${injectOrigin(origin)}' --wasm-file ${wasmFile} --method-name ${methodName} --input \'${input}\' --state \'${stateInput}\' ${profiling ? "--timings" : ""} > result.json`) + + // parse the output + const contentRaw = fs.readFileSync('result.json'); + const content = JSON.parse(contentRaw.toString()); + const stateB64 = JSON.parse(content.state); + let state: {[key: string]: string} = {} + + for (const key in stateB64) { + const k = u8aToString(toByteArray(key)) + const v = u8aToString(toByteArray(stateB64[key])) + state[k] = v; + } + + console.log() + console.log("-------EXEC RESULT BEGINS-------"); + try { + console.log("Return Value", u8aToString(Uint8Array.from(JSON.parse(content.outcome)))); + } catch(err) { + // pass - in case of the outcome is 'None' + // console.error(err) + } + + console.log(state); + console.log("------- EXEC RESULT ENDS -------"); + console.log() + + return stateB64; +} + +compile() + +let state = {} + +state = runVM({ + methodName: 'set_greeting', + input: '{"message": "system_hello"}', + stateInput: '{}', +}) + +// state = runVM({ +// contextFile: './context/bob.json', +// methodName: 'set_greeting', +// input: '{"message": "bob_hello"}', +// stateInput: JSON.stringify(state), +// }) + +// state = runVM({ +// contextFile: './context/zs.json', +// methodName: 'set_greeting', +// input: '{"message": "zs_hello"}', +// stateInput: JSON.stringify(state), +// }) + +// state = runVM({ +// methodName: 'get_greeting', +// input: '{"account_id": "bob.sk"}', +// stateInput: JSON.stringify(state), +// }) diff --git a/mock-enclave/src/near-vm-logic/Cargo.lock b/mock-enclave/src/near-vm-logic/Cargo.lock new file mode 100644 index 0000000..6cf2bd9 --- /dev/null +++ b/mock-enclave/src/near-vm-logic/Cargo.lock @@ -0,0 +1,1117 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "ahash" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" + +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + +[[package]] +name = "arrayvec" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b" + +[[package]] +name = "arrayvec" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8da52d66c7071e2e3fa2a1e5c6d088fec47b593032b254f5e980de8ea54454d6" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" + +[[package]] +name = "bitvec" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7774144344a4faa177370406a7ff5f1da24303817368584c6206c8303eb07848" +dependencies = [ + "funty", + "radium", + "tap", + "wyz", +] + +[[package]] +name = "blake2" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" +dependencies = [ + "crypto-mac", + "digest", + "opaque-debug", +] + +[[package]] +name = "block-buffer" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" +dependencies = [ + "block-padding", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" + +[[package]] +name = "borsh" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18dda7dc709193c0d86a1a51050a926dc3df1cf262ec46a23a25dba421ea1924" +dependencies = [ + "borsh-derive", + "hashbrown 0.9.1", +] + +[[package]] +name = "borsh-derive" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "684155372435f578c0fa1acd13ebbb182cc19d6b38b64ae7901da4393217d264" +dependencies = [ + "borsh-derive-internal", + "borsh-schema-derive-internal", + "proc-macro-crate 0.1.5", + "proc-macro2", + "syn", +] + +[[package]] +name = "borsh-derive-internal" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2102f62f8b6d3edeab871830782285b64cc1830168094db05c8e458f209bc5c3" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "borsh-schema-derive-internal" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "196c978c4c9b0b142d446ef3240690bf5a8a33497074a113ff9a337ccb750483" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bs58" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771fe0050b883fcc3ea2359b1a96bcfbc090b7116eae7c3c512c7a083fdf23d3" + +[[package]] +name = "byte-slice-cast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d30c751592b77c499e7bce34d99d67c2c11bdc0574e9a488ddade14150a4698" + +[[package]] +name = "byteorder" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d27dae93fe7b1e0424dc57179ac396908c26b035a87234809f5c4dfd1b47dc80" +dependencies = [ + "cipher", + "ppv-lite86", +] + +[[package]] +name = "cc" +version = "1.0.72" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee" + +[[package]] +name = "cfg-if" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" + +[[package]] +name = "cfg-if" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" +dependencies = [ + "generic-array", +] + +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + +[[package]] +name = "cpufeatures" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95059428f66df56b63431fdb4e1947ed2190586af5c5a8a8b71122bdf5a7f469" +dependencies = [ + "libc", +] + +[[package]] +name = "crunchy" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" + +[[package]] +name = "crypto-mac" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" +dependencies = [ + "generic-array", + "subtle", +] + +[[package]] +name = "curve25519-dalek" +version = "3.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" +dependencies = [ + "byteorder", + "digest", + "rand_core 0.5.1", + "subtle", + "zeroize", +] + +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version", + "syn", +] + +[[package]] +name = "digest" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +dependencies = [ + "generic-array", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74e1069e39f1454367eb2de793ed062fac4c35c2934b76a81d90dd9abcd28816" +dependencies = [ + "signature", +] + +[[package]] +name = "ed25519-dalek" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +dependencies = [ + "curve25519-dalek", + "ed25519", + "rand 0.7.3", + "serde", + "sha2", + "zeroize", +] + +[[package]] +name = "fixed-hash" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcf0ed7fe52a17a03854ec54a9f76d6d84508d1c0e66bc1793301c73fc8493c" +dependencies = [ + "byteorder", + "rand 0.8.4", + "rustc-hex", + "static_assertions", +] + +[[package]] +name = "funty" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" + +[[package]] +name = "generic-array" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.1.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fc3cb4d91f53b50155bdcfd23f6a4c39ae1969c2ae85982b135750cccaf5fce" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.9.0+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcd999463524c52659517fe2cea98493cfe485d10565e7b0fb07dbba7ad2753" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "wasi 0.10.2+wasi-snapshot-preview1", +] + +[[package]] +name = "hashbrown" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" +dependencies = [ + "ahash", +] + +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +dependencies = [ + "serde", +] + +[[package]] +name = "impl-codec" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "161ebdfec3c8e3b52bf61c4f3550a1eea4f9579d10dc1b936f3171ebdcd6c443" +dependencies = [ + "parity-scale-codec", +] + +[[package]] +name = "impl-trait-for-tuples" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5dacb10c5b3bb92d46ba347505a9041e676bb20ad220101326bffb0c93031ee" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "indexmap" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" +dependencies = [ + "autocfg", + "hashbrown 0.11.2", +] + +[[package]] +name = "itoa" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" + +[[package]] +name = "keccak" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" + +[[package]] +name = "near-account-id" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "borsh", + "serde", +] + +[[package]] +name = "near-crypto" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "arrayref", + "blake2", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "libc", + "near-account-id", + "once_cell", + "parity-secp256k1", + "primitive-types", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle", + "thiserror", +] + +[[package]] +name = "near-primitives" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "borsh", + "byteorder", + "bytesize", + "chrono", + "derive_more", + "easy-ext", + "hex", + "near-crypto", + "near-primitives-core", + "near-rpc-error-macro", + "near-vm-errors 0.0.0", + "num-rational", + "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#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "base64 0.11.0", + "borsh", + "bs58", + "derive_more", + "near-account-id", + "num-rational", + "serde", + "serde_json", + "sha2", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-macro" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "near-rpc-error-core", + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn", +] + +[[package]] +name = "near-vm-errors" +version = "0.0.0" +source = "git+https://github.com/near/nearcore#ca529c65acd0668e3178aa49dfd3f6a8c1c6a29c" +dependencies = [ + "borsh", + "hex", + "near-account-id", + "near-rpc-error-macro", + "serde", +] + +[[package]] +name = "near-vm-errors" +version = "0.1.0" +dependencies = [ + "borsh", + "hex", + "near-account-id", + "serde", +] + +[[package]] +name = "near-vm-logic" +version = "0.0.0" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "byteorder", + "hex", + "near-account-id", + "near-crypto", + "near-primitives", + "near-primitives-core", + "near-vm-errors 0.1.0", + "ripemd160", + "serde", + "serde_json", + "sha2", + "sha3", + "zeropool-bn", +] + +[[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-integer" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2cc698a63b549a70bc047073d2949cce27cd1c7b0a4a862d08a8031bc2801db" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-rational" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" +dependencies = [ + "autocfg", + "num-bigint", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-traits" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a64b1ec5cda2586e284722486d802acf1f7dbdc623e2bfc57e65ca1cd099290" +dependencies = [ + "autocfg", +] + +[[package]] +name = "once_cell" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" + +[[package]] +name = "opaque-debug" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" + +[[package]] +name = "parity-scale-codec" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373b1a4c1338d9cd3d1fa53b3a11bdab5ab6bd80a20f7f7becd76953ae2be909" +dependencies = [ + "arrayvec 0.7.2", + "bitvec", + "byte-slice-cast", + "impl-trait-for-tuples", + "parity-scale-codec-derive", + "serde", +] + +[[package]] +name = "parity-scale-codec-derive" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1557010476e0595c9b568d16dcfb81b93cdeb157612726f5170d31aa707bed27" +dependencies = [ + "proc-macro-crate 1.1.0", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "parity-secp256k1" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fca4f82fccae37e8bbdaeb949a4a218a1bbc485d11598f193d2a908042e5fc1" +dependencies = [ + "arrayvec 0.5.2", + "cc", + "cfg-if 0.1.10", + "rand 0.7.3", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" + +[[package]] +name = "primitive-types" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05e4722c697a58a99d5d06a08c30821d7c082a4632198de1eaa5a6c22ef42373" +dependencies = [ + "fixed-hash", + "impl-codec", + "uint", +] + +[[package]] +name = "proc-macro-crate" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d6ea3c4595b96363c13943497db34af4460fb474a95c43f4446ad341b8c9785" +dependencies = [ + "toml", +] + +[[package]] +name = "proc-macro-crate" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebace6889caf889b4d3f76becee12e90353f2b8c7d875534a71e5742f8f6f83" +dependencies = [ + "thiserror", + "toml", +] + +[[package]] +name = "proc-macro2" +version = "1.0.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" +dependencies = [ + "unicode-xid", +] + +[[package]] +name = "quote" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "radium" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "643f8f41a8ebc4c5dc4515c82bb8abd397b527fc20fd681b7c011c2aee5d44fb" + +[[package]] +name = "rand" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +dependencies = [ + "getrandom 0.1.16", + "libc", + "rand_chacha 0.2.2", + "rand_core 0.5.1", + "rand_hc", +] + +[[package]] +name = "rand" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e7573632e6454cf6b99d7aac4ccca54be06da05aca2ef7423d22d27d4d4bcd8" +dependencies = [ + "libc", + "rand_chacha 0.3.1", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_chacha" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" +dependencies = [ + "ppv-lite86", + "rand_core 0.5.1", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", + "rand_core 0.6.3", +] + +[[package]] +name = "rand_core" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" +dependencies = [ + "getrandom 0.1.16", +] + +[[package]] +name = "rand_core" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +dependencies = [ + "getrandom 0.2.3", +] + +[[package]] +name = "rand_hc" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" +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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" +dependencies = [ + "block-buffer", + "digest", + "opaque-debug", +] + +[[package]] +name = "rustc-hex" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver", +] + +[[package]] +name = "ryu" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" + +[[package]] +name = "semver" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" + +[[package]] +name = "serde" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97565067517b60e2d1ea8b268e59ce036de907ac523ad83a0475da04e818989a" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed201699328568d8d08208fdd080e3ff594e6c422e438b6705905da01005d537" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.74" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" +dependencies = [ + "indexmap", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha2" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +dependencies = [ + "block-buffer", + "cfg-if 1.0.0", + "cpufeatures", + "digest", + "opaque-debug", +] + +[[package]] +name = "sha3" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" +dependencies = [ + "block-buffer", + "digest", + "keccak", + "opaque-debug", +] + +[[package]] +name = "signature" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f054c6c1a6e95179d6f23ed974060dcefb2d9388bb7256900badad682c499de4" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "133659a15339456eeeb07572eb02a91c91e9815e9cbc89566944d2c8d3efdbf6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "spin" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" + +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + +[[package]] +name = "subtle" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" + +[[package]] +name = "syn" +version = "1.0.85" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" +dependencies = [ + "proc-macro2", + "quote", + "unicode-xid", +] + +[[package]] +name = "synstructure" +version = "0.12.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f36bdaa60a83aca3921b5259d5400cbf5e90fc51931376a9bd4a0eb79aa7210f" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "unicode-xid", +] + +[[package]] +name = "tap" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" + +[[package]] +name = "thiserror" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "854babe52e4df1653706b98fcfc05843010039b406875930a70e4d9644e5c417" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa32fd3f627f367fe16f893e2597ae3c05020f8bba2666a4e6ea73d377e5714b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31142970826733df8241ef35dc040ef98c679ab14d7c3e54d827099b3acecaa" +dependencies = [ + "serde", +] + +[[package]] +name = "typenum" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" + +[[package]] +name = "uint" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6470ab50f482bde894a037a57064480a246dbfdd5960bd65a44824693f08da5f" +dependencies = [ + "byteorder", + "crunchy", + "hex", + "static_assertions", +] + +[[package]] +name = "unicode-xid" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "wasi" +version = "0.9.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519" + +[[package]] +name = "wasi" +version = "0.10.2+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" + +[[package]] +name = "zeroize" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d68d9dcec5f9b43a30d38c49f91dfedfaac384cb8f085faca366c26207dd1619" +dependencies = [ + "zeroize_derive", +] + +[[package]] +name = "zeroize_derive" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65f1a51723ec88c66d5d1fe80c841f17f63587d6691901d66be9bec6c3b51f73" +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/near-vm-logic/src/logic.rs b/mock-enclave/src/near-vm-logic/src/logic.rs index 16ae296..d3d4458 100644 --- a/mock-enclave/src/near-vm-logic/src/logic.rs +++ b/mock-enclave/src/near-vm-logic/src/logic.rs @@ -1580,7 +1580,7 @@ impl<'a> VMLogic<'a> { let receiver_id = self.get_account_by_receipt(&receipt_idx); let is_receiver_implicit = is_implicit_account_creation_enabled(self.current_protocol_version) - && AccountId::is_implicit(receiver_id.as_ref()); + && receiver_id.is_implicit(); let send_fee = transfer_send_fee(&self.fees_config.action_creation_config, sir, is_receiver_implicit); diff --git a/mock-enclave/src/near-vm-runner-standalone/rust-toolchain.toml b/mock-enclave/src/near-vm-runner-standalone/rust-toolchain.toml index d804775..caa1a41 100644 --- a/mock-enclave/src/near-vm-runner-standalone/rust-toolchain.toml +++ b/mock-enclave/src/near-vm-runner-standalone/rust-toolchain.toml @@ -1,4 +1 @@ -[toolchain] -channel = "1.56.0" -components = [ "rustfmt" ] -targets = [ "wasm32-unknown-unknown" ] +nightly-2021-11-11 diff --git a/mock-enclave/src/near-vm-runner-standalone/src/main.rs b/mock-enclave/src/near-vm-runner-standalone/src/main.rs index 12342e5..5553f54 100644 --- a/mock-enclave/src/near-vm-runner-standalone/src/main.rs +++ b/mock-enclave/src/near-vm-runner-standalone/src/main.rs @@ -6,7 +6,6 @@ use crate::script::Script; use clap::Clap; use near_vm_logic::VMOutcome; use near_vm_logic::{mocks::mock_external::Receipt, ProtocolVersion}; -use near_vm_runner::internal::VMKind; use serde::{ de::{MapAccess, Visitor}, ser::SerializeMap, @@ -120,12 +119,12 @@ fn main() { let mut script = Script::default(); - match cli_args.vm_kind.as_deref() { - // Some("wasmtime") => script.vm_kind(VMKind::Wasmtime), - // Some("wasmer") => script.vm_kind(VMKind::Wasmer0), - Some("wasmer2") => script.vm_kind(VMKind::Wasmer2), - _ => (), - }; + // match cli_args.vm_kind.as_deref() { + // // Some("wasmtime") => script.vm_kind(VMKind::Wasmtime), + // // Some("wasmer") => script.vm_kind(VMKind::Wasmer0), + // Some("wasmer2") => script.vm_kind(VMKind::Wasmer2), + // _ => (), + // }; if let Some(config) = &cli_args.config { script.vm_config(serde_json::from_str(config).unwrap()); } diff --git a/mock-enclave/src/near-vm-runner-standalone/src/script.rs b/mock-enclave/src/near-vm-runner-standalone/src/script.rs index 15c2957..e3ac6d8 100644 --- a/mock-enclave/src/near-vm-runner-standalone/src/script.rs +++ b/mock-enclave/src/near-vm-runner-standalone/src/script.rs @@ -8,8 +8,9 @@ use near_primitives::version::PROTOCOL_VERSION; use near_vm_logic::mocks::mock_external::MockedExternal; use near_vm_logic::types::PromiseResult; use near_vm_logic::{ProtocolVersion, VMConfig, VMContext, VMOutcome}; -use near_vm_runner::internal::VMKind; +// use near_vm_runner::internal::VMKind; use near_vm_runner::{MockCompiledContractCache, VMError}; +use near_vm_runner::wasmi_runner::WasmiVM; use crate::State; @@ -20,7 +21,6 @@ pub struct Contract(usize); /// intended for VM benchmarking. pub struct Script { contracts: Vec, - vm_kind: VMKind, vm_config: VMConfig, protocol_version: ProtocolVersion, contract_cache: Option>, @@ -48,7 +48,6 @@ impl Default for Script { let runtime_config = config_store.get_config(protocol_version).as_ref(); Script { contracts: Vec::new(), - vm_kind: VMKind::Wasmer2, vm_config: runtime_config.wasm_config.clone(), protocol_version, contract_cache: None, @@ -71,10 +70,6 @@ impl Script { self.contract(data) } - pub(crate) fn vm_kind(&mut self, vm_kind: VMKind) { - self.vm_kind = vm_kind; - } - pub(crate) fn vm_config(&mut self, vm_config: VMConfig) { self.vm_config = vm_config; } @@ -119,26 +114,22 @@ impl Script { let config_store = RuntimeConfigStore::new(None); let runtime_fees_config = &config_store.get_config(self.protocol_version).transaction_costs; let mut outcomes = Vec::new(); - if let Some(runtime) = self.vm_kind.runtime() { - for step in &self.steps { - for _ in 0..step.repeat { - let res = runtime.run( - &self.contracts[step.contract.0], - &step.method, - &mut external, - step.vm_context.clone(), - &self.vm_config, - runtime_fees_config, - &step.promise_results, - self.protocol_version, - self.contract_cache.as_deref(), - ); - outcomes.push(res); - } + // let runtime = &WasmiVM as &'static dyn VM; + for step in &self.steps { + for _ in 0..step.repeat { + let res = WasmiVM::run( + &self.contracts[step.contract.0], + &step.method, + &mut external, + step.vm_context.clone(), + &self.vm_config, + runtime_fees_config, + &step.promise_results, + self.protocol_version, + self.contract_cache.as_deref(), + ); + outcomes.push(res); } - } else { - // TODO(nagisa): this probably could be reported to the user in a better way. - panic!("the {:?} runtime has not been enabled at compile time", self.vm_kind); } ScriptResults { outcomes, state: external } } diff --git a/mock-enclave/src/near-vm-runner/Cargo.lock b/mock-enclave/src/near-vm-runner/Cargo.lock index 4e970ac..22c8b6c 100644 --- a/mock-enclave/src/near-vm-runner/Cargo.lock +++ b/mock-enclave/src/near-vm-runner/Cargo.lock @@ -1,13 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -[[package]] -name = "addr2line" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" -dependencies = [ - "gimli 0.23.0", -] +version = 3 [[package]] name = "addr2line" @@ -15,7 +8,7 @@ version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9ecd88a8c8378ca913a680cd98f0f13ac67383d35993f86c90a70e3f137816b" dependencies = [ - "gimli 0.26.1", + "gimli", ] [[package]] @@ -30,6 +23,17 @@ version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e" +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom 0.2.3", + "once_cell", + "version_check", +] + [[package]] name = "anyhow" version = "1.0.49" @@ -92,12 +96,12 @@ version = "0.3.63" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "321629d8ba6513061f26707241fa9bc89524ff1cd7a915a97ef0c62c666ce1b6" dependencies = [ - "addr2line 0.17.0", + "addr2line", "cc", "cfg-if 1.0.0", "libc", "miniz_oxide", - "object 0.27.1", + "object", "rustc-demangle", ] @@ -113,15 +117,6 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "904dfeac50f3cdaba28fc6f57fdcddb75f49ed61346676a78c4ffe55877802fd" -[[package]] -name = "bincode" -version = "1.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" -dependencies = [ - "serde", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -147,25 +142,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ "crypto-mac", - "digest 0.9.0", + "digest", "opaque-debug", ] -[[package]] -name = "blake3" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b64485778c4f16a6a5a9d335e80d449ac6c70cdd6a06d2af18a6f6f775a125b3" -dependencies = [ - "arrayref", - "arrayvec 0.5.2", - "cc", - "cfg-if 0.1.10", - "constant_time_eq", - "crypto-mac", - "digest 0.9.0", -] - [[package]] name = "block-buffer" version = "0.9.0" @@ -173,7 +153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ "block-padding", - "generic-array 0.14.4", + "generic-array", ] [[package]] @@ -182,63 +162,29 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8d696c370c750c948ada61c69a0ee2cbbb9c50b1019ddb86d9317157a99c2cae" -[[package]] -name = "borsh" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09a7111f797cc721407885a323fb071636aee57f750b1a4ddc27397eba168a74" -dependencies = [ - "borsh-derive 0.8.2", - "hashbrown 0.9.1", -] - [[package]] name = "borsh" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "18dda7dc709193c0d86a1a51050a926dc3df1cf262ec46a23a25dba421ea1924" dependencies = [ - "borsh-derive 0.9.1", + "borsh-derive", "hashbrown 0.9.1", ] -[[package]] -name = "borsh-derive" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307f3740906bac2c118a8122fe22681232b244f1369273e45f1156b45c43d2dd" -dependencies = [ - "borsh-derive-internal 0.8.2", - "borsh-schema-derive-internal 0.8.2", - "proc-macro-crate 0.1.5", - "proc-macro2", - "syn", -] - [[package]] name = "borsh-derive" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "684155372435f578c0fa1acd13ebbb182cc19d6b38b64ae7901da4393217d264" dependencies = [ - "borsh-derive-internal 0.9.1", - "borsh-schema-derive-internal 0.9.1", + "borsh-derive-internal", + "borsh-schema-derive-internal", "proc-macro-crate 0.1.5", "proc-macro2", "syn", ] -[[package]] -name = "borsh-derive-internal" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2104c73179359431cc98e016998f2f23bc7a05bc53e79741bcba705f30047bc" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "borsh-derive-internal" version = "0.9.1" @@ -250,17 +196,6 @@ dependencies = [ "syn", ] -[[package]] -name = "borsh-schema-derive-internal" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae29eb8418fcd46f723f8691a2ac06857d31179d33d2f2d91eb13967de97c728" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "borsh-schema-derive-internal" version = "0.9.1" @@ -290,6 +225,27 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d30c751592b77c499e7bce34d99d67c2c11bdc0574e9a488ddade14150a4698" +[[package]] +name = "bytecheck" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "314889ea31cda264cb7c3d6e6e5c9415a987ecb0e72c17c00d36fbb881d34abe" +dependencies = [ + "bytecheck_derive", + "ptr_meta", +] + +[[package]] +name = "bytecheck_derive" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a2b3b92c135dae665a6f760205b89187638e83bed17ef3e44e83c712cf30600" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "byteorder" version = "1.4.3" @@ -345,26 +301,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3a4f925191b4367301851c6d99b09890311d74b0d43f274c0b34c86d308a3663" -[[package]] -name = "capstone" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f60e7f097987a09a9b678c6214b5a5eb326f9fc1e3eac88cce5d086c2b3b8dc9" -dependencies = [ - "capstone-sys", - "libc", -] - -[[package]] -name = "capstone-sys" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aebe07897b48983847943662bfc3198aabfa51636c81313c1955d04d857ed739" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "cc" version = "1.0.72" @@ -403,39 +339,15 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12f8e7987cbd042a63249497f41aed09f8e65add917ea6566effbc56578d6801" dependencies = [ - "generic-array 0.14.4", + "generic-array", ] -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - -[[package]] -name = "constant_time_eq" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc" - [[package]] name = "convert_case" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" -[[package]] -name = "cpp_demangle" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "931ab2a3e6330a07900b8e7ca4e106cdcbb93f2b9a52df55e54ee53d8305b55d" -dependencies = [ - "cfg-if 1.0.0", -] - [[package]] name = "cpufeatures" version = "0.2.1" @@ -445,102 +357,6 @@ dependencies = [ "libc", ] -[[package]] -name = "cranelift-bforest" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841476ab6d3530136b5162b64a2c6969d68141843ad2fd59126e5ea84fd9b5fe" -dependencies = [ - "cranelift-entity", -] - -[[package]] -name = "cranelift-codegen" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b5619cef8d19530298301f91e9a0390d369260799a3d8dd01e28fc88e53637a" -dependencies = [ - "byteorder", - "cranelift-bforest", - "cranelift-codegen-meta", - "cranelift-codegen-shared", - "cranelift-entity", - "gimli 0.23.0", - "log", - "regalloc", - "serde", - "smallvec", - "target-lexicon 0.11.2", - "thiserror", -] - -[[package]] -name = "cranelift-codegen-meta" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a319709b8267939155924114ea83f2a5b5af65ece3ac6f703d4735f3c66bb0d" -dependencies = [ - "cranelift-codegen-shared", - "cranelift-entity", -] - -[[package]] -name = "cranelift-codegen-shared" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15925b23cd3a448443f289d85a8f53f3cf7a80f0137aa53c8e3b01ae8aefaef7" -dependencies = [ - "serde", -] - -[[package]] -name = "cranelift-entity" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "610cf464396c89af0f9f7c64b5aa90aa9e8812ac84084098f1565b40051bc415" -dependencies = [ - "serde", -] - -[[package]] -name = "cranelift-frontend" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d20c8bd4a1c41ded051734f0e33ad1d843a0adc98b9bd975ee6657e2c70cdc9" -dependencies = [ - "cranelift-codegen", - "log", - "smallvec", - "target-lexicon 0.11.2", -] - -[[package]] -name = "cranelift-native" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "304e100df41f34a5a15291b37bfe0fd7abd0427a2c84195cc69578b4137f9099" -dependencies = [ - "cranelift-codegen", - "target-lexicon 0.11.2", -] - -[[package]] -name = "cranelift-wasm" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4efd473b2917303957e0bfaea6ea9d08b8c93695bee015a611a2514ce5254abc" -dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "itertools", - "log", - "serde", - "smallvec", - "thiserror", - "wasmparser 0.76.0", -] - [[package]] name = "crc32fast" version = "1.2.2" @@ -606,7 +422,7 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b584a330336237c1eecd3e94266efb216c56ed91225d634cb2991c5f3fd1aeab" dependencies = [ - "generic-array 0.14.4", + "generic-array", "subtle", ] @@ -617,7 +433,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b9fdf9972b2bd6af2d913799d9ebc165ea4d2e65878e329d9c6b372c4491b61" dependencies = [ "byteorder", - "digest 0.9.0", + "digest", "rand_core 0.5.1", "subtle", "zeroize", @@ -667,38 +483,24 @@ dependencies = [ "convert_case", "proc-macro2", "quote", - "rustc_version 0.3.3", - "syn", -] - -[[package]] -name = "derive_utils" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "532b4c15dccee12c7044f1fcad956e98410860b22231e44a3b827464797ca7bf" -dependencies = [ - "proc-macro2", - "quote", + "rustc_version", "syn", ] [[package]] name = "digest" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.12.4", + "generic-array", ] [[package]] -name = "digest" -version = "0.9.0" +name = "downcast-rs" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" -dependencies = [ - "generic-array 0.14.4", -] +checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] name = "dynasm" @@ -723,7 +525,7 @@ checksum = "c20c69d1e16ae47889b47c301c790f48615cd9bfbdf586e3f6d4fde64af3d259" dependencies = [ "byteorder", "dynasm", - "memmap2 0.5.0", + "memmap2", ] [[package]] @@ -782,39 +584,12 @@ dependencies = [ "syn", ] -[[package]] -name = "errno" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" -dependencies = [ - "errno-dragonfly", - "libc", - "winapi", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" -dependencies = [ - "cc", - "libc", -] - [[package]] name = "event-listener" version = "2.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" -[[package]] -name = "fallible-iterator" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" - [[package]] name = "fixed-hash" version = "0.7.0" @@ -928,15 +703,6 @@ dependencies = [ "slab", ] -[[package]] -name = "generic-array" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" -dependencies = [ - "typenum", -] - [[package]] name = "generic-array" version = "0.14.4" @@ -969,17 +735,6 @@ dependencies = [ "wasi 0.10.2+wasi-snapshot-preview1", ] -[[package]] -name = "gimli" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" -dependencies = [ - "fallible-iterator", - "indexmap", - "stable_deref_trait", -] - [[package]] name = "gimli" version = "0.26.1" @@ -992,7 +747,7 @@ version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04" dependencies = [ - "ahash", + "ahash 0.4.7", ] [[package]] @@ -1000,6 +755,9 @@ name = "hashbrown" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +dependencies = [ + "ahash 0.7.6", +] [[package]] name = "hermit-abi" @@ -1053,26 +811,6 @@ dependencies = [ "serde", ] -[[package]] -name = "iter-enum" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cad34f24d3b48ceffdff38af2df5ce1b7d1d9cc113e503d8e86fe8cdb889c871" -dependencies = [ - "derive_utils", - "quote", - "syn", -] - -[[package]] -name = "itertools" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.4.8" @@ -1099,9 +837,6 @@ name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -dependencies = [ - "spin", -] [[package]] name = "leb128" @@ -1126,35 +861,10 @@ dependencies = [ ] [[package]] -name = "lightbeam" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b652a581265a38719e27cb26b50c21ec0cedad0c75760c1f416f54f92ebda1" -dependencies = [ - "arrayvec 0.5.2", - "capstone", - "cranelift-codegen", - "derive_more", - "dynasm", - "dynasmrt", - "iter-enum", - "itertools", - "memoffset", - "more-asserts", - "smallvec", - "thiserror", - "typemap", - "wasmparser 0.76.0", -] - -[[package]] -name = "lock_api" -version = "0.3.4" +name = "libm" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4da24a77a3d8a6d4862d95f72e6fdb9c09a643ecdb402d754004a557f2bec75" -dependencies = [ - "scopeguard", -] +checksum = "c7d73b3f436185384286bd8098d17ec07c9a7d2388a6599f824d8502b529702a" [[package]] name = "log" @@ -1201,25 +911,6 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" -[[package]] -name = "memmap" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "memmap2" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723e3ebdcdc5c023db1df315364573789f8857c11b631a2fdfad7c00f5c046b4" -dependencies = [ - "libc", -] - [[package]] name = "memmap2" version = "0.5.0" @@ -1238,6 +929,12 @@ dependencies = [ "autocfg", ] +[[package]] +name = "memory_units" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" + [[package]] name = "miniz_oxide" version = "0.4.4" @@ -1259,7 +956,7 @@ name = "near-account-id" version = "0.0.0" source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" dependencies = [ - "borsh 0.9.1", + "borsh", "serde", ] @@ -1270,7 +967,7 @@ source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe1 dependencies = [ "arrayref", "blake2", - "borsh 0.9.1", + "borsh", "bs58", "c2-chacha", "curve25519-dalek", @@ -1295,7 +992,7 @@ version = "0.0.0" source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" dependencies = [ "base64 0.13.0", - "borsh 0.9.1", + "borsh", "bs58", "byteorder", "bytesize", @@ -1307,7 +1004,7 @@ dependencies = [ "near-primitives-core", "near-rpc-error-macro", "near-vm-errors 0.0.0", - "num-rational", + "num-rational 0.3.2", "primitive-types", "rand 0.7.3", "reed-solomon-erasure", @@ -1323,11 +1020,11 @@ version = "0.0.0" source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" dependencies = [ "base64 0.11.0", - "borsh 0.9.1", + "borsh", "bs58", "derive_more", "near-account-id", - "num-rational", + "num-rational 0.3.2", "serde", "serde_json", "sha2", @@ -1376,7 +1073,7 @@ name = "near-vm-errors" version = "0.0.0" source = "git+https://github.com/near/nearcore#3f40407d27b8df34dcd7e9b587ebc7fe16a36a30" dependencies = [ - "borsh 0.9.1", + "borsh", "hex", "near-account-id", "near-rpc-error-macro", @@ -1387,7 +1084,7 @@ dependencies = [ name = "near-vm-errors" version = "0.1.0" dependencies = [ - "borsh 0.9.1", + "borsh", "hex", "near-account-id", "serde", @@ -1398,7 +1095,7 @@ name = "near-vm-logic" version = "0.0.0" dependencies = [ "base64 0.13.0", - "borsh 0.9.1", + "borsh", "bs58", "byteorder", "near-account-id", @@ -1410,7 +1107,6 @@ dependencies = [ "serde", "sha2", "sha3", - "zeropool-bn", ] [[package]] @@ -1420,7 +1116,7 @@ dependencies = [ "anyhow", "assert_matches", "base64 0.13.0", - "borsh 0.9.1", + "borsh", "cached", "memoffset", "near-primitives", @@ -1428,7 +1124,7 @@ dependencies = [ "near-test-contracts", "near-vm-errors 0.1.0", "near-vm-logic", - "parity-wasm", + "parity-wasm 0.41.0", "pwasm-utils", "serde", "threadpool", @@ -1436,33 +1132,29 @@ dependencies = [ "wasmer-compiler-singlepass-near", "wasmer-engine-universal-near", "wasmer-near", - "wasmer-runtime-core-near", - "wasmer-runtime-near", "wasmer-types-near", "wasmer-vm-near", - "wasmparser 0.78.2", - "wasmtime", + "wasmi", + "wasmparser", "wat", ] [[package]] -name = "nix" -version = "0.15.0" +name = "num-bigint" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b2e0b4f3320ed72aaedb9a5ac838690a8047c7b275da22711fddff4f8a14229" +checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" dependencies = [ - "bitflags", - "cc", - "cfg-if 0.1.10", - "libc", - "void", + "autocfg", + "num-integer", + "num-traits", ] [[package]] name = "num-bigint" -version = "0.3.3" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6f7833f2cbf2360a6cfd58cd41a53aa7a90bd4c202f5b1c7dd2ed73c57b2c3" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" dependencies = [ "autocfg", "num-integer", @@ -1486,12 +1178,24 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12ac428b1cb17fce6f731001d307d351ec70a6d202fc2e60f7d4c5e42d8f4f07" dependencies = [ "autocfg", - "num-bigint", + "num-bigint 0.3.3", "num-integer", "num-traits", "serde", ] +[[package]] +name = "num-rational" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d41702bd167c2df5520b384281bc111a4b5efcf7fbc4c9c222c815b07e0a6a6a" +dependencies = [ + "autocfg", + "num-bigint 0.4.3", + "num-integer", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.14" @@ -1511,33 +1215,14 @@ dependencies = [ "libc", ] -[[package]] -name = "object" -version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" -dependencies = [ - "crc32fast", - "indexmap", -] - -[[package]] -name = "object" -version = "0.25.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a38f2be3697a57b4060074ff41b44c16870d916ad7877c17696e063257482bc7" -dependencies = [ - "crc32fast", - "indexmap", - "memchr", -] - [[package]] name = "object" version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "67ac1d3f9a1d3616fd9a60c8d74296f22406a238b6a72f5cc1e6f314df4ffbf9" dependencies = [ + "crc32fast", + "indexmap", "memchr", ] @@ -1553,16 +1238,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" -[[package]] -name = "page_size" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eebde548fbbf1ea81a99b128872779c437752fb99f217c45245e1a61dcd9edcd" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "parity-scale-codec" version = "2.3.1" @@ -1608,34 +1283,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" [[package]] -name = "parking_lot" -version = "0.10.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3a704eb390aafdc107b0e392f56a82b668e3a71366993b5340f5833fd62505e" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d58c7c768d4ba344e3e8d72518ac13e259d7c7ade24167003b8488e10b6740a3" -dependencies = [ - "cfg-if 0.1.10", - "cloudabi", - "libc", - "redox_syscall 0.1.57", - "smallvec", - "winapi", -] - -[[package]] -name = "paste" -version = "1.0.6" +name = "parity-wasm" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5" +checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" [[package]] name = "pest" @@ -1727,15 +1378,6 @@ dependencies = [ "unicode-xid", ] -[[package]] -name = "psm" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd136ff4382c4753fc061cb9e4712ab2af263376b95bbd5bd8cd50c020b78e69" -dependencies = [ - "cc", -] - [[package]] name = "ptr_meta" version = "0.1.4" @@ -1764,7 +1406,7 @@ checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192" dependencies = [ "byteorder", "log", - "parity-wasm", + "parity-wasm 0.41.0", ] [[package]] @@ -1888,12 +1530,6 @@ dependencies = [ "num_cpus", ] -[[package]] -name = "redox_syscall" -version = "0.1.57" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41cc0f7e4d5d4544e8861606a285bb08d3e70712ccc7d2b84d7c0ccfaf4b05ce" - [[package]] name = "redox_syscall" version = "0.2.10" @@ -1912,30 +1548,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "regalloc" -version = "0.0.31" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" -dependencies = [ - "log", - "rustc-hash", - "serde", - "smallvec", -] - -[[package]] -name = "region" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "877e54ea2adcd70d80e9179344c97f93ef0dffd6b03e1f4529e6e83ab2fa9ae0" -dependencies = [ - "bitflags", - "libc", - "mach", - "winapi", -] - [[package]] name = "region" version = "3.0.0" @@ -1957,6 +1569,15 @@ dependencies = [ "winapi", ] +[[package]] +name = "rend" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "79af64b4b6362ffba04eef3a4e10829718a4896dac19daa741851c86781edf95" +dependencies = [ + "bytecheck", +] + [[package]] name = "ripemd160" version = "0.9.1" @@ -1964,27 +1585,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eca4ecc81b7f313189bf73ce724400a07da2a6dac19588b03c8bd76a2dcc251" dependencies = [ "block-buffer", - "digest 0.9.0", + "digest", "opaque-debug", ] [[package]] name = "rkyv" -version = "0.6.7" +version = "0.7.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb135b3e5e3311f0a254bfb00333f4bac9ef1d89888b84242a89eb8722b09a07" +checksum = "49a37de5dfc60bae2d94961dacd03c7b80e426b66a99fa1b17799570dbdd8f96" dependencies = [ - "memoffset", + "bytecheck", + "hashbrown 0.11.2", "ptr_meta", + "rend", "rkyv_derive", "seahash", ] [[package]] name = "rkyv_derive" -version = "0.6.7" +version = "0.7.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba8f489f6b6d8551bb15904293c1ad58a6abafa7d8390d15f7ed05a2afcd87d5" +checksum = "719d447dd0e84b23cee6cb5b32d97e21efb112a3e3c636c8da36647b938475a1" dependencies = [ "proc-macro2", "quote", @@ -1997,34 +1620,19 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7ef03e0a2b150c7a90d01faf6254c9c48a41e95fb2a8c2ac1c6f0d2b9aefc342" -[[package]] -name = "rustc-hash" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" - [[package]] name = "rustc-hex" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e75f6a532d0fd9f7f13144f392b6ad56a32696bfcd9c78f797f16bbb6f072d6" -[[package]] -name = "rustc_version" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -dependencies = [ - "semver 0.9.0", -] - [[package]] name = "rustc_version" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0dfe2087c51c460008730de8b57e6a320782fbfb312e1f4d520e6c6fae155ee" dependencies = [ - "semver 0.11.0", + "semver", ] [[package]] @@ -2051,30 +1659,15 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c107b6f4780854c8b126e228ea8869f4d7b71260f962fefb57b996b8959ba6b" -[[package]] -name = "semver" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" -dependencies = [ - "semver-parser 0.7.0", -] - [[package]] name = "semver" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f301af10236f6df4160f7c3f04eec6dbc70ace82d23326abad5edee88801c6b6" dependencies = [ - "semver-parser 0.10.2", + "semver-parser", ] -[[package]] -name = "semver-parser" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" - [[package]] name = "semver-parser" version = "0.10.2" @@ -2093,16 +1686,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde-bench" -version = "0.0.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d733da87e79faaac25616e33d26299a41143fd4cd42746cbb0e91d8feea243fd" -dependencies = [ - "byteorder", - "serde", -] - [[package]] name = "serde_bytes" version = "0.11.5" @@ -2144,7 +1727,7 @@ dependencies = [ "block-buffer", "cfg-if 1.0.0", "cpufeatures", - "digest 0.9.0", + "digest", "opaque-debug", ] @@ -2155,7 +1738,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f81199417d4e5de3f04b1e871023acea7389672c4135918f05aa9cbf2f2fa809" dependencies = [ "block-buffer", - "digest 0.9.0", + "digest", "keccak", "opaque-debug", ] @@ -2189,18 +1772,6 @@ dependencies = [ "syn", ] -[[package]] -name = "spin" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" - -[[package]] -name = "stable_deref_trait" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" - [[package]] name = "static_assertions" version = "1.1.0" @@ -2248,18 +1819,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" -[[package]] -name = "target-lexicon" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab0e7238dcc7b40a7be719a25365910f6807bd864f4cce6b2e6b873658e2b19d" - -[[package]] -name = "target-lexicon" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "422045212ea98508ae3d28025bc5aaa2bd4a9cdaecd442a08da2ee620ee9ea95" - [[package]] name = "target-lexicon" version = "0.12.2" @@ -2275,7 +1834,7 @@ dependencies = [ "cfg-if 1.0.0", "libc", "rand 0.8.4", - "redox_syscall 0.2.10", + "redox_syscall", "remove_dir_all", "winapi", ] @@ -2335,6 +1894,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "375a639232caf30edfc78e8d89b2d4c375515393e7af7e16f01cd96917fb2105" dependencies = [ "cfg-if 1.0.0", + "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -2360,21 +1920,6 @@ dependencies = [ "lazy_static", ] -[[package]] -name = "traitobject" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" - -[[package]] -name = "typemap" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "653be63c80a3296da5551e1bfd2cca35227e13cdd08c6668903ae2f4f77aa1f6" -dependencies = [ - "unsafe-any", -] - [[package]] name = "typenum" version = "1.14.0" @@ -2405,27 +1950,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" -[[package]] -name = "unsafe-any" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f30360d7979f5e9c6e6cea48af192ea8fab4afb3cf72597154b8f08935bc9c7f" -dependencies = [ - "traitobject", -] - [[package]] name = "version_check" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" -[[package]] -name = "void" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" - [[package]] name = "wasi" version = "0.9.0+wasi-snapshot-preview1" @@ -2494,9 +2024,9 @@ checksum = "0237232789cf037d5480773fe568aac745bfe2afbc11a863e97901780a6b47cc" [[package]] name = "wasmer-compiler" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc86dda6f715f03104800be575a38382b35c3962953af9e9d8722dcf0bd2458f" +checksum = "88c51cc589772c5f90bd329244c2416976d6cb2ee00d59429aaa8f421d9fe447" dependencies = [ "enumset", "loupe", @@ -2504,18 +2034,18 @@ dependencies = [ "serde", "serde_bytes", "smallvec", - "target-lexicon 0.12.2", + "target-lexicon", "thiserror", "wasmer-types", "wasmer-vm", - "wasmparser 0.78.2", + "wasmparser", ] [[package]] name = "wasmer-compiler-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7337099b0683652e52606b5630917a10f836dc210d4ee253bf3f83facff83b1a" +checksum = "2992fc265c0207ea423d6565a27adf1a01210eae4bb4db7aa18778a2b84f588d" dependencies = [ "enumset", "loupe", @@ -2523,18 +2053,18 @@ dependencies = [ "serde", "serde_bytes", "smallvec", - "target-lexicon 0.12.2", + "target-lexicon", "thiserror", "wasmer-types-near", "wasmer-vm-near", - "wasmparser 0.78.2", + "wasmparser", ] [[package]] name = "wasmer-compiler-singlepass-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b878963f500ee97bb86b4c7cef3d55b536f5b14d1b49d9ab36f38be2158f4c0d" +checksum = "d821094fe6e9371d528c27b0006de76b1411cf5341d7b56b1b78bf0809119313" dependencies = [ "byteorder", "dynasm", @@ -2552,9 +2082,9 @@ dependencies = [ [[package]] name = "wasmer-derive-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be5e7432ff6a7357c8a8c52d8d9af94e11e6dfe6b85026f7839556a1666e1b7" +checksum = "0c3fcfc8f5838baf311380dcf3ef9843120967ddb073273aa514a4009f50f052" dependencies = [ "proc-macro-error", "proc-macro2", @@ -2564,19 +2094,20 @@ dependencies = [ [[package]] name = "wasmer-engine" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8454ead320a4017ba36ddd9ab4fbf7776fceea6ab0b79b5e53664a1682569fc3" +checksum = "ab20311c354fe2c12bc766417e0a1a45f399c1cd8ff262127d1dc86d0588971a" dependencies = [ "backtrace", + "enumset", "lazy_static", "loupe", - "memmap2 0.2.3", + "memmap2", "more-asserts", "rustc-demangle", "serde", "serde_bytes", - "target-lexicon 0.12.2", + "target-lexicon", "thiserror", "wasmer-compiler", "wasmer-types", @@ -2585,11 +2116,12 @@ dependencies = [ [[package]] name = "wasmer-engine-dylib" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6aa390d123ebe23d5315c39f6063fcc18319661d03c8000f23d0fe1c011e8135" +checksum = "8dd5b7a74731e1dcccaf10a8ff5f72216c82f12972ce17cc81c6caa1afff75ea" dependencies = [ "cfg-if 1.0.0", + "enumset", "leb128", "libloading", "loupe", @@ -2607,19 +2139,20 @@ dependencies = [ [[package]] name = "wasmer-engine-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a44104129ff924c906c59adc4b12b4caa1867bbdb819cb0c1993597ec06db35" +checksum = "3234ef4ddd114bf4cf77b3b719d9c8727372cf05ec79d574ba447b169438eb9f" dependencies = [ "backtrace", + "enumset", "lazy_static", "loupe", - "memmap2 0.2.3", + "memmap2", "more-asserts", "rustc-demangle", "serde", "serde_bytes", - "target-lexicon 0.12.2", + "target-lexicon", "thiserror", "wasmer-compiler-near", "wasmer-types-near", @@ -2628,14 +2161,15 @@ dependencies = [ [[package]] name = "wasmer-engine-universal-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ef683f2e7236f91e20297d7dab6c82f3d1c09c45c95576af4bc4454be48f75" +checksum = "33e12a0d35b4ed05e8c881a6e04c4f5c0e66ed11a42e8a9b012482c7d0d92231" dependencies = [ "cfg-if 1.0.0", + "enumset", "leb128", "loupe", - "region 3.0.0", + "region", "rkyv", "wasmer-compiler-near", "wasmer-engine-near", @@ -2646,16 +2180,16 @@ dependencies = [ [[package]] name = "wasmer-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e92829f083cc2e319695ef1172cc114a13d45c8ef714f9cb3a7f9aabc4b10bd" +checksum = "89b1428287e6fff52908b7c74e88f49b557d3e71b6b94b67ce532bcd5f872194" dependencies = [ "cfg-if 1.0.0", "indexmap", "js-sys", "loupe", "more-asserts", - "target-lexicon 0.12.2", + "target-lexicon", "thiserror", "wasm-bindgen", "wasmer-compiler-near", @@ -2671,85 +2205,21 @@ dependencies = [ [[package]] name = "wasmer-object" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c541c985799fc1444702501c15d41becfb066c92d9673defc1c7417fd8739e15" +checksum = "c3d4714e4f3bdc3b2157c24284417d19cd99de036da31d00ec5664712dcb72f7" dependencies = [ - "object 0.25.3", + "object", "thiserror", "wasmer-compiler", "wasmer-types", ] -[[package]] -name = "wasmer-runtime-core-near" -version = "0.18.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2cf26de331c8ef4257bef33649b4665535b105c927ab2e00715f17891362efe8" -dependencies = [ - "bincode", - "blake3", - "borsh 0.9.1", - "cc", - "digest 0.8.1", - "errno", - "hex", - "indexmap", - "lazy_static", - "libc", - "nix", - "page_size", - "parking_lot", - "rustc_version 0.2.3", - "serde", - "serde-bench", - "serde_bytes", - "serde_derive", - "smallvec", - "target-lexicon 0.10.0", - "wasmparser 0.51.4", - "winapi", -] - -[[package]] -name = "wasmer-runtime-near" -version = "0.18.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "158e6fff11e5e1ef805af50637374d5bd43d92017beafa18992cdf7f3f7ae3e4" -dependencies = [ - "lazy_static", - "memmap", - "serde", - "serde_derive", - "wasmer-runtime-core-near", - "wasmer-singlepass-backend-near", -] - -[[package]] -name = "wasmer-singlepass-backend-near" -version = "0.18.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f6edd0ba6c0bcf9b279186d4dbe81649dda3e5ef38f586865943de4dcd653f8" -dependencies = [ - "bincode", - "borsh 0.9.1", - "byteorder", - "dynasm", - "dynasmrt", - "lazy_static", - "libc", - "nix", - "serde", - "serde_derive", - "smallvec", - "wasmer-runtime-core-near", -] - [[package]] name = "wasmer-types" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c91f75d3c31f8b1f8d818ff49624fc974220243cbc07a2252f408192e97c6b51" +checksum = "434e1c0177da0a74ecca90b2aa7d5e86198260f07e8ba83be89feb5f0a4aeead" dependencies = [ "indexmap", "loupe", @@ -2760,9 +2230,9 @@ dependencies = [ [[package]] name = "wasmer-types-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de952d66292b33d02350b89fcb434aba0fefd01da6507905d42ca1eb6759dc6a" +checksum = "bced21cd7e4b8a35ff58e19645000b9097ed81febba790900031c32553009464" dependencies = [ "indexmap", "loupe", @@ -2773,9 +2243,9 @@ dependencies = [ [[package]] name = "wasmer-vm" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "469a12346a4831e7dac639b9646d8c9b24c7d2cf0cf458b77f489edb35060c1f" +checksum = "cc8f964ebba70d9f81340228b98a164782591f00239fc7f01e1b67afcf0e0156" dependencies = [ "backtrace", "cc", @@ -2785,7 +2255,7 @@ dependencies = [ "loupe", "memoffset", "more-asserts", - "region 2.2.0", + "region", "rkyv", "serde", "thiserror", @@ -2795,9 +2265,9 @@ dependencies = [ [[package]] name = "wasmer-vm-near" -version = "2.0.3" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d55b8cf3d69904542534adf18370351b75fdc9bc451b7eb2dbe031d9e176c42" +checksum = "8d6848605c8cc6821314f9099a34c7163ee56e82524ebb9080b82baa3895d257" dependencies = [ "backtrace", "cc", @@ -2807,7 +2277,7 @@ dependencies = [ "loupe", "memoffset", "more-asserts", - "region 3.0.0", + "region", "rkyv", "serde", "thiserror", @@ -2816,200 +2286,34 @@ dependencies = [ ] [[package]] -name = "wasmparser" -version = "0.51.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" - -[[package]] -name = "wasmparser" -version = "0.76.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "755a9a4afe3f6cccbbe6d7e965eef44cf260b001f93e547eba84255c1d0187d8" - -[[package]] -name = "wasmparser" -version = "0.78.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" - -[[package]] -name = "wasmtime" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26ea2ad49bb047e10ca292f55cd67040bef14b676d07e7b04ed65fd312d52ece" -dependencies = [ - "anyhow", - "backtrace", - "bincode", - "cfg-if 1.0.0", - "cpp_demangle", - "indexmap", - "libc", - "log", - "paste", - "region 2.2.0", - "rustc-demangle", - "serde", - "smallvec", - "target-lexicon 0.11.2", - "wasmparser 0.76.0", - "wasmtime-environ", - "wasmtime-jit", - "wasmtime-profiling", - "wasmtime-runtime", - "winapi", -] - -[[package]] -name = "wasmtime-cranelift" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e769b80abbb89255926f69ba37085f7dd6608c980134838c3c89d7bf6e776bc" -dependencies = [ - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "cranelift-wasm", - "wasmparser 0.76.0", - "wasmtime-environ", -] - -[[package]] -name = "wasmtime-debug" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38501788c936a4932b0ddf61135963a4b7d1f549f63a6908ae56a1c86d74fc7b" -dependencies = [ - "anyhow", - "gimli 0.23.0", - "more-asserts", - "object 0.23.0", - "target-lexicon 0.11.2", - "thiserror", - "wasmparser 0.76.0", - "wasmtime-environ", -] - -[[package]] -name = "wasmtime-environ" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fae793ea1387b2fede277d209bb27285366df58f0a3ae9d59e58a7941dce60fa" -dependencies = [ - "anyhow", - "cfg-if 1.0.0", - "cranelift-codegen", - "cranelift-entity", - "cranelift-wasm", - "gimli 0.23.0", - "indexmap", - "log", - "more-asserts", - "region 2.2.0", - "serde", - "thiserror", - "wasmparser 0.76.0", -] - -[[package]] -name = "wasmtime-jit" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b3bd0fae8396473a68a1491559d61776127bb9bea75c9a6a6c038ae4a656eb2" -dependencies = [ - "addr2line 0.14.1", - "anyhow", - "cfg-if 1.0.0", - "cranelift-codegen", - "cranelift-entity", - "cranelift-frontend", - "cranelift-native", - "cranelift-wasm", - "gimli 0.23.0", - "log", - "more-asserts", - "object 0.23.0", - "region 2.2.0", - "serde", - "target-lexicon 0.11.2", - "thiserror", - "wasmparser 0.76.0", - "wasmtime-cranelift", - "wasmtime-debug", - "wasmtime-environ", - "wasmtime-lightbeam", - "wasmtime-obj", - "wasmtime-profiling", - "wasmtime-runtime", - "winapi", -] - -[[package]] -name = "wasmtime-lightbeam" -version = "0.25.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9e126bc279afd94e0b19910bc9868c8902a281d50231e5a794983c4b970db29" -dependencies = [ - "cranelift-codegen", - "lightbeam", - "wasmparser 0.76.0", - "wasmtime-environ", -] - -[[package]] -name = "wasmtime-obj" -version = "0.25.0" +name = "wasmi" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a79fa098a3be8fabc50f5be60f8e47694d569afdc255de37850fc80295485012" +checksum = "03919fcab96ed058e0c411c47b370883d6393c40307f3140876f68a9256cadb1" dependencies = [ - "anyhow", - "more-asserts", - "object 0.23.0", - "target-lexicon 0.11.2", - "wasmtime-debug", - "wasmtime-environ", + "downcast-rs", + "libm", + "memory_units", + "num-rational 0.4.0", + "num-traits", + "parity-wasm 0.42.2", + "wasmi-validation", ] [[package]] -name = "wasmtime-profiling" -version = "0.25.0" +name = "wasmi-validation" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d81e2106efeef4c01917fd16956a91d39bb78c07cf97027abdba9ca98da3f258" +checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" dependencies = [ - "anyhow", - "cfg-if 1.0.0", - "lazy_static", - "libc", - "serde", - "target-lexicon 0.11.2", - "wasmtime-environ", - "wasmtime-runtime", + "parity-wasm 0.42.2", ] [[package]] -name = "wasmtime-runtime" -version = "0.25.0" +name = "wasmparser" +version = "0.78.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f747c656ca4680cad7846ae91c57d03f2dd4f4170da77a700df4e21f0d805378" -dependencies = [ - "anyhow", - "backtrace", - "cc", - "cfg-if 1.0.0", - "indexmap", - "lazy_static", - "libc", - "log", - "memoffset", - "more-asserts", - "psm", - "rand 0.7.3", - "region 2.2.0", - "thiserror", - "wasmtime-environ", - "winapi", -] +checksum = "52144d4c78e5cf8b055ceab8e5fa22814ce4315d6002ad32cfd914f37c12fd65" [[package]] name = "wast" @@ -3088,17 +2392,3 @@ dependencies = [ "syn", "synstructure", ] - -[[package]] -name = "zeropool-bn" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "756e713befb81061c2eb8ad800c9c41ddfa2bbf4ea58da637aff31d47b937bf2" -dependencies = [ - "borsh 0.8.2", - "byteorder", - "crunchy", - "lazy_static", - "rand 0.8.4", - "rustc-hex", -] diff --git a/mock-enclave/src/near-vm-runner/Cargo.toml b/mock-enclave/src/near-vm-runner/Cargo.toml index 406329e..2c41fff 100644 --- a/mock-enclave/src/near-vm-runner/Cargo.toml +++ b/mock-enclave/src/near-vm-runner/Cargo.toml @@ -16,25 +16,11 @@ This crate implements the specification of the interface that Near blockchain ex [dependencies] borsh = "0.9" serde = { version = "1", features = ["derive"] } -wasmer-runtime = { version = "0.18.0", features = ["default-backend-singlepass"], default-features = false, package = "wasmer-runtime-near", optional = true } -wasmer-runtime-core = { version = "0.18.2", package = "wasmer-runtime-core-near", optional = true} wasmparser = "0.78" memoffset = "0.6" - -# Use the following for development versions of Wasmer. -# wasmer = { package = "wasmer-near", git = "https://github.com/near/wasmer", branch = "near-main", optional = true, default-features = false, features = ["singlepass", "universal"] } -# wasmer-types = { package = "wasmer-types-near", git = "https://github.com/near/wasmer", branch = "near-main", optional = true } -# wasmer-compiler-singlepass = { package = "wasmer-compiler-singlepass-near", git = "https://github.com/near/wasmer", branch = "near-main", optional = true } -# wasmer-engine-universal = { package = "wasmer-engine-universal-near", git = "https://github.com/near/wasmer", branch = "near-main", optional = true } -# wasmer-vm = { package = "wasmer-vm-near", git = "https://github.com/near/wasmer", branch = "near-main" } -wasmer = { package = "wasmer-near", version = "=2.0.3", optional = true, default-features = false, features = ["singlepass", "universal"] } -wasmer-types = { package = "wasmer-types-near", version = "=2.0.3", optional = true } -wasmer-compiler-singlepass = { package = "wasmer-compiler-singlepass-near", version = "=2.0.3", optional = true } -wasmer-engine-universal = { package = "wasmer-engine-universal-near", version = "=2.0.3", optional = true } -wasmer-vm = { package = "wasmer-vm-near", version = "=2.0.3" } - pwasm-utils = "0.12" parity-wasm = "0.41" +wasmi = "0.10.0" anyhow = { version = "1.0.19", optional = true } near-vm-logic = { path = "../near-vm-logic", default-features = false, features = [] } near-vm-errors = { path = "../near-vm-errors" } @@ -44,6 +30,12 @@ cached = "0.23.0" tracing = { version = "0.1", default-features = false } threadpool = "1.8.1" +wasmer = { package = "wasmer-near", version = "=2.1.2", optional = true, default-features = false, features = ["singlepass", "universal"] } +wasmer-types = { package = "wasmer-types-near", version = "=2.1.2", optional = true } +wasmer-compiler-singlepass = { package = "wasmer-compiler-singlepass-near", version = "=2.1.2", optional = true } +wasmer-engine-universal = { package = "wasmer-engine-universal-near", version = "=2.1.2", optional = true } +wasmer-vm = { package = "wasmer-vm-near", version = "=2.1.2" } + [dev-dependencies] near-test-contracts = { git = "https://github.com/near/nearcore" } assert_matches = "1.3" diff --git a/mock-enclave/src/near-vm-runner/src/cache.rs b/mock-enclave/src/near-vm-runner/src/cache.rs index 7d8092d..440f538 100644 --- a/mock-enclave/src/near-vm-runner/src/cache.rs +++ b/mock-enclave/src/near-vm-runner/src/cache.rs @@ -1,7 +1,7 @@ use crate::errors::ContractPrecompilatonResult; use crate::prepare; -use crate::vm_kind::VMKind; -use crate::wasmer2_runner::{default_wasmer2_store, wasmer2_vm_hash}; +use crate::wasmi_runner::{wasmi_vm_hash}; +use parity_wasm::elements::Module; use borsh::{BorshDeserialize, BorshSerialize}; #[cfg(not(feature = "no_cache"))] use cached::{cached_key, SizedCache}; @@ -19,7 +19,6 @@ enum ContractCacheKey { Version1 { code_hash: CryptoHash, vm_config_non_crypto_hash: u64, - vm_kind: VMKind, vm_hash: u64, }, } @@ -32,15 +31,13 @@ enum CacheRecord { pub fn get_contract_cache_key( code: &ContractCode, - vm_kind: VMKind, config: &VMConfig, ) -> CryptoHash { let _span = tracing::debug_span!(target: "vm", "get_key").entered(); let key = ContractCacheKey::Version1 { code_hash: *code.hash(), vm_config_non_crypto_hash: config.non_crypto_hash(), - vm_kind, - vm_hash: wasmer2_vm_hash(), + vm_hash: wasmi_vm_hash(), }; near_primitives::hash::hash(&key.try_to_vec().unwrap()) } @@ -100,53 +97,35 @@ impl fmt::Debug for MockCompiledContractCache { #[cfg(not(feature = "no_cache"))] const CACHE_SIZE: usize = 128; -#[cfg(feature = "wasmer2_vm")] -pub mod wasmer2_cache { +pub mod wasmi_cache { use near_primitives::contract::ContractCode; use super::*; - fn compile_module_wasmer2( + fn compile_module_wasmi( code: &[u8], config: &VMConfig, - store: &wasmer::Store, - ) -> Result { - let _span = tracing::debug_span!(target: "vm", "compile_module_wasmer2").entered(); + ) -> Result { + let _span = tracing::debug_span!(target: "vm", "compile_module_wasmi").entered(); let prepared_code = prepare::prepare_contract(code, config).map_err(CompilationError::PrepareError)?; - wasmer::Module::new(&store, prepared_code).map_err(|err| match err { - wasmer::CompileError::Wasm(_) => { - CompilationError::WasmerCompileError { msg: err.to_string() } - } - wasmer::CompileError::Codegen(_) => { - CompilationError::WasmerCompileError { msg: err.to_string() } - } - wasmer::CompileError::Validate(_) => { - CompilationError::WasmerCompileError { msg: err.to_string() } - } - wasmer::CompileError::UnsupportedFeature(_) => { - CompilationError::WasmerCompileError { msg: err.to_string() } - } - wasmer::CompileError::UnsupportedTarget(_) => { - CompilationError::WasmerCompileError { msg: err.to_string() } - } - wasmer::CompileError::Resource(_) => { + 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_wasmer2( + pub(crate) fn compile_and_serialize_wasmi( wasm_code: &[u8], key: &CryptoHash, config: &VMConfig, cache: &dyn CompiledContractCache, - store: &wasmer::Store, - ) -> Result, CacheError> { - let _span = tracing::debug_span!(target: "vm", "compile_and_serialize_wasmer2").entered(); + ) -> Result, CacheError> { + let _span = tracing::debug_span!(target: "vm", "compile_and_serialize_wasmi").entered(); - let module = match compile_module_wasmer2(wasm_code, config, store) { + let module = match compile_module_wasmi(wasm_code, config) { Ok(module) => module, Err(err) => { cache_error(&err, key, cache)?; @@ -155,16 +134,15 @@ pub mod wasmer2_cache { }; let code = - module.serialize().map_err(|_e| CacheError::SerializationError { hash: key.0 })?; + 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_wasmer2( + fn deserialize_wasmi( serialized: &[u8], - store: &wasmer::Store, - ) -> Result, CacheError> { + ) -> Result, CacheError> { let _span = tracing::debug_span!(target: "vm", "deserialize_wasmer2").entered(); let record = CacheRecord::try_from_slice(serialized) @@ -174,65 +152,63 @@ pub mod wasmer2_cache { CacheRecord::Code(code) => code, }; unsafe { - Ok(Ok(wasmer::Module::deserialize(store, serialized_module.as_slice()) - .map_err(|_e| CacheError::DeserializationError)?)) + Ok(Ok(Module::fron_bytes(serialized_module.as_slice().map_err(|_e| CacheError::DeserializationError)?))) } } - fn compile_module_cached_wasmer2_impl( + fn compile_module_cached_wasmi_impl( key: CryptoHash, wasm_code: &[u8], config: &VMConfig, cache: Option<&dyn CompiledContractCache>, - store: &wasmer::Store, - ) -> Result, CacheError> { + ) -> Result, CacheError> { match cache { - None => Ok(compile_module_wasmer2(wasm_code, config, store)), + 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_wasmer2(serialized.as_slice(), store), - None => compile_and_serialize_wasmer2(wasm_code, &key, config, cache, store), + Some(serialized) => deserialize_wasmi(serialized.as_slice()), + None => compile_and_serialize_wasmi(wasm_code, &key, config, cache), } } } } - #[cfg(not(feature = "no_cache"))] - cached_key! { - MODULES: SizedCache, CacheError>> - = SizedCache::with_size(CACHE_SIZE); - Key = { - key - }; - - fn memcache_compile_module_cached_wasmer2( - key: CryptoHash, - wasm_code: &[u8], - config: &VMConfig, - cache: Option<&dyn CompiledContractCache>, - store: &wasmer::Store - ) -> Result, CacheError> = { - compile_module_cached_wasmer2_impl(key, wasm_code, config, cache, store) - } - } - - pub(crate) fn compile_module_cached_wasmer2( + // #[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>, - store: &wasmer::Store, - ) -> Result, CacheError> { - let key = get_contract_cache_key(code, VMKind::Wasmer2, config); - #[cfg(not(feature = "no_cache"))] - return memcache_compile_module_cached_wasmer2(key, &code.code(), config, cache, store); + ) -> 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_wasmer2_impl(key, &code.code(), config, cache, store); + return compile_module_cached_wasmi_impl(key, &code.code(), config, cache); } } -pub fn precompile_contract_vm( - vm_kind: VMKind, +/// 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>, @@ -241,7 +217,8 @@ pub fn precompile_contract_vm( None => return Ok(Ok(ContractPrecompilatonResult::CacheNotAvailable)), Some(it) => it, }; - let key = get_contract_cache_key(wasm_code, vm_kind, config); + + 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. @@ -249,28 +226,13 @@ pub fn precompile_contract_vm( None => {} }; let res = { - let store = default_wasmer2_store(); - wasmer2_cache::compile_and_serialize_wasmer2( + wasmi_cache::compile_and_serialize_wasmi( wasm_code.code(), &key, config, cache, - &store, )? .map(|_module| ()) }; Ok(res.map(|()| ContractPrecompilatonResult::ContractCompiled)) } - -/// 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, - current_protocol_version: ProtocolVersion, - cache: Option<&dyn CompiledContractCache>, -) -> Result, CacheError> { - let vm_kind = VMKind::for_protocol_version(current_protocol_version); - precompile_contract_vm(vm_kind, wasm_code, config, cache) -} diff --git a/mock-enclave/src/near-vm-runner/src/imports.rs b/mock-enclave/src/near-vm-runner/src/imports.rs index ff49932..16bd12b 100644 --- a/mock-enclave/src/near-vm-runner/src/imports.rs +++ b/mock-enclave/src/near-vm-runner/src/imports.rs @@ -1,231 +1,448 @@ -use near_primitives::version::ProtocolVersion; -use near_vm_logic::VMLogic; +//! Host function interface for smart contracts. +//! +//! Besides native WASM operations, smart contracts can call into runtime to +//! gain access to extra functionality, like operations with store. Such +//! "extras" are called "Host function", and play a role similar to syscalls. In +//! this module, we integrate host functions with various wasm runtimes we +//! support. The actual definitions of host functions live in the `vm-logic` +//! crate. +//! +//! Basically, what the following code does is (in pseudo-code): +//! +//! ```ignore +//! for host_fn in all_host_functions { +//! wasm_imports.define("env", host_fn.name, |args| host_fn(args)) +//! } +//! ``` +//! +//! The actual implementation is a bit more complicated, for two reasons. First, +//! host functions have different signatures, so there isn't a trivial single +//! type one can use to hold a host function. Second, we want to use direct +//! calls in the compiled WASM, so we need to avoid dynamic dispatch and hand +//! functions as ZSTs to the WASM runtimes. This basically means that we need to +//! code the above for-loop as a macro. +//! +//! So, the `imports!` macro invocation is the main "public" API -- it just list +//! all host functions with their signatures. `imports! { foo, bar, baz }` +//! expands to roughly +//! +//! ```ignore +//! macro_rules! for_each_available_import { +//! $($M:ident) => { +//! $M!(foo); +//! $M!(bar); +//! $M!(baz); +//! } +//! } +//! ``` +//! +//! That is, `for_each_available_import` is a high-order macro which takes macro +//! `M` as a parameter, and calls `M!` with each import. Each supported WASM +//! runtime (see submodules of this module) then calls +//! `for_each_available_import` with its own import definition logic. +//! +//! The real `for_each_available_import` takes one more argument -- +//! `protocol_version`. We can add new imports, but we must make sure that they +//! are only available to contracts at a specific protocol version -- we can't +//! make imports retroactively available to old transactions. So +//! `for_each_available_import` takes care to invoke `M!` only for currently +//! available imports. -use std::ffi::c_void; +// macro_rules! imports { +// ( +// $($(#[$stable_feature:ident])? $(#[$feature_name:literal, $feature:ident])* +// $func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] >,)* +// ) => { +// macro_rules! for_each_available_import { +// ($protocol_version:ident, $M:ident) => {$( +// $(#[cfg(feature = $feature_name)])* +// if true +// $(&& near_primitives::checked_feature!($feature_name, $feature, $protocol_version))* +// $(&& near_primitives::checked_feature!("stable", $stable_feature, $protocol_version))? +// { +// $M!($func < [ $( $arg_name : $arg_type ),* ] -> [ $( $returns ),* ] >); +// } +// )*} +// } +// } +// } -#[derive(Clone, Copy)] -pub struct ImportReference(pub *mut c_void); -unsafe impl Send for ImportReference {} -unsafe impl Sync for ImportReference {} -#[cfg(feature = "wasmer2_vm")] -use wasmer::{Memory, WasmerEnv}; +macro_rules! index_to_field_name { + (0) => ("read_register"); + (1) => ("register_len"); + (2) => ("write_register"); + (3) => ("current_account_id"); + (4) => ("signer_account_id"); + (5) => ("signer_account_pk"); + (6) => ("predecessor_account_id"); + (7) => ("input"); + (8) => ("block_index"); + (9) => ("block_timestamp"); + (10) => ("epoch_height"); + (11) => ("storage_usage"); + (12) => ("account_balance"); + (13) => ("account_locked_balance"); + (14) => ("attached_deposit"); + (15) => ("prepaid_gas"); + (16) => ("used_gas"); + (17) => ("random_seed"); + (18) => ("sha256"); + (19) => ("keccak256"); + (20) => ("keccak512"); + (21) => ("ripemd160"); + (22) => ("ecrecover"); + (23) => ("value_return"); + (24) => ("panic"); + (25) => ("panic_utf8"); + (26) => ("log_utf8"); + (27) => ("log_utf16"); + (28) => ("abort"); + (29) => ("promise_create"); + (30) => ("promise_then"); + (31) => ("promise_and"); + (32) => ("promise_batch_create"); + (33) => ("promise_batch_then"); + (34) => ("promise_batch_action_create_account"); + (35) => ("promise_batch_action_deploy_contract"); + (36) => ("promise_batch_action_function_call"); + (37) => ("promise_batch_action_transfer"); + (38) => ("promise_batch_action_stake"); + (39) => ("promise_batch_action_add_key_with_full_access"); + (40) => ("promise_batch_action_add_key_with_function_call"); + (41) => ("promise_batch_action_delete_key"); + (42) => ("promise_batch_action_delete_account"); + (43) => ("promise_results_count"); + (44) => ("promise_result"); + (45) => ("promise_return"); + (46) => ("storage_write"); + (47) => ("storage_read"); + (48) => ("storage_remove"); + (49) => ("storage_has_key"); + (50) => ("storage_iter_prefix"); + (51) => ("storage_iter_range"); + (52) => ("storage_iter_next"); + (53) => ("gas"); + (54) => ("validator_stake"); + (55) => ("validator_total_stake"); +} -#[derive(WasmerEnv, Clone)] -#[cfg(feature = "wasmer2_vm")] -pub struct NearWasmerEnv { - pub memory: Memory, - pub logic: ImportReference, +macro_rules! filed_name_to_index { + ("read_register") => {0}; + ("register_len") => {1}; + ("write_register") => {2}; + ("current_account_id") => {3}; + ("signer_account_id") => {4}; + ("signer_account_pk") => {5}; + ("predecessor_account_id") => {6}; + ("input") => {7}; + ("block_index") => {8}; + ("block_timestamp") => {9}; + ("epoch_height") => {10}; + ("storage_usage") => {11}; + ("account_balance") => {12}; + ("account_locked_balance") => {13}; + ("attached_deposit") => {14}; + ("prepaid_gas") => {15}; + ("used_gas") => {16}; + ("random_seed") => {17}; + ("sha256") => {18}; + ("keccak256") => {19}; + ("keccak512") => {20}; + ("ripemd160") => {21}; + ("ecrecover") => {22}; + ("value_return") => {23}; + ("panic") => {24}; + ("panic_utf8") => {25}; + ("log_utf8") => {26}; + ("log_utf16") => {27}; + ("abort") => {28}; + ("promise_create") => {29}; + ("promise_then") => {30}; + ("promise_and") => {31}; + ("promise_batch_create") => {32}; + ("promise_batch_then") => {33}; + ("promise_batch_action_create_account") => {34}; + ("promise_batch_action_deploy_contract") => {35}; + ("promise_batch_action_function_call") => {36}; + ("promise_batch_action_transfer") => {37}; + ("promise_batch_action_stake") => {38}; + ("promise_batch_action_add_key_with_full_access") => {39}; + ("promise_batch_action_add_key_with_function_call") => {40}; + ("promise_batch_action_delete_key") => {41}; + ("promise_batch_action_delete_account") => {42}; + ("promise_results_count") => {43}; + ("promise_result") => {44}; + ("promise_return") => {45}; + ("storage_write") => {46}; + ("storage_read") => {47}; + ("storage_remove") => {48}; + ("storage_has_key") => {49}; + ("storage_iter_prefix") => {50}; + ("storage_iter_range") => {51}; + ("storage_iter_next") => {52}; + ("gas") => {53}; + ("validator_stake") => {54}; + ("validator_total_stake") => {55}; } -const fn str_eq(s1: &str, s2: &str) -> bool { - let s1 = s1.as_bytes(); - let s2 = s2.as_bytes(); - if s1.len() != s2.len() { - return false; - } - let mut i = 0; - while i < s1.len() { - if s1[i] != s2[i] { - return false; +macro_rules! imports { + ( + $($func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] >,)* + ) => { + macro_rules! for_each_available_import { + ($M:ident) => {$( + $M!($func < [ $( $arg_name : $arg_type ),* ] -> [ $( $returns ),* ] >); + )*} } - i += 1; } - true } -macro_rules! wrapped_imports { - ( $($(#[$stable_feature:ident])? $(#[$feature_name:literal, $feature:ident])* $func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] >, )* ) => { - - #[cfg(feature = "wasmer2_vm")] - pub mod wasmer2_ext { - use near_vm_logic::VMLogic; - use crate::imports::NearWasmerEnv; - use crate::imports::str_eq; - - type VMResult = ::std::result::Result; - $( - #[allow(unused_parens)] - $(#[cfg(feature = $feature_name)])* - pub fn $func(env: &NearWasmerEnv, $( $arg_name: $arg_type ),* ) -> VMResult<($( $returns ),*)> { - const IS_GAS: bool = str_eq(stringify!($func), "gas"); - let _span = if IS_GAS { - None - } else { - Some(tracing::debug_span!(target: "host-function", stringify!($func)).entered()) - }; - let logic: &mut VMLogic = unsafe { &mut *(env.logic.0 as *mut VMLogic<'_>) }; - logic.$func( $( $arg_name, )* ) - } - )* - } - - #[allow(unused_variables)] - #[cfg(feature = "wasmer2_vm")] - pub(crate) fn build_wasmer2( - store: &wasmer::Store, - memory: wasmer::Memory, - logic: &mut VMLogic<'_>, - protocol_version: ProtocolVersion, - ) -> wasmer::ImportObject { - let env = NearWasmerEnv {logic: ImportReference(logic as * mut _ as * mut c_void), memory: memory.clone()}; - let mut import_object = wasmer::ImportObject::new(); - let mut namespace = wasmer::Exports::new(); - namespace.insert("memory", memory); - $({ - $(#[cfg(feature = $feature_name)])* - if true $(&& near_primitives::checked_feature!($feature_name, $feature, protocol_version))* $(&& near_primitives::checked_feature!("stable", $stable_feature, protocol_version))? { - namespace.insert(stringify!($func), wasmer::Function::new_native_with_env(&store, env.clone(), wasmer2_ext::$func)); - } - })* - import_object.register("env", namespace); - import_object - } - } - } +macro_rules! wasm_to_rust_types { + (I32) => {u32}; + (I64) => {u64}; + () => (); +} -wrapped_imports! { +imports! { // ############# // # Registers # // ############# - read_register<[register_id: u64, ptr: u64] -> []>, - register_len<[register_id: u64] -> [u64]>, - write_register<[register_id: u64, data_len: u64, data_ptr: u64] -> []>, + read_register<[0: I64, 1: I64] -> []>, + register_len<[0: I64] -> [I64]>, + write_register<[0: I64, 1: I64, 2: I64] -> []>, // ############### // # Context API # // ############### - current_account_id<[register_id: u64] -> []>, - signer_account_id<[register_id: u64] -> []>, - signer_account_pk<[register_id: u64] -> []>, - predecessor_account_id<[register_id: u64] -> []>, - input<[register_id: u64] -> []>, - // TODO #1903 rename to `block_height` - block_index<[] -> [u64]>, - block_timestamp<[] -> [u64]>, - epoch_height<[] -> [u64]>, - storage_usage<[] -> [u64]>, + current_account_id<[0: I64] -> []>, + signer_account_id<[0: I64] -> []>, + signer_account_pk<[0: I64] -> []>, + predecessor_account_id<[0: I64] -> []>, + input<[0: I64] -> []>, + block_index<[] -> [I64]>, + block_timestamp<[] -> [I64]>, + epoch_height<[] -> [I64]>, + storage_usage<[] -> [I64]>, // ################# // # Economics API # // ################# - account_balance<[balance_ptr: u64] -> []>, - account_locked_balance<[balance_ptr: u64] -> []>, - attached_deposit<[balance_ptr: u64] -> []>, - prepaid_gas<[] -> [u64]>, - used_gas<[] -> [u64]>, + account_balance<[0: I64] -> []>, + account_locked_balance<[0: I64] -> []>, + attached_deposit<[0: I64] -> []>, + prepaid_gas<[] -> [I64]>, + used_gas<[] -> [I64]>, // ############ // # Math API # // ############ - random_seed<[register_id: u64] -> []>, - sha256<[value_len: u64, value_ptr: u64, register_id: u64] -> []>, - keccak256<[value_len: u64, value_ptr: u64, register_id: u64] -> []>, - keccak512<[value_len: u64, value_ptr: u64, register_id: u64] -> []>, - #[MathExtension] ripemd160<[value_len: u64, value_ptr: u64, register_id: u64] -> []>, - #[MathExtension] ecrecover<[hash_len: u64, hash_ptr: u64, sign_len: u64, sig_ptr: u64, v: u64, malleability_flag: u64, register_id: u64] -> [u64]>, + random_seed<[0: I64] -> []>, + sha256<[0: I64, 1: I64, 2: I64] -> []>, + keccak256<[0: I64, 1: I64, 2: I64] -> []>, + keccak512<[0: I64, 1: I64, 2: I64] -> []>, + #[MathExtension] ripemd160<[0: I64, 1: I64, 2: I64] -> []>, + #[MathExtension] ecrecover<[0: I64, 1: I64, 2: I64, 3: I64, 4: I64, 5: I64, 6: I64] -> [I64]>, // ##################### // # Miscellaneous API # // ##################### - value_return<[value_len: u64, value_ptr: u64] -> []>, + value_return<[0: I64, 1: I64] -> []>, panic<[] -> []>, - panic_utf8<[len: u64, ptr: u64] -> []>, - log_utf8<[len: u64, ptr: u64] -> []>, - log_utf16<[len: u64, ptr: u64] -> []>, - abort<[msg_ptr: u32, filename_ptr: u32, line: u32, col: u32] -> []>, + panic_utf8<[0: I64, 1: I64] -> []>, + log_utf8<[0: I64, 1: I64] -> []>, + log_utf16<[0: I64, 1: I64] -> []>, + abort<[0: I32, 1: I32, 2: I32, 3: I32] -> []>, // ################ // # Promises API # // ################ promise_create<[ - account_id_len: u64, - account_id_ptr: u64, - method_name_len: u64, - method_name_ptr: u64, - arguments_len: u64, - arguments_ptr: u64, - amount_ptr: u64, - gas: u64 - ] -> [u64]>, + 0: I64, + 1: I64, + 2: I64, + 3: I64, + 4: I64, + 5: I64, + 6: I64, + 7: I64 + ] -> [I64]>, promise_then<[ - promise_index: u64, - account_id_len: u64, - account_id_ptr: u64, - method_name_len: u64, - method_name_ptr: u64, - arguments_len: u64, - arguments_ptr: u64, - amount_ptr: u64, - gas: u64 - ] -> [u64]>, - promise_and<[promise_idx_ptr: u64, promise_idx_count: u64] -> [u64]>, - promise_batch_create<[account_id_len: u64, account_id_ptr: u64] -> [u64]>, - promise_batch_then<[promise_index: u64, account_id_len: u64, account_id_ptr: u64] -> [u64]>, + 0: I64, + 1: I64, + 2: I64, + 3: I64, + 4: I64, + 5: I64, + 6: I64, + 7: I64, + 8: I64 + ] -> [I64]>, + promise_and<[0: I64, 1: I64] -> [I64]>, + promise_batch_create<[0: I64, 1: I64] -> [I64]>, + promise_batch_then<[0: I64, 1: I64, 2: I64] -> [I64]>, // ####################### // # Promise API actions # // ####################### - promise_batch_action_create_account<[promise_index: u64] -> []>, - promise_batch_action_deploy_contract<[promise_index: u64, code_len: u64, code_ptr: u64] -> []>, + promise_batch_action_create_account<[0: I64] -> []>, + promise_batch_action_deploy_contract<[0: I64, 1: I64, 2: I64] -> []>, promise_batch_action_function_call<[ - promise_index: u64, - method_name_len: u64, - method_name_ptr: u64, - arguments_len: u64, - arguments_ptr: u64, - amount_ptr: u64, - gas: u64 + 0: I64, + 1: I64, + 2: I64, + 3: I64, + 4: I64, + 5: I64, + 6: I64 ] -> []>, - promise_batch_action_transfer<[promise_index: u64, amount_ptr: u64] -> []>, + promise_batch_action_transfer<[0: I64, 1: I64] -> []>, promise_batch_action_stake<[ - promise_index: u64, - amount_ptr: u64, - public_key_len: u64, - public_key_ptr: u64 + 0: I64, + 1: I64, + 2: I64, + 3: I64 ] -> []>, promise_batch_action_add_key_with_full_access<[ - promise_index: u64, - public_key_len: u64, - public_key_ptr: u64, - nonce: u64 + 0: I64, + 1: I64, + 2: I64, + 3: I64 ] -> []>, 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 + 0: I64, + 1: I64, + 2: I64, + 3: I64, + 4: I64, + 5: I64, + 6: I64, + 7: I64, + 8: I64 ] -> []>, promise_batch_action_delete_key<[ - promise_index: u64, - public_key_len: u64, - public_key_ptr: u64 + 0: I64, + 1: I64, + 2: I64 ] -> []>, promise_batch_action_delete_account<[ - promise_index: u64, - beneficiary_id_len: u64, - beneficiary_id_ptr: u64 + 0: I64, + 1: I64, + 2: I64 ] -> []>, // ####################### // # Promise API results # // ####################### - promise_results_count<[] -> [u64]>, - promise_result<[result_idx: u64, register_id: u64] -> [u64]>, - promise_return<[promise_idx: u64] -> []>, + promise_results_count<[] -> [I64]>, + promise_result<[0: I64, 1: I64] -> [I64]>, + promise_return<[0: I64] -> []>, // ############### // # Storage API # // ############### - storage_write<[key_len: u64, key_ptr: u64, value_len: u64, value_ptr: u64, register_id: u64] -> [u64]>, - storage_read<[key_len: u64, key_ptr: u64, register_id: u64] -> [u64]>, - storage_remove<[key_len: u64, key_ptr: u64, register_id: u64] -> [u64]>, - storage_has_key<[key_len: u64, key_ptr: u64] -> [u64]>, - storage_iter_prefix<[prefix_len: u64, prefix_ptr: u64] -> [u64]>, - storage_iter_range<[start_len: u64, start_ptr: u64, end_len: u64, end_ptr: u64] -> [u64]>, - storage_iter_next<[iterator_id: u64, key_register_id: u64, value_register_id: u64] -> [u64]>, + storage_write<[0: I64, 1: I64, 2: I64, value_ptr: I64, 3: I64] -> [I64]>, + storage_read<[0: I64, 1: I64, 2: I64] -> [I64]>, + storage_remove<[0: I64, 1: I64, 2: I64] -> [I64]>, + storage_has_key<[0: I64, 1: I64] -> [I64]>, + storage_iter_prefix<[0: I64, 1: I64] -> [I64]>, + storage_iter_range<[0: I64, 1: I64, 2: I64, 3: I64] -> [I64]>, + storage_iter_next<[0: I64, 1: I64, 2: I64] -> [I64]>, // Function for the injected gas counter. Automatically called by the gas meter. - gas<[gas_amount: u32] -> []>, + gas<[0: I32] -> []>, // ############### // # Validator API # // ############### - validator_stake<[account_id_len: u64, account_id_ptr: u64, stake_ptr: u64] -> []>, - validator_total_stake<[stake_ptr: u64] -> []>, + validator_stake<[0: I64, 1: I64, 2: I64] -> []>, + validator_total_stake<[0: I64] -> []>, +} + +pub(crate) mod wasmi_import { + use near_vm_logic::{ProtocolVersion, VMLogic, VMLogicError}; + use wasmi::{ + Externals, RuntimeValue, RuntimeArgs, Error, ModuleImportResolver, + FuncRef, Signature, FuncInstance, Trap, ValueType, ImportsBuilder, + }; + + #[derive(Clone)] + struct HostExternals {} + + impl Externals for HostExternals { + fn invoke_index( + &mut self, + index: usize, + args: RuntimeArgs, + ) -> Result, Trap> { + macro_rules! add_impl_by_index { + ( + $func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] > + ) => { + filed_name_to_index!(stringify!($func)) => { + const IS_GAS: bool = str_eq(stringify!($func), "gas"); + let _span = if IS_GAS { + None + } else { + Some(tracing::trace_span!(target: "host-function", stringify!($func)).entered()) + }; + let logic: &mut VMLogic = unsafe { &mut *(args.nth_checked(0)?.logic as *mut VMLogic<'_>) }; + let out = logic.$func( $( args.nth_checked($arg_name)?, )* ); + Ok(Some(RuntimeValue::$returns(result as wasm_to_rust_types!($returns)))) + } + }; + } + + match index { + for_each_available_import!(add_impl_by_index) + // _ => panic!("Unimplemented function at {}", index), + } + } + } + + impl ModuleImportResolver for HostExternals { + fn resolve_func( + &self, + field_name: &str, + signature: &Signature + ) -> Result { + macro_rules! get_index_from_name { + ( + $func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] > + ) => { + stringify!($func) => index_to_field_name!(stringify!($func)) + }; + } + + let index = match field_name { + for_each_available_import!(get_index_from_name) + // _ => { + // return Err(Error::Instantiation( + // format!("Export {} not found", field_name), + // )) + // } + }; + + macro_rules! get_sig_by_index { + ( + $func:ident < [ $( $arg_name:ident : $arg_type:ident ),* ] -> [ $( $returns:ident ),* ] > + ) => { + filed_name_to_index!(stringify!($func)) => (&[$( ValueType($arg_type)?, )*], Some(ValueType::$returns)) + }; + } + let (params, ret_ty): (&[ValueType], Option) = match index { + for_each_available_import!(get_sig_by_index) + // _ => return false, + }; + + if !(signature.params() == params && signature.return_type() == ret_ty) { + return Err(Error::Instantiation( + format!("Export {} has a bad signature", field_name) + )); + } + + Ok(FuncInstance::alloc_host( + Signature::new(params, ret_ty), + index, + )) + } + } + + + pub(crate) fn build<'a>( + logic: &'a mut VMLogic<'_>, + ) -> ImportsBuilder<'a> { + ImportsBuilder::new() + .with_resolver("env", &HostExternals) + } } diff --git a/mock-enclave/src/near-vm-runner/src/lib.rs b/mock-enclave/src/near-vm-runner/src/lib.rs index 5d41d5c..77159ce 100644 --- a/mock-enclave/src/near-vm-runner/src/lib.rs +++ b/mock-enclave/src/near-vm-runner/src/lib.rs @@ -9,8 +9,7 @@ mod runner; #[cfg(test)] mod tests; mod vm_kind; -#[cfg(feature = "wasmer2_vm")] -mod wasmer2_runner; +mod wasmi_runner; pub use near_vm_errors::VMError; pub use near_vm_logic::with_ext_cost_counter; @@ -21,10 +20,4 @@ pub use cache::precompile_contract_vm; pub use cache::MockCompiledContractCache; pub use preload::{ContractCallPrepareRequest, ContractCallPrepareResult, ContractCaller}; pub use runner::{run, VM}; - -/// This is public for internal experimentation use only, and should otherwise be considered an -/// implementation detail of `near-vm-runner`. -#[doc(hidden)] -pub mod internal { - pub use crate::vm_kind::VMKind; -} +pub use wasmi_runner; diff --git a/mock-enclave/src/near-vm-runner/src/runner.rs b/mock-enclave/src/near-vm-runner/src/runner.rs index b1f46c4..92bbd76 100644 --- a/mock-enclave/src/near-vm-runner/src/runner.rs +++ b/mock-enclave/src/near-vm-runner/src/runner.rs @@ -6,8 +6,6 @@ use near_vm_errors::VMError; use near_vm_logic::types::PromiseResult; use near_vm_logic::{External, VMContext, VMOutcome}; -use crate::vm_kind::VMKind; - /// Validate and run the specified contract. /// /// This is the entry point for executing a NEAR protocol contract. Before the entry point (as @@ -32,22 +30,19 @@ pub fn run( current_protocol_version: ProtocolVersion, cache: Option<&dyn CompiledContractCache>, ) -> (Option, Option) { - let vm_kind = VMKind::for_protocol_version(current_protocol_version); - if let Some(runtime) = vm_kind.runtime() { - runtime.run( - code, - method_name, - ext, - context, - wasm_config, - fees_config, - promise_results, - current_protocol_version, - cache, - ) - } else { - panic!("the {:?} runtime has not been enabled at compile time", vm_kind); - } + use crate::wasmi_runner::WasmiVM; + // let runtime = &WasmiVM as &'static dyn VM; + WasmiVM::run( + code, + method_name, + ext, + context, + wasm_config, + fees_config, + promise_results, + current_protocol_version, + cache, + ) } pub trait VM { @@ -91,20 +86,3 @@ pub trait VM { /// This is intended primarily for testing purposes. fn check_compile(&self, code: &Vec) -> bool; } - -impl VMKind { - /// Make a [`Runtime`] for this [`VMKind`]. - /// - /// This is not intended to be used by code other than standalone-vm-runner. - pub fn runtime(&self) -> Option<&'static dyn VM> { - match self { - #[cfg(feature = "wasmer2_vm")] - Self::Wasmer2 => { - use crate::wasmer2_runner::Wasmer2VM; - Some(&Wasmer2VM as &'static dyn VM) - } - #[allow(unreachable_patterns)] // reachable when some of the VMs are disabled. - _ => None, - } - } -} diff --git a/mock-enclave/src/near-vm-runner/src/vm_kind.rs b/mock-enclave/src/near-vm-runner/src/vm_kind.rs deleted file mode 100644 index 0415d63..0000000 --- a/mock-enclave/src/near-vm-runner/src/vm_kind.rs +++ /dev/null @@ -1,33 +0,0 @@ -use borsh::BorshSerialize; -use near_primitives::checked_feature; -use near_vm_logic::ProtocolVersion; -use std::hash::Hash; - -#[derive(Clone, Copy, Debug, Hash, BorshSerialize)] -// Note, that VMKind is part of serialization protocol, so we cannor remove entries -// from this list if particular VM reached publically visible networks. -// -// Additionally, this is public only for the purposes of the standalone VM runner. This API should -// otherwise be considered a private implementation detail of the `near-vm-runner` crate. -pub enum VMKind { - // /// Wasmer 0.17.x VM. - // Wasmer0, - // /// Wasmtime VM. - // Wasmtime, - // Wasmer 2.x VM, - Wasmer2, -} - -impl VMKind { - pub fn for_protocol_version(protocol_version: ProtocolVersion) -> VMKind { - if cfg!(feature = "force_wasmer2") { - return VMKind::Wasmer2; - } - - if checked_feature!("stable", Wasmer2, protocol_version) { - VMKind::Wasmer2 - } else { - VMKind::Wasmer2 - } - } -} diff --git a/mock-enclave/src/near-vm-runner/src/wasmi_runner.rs b/mock-enclave/src/near-vm-runner/src/wasmi_runner.rs new file mode 100644 index 0000000..f9c9ef5 --- /dev/null +++ b/mock-enclave/src/near-vm-runner/src/wasmi_runner.rs @@ -0,0 +1,311 @@ +use crate::cache::into_vm_result; +use crate::errors::IntoVMError; +use crate::{cache, imports}; +use near_primitives::contract::ContractCode; +use near_primitives::runtime::fees::RuntimeFeesConfig; +use near_primitives::types::CompiledContractCache; +use near_primitives::errors::RuntimeError; + +use near_vm_errors::{ + CompilationError, FunctionCallError, HostError, MethodResolveError, PrepareError, VMError, + WasmTrap, +}; +use near_vm_logic::types::{PromiseResult, ProtocolVersion}; +use near_vm_logic::{External, MemoryLike, VMConfig, VMContext, VMLogic, VMOutcome}; +use wasmi::{ + MemoryInstance, TrapKind, ModuleInstance, + memory_units::{Pages, Bytes}, NopExternals, ImportsBuilder +}; +use parity_wasm::elements::Module; + +pub struct WasmiMemory(MemoryInstance); + +impl WasmiMemory { + pub fn new( + initial_memory_pages: usize, + max_memory_pages: usize, + ) -> Result { + Ok(WasmiMemory( + MemoryInstance::alloc( + Pages(initial_memory_pages), Some(Pages(max_memory_pages)) + ) + .expect("TODO creating memory cannot fail"), + )) + } + + pub fn clone(&self) -> MemoryInstance { + self.0.clone() + } +} + +impl MemoryLike for WasmiMemory { + fn fits_memory(&self, offset: u64, len: u64) -> bool { + match offset.checked_add(len) { + None => false, + Some(end) => self.0.current_size().byte_size() >= Bytes(end as usize), + } + } + + fn read_memory(&self, offset: u64, buffer: &mut [u8]) { + let offset = offset as u32; + + // TODO: handle Error::OutOfBounds + self.0.get_into(offset, buffer); + } + + fn read_memory_u8(&self, offset: u64) -> u8 { + + // TODO: handle Error::OutOfBounds + self.0.get_value(offset as u32).expect("Memory read error u8") + } + + fn write_memory(&mut self, offset: u64, buffer: &[u8]) { + let offset = offset as usize; + + // ref: sp-sandbox - embedded_executor + self.0.set(offset, buffer); + // buffer.iter() + // .enumerate() + // .for_each(|i, v| self.0.set_value(offset + i, *v)); + } +} + +impl IntoVMError for wasmi::Trap { + fn into_vm_error(self) -> VMError { + // These vars are not used in every cases, however, downcast below use Arc::try_unwrap + // so we cannot clone self + // let error_msg = self.message(); + let trap_code = self.kind(); + // if let Ok(e) = self.downcast::() { + // return (&e).into(); + // } + + let error = match trap_code { + TrapKind::StackOverflow => FunctionCallError::WasmTrap(WasmTrap::StackOverflow), + TrapKind::MemoryAccessOutOfBounds => { + FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds) + } + TrapKind::TableAccessOutOfBounds => { + FunctionCallError::WasmTrap(WasmTrap::MemoryOutOfBounds) + } + TrapKind::ElemUninitialized => { + FunctionCallError::WasmTrap(WasmTrap::IndirectCallToNull) + } + TrapKind::UnexpectedSignature => { + FunctionCallError::WasmTrap(WasmTrap::IncorrectCallIndirectSignature) + } + TrapKind::DivisionByZero => { + FunctionCallError::WasmTrap(WasmTrap::IllegalArithmetic) + } + TrapKind::InvalidConversionToInt => { + FunctionCallError::WasmTrap(WasmTrap::IllegalArithmetic) + } + TrapKind::Unreachable => FunctionCallError::WasmTrap(WasmTrap::Unreachable), + _ => FunctionCallError::WasmTrap(WasmTrap::GenericTrap) + }; + VMError::FunctionCallError(error) + } +} + +fn check_method(module: &ModuleInstance, method_name: &str) -> Result<(), VMError> { + use wasmi::{ExternVal, ExternVal::Func}; + if let Some(ExternVal::Func(func)) = module.export_by_name(method_name) { + let sig = *(func).signature(); + if sig.params().is_empty() && sig.return_type().is_empty() { + Ok(()) + } else { + Err(VMError::FunctionCallError(FunctionCallError::MethodResolveError( + MethodResolveError::MethodInvalidSignature, + ))) + } + } else { + Err(VMError::FunctionCallError(FunctionCallError::MethodResolveError( + MethodResolveError::MethodNotFound, + ))) + } +} + +fn run_method( + module: &Module, + import: &ImportsBuilder, + method_name: &str, + logic: &mut VMLogic, +) -> Result<(), VMError> { + let _span = tracing::debug_span!(target: "vm", "run_method").entered(); + + let instance = { + let _span = tracing::debug_span!(target: "vm", "run_method/instantiate").entered(); + ModuleInstance::new( + &module, + &import, + )? + }; + + { + let _span = tracing::debug_span!(target: "vm", "run_method/call").entered(); + + // ref: sp-sandbox - embedded exec + // NopExternals needs to be replaced by a GuestExternals + // let mut externals = GuestExternals { + // state, defined_host_functions: & self.defined_host_functions + // }; + + instance + .invoke_export(method_name, &[], &mut NopExternals) + .map_err(|err| translate_runtime_error(err, logic))? + } + + { + let _span = tracing::debug_span!(target: "vm", "run_method/drop_instance").entered(); + drop(instance) + } + + Ok(()) +} + +pub(crate) fn wasmi_vm_hash() -> u64 { + 2_619u64 +} + +pub(crate) fn run_wasmi_module<'a>( + module: &Module, + memory: &mut WasmiMemory, + method_name: &str, + ext: &mut dyn External, + context: VMContext, + wasm_config: &'a VMConfig, + fees_config: &'a RuntimeFeesConfig, + promise_results: &'a [PromiseResult], + current_protocol_version: ProtocolVersion, +) -> (Option, Option) { + // Do we really need that code? + if method_name.is_empty() { + return ( + None, + Some(VMError::FunctionCallError(FunctionCallError::MethodResolveError( + MethodResolveError::MethodEmptyName, + ))), + ); + } + + // Note that we don't clone the actual backing memory, just increase the RC. + let memory_copy = memory.clone(); + + let mut logic = VMLogic::new_with_protocol_version( + ext, + context, + wasm_config, + fees_config, + promise_results, + memory, + current_protocol_version, + ); + + let import = imports::wasmi_import::build(memory_copy, &mut logic, current_protocol_version); + + if let Err(e) = check_method(&module, method_name) { + return (None, Some(e)); + } + + let err = run_method(module, &import, method_name, &mut logic).err(); + (Some(logic.outcome()), err) +} + +pub(crate) struct WasmiVM; + +impl crate::runner::VM for WasmiVM { + fn run( + &self, + code: &ContractCode, + method_name: &str, + ext: &mut dyn External, + context: VMContext, + wasm_config: &VMConfig, + fees_config: &RuntimeFeesConfig, + promise_results: &[PromiseResult], + current_protocol_version: ProtocolVersion, + cache: Option<&dyn CompiledContractCache>, + ) -> (Option, Option) { + let _span = tracing::debug_span!( + target: "vm", + "run_wasmi", + "code.len" = code.code().len(), + %method_name + ) + .entered(); + + if method_name.is_empty() { + return ( + None, + Some(VMError::FunctionCallError(FunctionCallError::MethodResolveError( + MethodResolveError::MethodEmptyName, + ))), + ); + } + + let module = + cache::wasmi_cache::compile_module_cached_wasmi(&code, wasm_config, cache); + let module = match into_vm_result(module) { + Ok(it) => it, + Err(err) => return (None, Some(err)), + }; + + 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"); + // Note that we don't clone the actual backing memory, just increase the RC. + let memory_copy = memory.clone(); + + let mut logic = VMLogic::new_with_protocol_version( + ext, + context, + wasm_config, + fees_config, + promise_results, + &mut memory, + current_protocol_version, + ); + + // TODO: remove, as those costs are incorrectly computed, and we shall account it on deployment. + if logic.add_contract_compile_fee(code.code().len() as u64).is_err() { + return ( + Some(logic.outcome()), + Some(VMError::FunctionCallError(FunctionCallError::HostError( + near_vm_errors::HostError::GasExceeded, + ))), + ); + } + + let import_object = + imports::wasmi_import::build(memory_copy, &mut logic, current_protocol_version); + + if let Err(e) = check_method(&module, method_name) { + return (None, Some(e)); + } + + let err = run_method(&module, &import_object, method_name, &mut logic).err(); + (Some(logic.outcome()), err) + } + + fn precompile( + &self, + code: &[u8], + code_hash: &near_primitives::hash::CryptoHash, + wasm_config: &VMConfig, + cache: &dyn CompiledContractCache, + ) -> Option { + let result = crate::cache::wasmi_cache::compile_and_serialize_wasmi( + code, + code_hash, + wasm_config, + cache, + ); + into_vm_result(result).err() + } + + fn check_compile(&self, code: &[u8]) -> bool { + Module::from_buffer(code).is_ok() + } +} diff --git a/package.json b/package.json index bdc48f7..636fd34 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,8 @@ "contract:compile": "node ./scripts/contract-compile.cjs", "mock-enclave:start": "yarn contract:compile && npx ts-node mock-enclave/host/index.ts", + "mock-enclave:vm": "cd mock-enclave && yarn start", + "mock-enclave:test": "cd mock-enclave && yarn test", "chaos:party": "cd chaos && yarn party" }