diff --git a/.github/workflows/builds.yml b/.github/workflows/builds.yml index bd2939d5d..e490a04b0 100644 --- a/.github/workflows/builds.yml +++ b/.github/workflows/builds.yml @@ -7,56 +7,46 @@ name: Builds jobs: release: name: Release - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make release - - run: ls -lH release.wasm - - name: Upload the release.wasm artifact + - run: ls -lH mainnet-release.wasm + - name: Upload the mainnet-release.wasm artifact uses: actions/upload-artifact@v2 with: - name: release.wasm - path: release.wasm + name: mainnet-release.wasm + path: mainnet-release.wasm - name: Update the latest release uses: svenstaro/upload-release-action@v2 with: tag: latest - file: release.wasm + file: mainnet-release.wasm overwrite: true repo_token: ${{ secrets.GITHUB_TOKEN }} - name: Update the latest tag uses: EndBug/latest-tag@latest debug: name: Debug - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make debug - - run: ls -lH debug.wasm - - name: Upload the debug.wasm artifact + - run: ls -lH mainnet-debug.wasm + - name: Upload the mainnet-debug.wasm artifact uses: actions/upload-artifact@v2 with: - name: debug.wasm - path: debug.wasm + name: mainnet-debug.wasm + path: mainnet-debug.wasm - name: Update the latest release uses: svenstaro/upload-release-action@v2 with: tag: latest - file: debug.wasm + file: mainnet-debug.wasm overwrite: true repo_token: ${{ secrets.GITHUB_TOKEN }} - name: Update the latest tag diff --git a/.github/workflows/lints.yml b/.github/workflows/lints.yml index 663f16501..354c0ffd6 100644 --- a/.github/workflows/lints.yml +++ b/.github/workflows/lints.yml @@ -5,49 +5,29 @@ name: Lints jobs: fmt: name: rustfmt - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true - components: rustfmt + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + run: cargo fmt --all -- --check clippy: name: Clippy - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true - components: clippy + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make etc/eth-contracts/res/EvmErc20.bin - name: Run Contract cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --no-default-features --features=contract -- -D warnings + run: cargo clippy --no-default-features --features=contract -- -D warnings - name: Run cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy + run: cargo clippy contracts: name: eth-contracts - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 diff --git a/.github/workflows/scheduled_lints.yml b/.github/workflows/scheduled_lints.yml index 52918b251..eea60553a 100644 --- a/.github/workflows/scheduled_lints.yml +++ b/.github/workflows/scheduled_lints.yml @@ -6,20 +6,11 @@ name: Scheduled_Lints jobs: clippy: name: Nightly_Clippy - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly - override: true - components: clippy + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make etc/eth-contracts/res/EvmErc20.bin - name: Run cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --no-default-features --features=mainnet -- -D warnings + run: cargo clippy --no-default-features --features=mainnet -- -D warnings diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2be24a71f..24c0deef9 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -3,45 +3,36 @@ on: [push, pull_request] name: Tests jobs: test: - name: Test suite - runs-on: ubuntu-latest + strategy: + matrix: + net: [main, test, beta] + name: Test suite (${{ matrix.net }}net) + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Cache Cargo artifacts - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true - - run: make test-build - - name: Run cargo test - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked --verbose --features meta-call + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH + - name: Cache lookup for target dir + run: cache-util -restore -path target -key aurora-engine-target@${{ matrix.net }}net@${{ hashFiles('**/Cargo.lock') }} + - run: make ${{ matrix.net }}net-test-build + - name: Run ${{ matrix.net }}net cargo test + run: cargo test --locked --verbose --features ${{ matrix.net }}net-test + - name: Caching target dir + run: cache-util -save -move -path target -key aurora-engine-target@${{ matrix.net }}net@${{ hashFiles('**/Cargo.lock') }} bully-build: name: Bully build - runs-on: ubuntu-latest + runs-on: self-hosted steps: - name: Clone the repository uses: actions/checkout@v2 - - name: Install the toolchain - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: nightly-2021-03-25 - override: true - - run: make evm-bully=yes - - run: ls -lH release.wasm + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH + - name: Cache lookup for target dir + run: cache-util -restore -path target -key aurora-engine-target@bully@${{ hashFiles('**/Cargo.lock') }} + - run: make mainnet-debug evm-bully=yes + - run: ls -lH mainnet-debug.wasm + - name: Cache target dir + run: cache-util -save -move -path target -key aurora-engine-target@bully@${{ hashFiles('**/Cargo.lock') }} env: CARGO_TERM_COLOR: always CARGO_INCREMENTAL: 0 + RUSTC_WRAPPER: sccache diff --git a/.gitignore b/.gitignore index 4c828c841..eb342215e 100644 --- a/.gitignore +++ b/.gitignore @@ -24,5 +24,4 @@ res/ etc/state-migration-test/target/ node_modules/* -artifacts/ cache diff --git a/CHANGES.md b/CHANGES.md index dd1c2f03e..fbb7e3962 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.5.0] - 2021-07-30 + ## [1.4.3] - 2021-07-08 ## [1.4.2] - 2021-06-25 @@ -21,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.0.0] - 2021-05-12 +[1.5.0]: https://github.com/aurora-is-near/aurora-engine/compare/1.4.3...1.5.0 [1.4.3]: https://github.com/aurora-is-near/aurora-engine/compare/1.4.2...1.4.3 [1.4.2]: https://github.com/aurora-is-near/aurora-engine/compare/1.4.1...1.4.2 [1.4.1]: https://github.com/aurora-is-near/aurora-engine/compare/1.4.0...1.4.1 diff --git a/Cargo.lock b/Cargo.lock index 21e681d2d..c9869aee9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,15 @@ version = "0.11.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +[[package]] +name = "addr2line" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a55f82cfe485775d02112886f4169bde0c5894d75e79ead7eafe7e40a25e45f7" +dependencies = [ + "gimli 0.23.0", +] + [[package]] name = "addr2line" version = "0.15.1" @@ -106,7 +115,7 @@ dependencies = [ [[package]] name = "aurora-engine" -version = "1.0.0" +version = "1.5.0" dependencies = [ "aurora-bn", "base64 0.13.0", @@ -123,12 +132,12 @@ dependencies = [ "lazy-static-include", "libsecp256k1", "logos", - "near-crypto", - "near-primitives-core 0.4.0", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", "near-sdk", "near-sdk-sim", - "near-vm-logic 4.0.0-pre.1", - "near-vm-runner", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-vm-runner 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", "num", "primitive-types", "rand 0.7.3", @@ -154,7 +163,7 @@ version = "0.3.59" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4717cfcbfaa661a0fd48f8453951837ae7e8f81e481fbb136e3202d72805a744" dependencies = [ - "addr2line", + "addr2line 0.15.1", "cc", "cfg-if 1.0.0", "libc", @@ -393,6 +402,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b700ce4376041dcd0a327fd0097c41095743c4c8af8887265942faf1100bd040" +[[package]] +name = "bytesize" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81a18687293a1546b67c246452202bbbf143d239cb43494cc163da14979082da" + [[package]] name = "c2-chacha" version = "0.3.0" @@ -543,21 +558,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] -name = "cpufeatures" -version = "0.1.1" +name = "cpp_demangle" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" +checksum = "8ea47428dc9d2237f3c6bc134472edfd63ebba0af932e783506dcfd66f10d18a" dependencies = [ - "libc", + "cfg-if 1.0.0", ] [[package]] -name = "cranelift-bforest" -version = "0.67.0" +name = "cpufeatures" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f065f6889758f817f61a230220d1811ba99a9762af2fb69ae23048314f75ff2" +checksum = "dec1028182c380cc45a2e2c5ec841134f2dfd0f8f5f0a5bcd68004f81b5efdf4" dependencies = [ - "cranelift-entity 0.67.0", + "libc", ] [[package]] @@ -570,23 +585,12 @@ dependencies = [ ] [[package]] -name = "cranelift-codegen" -version = "0.67.0" +name = "cranelift-bforest" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "510aa2ab4307644100682b94e449940a0ea15c5887f1d4b9678b8dd5ef31e736" +checksum = "841476ab6d3530136b5162b64a2c6969d68141843ad2fd59126e5ea84fd9b5fe" dependencies = [ - "byteorder", - "cranelift-bforest 0.67.0", - "cranelift-codegen-meta 0.67.0", - "cranelift-codegen-shared 0.67.0", - "cranelift-entity 0.67.0", - "gimli 0.21.0", - "log", - "regalloc 0.0.30", - "serde", - "smallvec", - "target-lexicon 0.11.2", - "thiserror", + "cranelift-entity 0.72.0", ] [[package]] @@ -602,20 +606,30 @@ dependencies = [ "cranelift-entity 0.68.0", "gimli 0.22.0", "log", - "regalloc 0.0.31", + "regalloc", "smallvec", "target-lexicon 0.11.2", "thiserror", ] [[package]] -name = "cranelift-codegen-meta" -version = "0.67.0" +name = "cranelift-codegen" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4cb0c7e87c60d63b35f9670c15479ee4a5e557dd127efab88b2f9b2ca83c9a0" +checksum = "2b5619cef8d19530298301f91e9a0390d369260799a3d8dd01e28fc88e53637a" dependencies = [ - "cranelift-codegen-shared 0.67.0", - "cranelift-entity 0.67.0", + "byteorder", + "cranelift-bforest 0.72.0", + "cranelift-codegen-meta 0.72.0", + "cranelift-codegen-shared 0.72.0", + "cranelift-entity 0.72.0", + "gimli 0.23.0", + "log", + "regalloc", + "serde", + "smallvec", + "target-lexicon 0.11.2", + "thiserror", ] [[package]] @@ -629,10 +643,14 @@ dependencies = [ ] [[package]] -name = "cranelift-codegen-shared" -version = "0.67.0" +name = "cranelift-codegen-meta" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60636227098693e06de8d6d88beea2a7d32ecf8a8030dacdb57c68e06f381826" +checksum = "2a319709b8267939155924114ea83f2a5b5af65ece3ac6f703d4735f3c66bb0d" +dependencies = [ + "cranelift-codegen-shared 0.72.0", + "cranelift-entity 0.72.0", +] [[package]] name = "cranelift-codegen-shared" @@ -641,10 +659,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6759012d6d19c4caec95793f052613e9d4113e925e7f14154defbac0f1d4c938" [[package]] -name = "cranelift-entity" -version = "0.67.0" +name = "cranelift-codegen-shared" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6156db73e0c9f65f80c512988d63ec736be0dee3dd66bf951e3e28aed9dc02d3" +checksum = "15925b23cd3a448443f289d85a8f53f3cf7a80f0137aa53c8e3b01ae8aefaef7" dependencies = [ "serde", ] @@ -658,13 +676,22 @@ 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.67.0" +version = "0.68.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e09cd158c9a820a4cc14a34076811da225cce1d31dc6d03c5ef85b91aef560b9" +checksum = "b608bb7656c554d0a4cf8f50c7a10b857e80306f6ff829ad6d468a7e2323c8d8" dependencies = [ - "cranelift-codegen 0.67.0", + "cranelift-codegen 0.68.0", "log", "smallvec", "target-lexicon 0.11.2", @@ -672,11 +699,11 @@ dependencies = [ [[package]] name = "cranelift-frontend" -version = "0.68.0" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b608bb7656c554d0a4cf8f50c7a10b857e80306f6ff829ad6d468a7e2323c8d8" +checksum = "4d20c8bd4a1c41ded051734f0e33ad1d843a0adc98b9bd975ee6657e2c70cdc9" dependencies = [ - "cranelift-codegen 0.68.0", + "cranelift-codegen 0.72.0", "log", "smallvec", "target-lexicon 0.11.2", @@ -684,28 +711,29 @@ dependencies = [ [[package]] name = "cranelift-native" -version = "0.67.0" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7054533ae1fc2048c1a6110bdf8f4314b77c60329ec6a7df79d2cfb84e3dcc1c" +checksum = "304e100df41f34a5a15291b37bfe0fd7abd0427a2c84195cc69578b4137f9099" dependencies = [ - "cranelift-codegen 0.67.0", - "raw-cpuid", + "cranelift-codegen 0.72.0", "target-lexicon 0.11.2", ] [[package]] name = "cranelift-wasm" -version = "0.67.0" +version = "0.72.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7aee0e0b68eba99f99a4923212d97aca9e44655ca8246f07fffe11236109b0d0" +checksum = "4efd473b2917303957e0bfaea6ea9d08b8c93695bee015a611a2514ce5254abc" dependencies = [ - "cranelift-codegen 0.67.0", - "cranelift-entity 0.67.0", - "cranelift-frontend 0.67.0", + "cranelift-codegen 0.72.0", + "cranelift-entity 0.72.0", + "cranelift-frontend 0.72.0", + "itertools 0.10.0", "log", "serde", + "smallvec", "thiserror", - "wasmparser 0.59.0", + "wasmparser 0.76.0", ] [[package]] @@ -783,7 +811,7 @@ dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", "lazy_static", - "memoffset 0.6.3", + "memoffset", "scopeguard", ] @@ -1150,8 +1178,7 @@ checksum = "f7531096570974c3a9dcf9e4b8e1cede1ec26cf5046219fb3b9d897503b9be59" [[package]] name = "evm" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50bbacb1b2149e29cc31bdd73dc2fe6d3cc0d291c438ec1cb3cdb7b2f8aa1c" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "environmental", "ethereum", @@ -1169,8 +1196,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7828a238e25e8c5b5a23a2114e6f3863780ffd1dca6f7f74eecfd51271a8c573" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "funty", "parity-scale-codec", @@ -1181,8 +1207,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b61792ef56c7772b6d9425674852241dddcbb5fd507e6849c63ce39d1ad74e5e" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "environmental", "evm-core", @@ -1193,8 +1218,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7b8ae833004b1d619997d8a31b61b291b0bb3a7ed0af709342331a9a217d53" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "environmental", "evm-core", @@ -1242,6 +1266,16 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs2" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "fs_extra" version = "1.2.0" @@ -1399,9 +1433,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.21.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcc8e0c9bce37868955864dbecd2b1ab2bdf967e6f28066d65aaac620444b65c" +checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" dependencies = [ "fallible-iterator", "indexmap", @@ -1410,9 +1444,9 @@ dependencies = [ [[package]] name = "gimli" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aaf91faf136cb47367fa430cd46e37a788775e7fa104f8b4bcb3861dc389b724" +checksum = "f6503fe142514ca4799d4c26297c4248239fe8838d827db6bd6065c6ed29a6ce" dependencies = [ "fallible-iterator", "indexmap", @@ -1889,15 +1923,6 @@ dependencies = [ "libc", ] -[[package]] -name = "memoffset" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" -dependencies = [ - "autocfg", -] - [[package]] name = "memoffset" version = "0.6.3" @@ -1929,11 +1954,26 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238" +[[package]] +name = "near-chain-configs" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" +dependencies = [ + "chrono", + "derive_more", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "num-rational 0.3.2", + "serde", + "serde_json", + "sha2 0.9.5", + "smart-default", +] + [[package]] name = "near-crypto" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb14bec070cfd808438712cda5d54703001b9cf1196c8afaeadc9514e06d00a3" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "arrayref", "blake2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1943,6 +1983,32 @@ dependencies = [ "curve25519-dalek", "derive_more", "ed25519-dalek", + "ethereum-types", + "lazy_static", + "libc", + "parity-secp256k1", + "rand 0.7.3", + "rand_core 0.5.1", + "serde", + "serde_json", + "subtle 2.4.0", + "thiserror", +] + +[[package]] +name = "near-crypto" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" +dependencies = [ + "arrayref", + "blake2 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "borsh", + "bs58", + "c2-chacha", + "curve25519-dalek", + "derive_more", + "ed25519-dalek", + "ethereum-types", "lazy_static", "libc", "parity-secp256k1", @@ -1957,8 +2023,7 @@ dependencies = [ [[package]] name = "near-metrics" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7b9dcbc960db15fcec85bcb29a78b57e4005b7b1a0afc70a26a97453862528e" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "lazy_static", "log", @@ -1967,21 +2032,19 @@ dependencies = [ [[package]] name = "near-pool" -version = "0.1.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde79472f7cfc0675733b65f79f9e50c20bfbb9806298ab2872916869a45dccd" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "borsh", - "near-crypto", - "near-primitives", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "rand 0.7.3", ] [[package]] name = "near-primitives" -version = "0.1.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75ed2263518ca67a3c158c144813832fd96f48ab239494bb9d7793d315f31417" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "base64 0.13.0", "borsh", @@ -1993,10 +2056,40 @@ dependencies = [ "hex", "jemallocator", "lazy_static", - "near-crypto", - "near-primitives-core 0.4.0", - "near-rpc-error-macro", - "near-vm-errors 4.0.0-pre.1", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-rpc-error-macro 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "num-rational 0.3.2", + "primitive-types", + "rand 0.7.3", + "reed-solomon-erasure", + "regex", + "serde", + "serde_json", + "sha2 0.9.5", + "smart-default", + "validator", +] + +[[package]] +name = "near-primitives" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" +dependencies = [ + "base64 0.13.0", + "borsh", + "bs58", + "byteorder", + "chrono", + "derive_more", + "easy-ext", + "hex", + "jemallocator", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-rpc-error-macro 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "num-rational 0.3.2", "primitive-types", "rand 0.7.3", @@ -2012,8 +2105,7 @@ dependencies = [ [[package]] name = "near-primitives-core" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92035b79bf9983502fe7b67b5a9fecea7604e979d439727827fd0d8f0d77720e" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "base64 0.11.0", "borsh", @@ -2029,11 +2121,10 @@ dependencies = [ [[package]] name = "near-primitives-core" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2b3fb5acf3a494aed4e848446ef2d6ebb47dbe91c681105d4d1786c2ee63e52" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ - "base64 0.13.0", + "base64 0.11.0", "borsh", "bs58", "derive_more", @@ -2048,23 +2139,31 @@ dependencies = [ [[package]] name = "near-rpc-error-core" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffa8dbf8437a28ac40fcb85859ab0d0b8385013935b000c7a51ae79631dd74d9" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn", +] + +[[package]] +name = "near-rpc-error-core" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "proc-macro2", "quote", "serde", - "serde_json", "syn", ] [[package]] name = "near-rpc-error-macro" version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6111d713e90c7c551dee937f4a06cb9ea2672243455a4454cc7566387ba2d9" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ - "near-rpc-error-core", + "near-rpc-error-core 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", "proc-macro2", "quote", "serde", @@ -2073,38 +2172,22 @@ dependencies = [ ] [[package]] -name = "near-runtime" -version = "4.0.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e4c0a4cd2ee5ccbc1fd5d492180ebf33ac1159d721b2e0c58c11953131fb449" +name = "near-rpc-error-macro" +version = "0.1.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ - "borsh", - "byteorder", - "ethereum-types", - "hex", - "lazy_static", - "log", - "near-crypto", - "near-metrics", - "near-primitives", - "near-runtime-utils 4.0.0-pre.1", - "near-store", - "near-vm-errors 4.0.0-pre.1", - "near-vm-logic 4.0.0-pre.1", - "near-vm-runner", - "num-bigint 0.3.2", - "num-rational 0.3.2", - "num-traits", - "rand 0.7.3", + "near-rpc-error-core 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "proc-macro2", + "quote", "serde", "serde_json", + "syn", ] [[package]] name = "near-runtime-utils" version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47f5c1891cec5a03e3dc99f985031408b19516305e2e59d64c4ce52b409e46a0" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "lazy_static", "regex", @@ -2112,9 +2195,8 @@ dependencies = [ [[package]] name = "near-runtime-utils" -version = "4.0.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a48d80c4ca1d4cf99bc16490e1e3d49826c150dfc4410ac498918e45c7d98e07" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "lazy_static", "regex", @@ -2122,15 +2204,15 @@ dependencies = [ [[package]] name = "near-sdk" -version = "3.0.0-pre.3" -source = "git+https://github.com/near/near-sdk-rs?rev=9d99077c6acfde68c06845f2a1eb2b5ed7983401#9d99077c6acfde68c06845f2a1eb2b5ed7983401" +version = "3.1.0" +source = "git+https://github.com/aurora-is-near/near-sdk-rs?rev=1b9843fe5b652928582e33879fc92ba87a639450#1b9843fe5b652928582e33879fc92ba87a639450" dependencies = [ "base64 0.13.0", "borsh", "bs58", - "near-primitives-core 0.1.0", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "near-sdk-macros", - "near-vm-logic 3.0.0", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "serde", "serde_json", "wee_alloc", @@ -2138,8 +2220,8 @@ dependencies = [ [[package]] name = "near-sdk-core" -version = "3.0.0-pre.3" -source = "git+https://github.com/near/near-sdk-rs?rev=9d99077c6acfde68c06845f2a1eb2b5ed7983401#9d99077c6acfde68c06845f2a1eb2b5ed7983401" +version = "3.1.0" +source = "git+https://github.com/aurora-is-near/near-sdk-rs?rev=1b9843fe5b652928582e33879fc92ba87a639450#1b9843fe5b652928582e33879fc92ba87a639450" dependencies = [ "Inflector", "proc-macro2", @@ -2149,8 +2231,8 @@ dependencies = [ [[package]] name = "near-sdk-macros" -version = "3.0.0-pre.3" -source = "git+https://github.com/near/near-sdk-rs?rev=9d99077c6acfde68c06845f2a1eb2b5ed7983401#9d99077c6acfde68c06845f2a1eb2b5ed7983401" +version = "3.1.0" +source = "git+https://github.com/aurora-is-near/near-sdk-rs?rev=1b9843fe5b652928582e33879fc92ba87a639450#1b9843fe5b652928582e33879fc92ba87a639450" dependencies = [ "near-sdk-core", "proc-macro2", @@ -2160,123 +2242,161 @@ dependencies = [ [[package]] name = "near-sdk-sim" -version = "3.0.0-pre.3" -source = "git+https://github.com/near/near-sdk-rs?rev=9d99077c6acfde68c06845f2a1eb2b5ed7983401#9d99077c6acfde68c06845f2a1eb2b5ed7983401" +version = "3.2.0" +source = "git+https://github.com/aurora-is-near/near-sdk-rs?rev=1b9843fe5b652928582e33879fc92ba87a639450#1b9843fe5b652928582e33879fc92ba87a639450" dependencies = [ + "chrono", "funty", "lazy-static-include", - "near-crypto", + "near-chain-configs", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "near-pool", - "near-primitives", - "near-runtime", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "near-sdk", "near-store", - "near-vm-logic 4.0.0-pre.1", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "node-runtime", ] [[package]] name = "near-store" -version = "0.1.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07e880d1d9a4ca5a1ca1ea0366fd80e295465f90cd0c1209f45d6d0b7a443ed4" +version = "2.2.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "borsh", "byteorder", + "bytesize", "cached", "derive_more", "elastic-array", + "fs2", "lazy_static", - "near-crypto", - "near-primitives", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "num_cpus", "rand 0.7.3", "rocksdb", "serde", "serde_json", "strum", + "thiserror", + "tracing", ] [[package]] name = "near-vm-errors" version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53a100dda565c5375ac061126167afc5c33cdba1f2e325cfae3ce08f4a5a432a" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "borsh", "hex", - "near-rpc-error-macro", + "near-rpc-error-macro 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", "serde", ] [[package]] name = "near-vm-errors" -version = "4.0.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e281d8730ed8cb0e3e69fb689acee6b93cdb43824cd69a8ffd7e1bfcbd1177d7" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "borsh", "hex", - "near-rpc-error-macro", + "near-rpc-error-macro 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "serde", ] [[package]] name = "near-vm-logic" version = "3.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a12201244dd59ae79506767afe7a8f51b5eb7bd0aa237d355dfa635f7b777c4a" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "base64 0.13.0", "borsh", "bs58", "byteorder", - "near-primitives-core 0.1.0", - "near-runtime-utils 3.0.0", - "near-vm-errors 3.0.0", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-runtime-utils 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "ripemd160", "serde", - "sha2 0.9.5", - "sha3 0.9.1", + "sha2 0.8.2", + "sha3 0.8.2", ] [[package]] name = "near-vm-logic" -version = "4.0.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e11cb28a2d07f37680efdaf860f4c9802828c44fc50c08009e7884de75d982c5" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" dependencies = [ "base64 0.13.0", "borsh", "bs58", "byteorder", - "near-primitives-core 0.4.0", - "near-runtime-utils 4.0.0-pre.1", - "near-vm-errors 4.0.0-pre.1", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-primitives-core 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-runtime-utils 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "ripemd160", "serde", - "sha2 0.9.5", - "sha3 0.9.1", + "sha2 0.8.2", + "sha3 0.8.2", ] [[package]] name = "near-vm-runner" -version = "4.0.0-pre.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93a66e94e12ec66a29674cc4efa975c280415aa0c944d7294cedbdb0c3858b48" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?branch=1.20.1#dde3ad6ad954d333407159225f712df379f186e2" dependencies = [ "anyhow", "borsh", "cached", - "log", - "near-primitives", - "near-vm-errors 4.0.0-pre.1", - "near-vm-logic 4.0.0-pre.1", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?branch=1.20.1)", + "parity-wasm", + "pwasm-utils", + "serde", + "threadpool", + "tracing", + "wasmer", + "wasmer-compiler-cranelift", + "wasmer-compiler-singlepass", + "wasmer-engine-native", + "wasmer-runtime-core-near", + "wasmer-runtime-near", + "wasmer-types", + "wasmer-vm", + "wasmtime", +] + +[[package]] +name = "near-vm-runner" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" +dependencies = [ + "anyhow", + "borsh", + "cached", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", "parity-wasm", "pwasm-utils", + "serde", + "threadpool", "tracing", "wasmer", + "wasmer-compiler-cranelift", "wasmer-compiler-singlepass", + "wasmer-engine-native", "wasmer-runtime-core-near", "wasmer-runtime-near", "wasmer-types", + "wasmer-vm", + "wasmparser 0.51.4", "wasmtime", ] @@ -2293,6 +2413,37 @@ dependencies = [ "void", ] +[[package]] +name = "node-runtime" +version = "3.0.0" +source = "git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90#8a37d39629885a41dde58b60642bcf1e99407d90" +dependencies = [ + "borsh", + "byteorder", + "ethereum-types", + "hex", + "lazy_static", + "log", + "near-chain-configs", + "near-crypto 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-metrics", + "near-primitives 0.1.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-runtime-utils 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-store", + "near-vm-errors 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-logic 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "near-vm-runner 3.0.0 (git+https://github.com/near/nearcore.git?rev=8a37d39629885a41dde58b60642bcf1e99407d90)", + "num-bigint 0.3.2", + "num-rational 0.3.2", + "num-traits", + "rand 0.7.3", + "rayon", + "serde", + "serde_json", + "thiserror", + "tracing", +] + [[package]] name = "nom" version = "5.1.2" @@ -2415,20 +2566,19 @@ dependencies = [ [[package]] name = "object" -version = "0.21.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37fd5004feb2ce328a52b0b3d01dbf4ffff72583493900ed15f22d4111c51693" +checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" dependencies = [ "crc32fast", "indexmap", - "wasmparser 0.57.0", ] [[package]] name = "object" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3b63360ec3cb337817c2dbd47ab4a0f170d285d8e5a2064600f3def1402397" +checksum = "a9a7ab5d64814df0fe4a4b5ead45ed6c5f181ee3ff04ba344313a6c80446c5d4" dependencies = [ "crc32fast", "indexmap", @@ -2585,6 +2735,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "paste" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58" + [[package]] name = "peeking_take_while" version = "0.1.2" @@ -2737,6 +2893,15 @@ version = "2.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45604fc7a88158e7d514d8e22e14ac746081e7a70d7690074dd0029ee37458d6" +[[package]] +name = "psm" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21ff0279b4a85e576b97e4a21d13e437ebcd56612706cde5d3f0d5c9399490c0" +dependencies = [ + "cc", +] + [[package]] name = "pwasm-utils" version = "0.12.0" @@ -2844,17 +3009,6 @@ dependencies = [ "rand_core 0.6.2", ] -[[package]] -name = "raw-cpuid" -version = "7.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb71f708fe39b2c5e98076204c3cc094ee5a4c12c4cdb119a2b72dc34164f41" -dependencies = [ - "bitflags", - "cc", - "rustc_version", -] - [[package]] name = "rayon" version = "1.5.0" @@ -2904,17 +3058,6 @@ dependencies = [ "smallvec", ] -[[package]] -name = "regalloc" -version = "0.0.30" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2041c2d34f6ff346d6f428974f03d8bf12679b0c816bb640dc5eb1d48848d8d1" -dependencies = [ - "log", - "rustc-hash", - "smallvec", -] - [[package]] name = "regalloc" version = "0.0.31" @@ -2923,6 +3066,7 @@ checksum = "571f7f397d61c4755285cd37853fe8e03271c243424a907415909379659381c5" dependencies = [ "log", "rustc-hash", + "serde", "smallvec", ] @@ -3013,9 +3157,9 @@ dependencies = [ [[package]] name = "rocksdb" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23d83c02c429044d58474eaf5ae31e062d0de894e21125b47437ec0edc1397e6" +checksum = "c749134fda8bfc90d0de643d59bfc841dcb3ac8a1062e12b6754bd60235c48b3" dependencies = [ "libc", "librocksdb-sys", @@ -3371,6 +3515,15 @@ dependencies = [ "syn", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "time" version = "0.1.43" @@ -3819,9 +3972,9 @@ dependencies = [ [[package]] name = "wasmer-runtime-core-near" -version = "0.17.1" +version = "0.17.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2390b0b8cf58615c2f8b454d9535e1aed1d14c510cc1ce1af806a1992ad53300" +checksum = "08ff9059d479dbff357e1953edbde198453d5421274119230c50754e61e8ec9f" dependencies = [ "bincode", "blake3", @@ -3901,7 +4054,7 @@ dependencies = [ "cfg-if 0.1.10", "indexmap", "libc", - "memoffset 0.6.3", + "memoffset", "more-asserts", "region", "serde", @@ -3918,41 +4071,37 @@ checksum = "aeb1956b19469d1c5e63e459d29e7b5aa0f558d9f16fcef09736f8a265e6c10a" [[package]] name = "wasmparser" -version = "0.57.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32fddd575d477c6e9702484139cf9f23dcd554b06d185ed0f56c857dd3a47aa6" - -[[package]] -name = "wasmparser" -version = "0.59.0" +version = "0.65.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a950e6a618f62147fd514ff445b2a0b53120d382751960797f85f058c7eda9b9" +checksum = "87cc2fe6350834b4e528ba0901e7aa405d78b89dc1fa3145359eb4de0e323fcf" [[package]] name = "wasmparser" -version = "0.65.0" +version = "0.76.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87cc2fe6350834b4e528ba0901e7aa405d78b89dc1fa3145359eb4de0e323fcf" +checksum = "755a9a4afe3f6cccbbe6d7e965eef44cf260b001f93e547eba84255c1d0187d8" [[package]] name = "wasmtime" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "373b87ebd6721f4121e28eeaaa41943548c48bcca04ac9bb063004207e5e7d70" +checksum = "26ea2ad49bb047e10ca292f55cd67040bef14b676d07e7b04ed65fd312d52ece" dependencies = [ "anyhow", "backtrace", "bincode", - "cfg-if 0.1.10", - "lazy_static", + "cfg-if 1.0.0", + "cpp_demangle", + "indexmap", "libc", "log", + "paste", "region", "rustc-demangle", "serde", "smallvec", "target-lexicon 0.11.2", - "wasmparser 0.59.0", + "wasmparser 0.76.0", "wasmtime-environ", "wasmtime-jit", "wasmtime-profiling", @@ -3962,75 +4111,78 @@ dependencies = [ [[package]] name = "wasmtime-cranelift" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40c01df908e54d40bed80326ade122825d464888991beafd950d186f1be309c2" +checksum = "5e769b80abbb89255926f69ba37085f7dd6608c980134838c3c89d7bf6e776bc" dependencies = [ - "cranelift-codegen 0.67.0", - "cranelift-entity 0.67.0", - "cranelift-frontend 0.67.0", + "cranelift-codegen 0.72.0", + "cranelift-entity 0.72.0", + "cranelift-frontend 0.72.0", "cranelift-wasm", + "wasmparser 0.76.0", "wasmtime-environ", ] [[package]] name = "wasmtime-debug" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28962772f96fadb79dc7be5ade135ca55d2b0017a012f4869e2476a03abbe733" +checksum = "38501788c936a4932b0ddf61135963a4b7d1f549f63a6908ae56a1c86d74fc7b" dependencies = [ "anyhow", - "gimli 0.21.0", + "gimli 0.23.0", "more-asserts", - "object 0.21.1", + "object 0.23.0", "target-lexicon 0.11.2", "thiserror", - "wasmparser 0.59.0", + "wasmparser 0.76.0", "wasmtime-environ", ] [[package]] name = "wasmtime-environ" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c0d7401bf253b7b1f426afd70d285bb23ea9a1c7605d6af788c95db5084edf5" +checksum = "fae793ea1387b2fede277d209bb27285366df58f0a3ae9d59e58a7941dce60fa" dependencies = [ "anyhow", - "cfg-if 0.1.10", - "cranelift-codegen 0.67.0", - "cranelift-entity 0.67.0", + "cfg-if 1.0.0", + "cranelift-codegen 0.72.0", + "cranelift-entity 0.72.0", "cranelift-wasm", - "gimli 0.21.0", + "gimli 0.23.0", "indexmap", "log", "more-asserts", + "region", "serde", "thiserror", - "wasmparser 0.59.0", + "wasmparser 0.76.0", ] [[package]] name = "wasmtime-jit" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c838a108318e7c5a2201addb3d3b27a6ef3d142f0eb0addc815b9c2541e5db5" +checksum = "9b3bd0fae8396473a68a1491559d61776127bb9bea75c9a6a6c038ae4a656eb2" dependencies = [ + "addr2line 0.14.1", "anyhow", - "cfg-if 0.1.10", - "cranelift-codegen 0.67.0", - "cranelift-entity 0.67.0", - "cranelift-frontend 0.67.0", + "cfg-if 1.0.0", + "cranelift-codegen 0.72.0", + "cranelift-entity 0.72.0", + "cranelift-frontend 0.72.0", "cranelift-native", "cranelift-wasm", - "gimli 0.21.0", + "gimli 0.23.0", "log", "more-asserts", - "object 0.21.1", + "object 0.23.0", "region", "serde", "target-lexicon 0.11.2", "thiserror", - "wasmparser 0.59.0", + "wasmparser 0.76.0", "wasmtime-cranelift", "wasmtime-debug", "wasmtime-environ", @@ -4042,13 +4194,13 @@ dependencies = [ [[package]] name = "wasmtime-obj" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc8422b0acce519b74c3ae5db59167c611ea92220e5c334ad406e977277e0f23" +checksum = "a79fa098a3be8fabc50f5be60f8e47694d569afdc255de37850fc80295485012" dependencies = [ "anyhow", "more-asserts", - "object 0.21.1", + "object 0.23.0", "target-lexicon 0.11.2", "wasmtime-debug", "wasmtime-environ", @@ -4056,12 +4208,12 @@ dependencies = [ [[package]] name = "wasmtime-profiling" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33f2689bf523f843555e57e24d59abf0c5013007366b866081d73a15e510b4b2" +checksum = "d81e2106efeef4c01917fd16956a91d39bb78c07cf97027abdba9ca98da3f258" dependencies = [ "anyhow", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "lazy_static", "libc", "serde", @@ -4072,19 +4224,22 @@ dependencies = [ [[package]] name = "wasmtime-runtime" -version = "0.20.0" +version = "0.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7353f5e79390048128e44b5ceda7255723b2066de4026df9a168b0b2593df71" +checksum = "f747c656ca4680cad7846ae91c57d03f2dd4f4170da77a700df4e21f0d805378" dependencies = [ + "anyhow", "backtrace", "cc", - "cfg-if 0.1.10", + "cfg-if 1.0.0", "indexmap", "lazy_static", "libc", "log", - "memoffset 0.5.6", + "memoffset", "more-asserts", + "psm", + "rand 0.7.3", "region", "thiserror", "wasmtime-environ", diff --git a/Cargo.toml b/Cargo.toml index 0d08a3839..f768d195c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aurora-engine" -version = "1.0.0" +version = "1.5.0" authors = ["NEAR "] edition = "2018" description = "" @@ -16,7 +16,7 @@ autobenches = false crate-type = ["cdylib", "rlib"] [profile.release] -opt-level = "z" +opt-level = 3 debug = false debug-assertions = false overflow-checks = true @@ -27,6 +27,7 @@ codegen-units = 1 rpath = false [profile.dev] +# Due to a strange bug, setting this to 3 will cause test failures opt-level = "z" debug = false debug-assertions = true @@ -37,12 +38,18 @@ incremental = false codegen-units = 1 rpath = false +[profile.bench] +# lto must be enabled in the bench profile as well for +# it to actually happen when running tests with --release +lto = true +opt-level = 3 + [dependencies] blake2 = { git = "https://github.com/near/near-blake2.git", version = "0.9.1", default-features = false } borsh = { version = "0.8.2", default-features = false } bn = { package = "aurora-bn", git = "https://github.com/aurora-is-near/aurora-bn.git", default-features = false } -evm = { version = "0.28.0", default-features = false } -evm-core = { version = "0.28.0", default-features = false } +evm = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "09d4fe09dcb5fcabed8c1076699c8a2e70f14c23", default-features = false } +evm-core = { git = "https://github.com/aurora-is-near/sputnikvm.git", rev = "09d4fe09dcb5fcabed8c1076699c8a2e70f14c23", default-features = false } libsecp256k1 = { version = "0.3.5", default-features = false } num = { version = "0.4.0", default-features = false, features = ["alloc"] } primitive-types = { version = "0.9.0", default-features = false, features = ["rlp"] } @@ -62,12 +69,12 @@ bstr = "0.2" serde = { version = "1", features = ["derive"] } serde_json = "1" hex = { version = "0.4.3", default-features = false } -near-sdk = { git = "https://github.com/near/near-sdk-rs", rev = "9d99077c6acfde68c06845f2a1eb2b5ed7983401" } -near-sdk-sim = { git = "https://github.com/near/near-sdk-rs", rev = "9d99077c6acfde68c06845f2a1eb2b5ed7983401" } -near-crypto = "0.1.0" -near-vm-runner = "4.0.0-pre.1" -near-vm-logic = "4.0.0-pre.1" -near-primitives-core = "0.4.0" +near-sdk = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "1b9843fe5b652928582e33879fc92ba87a639450" } +near-sdk-sim = { git = "https://github.com/aurora-is-near/near-sdk-rs.git", rev = "1b9843fe5b652928582e33879fc92ba87a639450" } +near-crypto = { git = "https://github.com/near/nearcore.git", branch = "1.20.1"} +near-vm-runner = { git = "https://github.com/near/nearcore.git", branch = "1.20.1"} +near-vm-logic = { git = "https://github.com/near/nearcore.git", branch = "1.20.1"} +near-primitives-core = { git = "https://github.com/near/nearcore.git", branch = "1.20.1"} libsecp256k1 = "0.3.5" rand = "0.7.3" criterion = "0.3.4" @@ -86,3 +93,6 @@ integration-test = ["log"] mainnet = ["contract", "log"] testnet = ["contract", "log"] betanet = ["contract", "log", "meta-call"] +mainnet-test = ["meta-call"] +testnet-test = ["meta-call"] +betanet-test = ["meta-call"] diff --git a/Makefile b/Makefile index 974389002..8e9b34172 100644 --- a/Makefile +++ b/Makefile @@ -6,25 +6,31 @@ ifeq ($(evm-bully),yes) FEATURES := $(FEATURES),evm_bully endif -all: release +# TODO: This isn't updating the `FEATURES` for some reason. Disabled to prevent accidental compilation of the same binary for release. +#all: mainnet testnet betanet + +release: mainnet mainnet: FEATURES=mainnet -mainnet: release +mainnet: mainnet-release.wasm testnet: FEATURES=testnet -testnet: release +testnet: testnet-release.wasm betanet: FEATURES=betanet -betanet: release +betanet: betanet-release.wasm + +mainnet-release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm + cp $< $@ -release: release.wasm +testnet-release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm + cp $< $@ -release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm - ln -sf $< $@ +betanet-release.wasm: target/wasm32-unknown-unknown/release/aurora_engine.wasm + cp $< $@ target/wasm32-unknown-unknown/release/aurora_engine.wasm: Cargo.toml Cargo.lock $(shell find src -name "*.rs") etc/eth-contracts/res/EvmErc20.bin RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=$(FEATURES) -Z avoid-dev-deps - ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm etc/eth-contracts/res/EvmErc20.bin: $(shell find etc/eth-contracts/contracts -name "*.sol") etc/eth-contracts/package.json cd etc/eth-contracts && yarn && yarn build @@ -32,22 +38,54 @@ etc/eth-contracts/res/EvmErc20.bin: $(shell find etc/eth-contracts/contracts -na etc/eth-contracts/artifacts/contracts/test/StateTest.sol/StateTest.json: $(shell find etc/eth-contracts/contracts -name "*.sol") etc/eth-contracts/package.json cd etc/eth-contracts && yarn && yarn build -debug: debug.wasm +# TODO: This isn't updating the `FEATURES` for some reason. Disabled to prevent accidental compilation of the same binary for debug. +#all-debug: mainnet-debug testnet-debug betanet-debug + +debug: mainnet-debug + +mainnet-debug: FEATURES=mainnet +mainnet-debug: mainnet-debug.wasm + +testnet-debug: FEATURES=testnet +testnet-debug: testnet-debug.wasm + +betanet-debug: FEATURES=betanet +betanet-debug: betanet-debug.wasm + +mainnet-debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm + cp $< $@ -debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm - ln -sf $< $@ +testnet-debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm + cp $< $@ + +betanet-debug.wasm: target/wasm32-unknown-unknown/debug/aurora_engine.wasm + cp $< $@ target/wasm32-unknown-unknown/debug/aurora_engine.wasm: Cargo.toml Cargo.lock $(wildcard src/*.rs) etc/eth-contracts/res/EvmErc20.bin $(CARGO) build --target wasm32-unknown-unknown --no-default-features --features=$(FEATURES) -Z avoid-dev-deps -test-build: etc/eth-contracts/artifacts/contracts/test/StateTest.sol/StateTest.json etc/eth-contracts/res/EvmErc20.bin - RUSTFLAGS='-C link-arg=-s' $(CARGO) build --target wasm32-unknown-unknown --release --no-default-features --features=mainnet,integration-test,meta-call -Z avoid-dev-deps - ln -sf target/wasm32-unknown-unknown/release/aurora_engine.wasm release.wasm - ls -l target/wasm32-unknown-unknown/release/aurora_engine.wasm +# test depends on release since `tests/test_upgrade.rs` includes `mainnet-release.wasm` +test: test-mainnet + +mainnet-test-build: FEATURES=mainnet,integration-test,meta-call +mainnet-test-build: mainnet-release.wasm + +betanet-test-build: FEATURES=betanet,integration-test,meta-call +betanet-test-build: betanet-release.wasm + +testnet-test-build: FEATURES=testnet,integration-test,meta-call +testnet-test-build: testnet-release.wasm -.PHONY: all release debug eth-contracts mainnet testnet betanet +test-mainnet: mainnet-test-build + $(CARGO) test --features mainnet-test -deploy: release.wasm +test-testnet: testnet-test-build + $(CARGO) test --features testnet-test + +test-betanet: betanet-test-build + $(CARGO) test --features betanet-test + +deploy: mainnet-release.wasm $(NEAR) deploy --account-id=$(or $(NEAR_EVM_ACCOUNT),aurora.test.near) --wasm-file=$< check: test test-sol check-format check-clippy @@ -58,10 +96,6 @@ check-format: check-clippy: $(CARGO) clippy --no-default-features --features=$(FEATURES) -- -D warnings -# test depends on release since `tests/test_upgrade.rs` includes `release.wasm` -test: test-build - $(CARGO) test --features meta-call - test-sol: cd etc/eth-contracts && yarn && yarn test @@ -69,9 +103,10 @@ format: $(CARGO) fmt clean: - @rm -Rf *.wasm target *~ + @rm -Rf *.wasm + cargo clean -.PHONY: deploy check check-format check-clippy test format clean +.PHONY: release mainnet testnet betanet compile-release test-build deploy check check-format check-clippy test test-sol format clean debug mainnet-debug testnet-debug betanet-debug compile-debug mainnet-test-build testnet-test-build betanet-test-build target/wasm32-unknown-unknown/release/aurora_engine.wasm target/wasm32-unknown-unknown/debug/aurora_engine.wasm .SECONDARY: .SUFFIXES: diff --git a/README.md b/README.md index 9754482f7..e15ee0bcb 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ documentation. Network | Contract ID | Chain ID | Status ------- | ------------------- | ---------- | ------ -Mainnet | [`aurora`][Mainnet] | 1313161554 | 🚧 -Testnet | [`aurora`][Testnet] | 1313161555 | 🚧 -Betanet | [`aurora`][Betanet] | 1313161556 | 🚧 +Mainnet | [`aurora`][Mainnet] | 1313161554 | ✅ +Testnet | [`aurora`][Testnet] | 1313161555 | ✅ +Betanet | [`aurora`][Betanet] | 1313161556 | ✅ Local | `aurora.test.near` | 1313161556 | ✅ [Mainnet]: https://explorer.near.org/accounts/aurora @@ -52,11 +52,15 @@ rustup target add wasm32-unknown-unknown --toolchain nightly-2021-03-25 ### Building the EVM binary ```sh +make release # produces mainnet-release.wasm (300+ KiB) make -B mainnet # produces Mainnet build make -B testnet # produces Testnet build make -B betanet # produces Betanet build -make release # produces release.wasm (300+ KiB) -make debug # produces debug.wasm (1+ MiB), which includes symbols + +make debug # produces mainnet-debug.wasm (1+ MiB), which includes symbols +make -B mainnet-debug # produces Mainnet debug build +make -B testnet-debug # produces Testnet debug build +make -B betanet-debug #produces Betanet debug build ``` ### Running unit & integration tests @@ -70,7 +74,7 @@ make check ### Downloading the latest EVM release ```sh -wget https://github.com/aurora-is-near/aurora-engine/releases/download/latest/release.wasm +wget https://github.com/aurora-is-near/aurora-engine/releases/download/latest/mainnet-release.wasm ``` ### Installing the Aurora CLI tool @@ -85,7 +89,7 @@ npm install -g aurora-is-near/aurora-cli export NEAR_ENV=local near delete aurora.test.near test.near # if needed near create-account aurora.test.near --master-account=test.near --initial-balance 1000000 -aurora install --chain 1313161556 --owner test.near release.wasm +aurora install --chain 1313161556 --owner test.near mainnet-release.wasm ``` ### Deploying the EVM without the CLI @@ -94,7 +98,7 @@ aurora install --chain 1313161556 --owner test.near release.wasm export NEAR_ENV=local near delete aurora.test.near test.near # if needed near create-account aurora.test.near --master-account=test.near --initial-balance 1000000 -near deploy --account-id=aurora.test.near --wasm-file=release.wasm +near deploy --account-id=aurora.test.near --wasm-file=mainnet-release.wasm aurora initialize --chain 1313161556 --owner test.near ``` diff --git a/VERSION b/VERSION index 428b770e3..bc80560fa 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.4.3 +1.5.0 diff --git a/etc/eth-contracts/hardhat.config.js b/etc/eth-contracts/hardhat.config.js index be67c79a9..fde0d36a5 100644 --- a/etc/eth-contracts/hardhat.config.js +++ b/etc/eth-contracts/hardhat.config.js @@ -1,10 +1,12 @@ require('@nomiclabs/hardhat-waffle'); require('solidity-coverage'); +require('./tasks/storage'); /** * @type import('hardhat/config').HardhatUserConfig */ module.exports = { + newStorageLayoutPath: './storageLayout', solidity: { version: '0.8.3', settings: { @@ -12,6 +14,11 @@ module.exports = { enabled: true, runs: 1000, }, + outputSelection: { + '*': { + '*': ['storageLayout'], + }, + }, }, }, }; diff --git a/etc/eth-contracts/package.json b/etc/eth-contracts/package.json index 6d36ab4dd..f0fb06ed2 100644 --- a/etc/eth-contracts/package.json +++ b/etc/eth-contracts/package.json @@ -8,6 +8,7 @@ "devDependencies": { "@nomiclabs/hardhat-ethers": "^2.0.1", "@nomiclabs/hardhat-waffle": "^2.0.1", + "hardhat-storage-layout": "^0.1.6", "chai": "^4.3.3", "eslint": "^6.3.0", "eslint-config-standard": "^14.1.0", diff --git a/etc/eth-contracts/tasks/storage.js b/etc/eth-contracts/tasks/storage.js new file mode 100644 index 000000000..879bb01a5 --- /dev/null +++ b/etc/eth-contracts/tasks/storage.js @@ -0,0 +1,9 @@ +require('hardhat-storage-layout'); +// eslint-disable-next-line no-undef +task('storageLayout', 'automatically generates the contract storage layout') + .setAction(async () => { + // eslint-disable-next-line no-undef + await hre.storageLayout.export(); + }); + +module.exports = {}; diff --git a/etc/eth-contracts/yarn.lock b/etc/eth-contracts/yarn.lock index 7155e5457..a8ab03d78 100644 --- a/etc/eth-contracts/yarn.lock +++ b/etc/eth-contracts/yarn.lock @@ -2995,6 +2995,13 @@ configstore@^5.0.1: write-file-atomic "^3.0.0" xdg-basedir "^4.0.0" +console-table-printer@^2.9.0: + version "2.9.0" + resolved "https://registry.yarnpkg.com/console-table-printer/-/console-table-printer-2.9.0.tgz#5d75374bc94ae57048587604829cb914b282a088" + integrity sha512-20o73riqnclLYJt5ggNqP2ZjtgL5OxJPWzTVi3LyVFVtubMH0XN+oOn9outL1XI5ldJgPcjdMAWc92vRscHAKA== + dependencies: + simple-wcswidth "^1.0.1" + constant-case@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/constant-case/-/constant-case-3.0.4.tgz#3b84a9aeaf4cf31ec45e6bf5de91bdfb0589faf1" @@ -5424,6 +5431,13 @@ har-validator@~5.1.3: ajv "^6.12.3" har-schema "^2.0.0" +hardhat-storage-layout@^0.1.6: + version "0.1.6" + resolved "https://registry.yarnpkg.com/hardhat-storage-layout/-/hardhat-storage-layout-0.1.6.tgz#b6ae33d4c00f385dbc1ff67c86d67b0198cfbd91" + integrity sha512-urp9PUDJmRrFaTnMkyYGAlU0OF7Q+inWMWKHvuGRyvBDwVQKXfj5WoerTax4bBpXukJ4fBYyUTjAr0x+j2LcKQ== + dependencies: + console-table-printer "^2.9.0" + hardhat@^2.1.1: version "2.2.1" resolved "https://registry.yarnpkg.com/hardhat/-/hardhat-2.2.1.tgz#bef0031b994e3f60a88d428f2097195c58cf9ed2" @@ -9022,6 +9036,11 @@ simple-get@^2.7.0: once "^1.3.1" simple-concat "^1.0.0" +simple-wcswidth@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/simple-wcswidth/-/simple-wcswidth-1.0.1.tgz#8ab18ac0ae342f9d9b629604e54d2aa1ecb018b2" + integrity sha512-xMO/8eNREtaROt7tJvWJqHBDTMFN4eiQ5I4JRMuilwfnFcV5W9u7RUkueNkdw0jPqGMX36iCywelS5yilTuOxg== + slash@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" diff --git a/etc/state-migration-test/Cargo.lock b/etc/state-migration-test/Cargo.lock index 2962588df..d440d8c53 100644 --- a/etc/state-migration-test/Cargo.lock +++ b/etc/state-migration-test/Cargo.lock @@ -306,8 +306,7 @@ dependencies = [ [[package]] name = "evm" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff50bbacb1b2149e29cc31bdd73dc2fe6d3cc0d291c438ec1cb3cdb7b2f8aa1c" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "ethereum", "evm-core", @@ -322,8 +321,7 @@ dependencies = [ [[package]] name = "evm-core" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7828a238e25e8c5b5a23a2114e6f3863780ffd1dca6f7f74eecfd51271a8c573" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "funty", "primitive-types", @@ -332,8 +330,7 @@ dependencies = [ [[package]] name = "evm-gasometer" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b61792ef56c7772b6d9425674852241dddcbb5fd507e6849c63ce39d1ad74e5e" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "evm-core", "evm-runtime", @@ -343,8 +340,7 @@ dependencies = [ [[package]] name = "evm-runtime" version = "0.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b7b8ae833004b1d619997d8a31b61b291b0bb3a7ed0af709342331a9a217d53" +source = "git+https://github.com/aurora-is-near/sputnikvm.git?rev=09d4fe09dcb5fcabed8c1076699c8a2e70f14c23#09d4fe09dcb5fcabed8c1076699c8a2e70f14c23" dependencies = [ "evm-core", "primitive-types", diff --git a/src/connector.rs b/src/connector.rs index 25b86a902..bed566ebf 100644 --- a/src/connector.rs +++ b/src/connector.rs @@ -11,8 +11,6 @@ use crate::engine::Engine; use crate::json::parse_json; use crate::prelude::*; use crate::storage::{self, EthConnectorStorageId, KeyPrefix}; -#[cfg(feature = "log")] -use alloc::format; use borsh::{BorshDeserialize, BorshSerialize}; pub(crate) const ERR_NOT_ENOUGH_BALANCE_FOR_FEE: &str = "ERR_NOT_ENOUGH_BALANCE_FOR_FEE"; diff --git a/src/engine.rs b/src/engine.rs index 30d415718..fa2f2e7b3 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -13,8 +13,8 @@ use crate::parameters::{ ViewCallArgs, }; -use crate::precompiles; -use crate::prelude::{Address, TryInto, Vec, H256, U256}; +use crate::precompiles::Precompiles; +use crate::prelude::{is_valid_account_id, Address, TryInto, Vec, H256, U256}; use crate::sdk; use crate::state::AuroraStackState; use crate::storage::{address_to_key, bytes_to_key, storage_to_key, KeyPrefix, KeyPrefixU8}; @@ -128,6 +128,50 @@ impl ExitIntoResult for ExitReason { } } +pub const ERR_INVALID_NEP141_ACCOUNT_ID: &str = "ERR_INVALID_NEP141_ACCOUNT_ID"; + +#[derive(Debug)] +pub enum GetErc20FromNep141Error { + InvalidNep141AccountId, + Nep141NotFound, +} + +impl GetErc20FromNep141Error { + pub fn to_str(&self) -> &str { + match self { + Self::InvalidNep141AccountId => ERR_INVALID_NEP141_ACCOUNT_ID, + Self::Nep141NotFound => "ERR_NEP141_NOT_FOUND", + } + } +} + +impl AsRef<[u8]> for GetErc20FromNep141Error { + fn as_ref(&self) -> &[u8] { + self.to_str().as_bytes() + } +} + +#[derive(Debug)] +pub enum RegisterTokenError { + InvalidNep141AccountId, + TokenAlreadyRegistered, +} + +impl RegisterTokenError { + pub fn to_str(&self) -> &str { + match self { + Self::InvalidNep141AccountId => ERR_INVALID_NEP141_ACCOUNT_ID, + Self::TokenAlreadyRegistered => "ERR_NEP141_TOKEN_ALREADY_REGISTERED", + } + } +} + +impl AsRef<[u8]> for RegisterTokenError { + fn as_ref(&self) -> &[u8] { + self.to_str().as_bytes() + } +} + #[derive(Debug)] pub enum EngineStateError { NotFound, @@ -340,7 +384,7 @@ impl Engine { pub fn deploy_code_with_input(&mut self, input: Vec) -> EngineResult { let origin = self.origin(); let value = Wei::zero(); - self.deploy_code(origin, value, input, u64::MAX) + self.deploy_code(origin, value, input, u64::MAX, Vec::new()) } pub fn deploy_code( @@ -349,11 +393,12 @@ impl Engine { value: Wei, input: Vec, gas_limit: u64, + access_list: Vec<(Address, Vec)>, // See EIP-2930 ) -> EngineResult { let mut executor = self.make_executor(gas_limit); let address = executor.create_address(CreateScheme::Legacy { caller: origin }); let (status, result) = ( - executor.transact_create(origin, value.raw(), input, gas_limit), + executor.transact_create(origin, value.raw(), input, gas_limit, access_list), address, ); let is_succeed = status.is_succeed(); @@ -378,7 +423,7 @@ impl Engine { let origin = self.origin(); let contract = Address(args.contract); let value = Wei::zero(); - self.call(origin, contract, value, args.input, u64::MAX) + self.call(origin, contract, value, args.input, u64::MAX, Vec::new()) } pub fn call( @@ -388,10 +433,11 @@ impl Engine { value: Wei, input: Vec, gas_limit: u64, + access_list: Vec<(Address, Vec)>, // See EIP-2930 ) -> EngineResult { let mut executor = self.make_executor(gas_limit); let (status, result) = - executor.transact_call(origin, contract, value.raw(), input, gas_limit); + executor.transact_call(origin, contract, value.raw(), input, gas_limit, access_list); let is_succeed = status.is_succeed(); if let Err(e) = status.into_result() { @@ -438,15 +484,15 @@ impl Engine { ) -> EngineResult> { let mut executor = self.make_executor(gas_limit); let (status, result) = - executor.transact_call(origin, contract, value.raw(), input, gas_limit); + executor.transact_call(origin, contract, value.raw(), input, gas_limit, Vec::new()); status.into_result()?; Ok(result) } - fn make_executor(&self, gas_limit: u64) -> StackExecutor { + fn make_executor(&self, gas_limit: u64) -> StackExecutor { let metadata = StackSubstateMetadata::new(gas_limit, CONFIG); let state = AuroraStackState::new(metadata, self); - StackExecutor::new_with_precompile(state, CONFIG, precompiles::istanbul_precompiles) + StackExecutor::new_with_precompile(state, CONFIG, Precompiles::new_istanbul()) } pub fn register_relayer(&mut self, account_id: &[u8], evm_address: Address) { @@ -463,15 +509,33 @@ impl Engine { .map(|result| Address(result.as_slice().try_into().unwrap())) } - pub fn register_token(&mut self, erc20_token: &[u8], nep141_token: &[u8]) { - // Check that this nep141 token was not registered before, they can only be registered once. - let map = Self::nep141_erc20_map(); - assert!(map.lookup_left(nep141_token).is_none()); - map.insert(nep141_token, erc20_token); + pub fn register_token( + &mut self, + erc20_token: &[u8], + nep141_token: &[u8], + ) -> Result<(), RegisterTokenError> { + match Self::get_erc20_from_nep141(nep141_token) { + Err(GetErc20FromNep141Error::Nep141NotFound) => (), + Err(GetErc20FromNep141Error::InvalidNep141AccountId) => { + return Err(RegisterTokenError::InvalidNep141AccountId) + } + Ok(_) => return Err(RegisterTokenError::TokenAlreadyRegistered), + } + + Self::nep141_erc20_map().insert(nep141_token, erc20_token); + Ok(()) } - pub fn get_erc20_from_nep141(&self, nep141_token: &[u8]) -> Option> { - Self::nep141_erc20_map().lookup_left(nep141_token) + pub fn get_erc20_from_nep141( + nep141_account_id: &[u8], + ) -> Result, GetErc20FromNep141Error> { + if !is_valid_account_id(nep141_account_id) { + return Err(GetErc20FromNep141Error::InvalidNep141AccountId); + } + + Self::nep141_erc20_map() + .lookup_left(nep141_account_id) + .ok_or(GetErc20FromNep141Error::Nep141NotFound) } /// Transfers an amount from a given sender to a receiver, provided that @@ -486,7 +550,7 @@ impl Engine { value: Wei, gas_limit: u64, ) -> EngineResult { - self.call(sender, receiver, value, Vec::new(), gas_limit) + self.call(sender, receiver, value, Vec::new(), gas_limit, Vec::new()) } /// Mint tokens for recipient on a particular ERC20 token @@ -503,8 +567,6 @@ impl Engine { let str_amount = crate::prelude::format!("\"{}\"", args.amount); let output_on_fail = str_amount.as_bytes(); - let token = sdk::predecessor_account_id(); - // Parse message to determine recipient and fee let (recipient, fee) = { // Message format: @@ -531,13 +593,11 @@ impl Engine { (recipient, fee) }; + let token = sdk::predecessor_account_id(); let erc20_token = Address(unwrap_res_or_finish!( - unwrap_res_or_finish!( - self.get_erc20_from_nep141(token.as_slice()).ok_or(()), - output_on_fail - ) - .as_slice() - .try_into(), + unwrap_res_or_finish!(Self::get_erc20_from_nep141(&token), output_on_fail) + .as_slice() + .try_into(), output_on_fail )); @@ -572,6 +632,7 @@ impl Engine { Wei::zero(), [selector, tail.as_slice()].concat(), u64::MAX, + Vec::new(), // TODO: are there values we should put here? ), output_on_fail ); diff --git a/src/json.rs b/src/json.rs index d1bae1ca8..dede148a2 100644 --- a/src/json.rs +++ b/src/json.rs @@ -2,6 +2,8 @@ use super::prelude::*; use core::convert::From; use rjson::{Array, Null, Object, Value}; +#[cfg(test)] +use std::collections::BTreeMap; pub enum JsonValue { Null, @@ -12,7 +14,7 @@ pub enum JsonValue { Object(BTreeMap), } -#[derive(Debug)] +#[derive(Ord, PartialOrd, Eq, PartialEq)] pub enum JsonError { NotJsonType, MissingValue, @@ -23,9 +25,17 @@ pub enum JsonError { InvalidString, InvalidArray, ExpectedStringGotNumber, + OutOfRange(JsonOutOfRangeError), } -#[derive(Debug)] +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] +pub enum JsonOutOfRangeError { + U8, + U64, + U128, +} + +#[derive(Debug, Ord, PartialOrd, Eq, PartialEq)] pub enum ParseError { InvalidAccountId, } @@ -49,7 +59,15 @@ impl JsonValue { pub fn u64(&self, key: &str) -> Result { match self { JsonValue::Object(o) => match o.get(key).ok_or(JsonError::MissingValue)? { - JsonValue::Number(n) => Ok(*n as u64), + JsonValue::Number(n) => { + if n.is_sign_negative() || n.is_infinite() || n > &(u64::MAX as f64) { + Err(JsonError::OutOfRange(JsonOutOfRangeError::U64)) + } else if n.is_nan() { + Err(JsonError::InvalidU64) + } else { + Ok(*n as u64) + } + } _ => Err(JsonError::InvalidU64), }, _ => Err(JsonError::NotJsonType), @@ -78,24 +96,16 @@ impl JsonValue { #[allow(dead_code)] pub fn parse_u8(v: &JsonValue) -> Result { match v { - JsonValue::Number(n) => Ok(*n as u8), + JsonValue::Number(n) => { + if n.is_sign_negative() || n > &(u8::MAX as f64) { + Err(JsonError::OutOfRange(JsonOutOfRangeError::U8)) + } else { + Ok(*n as u8) + } + } _ => Err(JsonError::InvalidU8), } } - - #[allow(dead_code)] - pub fn array(&self, key: &str, call: F) -> Result, JsonError> - where - F: FnMut(&JsonValue) -> T, - { - match self { - JsonValue::Object(o) => match o.get(key).ok_or(JsonError::MissingValue)? { - JsonValue::Array(arr) => Ok(arr.iter().map(call).collect()), - _ => Err(JsonError::InvalidArray), - }, - _ => Err(JsonError::NotJsonType), - } - } } impl AsRef<[u8]> for JsonError { @@ -110,10 +120,38 @@ impl AsRef<[u8]> for JsonError { Self::InvalidString => b"ERR_FAILED_PARSE_STRING", Self::InvalidArray => b"ERR_FAILED_PARSE_ARRAY", Self::ExpectedStringGotNumber => b"ERR_EXPECTED_STRING_GOT_NUMBER", + Self::OutOfRange(err) => err.as_ref(), } } } +impl AsRef<[u8]> for JsonOutOfRangeError { + fn as_ref(&self) -> &[u8] { + match self { + Self::U8 => b"ERR_OUT_OF_RANGE_U8", + Self::U64 => b"ERR_OUT_OF_RANGE_U64", + Self::U128 => b"ERR_OUT_OF_RANGE_U128", + } + } +} + +#[cfg(test)] +impl std::fmt::Debug for JsonError { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + f.write_fmt(format_args!( + "{}", + std::str::from_utf8(self.as_ref()).unwrap() + )) + } +} + +#[cfg(test)] +impl std::fmt::Display for JsonError { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + f.write_fmt(format_args!("{:?}", *self)) + } +} + impl Array for JsonArray { fn new() -> Self { JsonArray(Vec::new()) @@ -175,7 +213,15 @@ impl TryFrom<&JsonValue> for u128 { fn try_from(value: &JsonValue) -> Result { match value { - JsonValue::String(n) => Ok(n.parse::().map_err(|_| JsonError::InvalidU128)?), + JsonValue::String(n) => { + if let Ok(x) = n.parse::() { + Ok(x) + } else if n.parse::().is_ok() { + Err(JsonError::OutOfRange(JsonOutOfRangeError::U128)) + } else { + Err(JsonError::InvalidU128) + } + } JsonValue::Number(_) => Err(JsonError::ExpectedStringGotNumber), _ => Err(JsonError::InvalidU128), } @@ -207,3 +253,204 @@ pub fn parse_json(data: &[u8]) -> Option { let mut index = 0; rjson::parse::(&*data_array, &mut index) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_json_type_string() { + let json = parse_json(r#"{"foo": "abcd"}"#.as_bytes()).unwrap(); + let string_data = json.string("foo").ok().unwrap(); + assert_eq!(string_data, "abcd"); + + let json = parse_json(r#"{"foo": 123}"#.as_bytes()).unwrap(); + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidString); + + let json = parse_json(r#"{"foo": true}"#.as_bytes()).unwrap(); + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidString); + + let json = parse_json(r#"{"foo": ["abcd"]}"#.as_bytes()).unwrap(); + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidString); + + let json = parse_json(r#"{"foo": {}}"#.as_bytes()).unwrap(); + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidString); + + let json = parse_json(r#"{"foo": null}"#.as_bytes()).unwrap(); + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidString); + + let json = JsonValue::Null; + let err = json.string("foo").unwrap_err(); + assert_eq!(err, JsonError::NotJsonType); + } + + #[test] + fn test_json_type_u64() { + let json = parse_json(r#"{"foo": 123}"#.as_bytes()).unwrap(); + let val = json.u64("foo").ok().unwrap(); + assert_eq!(val, 123); + + let json = parse_json(format!(r#"{{"foo": {} }}"#, u64::MAX).as_bytes()).unwrap(); + let val = json.u64("foo").ok().unwrap(); + assert_eq!(val, u64::MAX); + + let json = parse_json(r#"{"foo": 12.99}"#.as_bytes()).unwrap(); + // TODO [#176]: should fail since it is not a `u64` + let val = json.u64("foo").ok().unwrap(); + assert_eq!(val, 12); + + let json = parse_json(format!(r#"{{"foo": {} }}"#, u128::MAX).as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::OutOfRange(JsonOutOfRangeError::U64)); + + let json = parse_json(r#"{"foo": -123}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::OutOfRange(JsonOutOfRangeError::U64)); + + let json = parse_json(r#"{"foo": "abcd"}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = parse_json(r#"{"foo": "123"}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = parse_json(r#"{"foo": true}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = parse_json(r#"{"foo": [123]}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = parse_json(r#"{"foo": {}}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = parse_json(r#"{"foo": null}"#.as_bytes()).unwrap(); + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU64); + + let json = JsonValue::Null; + let err = json.u64("foo").unwrap_err(); + assert_eq!(err, JsonError::NotJsonType); + } + + #[test] + fn test_json_type_u128() { + let json = parse_json(r#"{"foo": "123"}"#.as_bytes()).unwrap(); + let val = json.u128("foo").ok().unwrap(); + assert_eq!(val, 123); + + let json = parse_json(r#"{"foo": "-123"}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::OutOfRange(JsonOutOfRangeError::U128)); + + let json = parse_json(r#"{"foo": 123}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::ExpectedStringGotNumber); + + let json = parse_json(r#"{"foo": 12.3}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::ExpectedStringGotNumber); + + let json = parse_json(r#"{"foo": "12.3"}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = parse_json(r#"{"foo": "abcd"}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = parse_json(r#"{"foo": true}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = parse_json(r#"{"foo": ["123"]}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = parse_json(r#"{"foo": {}}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = parse_json(r#"{"foo": null}"#.as_bytes()).unwrap(); + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidU128); + + let json = JsonValue::Null; + let err = json.u128("foo").unwrap_err(); + assert_eq!(err, JsonError::NotJsonType); + } + + #[test] + fn test_json_type_bool() { + let json = parse_json(r#"{"foo": true}"#.as_bytes()).unwrap(); + let val = json.bool("foo").ok().unwrap(); + assert_eq!(val, true); + + let json = parse_json(r#"{"foo": false}"#.as_bytes()).unwrap(); + let val = json.bool("foo").ok().unwrap(); + assert_eq!(val, false); + + let json = parse_json(r#"{"foo": "true"}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": "false"}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": [true]}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": 123}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": 12.3}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": "abcd"}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": {}}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = parse_json(r#"{"foo": null}"#.as_bytes()).unwrap(); + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::InvalidBool); + + let json = JsonValue::Null; + let err = json.bool("foo").unwrap_err(); + assert_eq!(err, JsonError::NotJsonType); + } + + #[test] + fn test_json_type_u8() { + let json = JsonValue::from(123f64); + let val = JsonValue::parse_u8(&json).ok().unwrap(); + assert_eq!(val, 123); + + let json = JsonValue::from(-1f64); + let err = JsonValue::parse_u8(&json).unwrap_err(); + assert_eq!(err, JsonError::OutOfRange(JsonOutOfRangeError::U8)); + + let json = JsonValue::from(256f64); + let err = JsonValue::parse_u8(&json).unwrap_err(); + assert_eq!(err, JsonError::OutOfRange(JsonOutOfRangeError::U8)); + + let json = JsonValue::from("abcd".to_string()); + let err = JsonValue::parse_u8(&json).unwrap_err(); + assert_eq!(err, JsonError::InvalidU8); + } +} diff --git a/src/lib.rs b/src/lib.rs index b50b81bba..3f2843730 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -81,13 +81,13 @@ mod contract { #[cfg(feature = "evm_bully")] use crate::parameters::{BeginBlockArgs, BeginChainArgs}; use crate::parameters::{ - DeployErc20TokenArgs, ExpectUtf8, FunctionCallArgs, GetStorageAtArgs, InitCallArgs, - IsUsedProofCallArgs, NEP141FtOnTransferArgs, NewCallArgs, PauseEthConnectorCallArgs, - SetContractDataCallArgs, TransferCallCallArgs, ViewCallArgs, + DeployErc20TokenArgs, ExpectUtf8, FunctionCallArgs, GetErc20FromNep141CallArgs, + GetStorageAtArgs, InitCallArgs, IsUsedProofCallArgs, NEP141FtOnTransferArgs, NewCallArgs, + PauseEthConnectorCallArgs, SetContractDataCallArgs, TransferCallCallArgs, ViewCallArgs, }; use crate::json::parse_json; - use crate::prelude::{format, Address, ToString, TryInto, H160, H256, U256}; + use crate::prelude::{Address, ToString, TryInto, H160, H256, U256}; use crate::sdk; use crate::storage::{bytes_to_key, KeyPrefix}; use crate::types::{ @@ -219,8 +219,7 @@ mod contract { let input = sdk::read_input(); - let EthTransaction::Legacy(signed_transaction) = - EthTransaction::try_from(input.as_slice()).sdk_unwrap(); + let signed_transaction = EthTransaction::try_from(input.as_slice()).sdk_unwrap(); let state = Engine::get_state().sdk_unwrap(); @@ -236,16 +235,13 @@ mod contract { .sender() .sdk_expect("ERR_INVALID_ECDSA_SIGNATURE"); - Engine::check_nonce(&sender, &signed_transaction.transaction.nonce).sdk_unwrap(); + Engine::check_nonce(&sender, signed_transaction.nonce()).sdk_unwrap(); // Check intrinsic gas is covered by transaction gas limit - match signed_transaction - .transaction - .intrinsic_gas(crate::engine::CONFIG) - { + match signed_transaction.intrinsic_gas(crate::engine::CONFIG) { None => sdk::panic_utf8(GAS_OVERFLOW.as_bytes()), Some(intrinsic_gas) => { - if signed_transaction.transaction.gas < intrinsic_gas.into() { + if signed_transaction.gas_limit() < &intrinsic_gas.into() { sdk::panic_utf8(b"ERR_INTRINSIC_GAS") } } @@ -253,18 +249,27 @@ mod contract { // Figure out what kind of a transaction this is, and execute it: let mut engine = Engine::new_with_state(state, sender); - let value = signed_transaction.transaction.value; - let gas_limit = signed_transaction - .transaction - .get_gas_limit() - .sdk_expect(GAS_OVERFLOW); - let data = signed_transaction.transaction.data; - let result = if let Some(receiver) = signed_transaction.transaction.to { - Engine::call(&mut engine, sender, receiver, value, data, gas_limit) + let (value, gas_limit, data, maybe_receiver, access_list) = + signed_transaction.destructure(); + let gas_limit = gas_limit.sdk_expect(GAS_OVERFLOW); + let access_list = access_list + .into_iter() + .map(|a| (a.address, a.storage_keys)) + .collect(); + let result = if let Some(receiver) = maybe_receiver { + Engine::call( + &mut engine, + sender, + receiver, + value, + data, + gas_limit, + access_list, + ) // TODO: charge for storage } else { // Execute a contract deployment: - Engine::deploy_code(&mut engine, sender, value, data, gas_limit) + Engine::deploy_code(&mut engine, sender, value, data, gas_limit, access_list) // TODO: charge for storage }; result @@ -294,6 +299,7 @@ mod contract { meta_call_args.value, meta_call_args.input, u64::MAX, // TODO: is there a gas limit with meta calls? + crate::prelude::Vec::new(), ); result .map(|res| res.try_to_vec().sdk_expect("ERR_SERIALIZE")) @@ -323,7 +329,6 @@ mod contract { let args: NEP141FtOnTransferArgs = parse_json(sdk::read_input().as_slice()) .sdk_unwrap() .try_into() - .map_err(|err| format!("ERR_JSON_{:?}", err)) .sdk_unwrap(); if sdk::predecessor_account_id() == sdk::current_account_id() { @@ -357,7 +362,12 @@ mod contract { ) .map(|res| { let address = H160(res.result.as_slice().try_into().unwrap()); - engine.register_token(address.as_bytes(), args.nep141.as_bytes()); + crate::log!( + crate::prelude::format!("Deployed ERC-20 in Aurora at: {:#?}", address).as_str() + ); + engine + .register_token(address.as_bytes(), &args.nep141.as_bytes()) + .sdk_unwrap(); res.result.try_to_vec().sdk_expect("ERR_SERIALIZE") }) .sdk_process(); @@ -568,10 +578,13 @@ mod contract { #[no_mangle] pub extern "C" fn get_erc20_from_nep141() { + let args: GetErc20FromNep141CallArgs = + GetErc20FromNep141CallArgs::try_from_slice(&sdk::read_input()) + .sdk_expect("ERR_ARG_PARSE"); + sdk::return_output( - Engine::nep141_erc20_map() - .lookup_left(sdk::read_input().as_slice()) - .sdk_expect("NEP141_NOT_FOUND") + Engine::get_erc20_from_nep141(&args.nep141.as_bytes()) + .sdk_unwrap() .as_slice(), ); } diff --git a/src/parameters.rs b/src/parameters.rs index f044026a9..58cd1c730 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -87,11 +87,15 @@ pub struct ViewCallArgs { pub input: Vec, } +/// Borsh-encoded parameters for `deploy_erc20_token` function. #[derive(BorshSerialize, BorshDeserialize, Debug, Eq, PartialEq)] pub struct DeployErc20TokenArgs { pub nep141: AccountId, } +/// Borsh-encoded parameters for `get_erc20_from_nep141` function. +pub type GetErc20FromNep141CallArgs = DeployErc20TokenArgs; + /// Borsh-encoded parameters for the `get_storage_at` function. #[derive(BorshSerialize, BorshDeserialize)] pub struct GetStorageAtArgs { @@ -171,7 +175,7 @@ impl TryFrom for String { } } -#[derive(BorshSerialize, BorshDeserialize)] +#[derive(Debug, BorshSerialize, BorshDeserialize)] pub struct PromiseCreateArgs { pub target_account_id: AccountId, pub method: String, diff --git a/src/precompiles/blake2.rs b/src/precompiles/blake2.rs index f78b82fa2..d064b6b42 100644 --- a/src/precompiles/blake2.rs +++ b/src/precompiles/blake2.rs @@ -1,8 +1,7 @@ use evm::{Context, ExitError}; use crate::precompiles::{Precompile, PrecompileOutput, PrecompileResult}; -use crate::prelude::{mem, Borrowed, PhantomData, TryInto}; -use crate::AuroraState; +use crate::prelude::{mem, Address, Borrowed, TryInto}; /// Blake2 costs. mod costs { @@ -15,13 +14,13 @@ mod consts { pub(super) const INPUT_LENGTH: usize = 213; } -pub(super) struct Blake2F(PhantomData); +pub(super) struct Blake2F; -impl Blake2F { - pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 9); +impl Blake2F { + pub(super) const ADDRESS: Address = super::make_address(0, 9); } -impl Precompile for Blake2F { +impl Precompile for Blake2F { fn required_gas(input: &[u8]) -> Result { let (int_bytes, _) = input.split_at(mem::size_of::()); Ok(u64::from(u32::from_be_bytes( @@ -43,7 +42,6 @@ impl Precompile for Blake2F { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { if input.len() != consts::INPUT_LENGTH { @@ -96,7 +94,7 @@ impl Precompile for Blake2F { #[cfg(test)] mod tests { use crate::prelude::Vec; - use crate::test_utils::{new_context, new_state}; + use crate::test_utils::new_context; use super::*; @@ -120,12 +118,12 @@ mod tests { fn test_blake2f_out_of_gas() -> PrecompileResult { let input = hex::decode(INPUT).unwrap(); - Blake2F::run(&input, 11, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 11, &new_context(), false) } fn test_blake2f_empty() -> PrecompileResult { let input = [0u8; 0]; - Blake2F::run(&input, 0, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 0, &new_context(), false) } fn test_blake2f_invalid_len_1() -> PrecompileResult { @@ -143,7 +141,7 @@ mod tests { 01", ) .unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) } fn test_blake2f_invalid_len_2() -> PrecompileResult { @@ -161,7 +159,7 @@ mod tests { 01", ) .unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) } fn test_blake2f_invalid_flag() -> PrecompileResult { @@ -179,7 +177,7 @@ mod tests { 02", ) .unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) } fn test_blake2f_r_0() -> Vec { @@ -197,14 +195,14 @@ mod tests { 01", ) .unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) .unwrap() .output } fn test_blake2f_r_12() -> Vec { let input = hex::decode(INPUT).unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) .unwrap() .output } @@ -224,7 +222,7 @@ mod tests { 00", ) .unwrap(); - Blake2F::run(&input, 12, &new_context(), &mut new_state(), false) + Blake2F::run(&input, 12, &new_context(), false) .unwrap() .output } diff --git a/src/precompiles/bn128.rs b/src/precompiles/bn128.rs index 73b46f57e..40b124fc1 100644 --- a/src/precompiles/bn128.rs +++ b/src/precompiles/bn128.rs @@ -2,7 +2,6 @@ use crate::precompiles::{ Byzantium, HardFork, Istanbul, Precompile, PrecompileOutput, PrecompileResult, }; use crate::prelude::*; -use crate::AuroraState; use evm::{Context, ExitError}; /// bn128 costs. @@ -44,15 +43,6 @@ mod consts { pub(super) const PAIR_ELEMENT_LEN: usize = 192; } -/// bn128 precompile addresses -pub(super) mod addresses { - use crate::precompiles; - - pub const ADD: [u8; 20] = precompiles::make_address(0, 6); - pub const MUL: [u8; 20] = precompiles::make_address(0, 7); - pub const PAIR: [u8; 20] = precompiles::make_address(0, 8); -} - /// Reads the `x` and `y` points from an input at a given position. fn read_point(input: &[u8], pos: usize) -> Result { use bn::{AffineG1, Fq, Group, G1}; @@ -76,9 +66,13 @@ fn read_point(input: &[u8], pos: usize) -> Result { }) } -pub(super) struct BN128Add(PhantomData, PhantomData); +pub(super) struct Bn128Add(PhantomData); -impl BN128Add { +impl Bn128Add { + pub(super) const ADDRESS: Address = super::make_address(0, 6); +} + +impl Bn128Add { fn run_inner(input: &[u8], _context: &Context) -> Result, ExitError> { use bn::AffineG1; @@ -100,7 +94,7 @@ impl BN128Add { } } -impl Precompile for BN128Add { +impl Precompile for Bn128Add { fn required_gas(_input: &[u8]) -> Result { Ok(costs::BYZANTIUM_ADD) } @@ -110,13 +104,7 @@ impl Precompile for BN128Add { /// /// See: https://eips.ethereum.org/EIPS/eip-196 /// See: https://etherscan.io/address/0000000000000000000000000000000000000006 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -127,7 +115,7 @@ impl Precompile for BN128Add { } } -impl Precompile for BN128Add { +impl Precompile for Bn128Add { fn required_gas(_input: &[u8]) -> Result { Ok(costs::ISTANBUL_ADD) } @@ -137,13 +125,7 @@ impl Precompile for BN128Add { /// /// See: https://eips.ethereum.org/EIPS/eip-196 /// See: https://etherscan.io/address/0000000000000000000000000000000000000006 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -154,9 +136,13 @@ impl Precompile for BN128Add { } } -pub(super) struct BN128Mul(PhantomData, PhantomData); +pub(super) struct Bn128Mul(PhantomData); -impl BN128Mul { +impl Bn128Mul { + pub(super) const ADDRESS: Address = super::make_address(0, 7); +} + +impl Bn128Mul { fn run_inner(input: &[u8], _context: &Context) -> Result, ExitError> { use bn::AffineG1; @@ -181,7 +167,7 @@ impl BN128Mul { } } -impl Precompile for BN128Mul { +impl Precompile for Bn128Mul { fn required_gas(_input: &[u8]) -> Result { Ok(costs::BYZANTIUM_MUL) } @@ -190,13 +176,7 @@ impl Precompile for BN128Mul { /// /// See: https://eips.ethereum.org/EIPS/eip-196 /// See: https://etherscan.io/address/0000000000000000000000000000000000000007 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -207,7 +187,7 @@ impl Precompile for BN128Mul { } } -impl Precompile for BN128Mul { +impl Precompile for Bn128Mul { fn required_gas(_input: &[u8]) -> Result { Ok(costs::ISTANBUL_MUL) } @@ -216,13 +196,7 @@ impl Precompile for BN128Mul { /// /// See: https://eips.ethereum.org/EIPS/eip-196 /// See: https://etherscan.io/address/0000000000000000000000000000000000000007 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -233,9 +207,13 @@ impl Precompile for BN128Mul { } } -pub(super) struct BN128Pair(PhantomData, PhantomData); +pub(super) struct Bn128Pair(PhantomData); + +impl Bn128Pair { + pub(super) const ADDRESS: Address = super::make_address(0, 8); +} -impl BN128Pair { +impl Bn128Pair { fn run_inner(input: &[u8], _context: &Context) -> Result, ExitError> { use bn::{arith::U256, AffineG1, AffineG2, Fq, Fq2, Group, Gt, G1, G2}; @@ -329,7 +307,7 @@ impl BN128Pair { } } -impl Precompile for BN128Pair { +impl Precompile for Bn128Pair { fn required_gas(input: &[u8]) -> Result { Ok( costs::BYZANTIUM_PAIR_PER_POINT * input.len() as u64 / consts::PAIR_ELEMENT_LEN as u64 @@ -341,13 +319,7 @@ impl Precompile for BN128Pair { /// /// See: https://eips.ethereum.org/EIPS/eip-197 /// See: https://etherscan.io/address/0000000000000000000000000000000000000008 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -358,7 +330,7 @@ impl Precompile for BN128Pair { } } -impl Precompile for BN128Pair { +impl Precompile for Bn128Pair { fn required_gas(input: &[u8]) -> Result { Ok( costs::ISTANBUL_PAIR_PER_POINT * input.len() as u64 / consts::PAIR_ELEMENT_LEN as u64 @@ -370,13 +342,7 @@ impl Precompile for BN128Pair { /// /// See: https://eips.ethereum.org/EIPS/eip-197 /// See: https://etherscan.io/address/0000000000000000000000000000000000000008 - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - _state: &mut S, - _is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, _is_static: bool) -> PrecompileResult { let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) @@ -389,7 +355,7 @@ impl Precompile for BN128Pair { #[cfg(test)] mod tests { - use crate::test_utils::{new_context, new_state}; + use crate::test_utils::new_context; use super::*; @@ -410,10 +376,9 @@ mod tests { ) .unwrap(); - let res = - BN128Add::::run(&input, 500, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Add::::run(&input, 500, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // zero sum test @@ -432,10 +397,9 @@ mod tests { ) .unwrap(); - let res = - BN128Add::::run(&input, 500, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Add::::run(&input, 500, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // out of gas test @@ -447,8 +411,7 @@ mod tests { 0000000000000000000000000000000000000000000000000000000000000000", ) .unwrap(); - let res = - BN128Add::::run(&input, 499, &new_context(), &mut new_state(), false); + let res = Bn128Add::::run(&input, 499, &new_context(), false); assert!(matches!(res, Err(ExitError::OutOfGas))); // no input test @@ -460,10 +423,9 @@ mod tests { ) .unwrap(); - let res = - BN128Add::::run(&input, 500, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Add::::run(&input, 500, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // point not on curve fail @@ -476,8 +438,7 @@ mod tests { ) .unwrap(); - let res = - BN128Add::::run(&input, 500, &new_context(), &mut new_state(), false); + let res = Bn128Add::::run(&input, 500, &new_context(), false); assert!(matches!( res, Err(ExitError::Other(Borrowed("ERR_BN128_INVALID_POINT"))) @@ -500,10 +461,9 @@ mod tests { ) .unwrap(); - let res = - BN128Mul::::run(&input, 40_000, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Mul::::run(&input, 40_000, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // out of gas test @@ -514,8 +474,7 @@ mod tests { 0200000000000000000000000000000000000000000000000000000000000000", ) .unwrap(); - let res = - BN128Mul::::run(&input, 39_999, &new_context(), &mut new_state(), false); + let res = Bn128Mul::::run(&input, 39_999, &new_context(), false); assert!(matches!(res, Err(ExitError::OutOfGas))); // zero multiplication test @@ -533,10 +492,9 @@ mod tests { ) .unwrap(); - let res = - BN128Mul::::run(&input, 40_000, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Mul::::run(&input, 40_000, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // no input test @@ -548,10 +506,9 @@ mod tests { ) .unwrap(); - let res = - BN128Mul::::run(&input, 40_000, &new_context(), &mut new_state(), false) - .unwrap() - .output; + let res = Bn128Mul::::run(&input, 40_000, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // point not on curve fail @@ -563,8 +520,7 @@ mod tests { ) .unwrap(); - let res = - BN128Mul::::run(&input, 40_000, &new_context(), &mut new_state(), false); + let res = Bn128Mul::::run(&input, 40_000, &new_context(), false); assert!(matches!( res, Err(ExitError::Other(Borrowed("ERR_BN128_INVALID_POINT"))) @@ -593,15 +549,9 @@ mod tests { hex::decode("0000000000000000000000000000000000000000000000000000000000000001") .unwrap(); - let res = BN128Pair::::run( - &input, - 260_000, - &new_context(), - &mut new_state(), - false, - ) - .unwrap() - .output; + let res = Bn128Pair::::run(&input, 260_000, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // out of gas test @@ -621,13 +571,7 @@ mod tests { 12c85ea5db8c6deb4aab71808dcb408fe3d1e7690c43d37b4ce6cc0166fa7daa", ) .unwrap(); - let res = BN128Pair::::run( - &input, - 259_999, - &new_context(), - &mut new_state(), - false, - ); + let res = Bn128Pair::::run(&input, 259_999, &new_context(), false); assert!(matches!(res, Err(ExitError::OutOfGas))); // no input test @@ -636,15 +580,9 @@ mod tests { hex::decode("0000000000000000000000000000000000000000000000000000000000000001") .unwrap(); - let res = BN128Pair::::run( - &input, - 260_000, - &new_context(), - &mut new_state(), - false, - ) - .unwrap() - .output; + let res = Bn128Pair::::run(&input, 260_000, &new_context(), false) + .unwrap() + .output; assert_eq!(res, expected); // point not on curve fail @@ -659,13 +597,7 @@ mod tests { ) .unwrap(); - let res = BN128Pair::::run( - &input, - 260_000, - &new_context(), - &mut new_state(), - false, - ); + let res = Bn128Pair::::run(&input, 260_000, &new_context(), false); assert!(matches!( res, Err(ExitError::Other(Borrowed("ERR_BN128_INVALID_A"))) @@ -681,13 +613,7 @@ mod tests { ) .unwrap(); - let res = BN128Pair::::run( - &input, - 260_000, - &new_context(), - &mut new_state(), - false, - ); + let res = Bn128Pair::::run(&input, 260_000, &new_context(), false); assert!(matches!( res, Err(ExitError::Other(Borrowed("ERR_BN128_INVALID_LEN",))) diff --git a/src/precompiles/hash.rs b/src/precompiles/hash.rs index 51ae03632..87e99256a 100644 --- a/src/precompiles/hash.rs +++ b/src/precompiles/hash.rs @@ -1,9 +1,7 @@ use crate::precompiles::{Precompile, PrecompileOutput, PrecompileResult}; -use crate::prelude::{vec, PhantomData}; +use crate::prelude::{vec, Address}; use evm::{Context, ExitError}; -use crate::AuroraState; - mod costs { pub(super) const SHA256_BASE: u64 = 60; @@ -21,13 +19,13 @@ mod consts { } /// SHA256 precompile. -pub struct SHA256(PhantomData); +pub struct SHA256; -impl SHA256 { - pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 2); +impl SHA256 { + pub(super) const ADDRESS: Address = super::make_address(0, 2); } -impl Precompile for SHA256 { +impl Precompile for SHA256 { fn required_gas(input: &[u8]) -> Result { Ok( (input.len() as u64 + consts::SHA256_WORD_LEN - 1) / consts::SHA256_WORD_LEN @@ -44,7 +42,6 @@ impl Precompile for SHA256 { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { use sha2::Digest; @@ -70,7 +67,6 @@ impl Precompile for SHA256 { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { use crate::sdk; @@ -86,13 +82,22 @@ impl Precompile for SHA256 { } /// RIPEMD160 precompile. -pub struct RIPEMD160(PhantomData); +pub struct RIPEMD160; + +impl RIPEMD160 { + pub(super) const ADDRESS: Address = super::make_address(0, 3); -impl RIPEMD160 { - pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 3); + #[cfg(not(feature = "testnet"))] + fn internal_impl(input: &[u8]) -> [u8; 20] { + use ripemd160::Digest; + let hash = ripemd160::Ripemd160::digest(input); + let mut output = [0u8; 20]; + output.copy_from_slice(&hash); + output + } } -impl Precompile for RIPEMD160 { +impl Precompile for RIPEMD160 { fn required_gas(input: &[u8]) -> Result { Ok( (input.len() as u64 + consts::RIPEMD_WORD_LEN - 1) / consts::RIPEMD_WORD_LEN @@ -108,16 +113,16 @@ impl Precompile for RIPEMD160 { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { - use ripemd160::Digest; - let cost = Self::required_gas(input)?; if cost > target_gas { Err(ExitError::OutOfGas) } else { - let hash = ripemd160::Ripemd160::digest(input); + #[cfg(not(feature = "testnet"))] + let hash = Self::internal_impl(input); + #[cfg(feature = "testnet")] + let hash = crate::sdk::ripemd160(input); // The result needs to be padded with leading zeros because it is only 20 bytes, but // the evm works with 32-byte words. let mut output = vec![0u8; 32]; @@ -129,7 +134,7 @@ impl Precompile for RIPEMD160 { #[cfg(test)] mod tests { - use crate::test_utils::{new_context, new_state}; + use crate::test_utils::new_context; use super::*; @@ -140,7 +145,7 @@ mod tests { hex::decode("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855") .unwrap(); - let res = SHA256::run(input, 60, &new_context(), &mut new_state(), false) + let res = SHA256::run(input, 60, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); @@ -153,7 +158,7 @@ mod tests { hex::decode("0000000000000000000000009c1185a5c5e9fc54612808977ee8f548b2258d31") .unwrap(); - let res = RIPEMD160::run(input, 600, &new_context(), &mut new_state(), false) + let res = RIPEMD160::run(input, 600, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); diff --git a/src/precompiles/identity.rs b/src/precompiles/identity.rs index 4053fe652..e750b6b72 100644 --- a/src/precompiles/identity.rs +++ b/src/precompiles/identity.rs @@ -1,8 +1,7 @@ use crate::precompiles::{Precompile, PrecompileOutput, PrecompileResult}; use evm::{Context, ExitError}; -use crate::prelude::PhantomData; -use crate::AuroraState; +use crate::prelude::Address; /// Identity precompile costs. mod costs { @@ -18,13 +17,13 @@ mod consts { pub(super) const IDENTITY_WORD_LEN: u64 = 32; } -pub struct Identity(PhantomData); +pub struct Identity; -impl Identity { - pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 4); +impl Identity { + pub(super) const ADDRESS: Address = super::make_address(0, 4); } -impl Precompile for Identity { +impl Precompile for Identity { fn required_gas(input: &[u8]) -> Result { Ok( (input.len() as u64 + consts::IDENTITY_WORD_LEN - 1) / consts::IDENTITY_WORD_LEN @@ -41,7 +40,6 @@ impl Precompile for Identity { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { let cost = Self::required_gas(input)?; @@ -57,7 +55,7 @@ impl Precompile for Identity { mod tests { use evm::ExitError; - use crate::test_utils::{new_context, new_state}; + use crate::test_utils::new_context; use super::*; @@ -66,19 +64,19 @@ mod tests { let input = [0u8, 1, 2, 3]; let expected = input[0..2].to_vec(); - let res = Identity::run(&input[0..2], 18, &new_context(), &mut new_state(), false) + let res = Identity::run(&input[0..2], 18, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); let expected = input.to_vec(); - let res = Identity::run(&input, 18, &new_context(), &mut new_state(), false) + let res = Identity::run(&input, 18, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); // gas fail - let res = Identity::run(&input[0..2], 17, &new_context(), &mut new_state(), false); + let res = Identity::run(&input[0..2], 17, &new_context(), false); assert!(matches!(res, Err(ExitError::OutOfGas))); @@ -87,7 +85,7 @@ mod tests { 0u8, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ]; - let res = Identity::run(&input, 21, &new_context(), &mut new_state(), false) + let res = Identity::run(&input, 21, &new_context(), false) .unwrap() .output; assert_eq!(res, input.to_vec()); diff --git a/src/precompiles/mod.rs b/src/precompiles/mod.rs index de50d069c..88423a9ac 100644 --- a/src/precompiles/mod.rs +++ b/src/precompiles/mod.rs @@ -1,19 +1,10 @@ -mod blake2; -mod bn128; -mod hash; -mod identity; -mod modexp; -#[cfg_attr(not(feature = "contract"), allow(dead_code))] -mod native; -mod secp256k1; -use evm::{Context, ExitError}; - +use crate::parameters::PromiseCreateArgs; pub(crate) use crate::precompiles::secp256k1::ecrecover; -use crate::prelude::Vec; +use crate::prelude::{vec, Vec}; use crate::AuroraState; use crate::{ precompiles::blake2::Blake2F, - precompiles::bn128::{BN128Add, BN128Mul, BN128Pair}, + precompiles::bn128::{Bn128Add, Bn128Mul, Bn128Pair}, precompiles::hash::{RIPEMD160, SHA256}, precompiles::identity::Identity, precompiles::modexp::ModExp, @@ -24,12 +15,23 @@ use crate::{ }; use evm::backend::Log; use evm::ExitSucceed; +use evm::{executor, Context, ExitError}; + +mod blake2; +mod bn128; +mod hash; +mod identity; +mod modexp; +#[cfg_attr(not(feature = "contract"), allow(dead_code))] +mod native; +mod secp256k1; #[derive(Debug)] pub struct PrecompileOutput { pub cost: u64, pub output: Vec, pub logs: Vec, + pub promise: Option, } impl PrecompileOutput { @@ -38,6 +40,7 @@ impl PrecompileOutput { cost, output, logs: Vec::new(), + promise: None, } } } @@ -48,6 +51,7 @@ impl Default for PrecompileOutput { cost: 0, output: Vec::new(), logs: Vec::new(), + promise: None, } } } @@ -69,18 +73,12 @@ type PrecompileResult = Result; type EvmPrecompileResult = Result; /// A precompiled function for use in the EVM. -pub trait Precompile { +pub trait Precompile { /// The required gas in order to run the precompile function. fn required_gas(input: &[u8]) -> Result; /// Runs the precompile function. - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - state: &mut S, - is_static: bool, - ) -> PrecompileResult; + fn run(input: &[u8], target_gas: u64, context: &Context, is_static: bool) -> PrecompileResult; } /// Hard fork marker. @@ -106,225 +104,150 @@ impl HardFork for Istanbul {} impl HardFork for Berlin {} -/// No precompiles, returns `None`. -#[cfg(feature = "contract")] -#[allow(dead_code)] -pub fn no_precompiles( - _address: Address, - _input: &[u8], - _target_gas: Option, - _context: &Context, - _state: &mut AuroraStackState, - _is_static: bool, -) -> Option { - None // no precompiles supported -} +type PrecompileFn = fn(&[u8], u64, &Context, bool) -> PrecompileResult; -/// Matches the address given to Homestead precompiles. -#[cfg(feature = "contract")] -#[allow(dead_code)] -pub fn homestead_precompiles( - address: Address, - input: &[u8], - target_gas: Option, - context: &Context, - state: &mut AuroraStackState, - is_static: bool, -) -> Option { - let target_gas = match target_gas { - Some(t) => t, - None => return Some(EvmPrecompileResult::Err(ExitError::OutOfGas)), - }; - - let output = match address.0 { - ECRecover::::ADDRESS => Some(ECRecover::::run( - input, target_gas, context, state, is_static, - )), - SHA256::::ADDRESS => Some(SHA256::::run( - input, target_gas, context, state, is_static, - )), - RIPEMD160::::ADDRESS => Some(RIPEMD160::::run( - input, target_gas, context, state, is_static, - )), - ExitToNear::::ADDRESS => Some(ExitToNear::::run( - input, target_gas, context, state, is_static, - )), - ExitToEthereum::::ADDRESS => Some( - ExitToEthereum::::run(input, target_gas, context, state, is_static), - ), - _ => None, - }; - output.map(|res| res.map(Into::into)) +pub(crate) struct Precompiles { + addresses: Vec
, + fun: Vec, } -/// Matches the address given to Byzantium precompiles. -#[cfg(feature = "contract")] -#[allow(dead_code)] -pub fn byzantium_precompiles( - address: Address, - input: &[u8], - target_gas: Option, - context: &Context, - state: &mut AuroraStackState, - is_static: bool, -) -> Option { - let target_gas = match target_gas { - Some(t) => t, - None => return Some(EvmPrecompileResult::Err(ExitError::OutOfGas)), - }; - - let output = match address.0 { - ECRecover::::ADDRESS => Some(ECRecover::::run( - input, target_gas, context, state, is_static, - )), - SHA256::::ADDRESS => Some(SHA256::::run( - input, target_gas, context, state, is_static, - )), - RIPEMD160::::ADDRESS => Some(RIPEMD160::::run( - input, target_gas, context, state, is_static, - )), - Identity::::ADDRESS => Some(Identity::::run( - input, target_gas, context, state, is_static, - )), - modexp::ADDRESS => Some(ModExp::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::ADD => Some(BN128Add::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::MUL => Some(BN128Mul::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::PAIR => Some(BN128Pair::::run( - input, target_gas, context, state, is_static, - )), - ExitToNear::::ADDRESS => Some(ExitToNear::::run( - input, target_gas, context, state, is_static, - )), - ExitToEthereum::::ADDRESS => Some( - ExitToEthereum::::run(input, target_gas, context, state, is_static), - ), - _ => None, - }; - output.map(|res| res.map(Into::into)) -} +impl Precompiles { + #[allow(dead_code)] + pub fn new_homestead() -> Self { + let addresses = vec![ + ECRecover::ADDRESS, + SHA256::ADDRESS, + RIPEMD160::ADDRESS, + ExitToNear::ADDRESS, + ExitToEthereum::ADDRESS, + ]; + let fun: Vec = vec![ + ECRecover::run, + SHA256::run, + RIPEMD160::run, + ExitToNear::run, + ExitToEthereum::run, + ]; + + Precompiles { addresses, fun } + } + + #[allow(dead_code)] + pub fn new_byzantium() -> Self { + let addresses = vec![ + ECRecover::ADDRESS, + SHA256::ADDRESS, + RIPEMD160::ADDRESS, + Identity::ADDRESS, + ModExp::::ADDRESS, + Bn128Add::::ADDRESS, + Bn128Mul::::ADDRESS, + Bn128Pair::::ADDRESS, + ExitToNear::ADDRESS, + ExitToEthereum::ADDRESS, + ]; + let fun: Vec = vec![ + ECRecover::run, + SHA256::run, + RIPEMD160::run, + Identity::run, + ModExp::::run, + Bn128Add::::run, + Bn128Mul::::run, + Bn128Pair::::run, + ExitToNear::run, + ExitToEthereum::run, + ]; + + Precompiles { addresses, fun } + } + + pub fn new_istanbul() -> Self { + let addresses = vec![ + ECRecover::ADDRESS, + SHA256::ADDRESS, + RIPEMD160::ADDRESS, + Identity::ADDRESS, + ModExp::::ADDRESS, + Bn128Add::::ADDRESS, + Bn128Mul::::ADDRESS, + Bn128Pair::::ADDRESS, + Blake2F::ADDRESS, + ExitToNear::ADDRESS, + ExitToEthereum::ADDRESS, + ]; + let fun: Vec = vec![ + ECRecover::run, + SHA256::run, + RIPEMD160::run, + Identity::run, + ModExp::::run, + Bn128Add::::run, + Bn128Mul::::run, + Bn128Pair::::run, + Blake2F::run, + ExitToNear::run, + ExitToEthereum::run, + ]; + + Precompiles { addresses, fun } + } + + #[allow(dead_code)] + fn new_berlin() -> Self { + Self::new_istanbul() + } -/// Matches the address given to Istanbul precompiles. -#[allow(dead_code)] -pub fn istanbul_precompiles( - address: Address, - input: &[u8], - target_gas: Option, - context: &Context, - state: &mut AuroraStackState, - is_static: bool, -) -> Option { - let target_gas = match target_gas { - Some(t) => t, - None => return Some(EvmPrecompileResult::Err(ExitError::OutOfGas)), - }; - - let output = match address.0 { - ECRecover::::ADDRESS => Some(ECRecover::::run( - input, target_gas, context, state, is_static, - )), - SHA256::::ADDRESS => Some(SHA256::::run( - input, target_gas, context, state, is_static, - )), - RIPEMD160::::ADDRESS => Some(RIPEMD160::::run( - input, target_gas, context, state, is_static, - )), - Identity::::ADDRESS => Some(Identity::::run( - input, target_gas, context, state, is_static, - )), - modexp::ADDRESS => Some(ModExp::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::ADD => Some(BN128Add::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::MUL => Some(BN128Mul::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::PAIR => Some(BN128Pair::::run( - input, target_gas, context, state, is_static, - )), - Blake2F::::ADDRESS => Some(Blake2F::::run( - input, target_gas, context, state, is_static, - )), - ExitToNear::::ADDRESS => Some(ExitToNear::::run( - input, target_gas, context, state, is_static, - )), - ExitToEthereum::::ADDRESS => Some( - ExitToEthereum::::run(input, target_gas, context, state, is_static), - ), - _ => None, - }; - output.map(|res| res.map(Into::into)) + fn get_fun(&self, address: &Address) -> Option { + self.addresses + .iter() + .position(|e| e == address) + .and_then(|i| self.fun.get(i)) + .copied() + } } -/// Matches the address given to Berlin precompiles. -#[cfg(feature = "contract")] -#[allow(dead_code)] -pub fn berlin_precompiles( - address: Address, - input: &[u8], - target_gas: Option, - context: &Context, - state: &mut AuroraStackState, - is_static: bool, -) -> Option { - let target_gas = match target_gas { - Some(t) => t, - None => return Some(EvmPrecompileResult::Err(ExitError::OutOfGas)), - }; - - let output = match address.0 { - ECRecover::::ADDRESS => Some(ECRecover::::run( - input, target_gas, context, state, is_static, - )), - SHA256::::ADDRESS => Some(SHA256::::run( - input, target_gas, context, state, is_static, - )), - RIPEMD160::::ADDRESS => Some(RIPEMD160::::run( - input, target_gas, context, state, is_static, - )), - Identity::::ADDRESS => Some(Identity::::run( - input, target_gas, context, state, is_static, - )), - modexp::ADDRESS => Some(ModExp::::run( - input, target_gas, context, state, is_static, - )), // TODO gas changes - bn128::addresses::ADD => Some(BN128Add::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::MUL => Some(BN128Mul::::run( - input, target_gas, context, state, is_static, - )), - bn128::addresses::PAIR => Some(BN128Pair::::run( - input, target_gas, context, state, is_static, - )), - Blake2F::::ADDRESS => Some(Blake2F::::run( - input, target_gas, context, state, is_static, - )), - ExitToNear::::ADDRESS => Some(ExitToNear::::run( - input, target_gas, context, state, is_static, - )), - ExitToEthereum::::ADDRESS => Some( - ExitToEthereum::::run(input, target_gas, context, state, is_static), - ), - _ => None, - }; - output.map(|res| res.map(Into::into)) +/// Matches the address given to Homestead precompiles. +impl<'backend, 'config> executor::Precompiles> for Precompiles { + fn run( + &self, + address: Address, + input: &[u8], + target_gas: Option, + context: &Context, + state: &mut AuroraStackState, + is_static: bool, + ) -> Option { + let target_gas = match target_gas { + Some(t) => t, + None => return Some(EvmPrecompileResult::Err(ExitError::OutOfGas)), + }; + + let output = self.get_fun(&address).map(|fun| { + let mut res = (fun)(input, target_gas, context, is_static); + if let Ok(output) = &mut res { + if let Some(promise) = output.promise.take() { + state.add_promise(promise) + } + } + res + }); + + output.map(|res| res.map(Into::into)) + } + + fn addresses(&self) -> &[Address] { + &self.addresses + } } /// const fn for making an address by concatenating the bytes from two given numbers, /// Note that 32 + 128 = 160 = 20 bytes (the length of an address). This function is used /// as a convenience for specifying the addresses of the various precompiles. -const fn make_address(x: u32, y: u128) -> [u8; 20] { +const fn make_address(x: u32, y: u128) -> Address { let x_bytes = x.to_be_bytes(); let y_bytes = y.to_be_bytes(); - [ + Address([ x_bytes[0], x_bytes[1], x_bytes[2], @@ -345,37 +268,26 @@ const fn make_address(x: u32, y: u128) -> [u8; 20] { y_bytes[13], y_bytes[14], y_bytes[15], - ] + ]) } #[cfg(test)] mod tests { - use crate::test_utils::MockState; + use crate::precompiles::{Byzantium, Istanbul}; + use crate::prelude::Address; use rand::Rng; #[test] fn test_precompile_addresses() { - assert_eq!( - super::secp256k1::ECRecover::::ADDRESS, - u8_to_address(1) - ); - assert_eq!(super::hash::SHA256::::ADDRESS, u8_to_address(2)); - assert_eq!( - super::hash::RIPEMD160::::ADDRESS, - u8_to_address(3) - ); - assert_eq!( - super::identity::Identity::::ADDRESS, - u8_to_address(4) - ); - assert_eq!(super::modexp::ADDRESS, u8_to_address(5)); - assert_eq!(super::bn128::addresses::ADD, u8_to_address(6)); - assert_eq!(super::bn128::addresses::MUL, u8_to_address(7)); - assert_eq!(super::bn128::addresses::PAIR, u8_to_address(8)); - assert_eq!( - super::blake2::Blake2F::::ADDRESS, - u8_to_address(9) - ); + assert_eq!(super::secp256k1::ECRecover::ADDRESS, u8_to_address(1)); + assert_eq!(super::hash::SHA256::ADDRESS, u8_to_address(2)); + assert_eq!(super::hash::RIPEMD160::ADDRESS, u8_to_address(3)); + assert_eq!(super::identity::Identity::ADDRESS, u8_to_address(4)); + assert_eq!(super::ModExp::::ADDRESS, u8_to_address(5)); + assert_eq!(super::Bn128Add::::ADDRESS, u8_to_address(6)); + assert_eq!(super::Bn128Mul::::ADDRESS, u8_to_address(7)); + assert_eq!(super::Bn128Pair::::ADDRESS, u8_to_address(8)); + assert_eq!(super::blake2::Blake2F::ADDRESS, u8_to_address(9)); } #[test] @@ -386,20 +298,20 @@ mod tests { let mut rng = rand::thread_rng(); for _ in 0..u8::MAX { - let address: [u8; 20] = rng.gen(); + let address: Address = Address(rng.gen()); let (x, y) = split_address(address); assert_eq!(address, super::make_address(x, y)) } } - fn u8_to_address(x: u8) -> [u8; 20] { + fn u8_to_address(x: u8) -> Address { let mut bytes = [0u8; 20]; bytes[19] = x; - bytes + Address(bytes) } // Inverse function of `super::make_address`. - fn split_address(a: [u8; 20]) -> (u32, u128) { + fn split_address(a: Address) -> (u32, u128) { let mut x_bytes = [0u8; 4]; let mut y_bytes = [0u8; 16]; diff --git a/src/precompiles/modexp.rs b/src/precompiles/modexp.rs index 0b56a38ba..0be784074 100644 --- a/src/precompiles/modexp.rs +++ b/src/precompiles/modexp.rs @@ -1,16 +1,17 @@ use crate::precompiles::{ Berlin, Byzantium, HardFork, Precompile, PrecompileOutput, PrecompileResult, }; -use crate::prelude::{PhantomData, Vec, U256}; -use crate::AuroraState; +use crate::prelude::{Address, PhantomData, Vec, U256}; use evm::{Context, ExitError}; use num::{BigUint, Integer}; -pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 5); +pub(super) struct ModExp(PhantomData); -pub(super) struct ModExp(PhantomData, PhantomData); +impl ModExp { + pub(super) const ADDRESS: Address = super::make_address(0, 5); +} -impl ModExp { +impl ModExp { // Note: the output of this function is bounded by 2^67 fn calc_iter_count(exp_len: u64, base_len: u64, bytes: &[u8]) -> U256 { #[allow(clippy::redundant_closure)] @@ -73,7 +74,7 @@ impl ModExp { } } -impl ModExp { +impl ModExp { // ouput of this function is bounded by 2^128 fn mul_complexity(x: u64) -> U256 { if x <= 64 { @@ -89,7 +90,7 @@ impl ModExp { } } -impl Precompile for ModExp { +impl Precompile for ModExp { fn required_gas(input: &[u8]) -> Result { let (base_len, exp_len, mod_len) = parse_lengths(input); @@ -107,7 +108,6 @@ impl Precompile for ModExp { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { let cost = Self::required_gas(input)?; @@ -120,7 +120,7 @@ impl Precompile for ModExp { } } -impl ModExp { +impl ModExp { // output bounded by 2^122 fn mul_complexity(base_len: u64, mod_len: u64) -> U256 { let max_len = core::cmp::max(mod_len, base_len); @@ -129,7 +129,7 @@ impl ModExp { } } -impl Precompile for ModExp { +impl Precompile for ModExp { fn required_gas(input: &[u8]) -> Result { let (base_len, exp_len, mod_len) = parse_lengths(input); @@ -145,7 +145,6 @@ impl Precompile for ModExp { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { let cost = Self::required_gas(input)?; @@ -194,7 +193,7 @@ fn parse_lengths(input: &[u8]) -> (u64, u64, u64) { #[cfg(test)] mod tests { - use crate::test_utils::{new_context, new_state, MockState}; + use crate::test_utils::new_context; use super::*; @@ -356,17 +355,10 @@ mod tests { fn test_modexp() { for (test, test_gas) in TESTS.iter().zip(BYZANTIUM_GAS.iter()) { let input = hex::decode(&test.input).unwrap(); - let mut state = new_state(); - - let res = ModExp::::run( - &input, - *test_gas, - &new_context(), - &mut state, - false, - ) - .unwrap() - .output; + + let res = ModExp::::run(&input, *test_gas, &new_context(), false) + .unwrap() + .output; let expected = hex::decode(&test.expected).unwrap(); assert_eq!(res, expected, "{}", test.name); } @@ -377,7 +369,7 @@ mod tests { for (test, test_gas) in TESTS.iter().zip(BYZANTIUM_GAS.iter()) { let input = hex::decode(&test.input).unwrap(); - let gas = ModExp::::required_gas(&input).unwrap(); + let gas = ModExp::::required_gas(&input).unwrap(); assert_eq!(gas, *test_gas, "{} gas", test.name); } } @@ -387,7 +379,7 @@ mod tests { for (test, test_gas) in TESTS.iter().zip(BERLIN_GAS.iter()) { let input = hex::decode(&test.input).unwrap(); - let gas = ModExp::::required_gas(&input).unwrap(); + let gas = ModExp::::required_gas(&input).unwrap(); assert_eq!(gas, *test_gas, "{} gas", test.name); } } @@ -408,7 +400,7 @@ mod tests { input.extend_from_slice(&crate::types::u256_to_arr(&exp)); // completes without any overflow - ModExp::::required_gas(&input).unwrap(); + ModExp::::required_gas(&input).unwrap(); } #[test] @@ -427,14 +419,12 @@ mod tests { input.extend_from_slice(&crate::types::u256_to_arr(&exp)); // completes without any overflow - ModExp::::required_gas(&input).unwrap(); + ModExp::::required_gas(&input).unwrap(); } #[test] fn test_berlin_modexp_empty_input() { - let mut state = new_state(); - let res = ModExp::::run(&[], 100_000, &new_context(), &mut state, false) - .unwrap(); + let res = ModExp::::run(&[], 100_000, &new_context(), false).unwrap(); let expected: Vec = Vec::new(); assert_eq!(res.output, expected) } diff --git a/src/precompiles/native.rs b/src/precompiles/native.rs index c03b12553..14a9df9b1 100644 --- a/src/precompiles/native.rs +++ b/src/precompiles/native.rs @@ -1,12 +1,10 @@ -use evm::{Context, ExitError}; - -use crate::prelude::PhantomData; +use crate::parameters::PromiseCreateArgs; +use crate::prelude::Address; #[cfg(not(feature = "contract"))] use crate::prelude::Vec; -use crate::AuroraState; +use evm::{Context, ExitError}; #[cfg(feature = "contract")] use { - crate::parameters::PromiseCreateArgs, crate::parameters::WithdrawCallArgs, crate::prelude::{is_valid_account_id, Cow, String, ToString, TryInto, U256}, crate::storage::{bytes_to_key, KeyPrefix}, @@ -19,6 +17,11 @@ use super::{Precompile, PrecompileResult}; const ERR_TARGET_TOKEN_NOT_FOUND: &str = "Target token not found"; use crate::precompiles::PrecompileOutput; +use crate::state::AuroraStackState; + +trait ReturnPromise { + fn promise(&self, state: &mut AuroraStackState) -> PromiseCreateArgs; +} mod costs { use crate::types::Gas; @@ -36,14 +39,14 @@ mod costs { pub(super) const WITHDRAWAL_GAS: Gas = 100_000_000_000_000; } -pub struct ExitToNear(PhantomData); //TransferEthToNear +pub struct ExitToNear; //TransferEthToNear -impl ExitToNear { +impl ExitToNear { /// Exit to NEAR precompile address /// /// Address: `0xe9217bc70b7ed1f598ddd3199e80b093fa71124f` /// This address is computed as: `&keccak("exitToNear")[12..]` - pub(super) const ADDRESS: [u8; 20] = + pub(super) const ADDRESS: Address = super::make_address(0xe9217bc7, 0x0b7ed1f598ddd3199e80b093fa71124f); } @@ -56,7 +59,7 @@ fn get_nep141_from_erc20(erc20_token: &[u8]) -> AccountId { .unwrap() } -impl Precompile for ExitToNear { +impl Precompile for ExitToNear { fn required_gas(_input: &[u8]) -> Result { Ok(costs::EXIT_TO_NEAR_GAS) } @@ -66,7 +69,6 @@ impl Precompile for ExitToNear { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { if Self::required_gas(input)? > target_gas { @@ -77,17 +79,12 @@ impl Precompile for ExitToNear { output: Vec::new(), cost: 0, logs: Vec::new(), + promise: None, }) } #[cfg(feature = "contract")] - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - state: &mut S, - is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, is_static: bool) -> PrecompileResult { if Self::required_gas(input)? > target_gas { return Err(ExitError::OutOfGas); } @@ -177,24 +174,25 @@ impl Precompile for ExitToNear { attached_gas: costs::FT_TRANSFER_GAS, }; - state.add_promise(promise); - - Ok(PrecompileOutput::default()) + Ok(PrecompileOutput { + promise: Some(promise), + ..Default::default() + }) } } -pub struct ExitToEthereum(PhantomData); +pub struct ExitToEthereum; -impl ExitToEthereum { +impl ExitToEthereum { /// Exit to Ethereum precompile address /// /// Address: `0xb0bd02f6a392af548bdf1cfaee5dfa0eefcc8eab` /// This address is computed as: `&keccak("exitToEthereum")[12..]` - pub(super) const ADDRESS: [u8; 20] = + pub(super) const ADDRESS: Address = super::make_address(0xb0bd02f6, 0xa392af548bdf1cfaee5dfa0eefcc8eab); } -impl Precompile for ExitToEthereum { +impl Precompile for ExitToEthereum { fn required_gas(_input: &[u8]) -> Result { Ok(costs::EXIT_TO_ETHEREUM_GAS) } @@ -204,7 +202,6 @@ impl Precompile for ExitToEthereum { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { if Self::required_gas(input)? > target_gas { @@ -215,17 +212,12 @@ impl Precompile for ExitToEthereum { output: Vec::new(), cost: 0, logs: Vec::new(), + promise: None, }) } #[cfg(feature = "contract")] - fn run( - input: &[u8], - target_gas: u64, - context: &Context, - state: &mut S, - is_static: bool, - ) -> PrecompileResult { + fn run(input: &[u8], target_gas: u64, context: &Context, is_static: bool) -> PrecompileResult { if Self::required_gas(input)? > target_gas { return Err(ExitError::OutOfGas); } @@ -318,9 +310,10 @@ impl Precompile for ExitToEthereum { attached_gas: costs::WITHDRAWAL_GAS, }; - state.add_promise(promise); - - Ok(PrecompileOutput::default()) + Ok(PrecompileOutput { + promise: Some(promise), + ..Default::default() + }) } } @@ -332,12 +325,12 @@ mod tests { #[test] fn test_precompile_id() { assert_eq!( - ExitToEthereum::<()>::ADDRESS, - near_account_to_evm_address("exitToEthereum".as_bytes()).0 + ExitToEthereum::ADDRESS, + near_account_to_evm_address("exitToEthereum".as_bytes()) ); assert_eq!( - ExitToNear::<()>::ADDRESS, - near_account_to_evm_address("exitToNear".as_bytes()).0 + ExitToNear::ADDRESS, + near_account_to_evm_address("exitToNear".as_bytes()) ); } } diff --git a/src/precompiles/secp256k1.rs b/src/precompiles/secp256k1.rs index f82f545ae..849d4fd28 100644 --- a/src/precompiles/secp256k1.rs +++ b/src/precompiles/secp256k1.rs @@ -3,8 +3,6 @@ use crate::prelude::*; use ethabi::Address; use evm::{Context, ExitError}; -use crate::AuroraState; - mod costs { pub(super) const ECRECOVER_BASE: u64 = 3_000; } @@ -18,10 +16,21 @@ mod consts { /// See: https://etherscan.io/address/0000000000000000000000000000000000000001 // Quite a few library methods rely on this and that should be changed. This // should only be for precompiles. -pub fn ecrecover(hash: H256, signature: &[u8]) -> Result { - use sha3::Digest; +pub(crate) fn ecrecover(hash: H256, signature: &[u8]) -> Result { assert_eq!(signature.len(), 65); + #[cfg(feature = "testnet")] + return crate::sdk::ecrecover(hash, signature) + .map_err(|e| ExitError::Other(Borrowed(e.as_str()))); + + #[cfg(not(feature = "testnet"))] + internal_impl(hash, signature) +} + +#[cfg(not(feature = "testnet"))] +fn internal_impl(hash: H256, signature: &[u8]) -> Result { + use sha3::Digest; + let hash = secp256k1::Message::parse_slice(hash.as_bytes()).unwrap(); let v = signature[64]; let signature = secp256k1::Signature::parse_slice(&signature[0..64]).unwrap(); @@ -38,16 +47,18 @@ pub fn ecrecover(hash: H256, signature: &[u8]) -> Result { } } - Err(ExitError::Other(Borrowed("invalid ECDSA signature"))) + Err(ExitError::Other(Borrowed( + crate::sdk::ECRecoverErr.as_str(), + ))) } -pub(super) struct ECRecover(PhantomData); +pub(super) struct ECRecover; -impl ECRecover { - pub(super) const ADDRESS: [u8; 20] = super::make_address(0, 1); +impl ECRecover { + pub(super) const ADDRESS: Address = super::make_address(0, 1); } -impl Precompile for ECRecover { +impl Precompile for ECRecover { fn required_gas(_input: &[u8]) -> Result { Ok(costs::ECRECOVER_BASE) } @@ -56,7 +67,6 @@ impl Precompile for ECRecover { input: &[u8], target_gas: u64, _context: &Context, - _state: &mut S, _is_static: bool, ) -> PrecompileResult { let cost = Self::required_gas(input)?; @@ -103,9 +113,8 @@ impl Precompile for ECRecover { #[cfg(test)] mod tests { - use crate::test_utils::{new_context, new_state}; - use super::*; + use crate::test_utils::new_context; fn ecverify(hash: H256, signature: &[u8], signer: Address) -> bool { matches!(ecrecover(hash, signature), Ok(s) if s == signer) @@ -132,7 +141,7 @@ mod tests { hex::decode("000000000000000000000000c08b5542d177ac6686946920409741463a15dddb") .unwrap(); - let res = ECRecover::run(&input, 3_000, &new_context(), &mut new_state(), false) + let res = ECRecover::run(&input, 3_000, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); @@ -140,7 +149,7 @@ mod tests { // out of gas let input = hex::decode("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap(); - let res = ECRecover::run(&input, 2_999, &new_context(), &mut new_state(), false); + let res = ECRecover::run(&input, 2_999, &new_context(), false); assert!(matches!(res, Err(ExitError::OutOfGas))); // bad inputs @@ -149,7 +158,7 @@ mod tests { hex::decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") .unwrap(); - let res = ECRecover::run(&input, 3_000, &new_context(), &mut new_state(), false) + let res = ECRecover::run(&input, 3_000, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); @@ -159,7 +168,7 @@ mod tests { hex::decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") .unwrap(); - let res = ECRecover::run(&input, 3_000, &new_context(), &mut new_state(), false) + let res = ECRecover::run(&input, 3_000, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); @@ -169,7 +178,7 @@ mod tests { hex::decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") .unwrap(); - let res = ECRecover::run(&input, 3_000, &new_context(), &mut new_state(), false) + let res = ECRecover::run(&input, 3_000, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); @@ -179,7 +188,7 @@ mod tests { hex::decode("ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") .unwrap(); - let res = ECRecover::run(&input, 3_000, &new_context(), &mut new_state(), false) + let res = ECRecover::run(&input, 3_000, &new_context(), false) .unwrap() .output; assert_eq!(res, expected); diff --git a/src/prelude.rs b/src/prelude.rs index fb55e90be..6c6fa89bf 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -49,7 +49,8 @@ pub use primitive_types::{H160, H256, U256}; pub type Address = H160; #[allow(non_snake_case, dead_code)] -pub fn Address(input: [u8; 20]) -> Address { +// Gets around the fact that you can't contract pub fields with types. +pub const fn Address(input: [u8; 20]) -> Address { H160(input) } diff --git a/src/sdk.rs b/src/sdk.rs index 8a78c3124..df8d5cad7 100644 --- a/src/sdk.rs +++ b/src/sdk.rs @@ -5,6 +5,12 @@ use borsh::{BorshDeserialize, BorshSerialize}; const READ_STORAGE_REGISTER_ID: u64 = 0; const INPUT_REGISTER_ID: u64 = 0; +#[cfg(feature = "testnet")] +const ECRECOVER_MESSAGE_SIZE: u64 = 32; +#[cfg(feature = "testnet")] +const ECRECOVER_SIGNATURE_LENGTH: u64 = 64; +#[cfg(feature = "testnet")] +const ECRECOVER_MALLEABILITY_FLAG: u64 = 1; /// Register used to record evicted values from the storage. const EVICTED_REGISTER: u64 = 0; @@ -45,6 +51,18 @@ mod exports { fn random_seed(register_id: u64); pub(crate) fn sha256(value_len: u64, value_ptr: u64, register_id: u64); pub(crate) fn keccak256(value_len: u64, value_ptr: u64, register_id: u64); + #[cfg(feature = "testnet")] + pub(crate) fn ripemd160(value_len: u64, value_ptr: u64, register_id: u64); + #[cfg(feature = "testnet")] + pub(crate) fn ecrecover( + hash_len: u64, + hash_ptr: u64, + sig_len: u64, + sig_ptr: u64, + v: u64, + malleability_flag: u64, + register_id: u64, + ) -> u64; // ##################### // # Miscellaneous API # // ##################### @@ -372,6 +390,51 @@ pub fn keccak(input: &[u8]) -> H256 { } } +/// Calls environment ripemd160 on given input. +#[cfg(feature = "testnet")] +pub fn ripemd160(input: &[u8]) -> [u8; 20] { + unsafe { + const REGISTER_ID: u64 = 1; + exports::ripemd160(input.len() as u64, input.as_ptr() as u64, REGISTER_ID); + let bytes = [0u8; 20]; + exports::read_register(REGISTER_ID, bytes.as_ptr() as u64); + bytes + } +} + +/// Recover address from message hash and signature. +#[cfg(feature = "testnet")] +pub fn ecrecover(hash: H256, signature: &[u8]) -> Result { + unsafe { + let hash_ptr = hash.as_ptr() as u64; + let sig_ptr = signature.as_ptr() as u64; + const RECOVER_REGISTER_ID: u64 = 1; + const KECCACK_REGISTER_ID: u64 = 2; + let result = exports::ecrecover( + ECRECOVER_MESSAGE_SIZE, + hash_ptr, + ECRECOVER_SIGNATURE_LENGTH, + sig_ptr, + signature[64] as u64, + ECRECOVER_MALLEABILITY_FLAG, + RECOVER_REGISTER_ID, + ); + if result == (true as u64) { + // The result from the ecrecover call is in a register; we can use this + // register directly for the input to keccak256. This is why the length is + // set to `u64::MAX`. + exports::keccak256(u64::MAX, RECOVER_REGISTER_ID, KECCACK_REGISTER_ID); + let keccak_hash_bytes = [0u8; 32]; + exports::read_register(KECCACK_REGISTER_ID, keccak_hash_bytes.as_ptr() as u64); + Ok(crate::prelude::Address::from_slice( + &keccak_hash_bytes[12..], + )) + } else { + Err(ECRecoverErr) + } + } +} + /// Returns account id of the current account. pub fn current_account_id() -> Vec { unsafe { @@ -578,3 +641,15 @@ impl AsRef<[u8]> for ReadU64Error { } } } + +pub struct ECRecoverErr; +impl ECRecoverErr { + pub fn as_str(&self) -> &'static str { + "ERR_ECRECOVER" + } +} +impl AsRef<[u8]> for ECRecoverErr { + fn as_ref(&self) -> &[u8] { + self.as_str().as_bytes() + } +} diff --git a/src/test_utils/mod.rs b/src/test_utils/mod.rs index 989038e2c..3ab166990 100644 --- a/src/test_utils/mod.rs +++ b/src/test_utils/mod.rs @@ -13,16 +13,39 @@ use rlp::RlpStream; use secp256k1::{self, Message, PublicKey, SecretKey}; use crate::fungible_token::FungibleToken; -use crate::parameters::{InitCallArgs, NewCallArgs, PromiseCreateArgs, SubmitResult}; +use crate::parameters::{InitCallArgs, NewCallArgs, SubmitResult}; use crate::prelude::Address; +use crate::storage; use crate::test_utils::solidity::{ContractConstructor, DeployedContract}; -use crate::transaction::{LegacyEthSignedTransaction, LegacyEthTransaction}; +use crate::transaction::{ + access_list::{self, AccessListEthSignedTransaction, AccessListEthTransaction}, + LegacyEthSignedTransaction, LegacyEthTransaction, +}; use crate::types; use crate::types::AccountId; -use crate::{storage, AuroraState}; +#[cfg(all( + feature = "mainnet-test", + not(any(feature = "testnet", feature = "betanet")) +))] lazy_static_include::lazy_static_include_bytes! { - EVM_WASM_BYTES => "release.wasm" + EVM_WASM_BYTES => "mainnet-release.wasm" +} + +#[cfg(all( + feature = "testnet-test", + not(any(feature = "mainnet", feature = "betanet")) +))] +lazy_static_include::lazy_static_include_bytes! { + EVM_WASM_BYTES => "testnet-release.wasm" +} + +#[cfg(all( + feature = "betanet-test", + not(any(feature = "mainnet", feature = "testnet")) +))] +lazy_static_include::lazy_static_include_bytes! { + EVM_WASM_BYTES => "betanet-release.wasm" } // TODO(Copied from #84): Make sure that there is only one Signer after both PR are merged. @@ -103,8 +126,7 @@ impl<'a> OneShotAuroraRunner<'a> { ); near_vm_runner::run( - self.base.code.hash.as_ref().to_vec(), - &self.base.code.code.as_slice(), + &self.base.code, method_name, &mut self.ext, self.context.clone(), @@ -169,8 +191,7 @@ impl AuroraRunner { ); let (maybe_outcome, maybe_error) = near_vm_runner::run( - self.code.hash.as_ref().to_vec(), - &self.code.code.as_slice(), + &self.code, method_name, &mut self.ext, self.context.clone(), @@ -215,6 +236,16 @@ impl AuroraRunner { trie.insert(ft_key, ft_value.try_to_vec().unwrap()); } + pub fn submit_with_signer LegacyEthTransaction>( + &mut self, + signer: &mut Signer, + make_tx: F, + ) -> Result { + let nonce = signer.use_nonce(); + let tx = make_tx(nonce.into()); + self.submit_transaction(&signer.secret_key, tx) + } + pub fn submit_transaction( &mut self, account: &SecretKey, @@ -277,8 +308,7 @@ impl AuroraRunner { address.as_bytes().to_vec(), ); let (outcome, maybe_error) = near_vm_runner::run( - self.code.hash.as_ref().to_vec(), - &self.code.code.as_slice(), + &self.code, method_name, &mut self.ext.clone(), context, @@ -363,6 +393,17 @@ pub(crate) fn deploy_evm() -> AuroraRunner { runner } +pub(crate) fn transfer(to: Address, amount: types::Wei, nonce: U256) -> LegacyEthTransaction { + LegacyEthTransaction { + nonce, + gas_price: Default::default(), + gas: u64::MAX.into(), + to: Some(to), + value: amount, + data: Vec::new(), + } +} + pub(crate) fn create_eth_transaction( to: Option
, value: types::Wei, @@ -407,6 +448,28 @@ pub(crate) fn sign_transaction( } } +pub(crate) fn sign_access_list_transaction( + tx: AccessListEthTransaction, + secret_key: &SecretKey, +) -> AccessListEthSignedTransaction { + let mut rlp_stream = RlpStream::new(); + rlp_stream.append(&access_list::TYPE_BYTE); + tx.rlp_append_unsigned(&mut rlp_stream); + let message_hash = types::keccak(rlp_stream.as_raw()); + let message = Message::parse_slice(message_hash.as_bytes()).unwrap(); + + let (signature, recovery_id) = secp256k1::sign(&message, secret_key); + let r = U256::from_big_endian(&signature.r.b32()); + let s = U256::from_big_endian(&signature.s.b32()); + + AccessListEthSignedTransaction { + transaction_data: tx, + parity: recovery_id.serialize(), + r, + s, + } +} + pub(crate) fn address_from_secret_key(sk: &SecretKey) -> Address { let pk = PublicKey::from_secret_key(sk); let hash = types::keccak(&pk.serialize()[1..]); @@ -440,13 +503,12 @@ pub fn new_context() -> Context { } } -#[derive(Default)] -pub struct MockState; - -impl AuroraState for MockState { - fn add_promise(&mut self, _promise: PromiseCreateArgs) {} -} +pub(crate) fn address_from_hex(address: &str) -> Address { + let bytes = if address.starts_with("0x") { + hex::decode(&address[2..]).unwrap() + } else { + hex::decode(address).unwrap() + }; -pub fn new_state() -> MockState { - Default::default() + Address::from_slice(&bytes) } diff --git a/src/tests/access_lists.rs b/src/tests/access_lists.rs new file mode 100644 index 000000000..5676e39a3 --- /dev/null +++ b/src/tests/access_lists.rs @@ -0,0 +1,65 @@ +use crate::prelude::{H256, U256}; +use crate::test_utils; +use crate::transaction::access_list::{self, AccessListEthTransaction, AccessTuple}; +use crate::transaction::EthTransaction; +use crate::types::Wei; +use std::convert::TryFrom; +use std::iter; + +// Test taken from https://github.com/ethereum/tests/blob/develop/GeneralStateTests/stExample/accessListExample.json +// TODO(#170): generally support Ethereum tests +#[test] +fn test_access_list_tx_encoding_decoding() { + let secret_key = secp256k1::SecretKey::parse_slice( + &hex::decode("45a915e4d060149eb4365960e6a7a45f334393093061116b197e3240065ff2d8").unwrap(), + ) + .unwrap(); + let transaction = AccessListEthTransaction { + chain_id: 1, + nonce: U256::zero(), + gas_price: U256::from(0x0a), + gas_limit: U256::from(0x061a80), + to: Some(test_utils::address_from_hex( + "0x095e7baea6a6c7c4c2dfeb977efac326af552d87", + )), + value: Wei::new_u64(0x0186a0), + data: vec![0], + access_list: vec![ + AccessTuple { + address: test_utils::address_from_hex("0x095e7baea6a6c7c4c2dfeb977efac326af552d87"), + storage_keys: vec![H256::zero(), one()], + }, + AccessTuple { + address: test_utils::address_from_hex("0x195e7baea6a6c7c4c2dfeb977efac326af552d87"), + storage_keys: vec![H256::zero()], + }, + ], + }; + + let signed_tx = test_utils::sign_access_list_transaction(transaction, &secret_key); + let bytes: Vec = iter::once(access_list::TYPE_BYTE) + .chain(rlp::encode(&signed_tx).into_iter()) + .collect(); + let expected_bytes = hex::decode("01f8f901800a83061a8094095e7baea6a6c7c4c2dfeb977efac326af552d87830186a000f893f85994095e7baea6a6c7c4c2dfeb977efac326af552d87f842a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000001f794195e7baea6a6c7c4c2dfeb977efac326af552d87e1a0000000000000000000000000000000000000000000000000000000000000000080a011c97e0bb8a356fe4f49b37863d059c6fe8cd3214a6ac06a8387a2f6f0b75f60a0212368a1097da30806edfd13d9c35662e1baee939235eb25de867980bd0eda26").unwrap(); + + assert_eq!(bytes, expected_bytes); + + let decoded_tx = match EthTransaction::try_from(expected_bytes.as_slice()) { + Ok(EthTransaction::AccessList(tx)) => tx, + Ok(EthTransaction::Legacy(_)) => panic!("Unexpected transaction type"), + Err(_) => panic!("Transaction parsing failed"), + }; + + assert_eq!(signed_tx, decoded_tx); + + assert_eq!( + signed_tx.sender().unwrap(), + test_utils::address_from_secret_key(&secret_key) + ) +} + +fn one() -> H256 { + let mut x = [0u8; 32]; + x[31] = 1; + H256(x) +} diff --git a/src/tests/erc20.rs b/src/tests/erc20.rs index 9abc36e84..95dd88bc2 100644 --- a/src/tests/erc20.rs +++ b/src/tests/erc20.rs @@ -2,6 +2,7 @@ use crate::prelude::{Address, U256}; use crate::test_utils::{ self, erc20::{ERC20Constructor, ERC20}, + Signer, }; use crate::types::Wei; use bstr::ByteSlice; @@ -13,69 +14,53 @@ const TRANSFER_AMOUNT: u64 = 67; #[test] fn erc20_mint() { - let (mut runner, source_account, dest_address, contract) = initialize_erc20(); + let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); // Validate pre-state assert_eq!( U256::zero(), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 1).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); // Do mint transaction let mint_amount: u64 = 10; - let mint_tx = contract.mint(dest_address, mint_amount.into(), (INITIAL_NONCE + 2).into()); - let outcome = runner.submit_transaction(&source_account, mint_tx); + let outcome = runner.submit_with_signer(&mut source_account, |nonce| { + contract.mint(dest_address, mint_amount.into(), nonce) + }); assert!(outcome.is_ok()); // Validate post-state assert_eq!( U256::from(mint_amount), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 3).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); } #[test] fn erc20_mint_out_of_gas() { - let (mut runner, source_account, dest_address, contract) = initialize_erc20(); + let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); // Validate pre-state assert_eq!( U256::zero(), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 1).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); // Try mint transaction let mint_amount: u64 = rand::random(); - let mut mint_tx = contract.mint(dest_address, mint_amount.into(), (INITIAL_NONCE + 2).into()); + let nonce = source_account.use_nonce(); + let mut mint_tx = contract.mint(dest_address, mint_amount.into(), nonce.into()); // not enough gas to cover intrinsic cost mint_tx.gas = (mint_tx.intrinsic_gas(&evm::Config::istanbul()).unwrap() - 1).into(); - let outcome = runner.submit_transaction(&source_account, mint_tx.clone()); + let outcome = runner.submit_transaction(&source_account.secret_key, mint_tx.clone()); let error = outcome.unwrap_err(); let error_message = format!("{:?}", error); assert!(error_message.contains("ERR_INTRINSIC_GAS")); // not enough gas to complete transaction mint_tx.gas = U256::from(67_000); - let outcome = runner.submit_transaction(&source_account, mint_tx); + let outcome = runner.submit_transaction(&source_account.secret_key, mint_tx); let error = outcome.unwrap_err(); let error_message = format!("{:?}", error); assert!(error_message.contains("ERR_OUT_OF_GAS")); @@ -83,7 +68,7 @@ fn erc20_mint_out_of_gas() { // Validate post-state test_utils::validate_address_balance_and_nonce( &runner, - test_utils::address_from_secret_key(&source_account), + test_utils::address_from_secret_key(&source_account.secret_key), Wei::new_u64(INITIAL_BALANCE), (INITIAL_NONCE + 3).into(), ); @@ -91,116 +76,68 @@ fn erc20_mint_out_of_gas() { #[test] fn erc20_transfer_success() { - let (mut runner, source_account, dest_address, contract) = initialize_erc20(); - let source_address = test_utils::address_from_secret_key(&source_account); + let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); - let mint_tx = contract.mint( - source_address, - INITIAL_BALANCE.into(), - (INITIAL_NONCE + 1).into(), - ); - let outcome = runner.submit_transaction(&source_account, mint_tx); + let outcome = runner.submit_with_signer(&mut source_account, |nonce| { + contract.mint(source_address, INITIAL_BALANCE.into(), nonce) + }); assert!(outcome.is_ok()); // Validate pre-state assert_eq!( U256::from(INITIAL_BALANCE), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 2).into(), - source_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, source_address, &contract) ); assert_eq!( U256::zero(), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 3).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); // Do transfer - let transfer_tx = contract.transfer( - dest_address, - TRANSFER_AMOUNT.into(), - (INITIAL_NONCE + 4).into(), - ); let outcome = runner - .submit_transaction(&source_account, transfer_tx) + .submit_with_signer(&mut source_account, |nonce| { + contract.transfer(dest_address, TRANSFER_AMOUNT.into(), nonce) + }) .unwrap(); assert!(outcome.status); // Validate post-state assert_eq!( U256::from(INITIAL_BALANCE - TRANSFER_AMOUNT), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 5).into(), - source_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, source_address, &contract) ); assert_eq!( U256::from(TRANSFER_AMOUNT), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 6).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); } #[test] fn erc20_transfer_insufficient_balance() { - let (mut runner, source_account, dest_address, contract) = initialize_erc20(); - let source_address = test_utils::address_from_secret_key(&source_account); + let (mut runner, mut source_account, dest_address, contract) = initialize_erc20(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); - let mint_tx = contract.mint( - source_address, - INITIAL_BALANCE.into(), - (INITIAL_NONCE + 1).into(), - ); - let outcome = runner.submit_transaction(&source_account, mint_tx); + let outcome = runner.submit_with_signer(&mut source_account, |nonce| { + contract.mint(source_address, INITIAL_BALANCE.into(), nonce) + }); assert!(outcome.is_ok()); // Validate pre-state assert_eq!( U256::from(INITIAL_BALANCE), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 2).into(), - source_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, source_address, &contract) ); assert_eq!( U256::zero(), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 3).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); // Do transfer - let transfer_tx = contract.transfer( - dest_address, - (2 * INITIAL_BALANCE).into(), - (INITIAL_NONCE + 4).into(), - ); let outcome = runner - .submit_transaction(&source_account, transfer_tx) + .submit_with_signer(&mut source_account, |nonce| { + contract.transfer(dest_address, (2 * INITIAL_BALANCE).into(), nonce) + }) .unwrap(); assert!(!outcome.status); // status == false means execution error let message = parse_erc20_error_message(&outcome.result); @@ -209,23 +146,11 @@ fn erc20_transfer_insufficient_balance() { // Validate post-state assert_eq!( U256::from(INITIAL_BALANCE), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 5).into(), - source_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, source_address, &contract) ); assert_eq!( U256::zero(), - get_address_erc20_balance( - &mut runner, - &source_account, - (INITIAL_NONCE + 6).into(), - dest_address, - &contract - ) + get_address_erc20_balance(&mut runner, &mut source_account, dest_address, &contract) ); } @@ -273,13 +198,11 @@ fn deploy_erc_20_out_of_gas() { fn get_address_erc20_balance( runner: &mut test_utils::AuroraRunner, - signing_account: &SecretKey, - nonce: U256, + signer: &mut Signer, address: Address, contract: &ERC20, ) -> U256 { - let balance_tx = contract.balance_of(address, nonce); - let outcome = runner.submit_transaction(signing_account, balance_tx); + let outcome = runner.submit_with_signer(signer, |nonce| contract.balance_of(address, nonce)); assert!(outcome.is_ok()); U256::from_big_endian(&outcome.unwrap().result) } @@ -291,7 +214,7 @@ fn parse_erc20_error_message(result: &[u8]) -> String { String::from_utf8(result[start_index..end_index].to_vec()).unwrap() } -fn initialize_erc20() -> (test_utils::AuroraRunner, SecretKey, Address, ERC20) { +fn initialize_erc20() -> (test_utils::AuroraRunner, Signer, Address, ERC20) { // set up Aurora runner and accounts let mut runner = test_utils::deploy_evm(); let mut rng = rand::thread_rng(); @@ -304,12 +227,15 @@ fn initialize_erc20() -> (test_utils::AuroraRunner, SecretKey, Address, ERC20) { ); let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng)); + let mut signer = Signer::new(source_account); + signer.nonce = INITIAL_NONCE; + let nonce = signer.use_nonce(); let constructor = ERC20Constructor::load(); let contract = ERC20(runner.deploy_contract( - &source_account, - |c| c.deploy("TestToken", "TEST", INITIAL_NONCE.into()), + &signer.secret_key, + |c| c.deploy("TestToken", "TEST", nonce.into()), constructor, )); - (runner, source_account, dest_address, contract) + (runner, signer, dest_address, contract) } diff --git a/src/tests/eth_connector.rs b/src/tests/eth_connector.rs index ca802856f..1f8994d60 100644 --- a/src/tests/eth_connector.rs +++ b/src/tests/eth_connector.rs @@ -45,16 +45,16 @@ fn init_contract( ) -> UserAccount { let contract_account = master_account.deploy( &crate::test_utils::AuroraRunner::default().code.code, - contract_name.to_string(), + contract_name.parse().unwrap(), to_yocto("1000000"), ); contract_account .call( - contract_name.to_string(), + contract_name.parse().unwrap(), "new", &NewCallArgs { chain_id: [0u8; 32], - owner_id: master_account.account_id.clone(), + owner_id: master_account.account_id.clone().into(), bridge_prover_id: accounts(0).to_string(), upgrade_delay_blocks: 1, } @@ -66,7 +66,7 @@ fn init_contract( .assert_success(); contract_account .call( - contract_name.to_string(), + contract_name.parse().unwrap(), "new_eth_connector", &InitCallArgs { prover_account: PROVER_ACCOUNT.into(), @@ -95,7 +95,7 @@ fn call_deposit_eth_to_near( ) -> Vec> { let proof: Proof = serde_json::from_str(PROOF_DATA_NEAR).unwrap(); let res = master_account.call( - contract.to_string(), + contract.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -114,7 +114,7 @@ fn call_deposit_eth_to_near( fn call_is_used_proof(account: &UserAccount, contract: &str, proof: &str) -> bool { let proof: Proof = serde_json::from_str(proof).unwrap(); let res = account.view( - contract.to_string(), + contract.parse().unwrap(), "is_used_proof", &proof.try_to_vec().unwrap(), ); @@ -150,7 +150,7 @@ fn print_logs(logs: &Vec) { fn call_deposit_eth_to_aurora(master_account: &UserAccount, contract: &str) { let proof: Proof = serde_json::from_str(PROOF_DATA_ETH).unwrap(); let res = master_account.call( - contract.to_string(), + contract.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -167,7 +167,7 @@ fn get_eth_on_near_balance(master_account: &UserAccount, acc: &str, contract: &s } let balance = master_account.view( - contract.to_string(), + contract.parse().unwrap(), "ft_balance_of", json!({ "account_id": acc }).to_string().as_bytes(), ); @@ -184,7 +184,7 @@ fn get_eth_balance(master_account: &UserAccount, address: EthAddress, contract: } let balance = master_account.view( - contract.to_string(), + contract.parse().unwrap(), "ft_balance_of_eth", &BalanceOfEthCallArgs { address }.try_to_vec().unwrap(), ); @@ -195,7 +195,7 @@ fn get_eth_balance(master_account: &UserAccount, address: EthAddress, contract: } fn total_supply(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view(contract.to_string(), "ft_total_supply", &[]); + let balance = master_account.view(contract.parse().unwrap(), "ft_total_supply", &[]); String::from_utf8(balance.unwrap()) .unwrap() .parse() @@ -203,7 +203,11 @@ fn total_supply(master_account: &UserAccount, contract: &str) -> u128 { } fn total_eth_supply_on_near(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view(contract.to_string(), "ft_total_eth_supply_on_near", &[]); + let balance = master_account.view( + contract.parse().unwrap(), + "ft_total_eth_supply_on_near", + &[], + ); String::from_utf8(balance.unwrap()) .unwrap() .parse() @@ -211,7 +215,11 @@ fn total_eth_supply_on_near(master_account: &UserAccount, contract: &str) -> u12 } fn total_eth_supply_on_aurora(master_account: &UserAccount, contract: &str) -> u128 { - let balance = master_account.view(contract.to_string(), "ft_total_eth_supply_on_aurora", &[]); + let balance = master_account.view( + contract.parse().unwrap(), + "ft_total_eth_supply_on_aurora", + &[], + ); String::from_utf8(balance.unwrap()) .unwrap() .parse() @@ -243,7 +251,7 @@ fn test_deposit_eth_to_near_balance_total_supply() { fn test_deposit_eth_to_aurora_balance_total_supply() { let (master_account, contract) = init(EVM_CUSTODIAN_ADDRESS); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "register_relayer", &RegisterRelayerCallArgs { address: validate_eth_address(CUSTODIAN_ADDRESS), @@ -290,7 +298,7 @@ fn test_withdraw_eth_from_near() { let withdraw_amount = 100; let recipient_addr = validate_eth_address(RECIPIENT_ETH_ADDRESS); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -333,7 +341,7 @@ fn test_ft_transfer() { let transfer_amount = 70; let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer", json!({ "receiver_id": DEPOSITED_RECIPIENT, @@ -378,7 +386,7 @@ fn test_ft_transfer_call_eth() { assert_eq!(balance, DEPOSITED_FEE); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "register_relayer", &RegisterRelayerCallArgs { address: validate_eth_address(CUSTODIAN_ADDRESS), @@ -396,7 +404,7 @@ fn test_ft_transfer_call_eth() { msg.append(&mut validate_eth_address(RECIPIENT_ETH_ADDRESS).to_vec()); let message = [CONTRACT_ACC, hex::encode(msg).as_str()].join(":"); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer_call", json!({ "receiver_id": CONTRACT_ACC, @@ -497,7 +505,7 @@ fn test_ft_transfer_call_without_relayer() { let relayer_id = "relayer.root"; let message = [relayer_id, hex::encode(msg).as_str()].join(":"); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer_call", json!({ "receiver_id": CONTRACT_ACC, @@ -553,7 +561,7 @@ fn test_ft_transfer_call_fee_greater_than_amount() { let relayer_id = "relayer.root"; let message = [relayer_id, hex::encode(msg).as_str()].join(":"); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer_call", json!({ "receiver_id": CONTRACT_ACC, @@ -607,7 +615,7 @@ fn call_deposit_with_proof( ) -> Vec> { let proof: Proof = serde_json::from_str(proof).unwrap(); let res = account.call( - contract.to_string(), + contract.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -622,7 +630,7 @@ fn call_set_paused_flags( paused_mask: PausedMask, ) -> ExecutionResult { let res = account.call( - contract.to_string(), + contract.parse().unwrap(), "set_paused_flags", &paused_mask.try_to_vec().unwrap(), DEFAULT_GAS, @@ -633,7 +641,7 @@ fn call_set_paused_flags( fn create_user_account(master_account: &UserAccount) -> UserAccount { let user_account = master_account.create_user( - "eth_recipient.root".to_string(), + "eth_recipient.root".parse().unwrap(), to_yocto("100"), // initial balance ); user_account @@ -675,7 +683,7 @@ fn test_admin_controlled_admin_can_peform_actions_when_paused() { // 1st withdraw call when unpaused - should succeed let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -714,7 +722,7 @@ fn test_admin_controlled_admin_can_peform_actions_when_paused() { // 2nd withdraw call when paused, but the admin is calling it - should succeed let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -787,7 +795,7 @@ fn test_withdraw_from_near_pausability() { let recipient_addr = validate_eth_address(RECIPIENT_ETH_ADDRESS); // 1st withdraw - should succeed let res = user_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -813,7 +821,7 @@ fn test_withdraw_from_near_pausability() { // 2nd withdraw - should fail let res = user_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -837,7 +845,7 @@ fn test_withdraw_from_near_pausability() { res.assert_success(); let res = user_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "withdraw", &WithdrawCallArgs { recipient_address: recipient_addr, @@ -864,7 +872,7 @@ fn test_get_accounts_counter() { call_deposit_eth_to_near(&contract, CONTRACT_ACC); let counter = master_account - .view(CONTRACT_ACC.into(), "get_accounts_counter", &[]) + .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) .unwrap(); assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); } @@ -875,13 +883,13 @@ fn test_get_accounts_counter_and_transfer() { call_deposit_eth_to_near(&contract, CONTRACT_ACC); let counter = master_account - .view(CONTRACT_ACC.into(), "get_accounts_counter", &[]) + .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) .unwrap(); assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); let transfer_amount = 70; let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer", json!({ "receiver_id": DEPOSITED_RECIPIENT, @@ -914,7 +922,7 @@ fn test_get_accounts_counter_and_transfer() { assert_eq!(balance, DEPOSITED_AMOUNT); let counter = master_account - .view(CONTRACT_ACC.into(), "get_accounts_counter", &[]) + .view(CONTRACT_ACC.parse().unwrap(), "get_accounts_counter", &[]) .unwrap(); assert_eq!(u64::try_from_slice(&counter[..]).unwrap(), 2); } @@ -925,7 +933,7 @@ fn test_deposit_to_near_with_zero_fee() { let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,249,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,23,160,7,139,123,21,146,99,81,234,117,153,151,30,67,221,231,90,105,219,121,127,196,224,201,83,178,31,173,155,190,123,227,174,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,109,150,79,199,61,172,73,162,195,49,105,169,235,252,47,207,92,249,136,136,160,227,202,170,144,85,104,169,90,220,93,227,155,76,252,229,223,163,146,127,223,157,121,27,238,116,64,112,216,124,129,107,9,160,158,128,122,7,117,120,186,231,92,224,181,67,43,66,153,79,155,38,238,166,68,1,151,100,134,126,214,86,59,66,174,201,160,235,177,124,164,253,179,174,206,160,196,186,61,51,64,217,35,121,86,229,24,251,162,51,82,72,31,218,240,150,32,157,48,185,1,0,0,0,8,0,0,32,0,0,0,0,0,0,128,0,0,0,2,0,128,0,64,32,0,0,0,0,0,0,64,0,0,10,0,0,0,0,0,0,3,0,0,0,0,64,128,0,0,64,0,0,0,0,0,16,0,0,130,0,1,16,0,32,4,0,0,0,0,0,2,1,0,0,0,0,0,8,0,8,0,0,32,0,4,128,2,0,128,0,0,0,0,0,0,0,0,0,4,32,0,8,2,0,0,0,128,65,0,136,0,0,40,0,0,0,8,0,0,128,0,34,0,4,0,185,2,0,0,4,32,128,0,2,0,0,0,128,0,0,10,0,1,0,1,0,0,0,0,32,1,8,128,0,0,4,0,0,0,128,128,0,70,0,0,0,0,0,0,16,64,0,64,0,34,64,0,0,0,4,0,0,0,0,1,128,0,9,0,0,0,0,0,16,0,0,64,2,0,0,0,132,0,64,32,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,4,0,0,0,32,8,0,16,0,8,0,16,68,0,0,0,16,0,0,0,128,0,64,0,0,128,0,0,0,0,0,0,0,16,0,1,0,16,132,49,181,116,68,131,157,92,101,131,122,18,0,131,101,155,9,132,96,174,110,74,153,216,131,1,10,1,132,103,101,116,104,134,103,111,49,46,49,54,135,119,105,110,100,111,119,115,160,228,82,26,232,236,82,141,6,111,169,92,14,115,254,59,131,192,3,202,209,126,79,140,182,163,12,185,45,210,17,60,38,136,84,114,37,115,236,183,145,213],"proof":[[248,145,160,187,129,186,104,13,250,13,252,114,170,223,247,137,53,113,225,188,217,54,244,108,193,247,236,197,29,0,161,119,76,227,184,160,66,209,234,66,254,223,80,22,246,80,204,38,2,90,115,201,183,79,207,47,192,234,143,221,89,78,36,199,127,9,55,190,160,91,160,251,58,165,255,90,2,105,47,46,220,67,3,52,105,42,182,130,224,19,162,115,159,136,158,218,93,187,148,188,9,128,128,128,128,128,160,181,223,248,223,173,187,103,169,52,204,62,13,90,70,147,236,199,27,201,112,157,4,139,63,188,12,98,117,10,82,85,125,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,249,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,184,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -957,7 +965,7 @@ fn test_deposit_to_near_with_zero_fee() { fn test_deposit_to_aurora_with_zero_fee() { let (master_account, contract) = init(EVM_CUSTODIAN_ADDRESS); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "register_relayer", &RegisterRelayerCallArgs { address: validate_eth_address(CUSTODIAN_ADDRESS), @@ -972,7 +980,7 @@ fn test_deposit_to_aurora_with_zero_fee() { let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":3,"receipt_data":[249,2,41,1,131,2,246,200,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,23,160,110,48,40,236,52,198,197,25,255,191,199,4,137,3,185,31,202,84,90,80,104,32,176,13,144,141,165,183,36,30,94,138,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,148,156,193,169,167,156,148,249,191,22,225,202,121,212,79,2,197,75,191,164,160,127,26,168,212,111,22,173,213,25,217,187,227,114,86,173,99,166,195,67,16,104,111,200,109,110,147,241,23,71,122,89,215,160,47,120,179,75,110,158,228,18,242,156,38,111,95,25,236,211,158,53,53,62,89,190,2,40,220,41,151,200,127,219,33,219,160,222,177,165,249,98,109,130,37,226,229,165,113,45,12,145,30,16,28,154,86,22,203,218,233,13,246,165,177,61,57,68,83,185,1,0,0,32,8,0,33,0,0,0,64,0,32,0,128,0,0,0,132,0,0,0,64,32,64,0,0,1,0,32,64,0,0,8,0,0,0,0,0,0,137,32,0,0,0,64,128,0,0,16,0,0,0,0,33,64,0,1,0,0,0,0,0,0,0,0,68,0,0,0,2,1,64,0,0,0,0,9,16,0,0,32,0,0,0,128,2,0,0,0,33,0,0,0,128,0,0,0,12,64,32,8,66,2,0,0,64,0,0,8,0,0,40,8,8,0,0,0,0,16,0,0,0,0,64,49,0,0,8,0,96,0,0,18,0,0,0,0,0,64,10,0,1,0,0,32,0,0,0,33,0,0,128,136,10,64,0,64,0,0,192,128,0,0,64,1,0,0,4,0,8,0,64,0,34,0,0,0,0,0,0,0,0,0,0,0,8,8,0,4,0,0,0,32,0,4,0,2,0,0,0,129,4,0,96,16,4,8,0,0,0,0,0,0,1,0,128,16,0,0,2,0,4,0,32,0,8,0,0,0,0,16,0,1,0,0,0,0,64,0,128,0,0,32,36,128,0,0,4,64,0,8,8,16,0,1,4,16,132,50,32,156,229,131,157,92,137,131,122,18,0,131,35,159,183,132,96,174,111,126,153,216,131,1,10,3,132,103,101,116,104,136,103,111,49,46,49,54,46,51,133,108,105,110,117,120,160,59,74,90,253,211,14,166,114,39,213,120,95,221,43,109,173,72,205,160,203,71,44,83,159,36,59,129,84,32,16,254,251,136,49,16,97,244,161,246,244,85],"proof":[[248,113,160,227,103,29,228,16,56,196,146,115,29,122,202,254,140,214,86,189,108,47,197,2,195,50,211,4,126,58,175,71,11,70,78,160,229,239,23,242,100,150,90,169,21,162,252,207,202,244,187,71,172,126,191,33,166,162,45,134,108,114,6,76,78,177,148,140,128,128,128,128,128,128,160,21,91,249,81,132,162,52,236,128,181,5,72,158,228,177,131,87,144,64,194,111,103,180,16,183,103,245,136,125,213,208,76,128,128,128,128,128,128,128,128],[249,1,241,128,160,52,154,34,8,39,210,121,1,151,92,91,225,198,154,204,207,11,204,187,59,223,154,187,102,115,110,193,141,201,198,95,253,160,218,19,188,241,210,48,51,3,76,125,48,152,171,188,45,136,109,71,236,171,242,162,10,34,245,160,191,5,120,9,80,129,160,147,160,142,184,113,171,112,171,131,124,150,117,65,27,207,149,119,136,120,65,7,99,155,114,169,57,91,125,26,117,49,67,160,173,217,104,114,149,170,18,227,251,73,78,11,220,243,240,66,117,32,199,64,138,173,169,43,8,122,39,47,210,54,41,192,160,139,116,124,73,113,242,225,65,167,48,33,13,149,51,152,196,79,93,126,103,116,48,177,25,80,186,34,55,15,116,2,13,160,67,10,207,13,108,228,254,73,175,10,166,107,144,157,150,135,173,179,140,112,129,205,168,132,194,4,191,175,239,50,66,245,160,26,193,195,232,40,106,60,72,133,32,204,205,104,90,20,60,166,16,214,184,115,44,216,62,82,30,141,124,160,72,173,62,160,67,5,174,33,105,28,248,245,48,15,129,153,96,27,97,125,29,194,233,139,228,8,243,221,79,2,151,52,75,30,47,136,160,103,94,192,58,117,224,88,80,21,183,254,178,135,21,78,20,233,250,7,22,243,14,41,56,12,118,206,224,75,42,96,77,160,225,64,237,254,248,145,134,195,166,49,205,129,233,54,142,136,235,242,10,14,175,76,73,131,26,135,102,237,64,23,102,213,160,167,104,45,101,228,93,89,216,167,142,125,0,216,77,167,4,245,156,140,98,117,19,165,25,185,204,84,161,175,153,193,20,160,53,22,192,197,176,225,102,6,251,115,216,238,53,110,254,106,193,134,232,100,173,93,211,71,195,10,192,107,97,190,165,12,160,104,206,244,51,77,131,79,209,64,233,97,35,142,75,42,205,198,120,222,90,199,168,126,235,12,225,30,240,214,56,253,168,160,230,94,127,56,22,169,3,159,236,49,217,88,2,175,168,22,104,177,154,127,106,165,176,238,236,141,83,64,123,28,177,206,160,140,137,2,195,227,9,182,245,76,62,215,174,168,254,15,125,111,241,30,50,110,189,66,58,230,2,252,104,182,247,223,94,128],[249,2,48,32,185,2,44,249,2,41,1,131,2,246,200,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,9,109,233,194,184,165,184,194,44,238,50,137,177,1,246,150,13,104,229,30,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,7,208,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1015,7 +1023,7 @@ fn test_deposit_to_near_amount_less_fee() { let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,139,92,51,142,163,95,21,160,61,29,148,206,54,147,187,96,77,109,244,8,130,155,249,198,206,30,173,216,144,176,252,123,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,218,9,209,192,173,39,133,109,141,57,2,146,184,12,94,217,6,138,173,67,121,185,24,179,133,189,219,40,81,210,73,106,160,219,108,244,199,44,203,84,71,126,74,82,240,203,255,238,20,226,29,239,51,7,19,144,34,156,137,232,159,71,30,164,29,160,209,61,241,33,17,103,192,203,57,156,112,250,18,166,26,237,248,153,226,185,87,220,156,93,249,17,39,190,125,96,247,239,185,1,0,0,0,8,0,0,0,0,0,0,0,0,1,0,0,0,0,0,128,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,32,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,32,0,0,0,0,8,0,0,2,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,8,0,0,0,0,0,0,40,0,0,0,0,0,0,0,0,0,0,0,0,0,144,4,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,132,91,80,110,139,131,157,118,104,131,122,18,0,131,30,4,87,132,96,175,154,220,140,115,112,105,100,101,114,49,48,1,2,9,64,160,80,163,212,151,183,11,70,219,178,190,167,172,64,187,47,14,29,226,253,132,116,145,81,143,54,249,121,123,193,241,120,249,136,244,120,239,134,243,43,177,139],"proof":[[248,81,160,164,35,68,182,184,52,174,73,6,81,4,92,187,190,187,106,255,124,123,24,244,168,161,247,60,181,75,29,192,175,96,140,128,128,128,128,128,128,128,160,169,157,199,164,106,205,109,88,111,183,255,180,108,15,155,137,126,163,108,44,117,125,138,221,3,188,93,85,146,129,19,139,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,88,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1038,7 +1046,7 @@ fn test_deposit_to_aurora_amount_less_fee() { let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,10,160,234,97,221,132,104,51,119,219,129,206,197,27,130,197,14,113,167,32,152,214,207,205,156,210,35,213,198,227,116,42,51,224,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,15,150,233,184,181,140,226,81,205,139,229,87,226,149,49,207,117,33,36,83,124,8,75,199,231,48,13,23,189,217,179,12,160,241,37,169,74,233,62,231,112,0,207,95,228,68,240,108,254,57,199,255,130,142,158,161,180,243,50,255,222,77,251,252,126,160,31,111,236,60,142,91,35,119,195,92,158,134,65,138,8,247,98,122,229,21,226,85,38,130,141,139,168,60,83,90,63,244,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,128,0,0,0,0,128,0,0,0,32,0,0,0,0,0,0,64,0,0,10,0,0,0,0,0,0,1,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1,0,0,0,0,0,8,0,0,2,0,0,0,4,0,2,0,0,0,0,0,0,0,0,0,0,0,4,0,0,8,2,0,0,0,0,0,0,136,0,4,40,0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,0,32,0,0,10,0,0,0,0,0,0,10,0,1,0,0,0,0,0,0,32,0,0,128,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,16,0,0,64,0,34,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,128,2,0,0,0,128,0,1,32,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,4,0,0,0,32,128,0,0,0,0,0,16,0,0,0,0,0,0,0,0,128,0,0,0,0,128,0,0,0,0,0,0,0,16,0,1,0,16,132,91,127,63,197,131,157,118,142,131,122,18,0,131,25,25,181,132,96,175,156,157,140,115,112,105,100,101,114,49,48,1,2,9,64,160,68,227,115,157,18,184,21,217,93,74,196,34,230,228,210,239,61,26,221,245,191,46,44,135,134,2,20,53,95,18,128,54,136,162,198,27,59,153,146,63,16],"proof":[[248,113,160,204,110,241,220,150,206,51,121,104,130,125,127,249,35,9,242,107,45,164,62,147,221,93,116,73,79,49,96,226,92,235,247,160,43,215,154,177,148,177,15,202,141,217,45,114,108,33,74,0,144,126,189,26,78,152,232,105,119,103,203,51,79,45,113,124,128,128,128,128,128,128,160,74,177,164,103,85,250,153,17,105,68,205,207,176,48,89,230,100,35,20,167,34,117,11,115,14,107,128,214,48,17,53,209,128,128,128,128,128,128,128,128],[249,2,47,48,185,2,43,249,2,40,1,130,121,119,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,150,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,132,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1061,7 +1069,7 @@ fn test_deposit_to_near_amount_zero_fee_non_zero() { let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,47,76,8,45,83,192,115,218,108,188,181,117,148,40,254,44,169,118,92,188,207,7,122,246,133,75,100,184,134,128,91,12,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,225,211,110,129,173,98,101,150,55,116,11,30,26,161,226,8,234,249,90,46,245,112,225,68,76,26,215,135,27,181,140,22,160,229,44,239,5,102,141,42,118,174,163,144,225,90,152,120,60,150,25,144,217,154,234,25,69,35,226,103,149,188,127,81,106,160,177,89,93,76,113,24,117,182,174,52,148,6,239,129,151,18,222,56,245,9,232,80,7,129,118,118,108,72,76,247,238,101,185,1,0,1,4,200,10,0,0,0,0,8,0,32,0,128,3,1,0,0,145,4,33,72,8,0,2,0,128,0,18,64,26,38,0,4,16,8,1,136,65,40,32,0,0,1,72,0,2,0,128,0,64,0,0,48,0,32,0,0,0,0,192,0,100,9,0,12,0,16,0,0,1,2,8,8,0,8,12,128,64,0,192,2,0,0,64,2,68,129,0,128,1,0,0,128,128,68,0,64,64,32,0,67,0,32,0,0,41,20,1,0,16,40,0,16,16,32,0,0,0,128,0,0,0,64,48,4,8,8,0,0,0,0,66,32,64,0,0,48,0,16,8,1,64,0,0,16,32,0,33,32,0,0,128,0,2,2,128,0,0,192,0,2,40,0,0,0,0,0,1,0,67,1,0,131,32,6,8,0,0,8,96,128,0,0,0,0,12,0,0,0,65,2,160,2,64,0,2,4,32,0,128,0,1,34,0,105,0,160,0,32,18,32,16,1,0,0,0,20,0,32,0,20,0,96,128,0,16,0,0,64,16,2,192,1,0,4,32,0,32,130,2,0,0,32,0,0,0,4,64,12,64,0,0,4,0,0,1,132,93,96,3,163,131,157,117,205,131,122,18,0,131,113,87,104,132,96,175,145,182,140,115,112,105,100,101,114,49,48,1,2,9,64,160,179,183,88,73,3,20,234,255,8,238,6,186,173,204,149,149,235,233,232,35,158,194,53,246,218,39,221,246,90,7,34,255,136,176,36,100,161,146,27,98,29],"proof":[[248,177,160,93,101,188,48,5,53,36,126,41,0,92,130,188,117,104,230,178,29,27,194,22,86,212,235,193,20,241,42,157,88,117,205,160,141,83,180,197,22,126,217,34,74,50,114,118,42,157,161,171,8,158,98,92,183,124,137,130,211,1,106,44,222,37,13,32,160,62,131,146,138,69,63,89,98,140,64,187,93,207,160,0,4,134,154,205,47,168,231,136,249,129,230,137,29,3,210,67,173,160,76,91,176,245,81,3,198,111,175,230,185,70,220,111,189,88,15,154,173,107,239,121,185,13,159,197,61,37,231,252,22,200,128,128,128,128,160,13,246,139,212,38,202,103,201,31,80,247,136,186,58,17,52,66,119,115,128,23,123,59,166,177,68,79,182,9,242,60,106,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,244,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1084,7 +1092,7 @@ fn test_deposit_to_aurora_amount_zero_fee_non_zero() { let proof_str = r#"{"log_index":0,"log_entry_data":[249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"receipt_index":1,"receipt_data":[249,2,41,1,131,1,110,54,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0],"header_data":[249,2,21,160,60,128,9,36,168,69,207,249,164,88,177,15,74,221,137,160,110,246,3,133,209,132,169,179,31,86,142,216,160,11,162,137,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,28,255,226,5,233,121,118,187,157,30,192,6,245,34,35,96,168,147,83,224,160,182,206,231,252,255,115,166,11,152,156,84,169,204,36,0,94,3,17,113,103,104,252,225,161,115,85,74,227,104,249,187,232,160,211,106,68,136,2,141,5,14,201,111,68,218,251,84,103,176,66,10,190,123,58,119,216,141,192,197,222,181,211,87,117,192,160,162,200,112,106,166,13,220,187,223,164,251,102,104,106,40,84,17,101,93,131,125,204,193,62,96,110,167,214,54,41,154,191,185,1,0,0,40,72,0,32,0,0,0,0,0,0,5,128,2,0,8,0,128,144,136,0,34,0,0,32,1,0,0,64,16,0,10,0,16,8,28,0,17,9,0,0,0,0,72,0,16,4,0,0,0,0,128,2,18,0,0,0,0,1,16,0,36,0,1,1,32,8,0,2,1,0,64,64,0,0,8,0,16,0,40,2,0,13,0,2,8,0,0,0,8,0,0,16,0,4,16,36,0,52,8,130,128,8,0,0,0,0,10,0,2,40,64,0,34,32,2,0,2,0,0,0,0,0,48,4,32,128,0,32,0,0,2,96,0,0,0,0,64,10,0,33,64,0,0,0,66,0,32,0,0,192,138,0,0,0,70,0,129,128,0,66,32,0,0,16,64,0,0,0,0,97,0,34,0,6,0,0,32,8,0,1,200,128,48,0,41,128,0,128,0,224,0,0,0,0,2,0,64,0,148,0,0,32,72,8,0,96,0,36,128,25,48,33,0,128,16,0,0,4,2,128,4,32,144,0,20,0,0,0,16,2,0,4,0,2,8,0,0,128,0,16,0,0,128,0,0,16,0,128,0,72,16,0,129,0,80,132,91,116,53,37,131,157,118,157,131,122,18,0,131,48,97,222,132,96,175,157,102,151,214,131,1,10,2,132,103,101,116,104,134,103,111,49,46,49,54,133,108,105,110,117,120,160,218,71,54,233,233,153,85,103,64,10,4,159,150,224,130,134,111,78,188,224,102,166,96,148,216,222,134,254,219,185,88,110,136,87,173,68,252,252,248,190,64],"proof":[[248,177,160,174,171,108,131,83,47,244,139,23,122,146,226,84,189,175,114,176,131,196,80,85,155,220,172,151,31,138,121,78,34,1,37,160,104,209,167,107,221,53,22,163,251,61,251,80,40,239,108,253,251,47,253,90,163,103,58,194,173,111,232,90,174,223,154,156,160,185,232,110,109,245,242,193,69,113,230,64,155,37,7,166,98,0,174,149,27,3,242,254,162,87,27,39,206,191,90,97,39,160,156,171,231,120,50,202,239,195,248,47,226,150,143,78,94,254,151,195,12,90,54,253,126,104,200,94,222,173,155,24,75,214,128,128,128,128,160,77,84,120,31,175,114,100,6,171,254,190,44,236,141,143,126,33,139,92,41,101,166,10,135,52,237,241,45,228,121,210,252,128,128,128,128,128,128,128,128],[249,1,241,128,160,112,174,178,81,116,140,64,238,179,40,62,38,72,120,77,248,199,242,3,227,104,227,174,247,54,169,115,176,134,87,216,196,160,208,65,39,69,237,92,207,141,20,26,113,245,146,250,71,165,184,6,221,105,202,34,201,192,206,144,30,169,82,146,191,130,160,250,127,168,75,47,196,128,16,232,187,94,131,103,164,17,74,154,178,32,193,229,188,234,15,63,149,127,95,2,85,36,38,160,9,173,49,32,69,145,114,254,67,59,110,57,126,204,241,26,85,145,117,55,165,249,149,252,11,213,14,224,142,203,167,165,160,49,16,36,243,207,150,120,119,173,146,213,84,201,84,33,132,103,245,138,209,190,215,89,31,100,50,79,241,11,27,117,232,160,38,102,178,111,249,250,245,239,103,241,97,55,179,25,194,214,51,83,145,244,160,76,255,88,140,94,66,211,135,147,231,233,160,86,244,54,180,248,80,19,60,89,82,142,50,237,41,148,80,99,93,184,17,160,129,174,200,175,79,56,156,152,116,246,19,160,141,144,121,114,242,95,79,178,182,13,237,0,226,45,215,70,186,238,115,124,4,185,167,106,170,121,37,27,22,90,85,154,160,38,169,214,240,80,51,77,173,121,227,163,72,68,190,21,194,23,235,129,2,183,83,211,21,67,152,206,246,236,168,183,65,160,220,198,172,57,188,229,136,230,231,56,249,171,3,156,137,119,188,173,183,120,220,15,214,253,121,102,45,164,53,244,173,237,160,222,126,139,114,159,32,8,38,110,8,161,127,50,42,173,124,148,83,169,13,252,160,28,62,186,159,153,201,217,244,7,198,160,29,57,238,34,65,21,193,24,140,71,159,181,152,57,184,3,168,102,8,32,23,158,117,205,137,200,143,228,205,234,96,193,160,58,189,88,46,177,57,9,115,13,24,65,37,199,71,182,207,65,18,246,93,175,169,131,142,153,178,213,138,143,236,72,168,160,182,214,186,170,95,22,45,113,224,141,88,205,33,22,49,65,219,4,25,205,180,125,40,18,42,158,62,30,25,244,226,104,160,123,14,60,111,154,53,84,127,228,3,253,5,6,81,188,37,133,89,45,219,175,223,9,211,254,199,3,74,27,75,37,136,128],[249,2,48,32,185,2,44,249,2,41,1,131,1,110,54,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,249,1,30,249,1,27,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,174,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,59,101,116,104,95,99,111,110,110,101,99,116,111,114,46,114,111,111,116,58,56,57,49,66,50,55,52,57,50,51,56,66,50,55,102,70,53,56,101,57,53,49,48,56,56,101,53,53,98,48,52,100,101,55,49,68,99,51,55,52,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1107,7 +1115,7 @@ fn test_deposit_to_near_amount_equal_fee_non_zero() { let proof_str = r#"{"log_index":0,"log_entry_data":[248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"receipt_index":0,"receipt_data":[249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"header_data":[249,2,10,160,218,232,90,75,133,17,151,21,23,64,121,155,74,131,239,243,28,65,81,101,213,156,148,217,134,34,235,41,62,11,232,147,160,29,204,77,232,222,199,93,122,171,133,181,103,182,204,212,26,211,18,69,27,148,138,116,19,240,161,66,253,64,212,147,71,148,124,28,230,160,8,239,64,193,62,78,177,68,166,204,116,240,224,174,172,126,160,25,127,76,71,206,220,252,85,22,156,38,36,158,35,56,3,255,85,230,138,132,44,102,196,217,205,43,20,129,6,50,114,160,217,211,225,144,113,34,139,65,28,148,21,243,90,204,109,152,98,172,147,56,158,109,65,77,74,110,116,227,7,143,157,97,160,35,108,188,133,254,137,74,53,234,147,11,115,83,161,215,174,6,192,214,61,8,113,178,151,91,57,163,102,121,177,113,30,185,1,0,144,48,72,0,8,0,0,0,48,0,0,1,128,128,128,0,128,128,0,8,64,2,1,0,5,1,0,32,64,16,129,8,0,16,8,8,128,1,9,8,4,0,0,104,0,0,0,24,8,0,4,0,8,0,0,0,0,128,64,32,16,32,0,0,92,2,8,0,10,1,80,24,1,0,0,8,17,1,0,40,0,0,5,0,130,17,0,0,6,0,0,1,128,0,2,16,40,0,96,16,2,2,0,0,0,0,32,8,0,64,40,65,0,0,32,0,0,8,0,0,2,0,0,112,0,0,0,4,8,0,64,2,0,0,5,0,161,212,88,1,5,0,0,32,8,0,2,32,0,0,2,136,0,0,4,66,34,0,128,0,2,8,128,0,0,0,0,128,44,8,0,0,19,20,2,8,2,0,8,128,132,0,0,0,0,56,0,0,0,4,33,32,32,129,0,2,0,0,128,145,64,0,96,112,136,2,32,0,32,16,0,0,65,0,84,16,64,2,0,16,161,0,34,128,128,16,0,0,8,16,2,12,2,0,0,18,64,4,128,0,152,0,44,0,8,0,0,0,64,0,32,148,0,16,128,0,132,91,126,153,161,131,157,118,120,131,122,18,0,131,55,185,255,132,96,175,155,143,140,115,112,105,100,101,114,49,48,1,2,9,64,160,29,62,139,98,163,60,78,159,159,190,165,213,126,42,39,157,104,12,168,1,9,24,24,157,45,96,113,188,166,18,114,253,136,161,226,143,133,82,9,96,55],"proof":[[248,145,160,153,98,12,82,79,154,121,176,11,226,192,161,140,213,198,195,143,185,79,36,156,98,17,141,146,111,76,206,149,161,186,244,160,29,41,24,128,95,59,50,57,188,69,166,227,81,94,29,115,178,144,71,219,248,16,233,179,158,64,222,175,67,156,221,186,160,221,78,89,28,71,2,204,57,50,75,194,224,88,108,127,122,110,247,48,111,72,110,252,199,127,138,177,160,1,244,75,250,128,128,128,128,128,160,96,141,238,91,85,76,114,97,220,74,251,25,18,72,46,126,72,190,245,222,173,235,62,157,59,131,133,200,217,240,218,101,128,128,128,128,128,128,128,128],[249,2,13,48,185,2,9,249,2,6,1,130,106,251,185,1,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,253,248,251,148,115,200,147,28,162,173,116,109,151,165,154,122,189,218,10,146,5,247,255,249,248,66,160,209,66,67,156,39,142,37,218,217,165,7,102,241,83,208,227,210,215,191,43,209,111,194,120,28,75,212,148,178,177,90,157,160,0,0,0,0,0,0,0,0,0,0,0,0,121,24,63,219,216,14,45,138,234,26,202,162,246,123,251,138,54,212,10,141,184,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,18,101,116,104,95,114,101,99,105,112,105,101,110,116,46,114,111,111,116,0,0,0,0,0,0,0,0,0,0,0,0,0,0]]}"#; let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1131,7 +1139,7 @@ fn test_deposit_to_aurora_amount_equal_fee_non_zero() { let proof: Proof = serde_json::from_str(proof_str).unwrap(); let res = master_account.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "deposit", &proof.try_to_vec().unwrap(), DEFAULT_GAS, @@ -1175,7 +1183,7 @@ fn test_ft_transfer_max_value() { let transfer_amount = u128::MAX; let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer", json!({ "receiver_id": DEPOSITED_RECIPIENT, @@ -1203,7 +1211,7 @@ fn test_ft_transfer_empty_value() { call_deposit_eth_to_near(&contract, CONTRACT_ACC); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer", json!({ "receiver_id": DEPOSITED_RECIPIENT, @@ -1231,7 +1239,7 @@ fn test_ft_transfer_wrong_u128_json_type() { call_deposit_eth_to_near(&contract, CONTRACT_ACC); let res = contract.call( - CONTRACT_ACC.to_string(), + CONTRACT_ACC.parse().unwrap(), "ft_transfer", json!({ "receiver_id": DEPOSITED_RECIPIENT, diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 110ff5d45..a5ce75ce2 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -1,3 +1,4 @@ +mod access_lists; mod contract_call; mod erc20; mod erc20_connector; diff --git a/src/tests/sanity.rs b/src/tests/sanity.rs index 0011edeed..b0faa2e74 100644 --- a/src/tests/sanity.rs +++ b/src/tests/sanity.rs @@ -1,6 +1,5 @@ use crate::prelude::Address; use crate::test_utils; -use crate::transaction::LegacyEthTransaction; use crate::types::{Wei, ERC20_MINT_SELECTOR}; use secp256k1::SecretKey; @@ -13,17 +12,8 @@ const TRANSFER_AMOUNT: Wei = Wei::new_u64(123); #[test] fn test_eth_transfer_success() { // set up Aurora runner and accounts - let (mut runner, source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account); - let transaction = test_utils::create_eth_transaction( - Some(dest_address), - TRANSFER_AMOUNT.into(), - vec![], - Some(runner.chain_id), - &source_account, - ); - let input = rlp::encode(&transaction).to_vec(); - let calling_account_id = "some-account.near".to_string(); + let (mut runner, mut source_account, dest_address) = initialize_transfer(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); // validate pre-state test_utils::validate_address_balance_and_nonce( @@ -35,8 +25,11 @@ fn test_eth_transfer_success() { test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // perform transfer - let (_, maybe_err) = runner.call(test_utils::SUBMIT, calling_account_id, input); - assert!(maybe_err.is_none()); + runner + .submit_with_signer(&mut source_account, |nonce| { + test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce) + }) + .unwrap(); // validate post-state test_utils::validate_address_balance_and_nonce( @@ -56,17 +49,8 @@ fn test_eth_transfer_success() { /// Tests the case where the transfer amount is larger than the address balance #[test] fn test_eth_transfer_insufficient_balance() { - let (mut runner, source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account); - let transaction = test_utils::create_eth_transaction( - Some(dest_address), - INITIAL_BALANCE + INITIAL_BALANCE, // trying to transfer more than we have - vec![], - Some(runner.chain_id), - &source_account, - ); - let input = rlp::encode(&transaction).to_vec(); - let calling_account_id = "some-account.near".to_string(); + let (mut runner, mut source_account, dest_address) = initialize_transfer(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); // validate pre-state test_utils::validate_address_balance_and_nonce( @@ -78,8 +62,13 @@ fn test_eth_transfer_insufficient_balance() { test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer - let (_, maybe_err) = runner.call(test_utils::SUBMIT, calling_account_id, input); - let error_message = format!("{:?}", maybe_err); + let err = runner + .submit_with_signer(&mut source_account, |nonce| { + // try to transfer more than we have + test_utils::transfer(dest_address, INITIAL_BALANCE + INITIAL_BALANCE, nonce) + }) + .unwrap_err(); + let error_message = format!("{:?}", err); assert!(error_message.contains("ERR_OUT_OF_FUND")); // validate post-state @@ -96,20 +85,8 @@ fn test_eth_transfer_insufficient_balance() { /// Tests the case where the nonce on the transaction does not match the address #[test] fn test_eth_transfer_incorrect_nonce() { - let (mut runner, source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account); - let transaction = LegacyEthTransaction { - nonce: (INITIAL_NONCE + 1).into(), - gas_price: Default::default(), - gas: Default::default(), - to: Some(dest_address), - value: TRANSFER_AMOUNT.into(), - data: vec![], - }; - let transaction = - test_utils::sign_transaction(transaction, Some(runner.chain_id), &source_account); - let input = rlp::encode(&transaction).to_vec(); - let calling_account_id = "some-account.near".to_string(); + let (mut runner, mut source_account, dest_address) = initialize_transfer(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); // validate pre-state test_utils::validate_address_balance_and_nonce( @@ -121,8 +98,13 @@ fn test_eth_transfer_incorrect_nonce() { test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer - let (_, maybe_err) = runner.call(test_utils::SUBMIT, calling_account_id, input); - let error_message = format!("{:?}", maybe_err); + let err = runner + .submit_with_signer(&mut source_account, |nonce| { + // creating transaction with incorrect nonce + test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce + 1) + }) + .unwrap_err(); + let error_message = format!("{:?}", err); assert!(error_message.contains("ERR_INCORRECT_NONCE")); // validate post-state (which is the same as pre-state in this case) @@ -137,20 +119,13 @@ fn test_eth_transfer_incorrect_nonce() { #[test] fn test_eth_transfer_not_enough_gas() { - let (mut runner, source_account, dest_address) = initialize_transfer(); - let source_address = test_utils::address_from_secret_key(&source_account); - let transaction = LegacyEthTransaction { - nonce: INITIAL_NONCE.into(), - gas_price: Default::default(), - gas: 10_000.into(), // this is not enough gas - to: Some(dest_address), - value: TRANSFER_AMOUNT.into(), - data: vec![], + let (mut runner, mut source_account, dest_address) = initialize_transfer(); + let source_address = test_utils::address_from_secret_key(&source_account.secret_key); + let transaction = |nonce| { + let mut tx = test_utils::transfer(dest_address, TRANSFER_AMOUNT, nonce); + tx.gas = 10_000.into(); // this is not enough gas + tx }; - let transaction = - test_utils::sign_transaction(transaction, Some(runner.chain_id), &source_account); - let input = rlp::encode(&transaction).to_vec(); - let calling_account_id = "some-account.near".to_string(); // validate pre-state test_utils::validate_address_balance_and_nonce( @@ -162,8 +137,10 @@ fn test_eth_transfer_not_enough_gas() { test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); // attempt transfer - let (_, maybe_err) = runner.call(test_utils::SUBMIT, calling_account_id, input); - let error_message = format!("{:?}", maybe_err); + let err = runner + .submit_with_signer(&mut source_account, transaction) + .unwrap_err(); + let error_message = format!("{:?}", err); assert!(error_message.contains("ERR_INTRINSIC_GAS")); // validate post-state (which is the same as pre-state in this case) @@ -176,7 +153,7 @@ fn test_eth_transfer_not_enough_gas() { test_utils::validate_address_balance_and_nonce(&runner, dest_address, Wei::zero(), 0.into()); } -fn initialize_transfer() -> (test_utils::AuroraRunner, SecretKey, Address) { +fn initialize_transfer() -> (test_utils::AuroraRunner, test_utils::Signer, Address) { // set up Aurora runner and accounts let mut runner = test_utils::deploy_evm(); let mut rng = rand::thread_rng(); @@ -184,8 +161,10 @@ fn initialize_transfer() -> (test_utils::AuroraRunner, SecretKey, Address) { let source_address = test_utils::address_from_secret_key(&source_account); runner.create_address(source_address, INITIAL_BALANCE, INITIAL_NONCE.into()); let dest_address = test_utils::address_from_secret_key(&SecretKey::random(&mut rng)); + let mut signer = test_utils::Signer::new(source_account); + signer.nonce = INITIAL_NONCE; - (runner, source_account, dest_address) + (runner, signer, dest_address) } use sha3::Digest; diff --git a/src/tests/standard_precompiles.rs b/src/tests/standard_precompiles.rs index b511f8c6a..bf2ca483a 100644 --- a/src/tests/standard_precompiles.rs +++ b/src/tests/standard_precompiles.rs @@ -36,32 +36,3 @@ fn standard_precompiles() { panic!("{}", String::from_utf8_lossy(&outcome.result)) } } - -#[test] -fn precompile_late_promise_create() { - let mut runner = test_utils::deploy_evm(); - let mut rng = rand::thread_rng(); - let source_account = SecretKey::random(&mut rng); - runner.create_address( - test_utils::address_from_secret_key(&source_account), - INITIAL_BALANCE.into(), - INITIAL_NONCE.into(), - ); - - let constructor = PrecompilesConstructor::load(); - let contract = PrecompilesContract(runner.deploy_contract( - &source_account, - |c| c.deploy(INITIAL_NONCE.into()), - constructor, - )); - - let test_all_tx = contract.call_method("test_all", (INITIAL_NONCE + 1).into()); - let outcome = runner - .submit_transaction(&source_account, test_all_tx) - .unwrap(); - - // status == false indicates failure - if !outcome.status { - panic!("{}", String::from_utf8_lossy(&outcome.result)) - } -} diff --git a/src/tests/state_migration.rs b/src/tests/state_migration.rs index 1be240a31..297501024 100644 --- a/src/tests/state_migration.rs +++ b/src/tests/state_migration.rs @@ -31,12 +31,12 @@ fn deploy_evm() -> AuroraAccount { let main_account = near_sdk_sim::init_simulator(None); let contract_account = main_account.deploy( &aurora_runner.code.code, - aurora_runner.aurora_account_id.clone(), + aurora_runner.aurora_account_id.parse().unwrap(), 5 * near_sdk_sim::STORAGE_AMOUNT, ); let new_args = NewCallArgs { chain_id: types::u256_to_arr(&U256::from(aurora_runner.chain_id)), - owner_id: main_account.account_id.clone(), + owner_id: main_account.account_id.clone().into(), bridge_prover_id: "prover.near".to_string(), upgrade_delay_blocks: 1, }; diff --git a/src/transaction/access_list.rs b/src/transaction/access_list.rs new file mode 100644 index 000000000..88312cfa6 --- /dev/null +++ b/src/transaction/access_list.rs @@ -0,0 +1,143 @@ +use crate::prelude::{Address, Vec, H256, U256}; +use crate::types::Wei; +use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; + +/// Type indicator (per EIP-2718) for access list transactions +pub const TYPE_BYTE: u8 = 0x01; + +#[derive(Debug, Eq, PartialEq, Clone)] +pub struct AccessTuple { + pub address: Address, + pub storage_keys: Vec, +} + +impl Decodable for AccessTuple { + fn decode(rlp: &Rlp<'_>) -> Result { + let address = rlp.val_at(0)?; + let storage_keys = rlp.list_at(1)?; + + Ok(Self { + address, + storage_keys, + }) + } +} + +/// See https://eips.ethereum.org/EIPS/eip-2930 +#[derive(Debug, Eq, PartialEq, Clone)] +pub struct AccessListEthTransaction { + pub chain_id: u64, + pub nonce: U256, + pub gas_price: U256, + pub gas_limit: U256, + pub to: Option
, + pub value: Wei, + pub data: Vec, + pub access_list: Vec, +} + +impl AccessListEthTransaction { + /// RLP encoding of the data for an unsigned message (used to make signature) + pub fn rlp_append_unsigned(&self, s: &mut RlpStream) { + self.rlp_append(s, 8); + } + + /// RLP encoding for a signed message (used to encode the transaction for sending to tx pool) + pub fn rlp_append_signed(&self, s: &mut RlpStream) { + self.rlp_append(s, 11); + } + + #[inline] + pub fn intrinsic_gas(&self, config: &evm::Config) -> Option { + super::intrinsic_gas(self.to.is_none(), &self.data, &self.access_list, config) + } + + fn rlp_append(&self, s: &mut RlpStream, list_len: usize) { + s.begin_list(list_len); + s.append(&self.chain_id); + s.append(&self.nonce); + s.append(&self.gas_price); + s.append(&self.gas_limit); + match self.to.as_ref() { + None => s.append(&""), + Some(address) => s.append(address), + }; + s.append(&self.value.raw()); + s.append(&self.data); + s.begin_list(self.access_list.len()); + for tuple in self.access_list.iter() { + s.begin_list(2); + s.append(&tuple.address); + s.begin_list(tuple.storage_keys.len()); + for key in tuple.storage_keys.iter() { + s.append(key); + } + } + } +} + +#[derive(Debug, Eq, PartialEq)] +pub struct AccessListEthSignedTransaction { + pub transaction_data: AccessListEthTransaction, + /// The parity (0 for even, 1 for odd) of the y-value of a secp256k1 signature. + pub parity: u8, + pub r: U256, + pub s: U256, +} + +impl AccessListEthSignedTransaction { + pub fn sender(&self) -> Option
{ + let mut rlp_stream = RlpStream::new(); + rlp_stream.append(&TYPE_BYTE); + self.transaction_data.rlp_append_unsigned(&mut rlp_stream); + let message_hash = crate::types::keccak(rlp_stream.as_raw()); + crate::precompiles::ecrecover( + message_hash, + &super::vrs_to_arr(self.parity, self.r, self.s), + ) + .ok() + } +} + +impl Encodable for AccessListEthSignedTransaction { + fn rlp_append(&self, s: &mut RlpStream) { + self.transaction_data.rlp_append_signed(s); + s.append(&self.parity); + s.append(&self.r); + s.append(&self.s); + } +} + +impl Decodable for AccessListEthSignedTransaction { + fn decode(rlp: &Rlp<'_>) -> Result { + if rlp.item_count() != Ok(11) { + return Err(rlp::DecoderError::RlpIncorrectListLen); + } + let chain_id = rlp.val_at(0)?; + let nonce = rlp.val_at(1)?; + let gas_price = rlp.val_at(2)?; + let gas_limit = rlp.val_at(3)?; + let to = super::rlp_extract_to(rlp, 4)?; + let value = Wei::new(rlp.val_at(5)?); + let data = rlp.val_at(6)?; + let access_list = rlp.list_at(7)?; + let parity = rlp.val_at(8)?; + let r = rlp.val_at(9)?; + let s = rlp.val_at(10)?; + Ok(Self { + transaction_data: AccessListEthTransaction { + chain_id, + nonce, + gas_price, + gas_limit, + to, + value, + data, + access_list, + }, + parity, + r, + s, + }) + } +} diff --git a/src/transaction.rs b/src/transaction/legacy.rs similarity index 73% rename from src/transaction.rs rename to src/transaction/legacy.rs index 7db660515..3dac15317 100644 --- a/src/transaction.rs +++ b/src/transaction/legacy.rs @@ -1,51 +1,7 @@ -use crate::prelude::{Address, TryFrom, Vec, U256}; +use crate::prelude::{Address, Vec, U256}; use crate::types::Wei; use rlp::{Decodable, DecoderError, Encodable, Rlp, RlpStream}; -/// Typed Transaction Envelope (see https://eips.ethereum.org/EIPS/eip-2718) -#[derive(Eq, PartialEq)] -pub enum EthTransaction { - Legacy(LegacyEthSignedTransaction), -} - -impl TryFrom<&[u8]> for EthTransaction { - type Error = ParseTransactionError; - - fn try_from(bytes: &[u8]) -> Result { - if bytes[0] <= 0x7f { - return Err(ParseTransactionError::UnknownTransactionType); - } else if bytes[0] == 0xff { - return Err(ParseTransactionError::ReservedSentinel); - } - - let legacy = LegacyEthSignedTransaction::decode(&Rlp::new(bytes))?; - Ok(Self::Legacy(legacy)) - } -} - -pub enum ParseTransactionError { - UnknownTransactionType, - // Per the EIP-2718 spec 0xff is a reserved value - ReservedSentinel, - RlpDecodeError(DecoderError), -} - -impl From for ParseTransactionError { - fn from(e: DecoderError) -> Self { - Self::RlpDecodeError(e) - } -} - -impl AsRef<[u8]> for ParseTransactionError { - fn as_ref(&self) -> &[u8] { - match self { - Self::UnknownTransactionType => b"ERR_UNKNOWN_TX_TYPE", - Self::ReservedSentinel => b"ERR_RESERVED_LEADING_TX_BYTE", - Self::RlpDecodeError(_) => b"ERR_TX_RLP_DECODE", - } - } -} - #[derive(Debug, Eq, PartialEq, Clone)] pub struct LegacyEthTransaction { /// A monotonically increasing transaction counter for this sender @@ -81,28 +37,9 @@ impl LegacyEthTransaction { } } + #[inline] pub fn intrinsic_gas(&self, config: &evm::Config) -> Option { - let is_contract_creation = self.to.is_none(); - - let base_gas = if is_contract_creation { - config.gas_transaction_create - } else { - config.gas_transaction_call - }; - - let num_zero_bytes = self.data.iter().filter(|b| **b == 0).count(); - let num_non_zero_bytes = self.data.len() - num_zero_bytes; - - let gas_zero_bytes = config - .gas_transaction_zero_data - .checked_mul(num_zero_bytes as u64)?; - let gas_non_zero_bytes = config - .gas_transaction_non_zero_data - .checked_mul(num_non_zero_bytes as u64)?; - - base_gas - .checked_add(gas_zero_bytes) - .and_then(|gas| gas.checked_add(gas_non_zero_bytes)) + super::intrinsic_gas(self.to.is_none(), &self.data, &[], config) } /// Returns self.gas as a u64, or None if self.gas > u64::MAX @@ -131,15 +68,15 @@ impl LegacyEthSignedTransaction { let mut rlp_stream = RlpStream::new(); // See details of CHAIN_ID computation here - https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md#specification let (chain_id, rec_id) = match self.v { - // ecrecover suppose to handle 0..=28 range for ids. - 0..=28 => (None, self.v as u8), + 0..=26 => return None, + 27..=28 => (None, (self.v - 27) as u8), 29..=34 => return None, _ => (Some((self.v - 35) / 2), ((self.v - 35) % 2) as u8), }; self.transaction .rlp_append_unsigned(&mut rlp_stream, chain_id); let message_hash = crate::types::keccak(rlp_stream.as_raw()); - crate::precompiles::ecrecover(message_hash, &vrs_to_arr(rec_id, self.r, self.s)).ok() + crate::precompiles::ecrecover(message_hash, &super::vrs_to_arr(rec_id, self.r, self.s)).ok() } /// Returns chain id encoded in `v` parameter of the signature if that was done, otherwise None. @@ -178,23 +115,7 @@ impl Decodable for LegacyEthSignedTransaction { let nonce = rlp.val_at(0)?; let gas_price = rlp.val_at(1)?; let gas = rlp.val_at(2)?; - let to = { - let value = rlp.at(3)?; - if value.is_empty() { - if value.is_data() { - None - } else { - return Err(rlp::DecoderError::RlpExpectedToBeData); - } - } else { - let v: Address = value.as_val()?; - if v == Address::zero() { - None - } else { - Some(v) - } - } - }; + let to = super::rlp_extract_to(rlp, 3)?; let value = Wei::new(rlp.val_at(4)?); let data = rlp.val_at(5)?; let v = rlp.val_at(6)?; @@ -216,14 +137,6 @@ impl Decodable for LegacyEthSignedTransaction { } } -fn vrs_to_arr(v: u8, r: U256, s: U256) -> [u8; 65] { - let mut result = [0u8; 65]; // (r, s, v), typed (uint256, uint256, uint8) - r.to_big_endian(&mut result[0..32]); - s.to_big_endian(&mut result[32..64]); - result[64] = v; - result -} - #[cfg(test)] mod tests { use super::*; diff --git a/src/transaction/mod.rs b/src/transaction/mod.rs new file mode 100644 index 000000000..eeaa75ba3 --- /dev/null +++ b/src/transaction/mod.rs @@ -0,0 +1,177 @@ +use crate::prelude::{Address, TryFrom, Vec, U256}; +use rlp::{Decodable, DecoderError, Rlp}; + +pub(crate) mod access_list; +pub(crate) mod legacy; + +use access_list::AccessTuple; +pub use legacy::{LegacyEthSignedTransaction, LegacyEthTransaction}; + +/// Typed Transaction Envelope (see https://eips.ethereum.org/EIPS/eip-2718) +#[derive(Eq, PartialEq)] +pub enum EthTransaction { + Legacy(LegacyEthSignedTransaction), + AccessList(access_list::AccessListEthSignedTransaction), +} + +impl EthTransaction { + pub fn chain_id(&self) -> Option { + match self { + Self::Legacy(tx) => tx.chain_id(), + Self::AccessList(tx) => Some(tx.transaction_data.chain_id), + } + } + + pub fn sender(&self) -> Option
{ + match self { + Self::Legacy(tx) => tx.sender(), + Self::AccessList(tx) => tx.sender(), + } + } + + pub fn nonce(&self) -> &U256 { + match self { + Self::Legacy(tx) => &tx.transaction.nonce, + Self::AccessList(tx) => &tx.transaction_data.nonce, + } + } + + pub fn intrinsic_gas(&self, config: &evm::Config) -> Option { + match self { + Self::Legacy(tx) => tx.transaction.intrinsic_gas(config), + Self::AccessList(tx) => tx.transaction_data.intrinsic_gas(config), + } + } + + pub fn gas_limit(&self) -> &U256 { + match self { + Self::Legacy(tx) => &tx.transaction.gas, + Self::AccessList(tx) => &tx.transaction_data.gas_limit, + } + } + + pub fn destructure( + self, + ) -> ( + crate::types::Wei, + Option, + Vec, + Option
, + Vec, + ) { + use crate::prelude::TryInto; + match self { + Self::Legacy(tx) => { + let tx = tx.transaction; + (tx.value, tx.gas.try_into().ok(), tx.data, tx.to, Vec::new()) + } + Self::AccessList(tx) => { + let tx = tx.transaction_data; + ( + tx.value, + tx.gas_limit.try_into().ok(), + tx.data, + tx.to, + tx.access_list, + ) + } + } + } +} + +impl TryFrom<&[u8]> for EthTransaction { + type Error = ParseTransactionError; + + fn try_from(bytes: &[u8]) -> Result { + if bytes[0] == access_list::TYPE_BYTE { + let access_list_tx = + access_list::AccessListEthSignedTransaction::decode(&Rlp::new(&bytes[1..]))?; + Ok(Self::AccessList(access_list_tx)) + } else if bytes[0] <= 0x7f { + Err(ParseTransactionError::UnknownTransactionType) + } else if bytes[0] == 0xff { + Err(ParseTransactionError::ReservedSentinel) + } else { + let legacy = LegacyEthSignedTransaction::decode(&Rlp::new(bytes))?; + Ok(Self::Legacy(legacy)) + } + } +} + +pub enum ParseTransactionError { + UnknownTransactionType, + // Per the EIP-2718 spec 0xff is a reserved value + ReservedSentinel, + RlpDecodeError(DecoderError), +} + +impl From for ParseTransactionError { + fn from(e: DecoderError) -> Self { + Self::RlpDecodeError(e) + } +} + +impl AsRef<[u8]> for ParseTransactionError { + fn as_ref(&self) -> &[u8] { + match self { + Self::UnknownTransactionType => b"ERR_UNKNOWN_TX_TYPE", + Self::ReservedSentinel => b"ERR_RESERVED_LEADING_TX_BYTE", + Self::RlpDecodeError(_) => b"ERR_TX_RLP_DECODE", + } + } +} + +fn rlp_extract_to(rlp: &Rlp<'_>, index: usize) -> Result, DecoderError> { + let value = rlp.at(index)?; + if value.is_empty() { + if value.is_data() { + Ok(None) + } else { + Err(rlp::DecoderError::RlpExpectedToBeData) + } + } else { + let v: Address = value.as_val()?; + if v == Address::zero() { + Ok(None) + } else { + Ok(Some(v)) + } + } +} + +// TODO: need to include access_list gas cost (see https://eips.ethereum.org/EIPS/eip-2930) +// Should go in the config, which requires upstream change. +fn intrinsic_gas( + is_contract_creation: bool, + data: &[u8], + _access_list: &[access_list::AccessTuple], + config: &evm::Config, +) -> Option { + let base_gas = if is_contract_creation { + config.gas_transaction_create + } else { + config.gas_transaction_call + }; + + let num_zero_bytes = data.iter().filter(|b| **b == 0).count(); + let num_non_zero_bytes = data.len() - num_zero_bytes; + + let gas_zero_bytes = config + .gas_transaction_zero_data + .checked_mul(num_zero_bytes as u64)?; + let gas_non_zero_bytes = config + .gas_transaction_non_zero_data + .checked_mul(num_non_zero_bytes as u64)?; + + base_gas + .checked_add(gas_zero_bytes) + .and_then(|gas| gas.checked_add(gas_non_zero_bytes)) +} + +fn vrs_to_arr(v: u8, r: U256, s: U256) -> [u8; 65] { + let mut result = [0u8; 65]; // (r, s, v), typed (uint256, uint256, uint8) + r.to_big_endian(&mut result[0..32]); + s.to_big_endian(&mut result[32..64]); + result[64] = v; + result +}