From 918a5a1be5e996361da664fced1357cda8caa883 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:08:40 +0200 Subject: [PATCH 01/54] edr-0.4.1 Co-authored-by: github-actions[bot] --- .changeset/fair-rice-vanish.md | 5 ----- .changeset/modern-ways-wash.md | 5 ----- .changeset/twelve-yaks-unite.md | 5 ----- crates/edr_napi/CHANGELOG.md | 8 ++++++++ crates/edr_napi/package.json | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 .changeset/fair-rice-vanish.md delete mode 100644 .changeset/modern-ways-wash.md delete mode 100644 .changeset/twelve-yaks-unite.md diff --git a/.changeset/fair-rice-vanish.md b/.changeset/fair-rice-vanish.md deleted file mode 100644 index cd90241f7..000000000 --- a/.changeset/fair-rice-vanish.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Provide a more helpful message when passing a timestamp bigger than 2^64 via JSON-RPC diff --git a/.changeset/modern-ways-wash.md b/.changeset/modern-ways-wash.md deleted file mode 100644 index d7bdbb21f..000000000 --- a/.changeset/modern-ways-wash.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixed a problem that prevented forking chains without mix hash fields in their blocks diff --git a/.changeset/twelve-yaks-unite.md b/.changeset/twelve-yaks-unite.md deleted file mode 100644 index 7656c54c3..000000000 --- a/.changeset/twelve-yaks-unite.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixed missing remote contract code when setting storage diff --git a/crates/edr_napi/CHANGELOG.md b/crates/edr_napi/CHANGELOG.md index 509a058d0..add82d2d1 100644 --- a/crates/edr_napi/CHANGELOG.md +++ b/crates/edr_napi/CHANGELOG.md @@ -1,5 +1,13 @@ # @nomicfoundation/edr +## 0.4.1 + +### Patch Changes + +- 245fd07: Provide a more helpful message when passing a timestamp bigger than 2^64 via JSON-RPC +- d87a8c4: Fixed a problem that prevented forking chains without mix hash fields in their blocks +- 5984f11: Fixed missing remote contract code when setting storage + ## 0.4.0 ### Minor Changes diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 81420a360..e69e944aa 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/edr", - "version": "0.4.0", + "version": "0.4.1", "main": "index.js", "types": "index.d.ts", "files": [ From 86986aae5fe505a8169cc934c46bd6f05d937fb8 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 2 Jul 2024 15:58:17 +0200 Subject: [PATCH 02/54] chore: run prettier (#535) --- .github/workflows/mdbook.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/mdbook.yml b/.github/workflows/mdbook.yml index dad2d2b77..9e5430d9b 100644 --- a/.github/workflows/mdbook.yml +++ b/.github/workflows/mdbook.yml @@ -31,7 +31,7 @@ jobs: - name: Setup mdBook uses: peaceiris/actions-mdbook@ee69d230fe19748b7abf22df32acaa93833fad08 # v2.0.0 with: - mdbook-version: '0.4.37' + mdbook-version: "0.4.37" - name: Setup Pages id: pages uses: actions/configure-pages@v5 From dfdd38047d7a41b061abfad5fe8676c391dfd2b3 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 2 Jul 2024 22:05:22 +0200 Subject: [PATCH 03/54] test: avoid unconditional reverts in stack traces tests (#537) --- .../call-message/multiple-modifiers-require/c.sol | 7 +++++-- .../call-message/multiple-modifiers-require/test.json | 2 +- .../create-message/multiple-modifiers-require/c.sol | 7 +++++-- .../create-message/multiple-modifiers-require/test.json | 2 +- .../within-receive/between-statements/c.sol | 5 ++++- .../within-receive/between-statements/test.json | 2 +- .../within-receive/no-other-statements/c.sol | 5 ++++- .../within-receive/no-other-statements/test.json | 2 +- .../within-receive/statement-after/c.sol | 5 ++++- .../within-receive/statement-after/test.json | 2 +- .../within-receive/statement-before/c.sol | 5 ++++- .../within-receive/statement-before/test.json | 2 +- 12 files changed, 32 insertions(+), 14 deletions(-) diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/c.sol index 6282f797a..a9f4bb830 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/c.sol @@ -7,8 +7,11 @@ contract C { _; } - function test(bool b) m1(b) m2(b) public { - revert(); + function test(bool b, bool doRevert) m1(b) m2(b) public { + // always true, used to prevent optimizations + if (doRevert) { + revert(); + } } modifier m1(bool b) { diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/test.json index 2d9b4e276..d8abf12a2 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/call-message/multiple-modifiers-require/test.json @@ -6,7 +6,7 @@ }, { "to": 0, - "params": [false], + "params": [false, true], "function": "test", "stackTrace": [ { diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/c.sol index a45d7f6b0..105a451f4 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/c.sol @@ -7,8 +7,11 @@ contract C { _; } - constructor(bool b) m1(b) m2(b) public { - revert(); + constructor(bool b, bool doRevert) m1(b) m2(b) public { + // always true, used to prevent optimizations + if (doRevert) { + revert(); + } } modifier m1(bool b) { diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/test.json index 36009d950..774b5eb3c 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/modifiers/create-message/multiple-modifiers-require/test.json @@ -3,7 +3,7 @@ { "file": "c.sol", "contract": "C", - "params": [false], + "params": [false, true], "stackTrace": [ { "type": "CALLSTACK_ENTRY", diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/c.sol index ce3b1307c..fedaa38a6 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/c.sol @@ -7,7 +7,10 @@ contract C { receive() external payable { i += 1; - revert(); + // always true, used to prevent optimizations + if (msg.value == 0) { + revert(); + } j += 2; } diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/test.json index 821a712d0..351662582 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/between-statements/test.json @@ -14,7 +14,7 @@ "contract": "C", "file": "c.sol", "function": "", - "line": 10 + "line": 12 } } ] diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/c.sol index a80dba788..b6f926537 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/c.sol @@ -5,7 +5,10 @@ contract C { receive() external payable { - revert(); + // always true, used to prevent optimizations + if (msg.value == 0) { + revert(); + } } } diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/test.json index f0122a5fa..821a712d0 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/no-other-statements/test.json @@ -14,7 +14,7 @@ "contract": "C", "file": "c.sol", "function": "", - "line": 8 + "line": 10 } } ] diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/c.sol index 7fff363cc..c98367efa 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/c.sol @@ -7,7 +7,10 @@ contract C { receive() external payable { - revert(); + // always true, used to prevent optimizations + if (msg.value == 0) { + revert(); + } i += 1; } diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/test.json index 821a712d0..351662582 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-after/test.json @@ -14,7 +14,7 @@ "contract": "C", "file": "c.sol", "function": "", - "line": 10 + "line": 12 } } ] diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/c.sol b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/c.sol index 6a24f9a97..53c471579 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/c.sol +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/c.sol @@ -7,7 +7,10 @@ contract C { receive() external payable { i += 1; - revert(); + // always true, used to prevent optimizations + if (msg.value == 0) { + revert(); + } } } diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/test.json b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/test.json index 821a712d0..351662582 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/test.json +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test-files/0_8/revert-without-message/revert-without-message/within-receive/statement-before/test.json @@ -14,7 +14,7 @@ "contract": "C", "file": "c.sol", "function": "", - "line": 10 + "line": 12 } } ] From b056511f24e7aec96c83ed81df5cba37619ce8c1 Mon Sep 17 00:00:00 2001 From: Wodann Date: Wed, 3 Jul 2024 09:24:17 -0500 Subject: [PATCH 04/54] fix: allow missing nonce in remote blocks (#539) * fix: allow missing nonce in remote blocks * misc: add changeset --- .changeset/big-boxes-drop.md | 5 +++++ crates/edr_evm/src/block/remote.rs | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 .changeset/big-boxes-drop.md diff --git a/.changeset/big-boxes-drop.md b/.changeset/big-boxes-drop.md new file mode 100644 index 000000000..0b3cd7cda --- /dev/null +++ b/.changeset/big-boxes-drop.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Fixes restriction to disallow remote blocks without a nonce diff --git a/crates/edr_evm/src/block/remote.rs b/crates/edr_evm/src/block/remote.rs index 31922eaf5..d22bec6e3 100644 --- a/crates/edr_evm/src/block/remote.rs +++ b/crates/edr_evm/src/block/remote.rs @@ -181,7 +181,9 @@ impl IntoRemoteBlock for edr_rpc_eth::Block Date: Wed, 3 Jul 2024 20:34:12 +0200 Subject: [PATCH 05/54] ci: upgrade pnpm/action-setup (#541) --- .github/workflows/edr-benchmark.yml | 2 +- .github/workflows/edr-ci.yml | 2 +- .github/workflows/edr-npm-release.yml | 14 +++++++------- .github/workflows/hardhat-tests.yml | 4 ++-- .github/workflows/release.yml | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/edr-benchmark.yml b/.github/workflows/edr-benchmark.yml index 09caf6a0e..3c87812ec 100644 --- a/.github/workflows/edr-benchmark.yml +++ b/.github/workflows/edr-benchmark.yml @@ -40,7 +40,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Install Node diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index efb3351e0..4560aa548 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -178,7 +178,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Install Node diff --git a/.github/workflows/edr-npm-release.yml b/.github/workflows/edr-npm-release.yml index 344c6f6b1..29daf26f9 100644 --- a/.github/workflows/edr-npm-release.yml +++ b/.github/workflows/edr-npm-release.yml @@ -94,7 +94,7 @@ jobs: echo "Number of build jobs: ${{ strategy.job-total }}" echo "Expected number of build jobs: $NUMBER_OF_TARGETS" test ${{ strategy.job-total }} -eq "$NUMBER_OF_TARGETS" - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Setup node @@ -174,7 +174,7 @@ jobs: working-directory: ./crates/edr_napi steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Setup node @@ -208,7 +208,7 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Setup node @@ -244,7 +244,7 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Setup node @@ -280,7 +280,7 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Download artifacts @@ -324,7 +324,7 @@ jobs: runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Download artifacts @@ -395,7 +395,7 @@ jobs: working-directory: ./crates/edr_napi steps: - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Setup node diff --git a/.github/workflows/hardhat-tests.yml b/.github/workflows/hardhat-tests.yml index 5bb7c2eff..8ad622f93 100644 --- a/.github/workflows/hardhat-tests.yml +++ b/.github/workflows/hardhat-tests.yml @@ -21,7 +21,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Install Node @@ -72,7 +72,7 @@ jobs: steps: - uses: actions/checkout@v3 - - uses: pnpm/action-setup@v2 + - uses: pnpm/action-setup@v4 with: version: 9 - name: Install Node diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 29a94f8f5..3d257774b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -20,7 +20,7 @@ jobs: fetch-depth: 0 - name: Setup pnpm - uses: pnpm/action-setup@v2 + uses: pnpm/action-setup@v4 with: version: 9 From 22bef83ea5abde968b8cfb07f08f8d85eef05bca Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Thu, 4 Jul 2024 00:06:18 +0200 Subject: [PATCH 06/54] ci: enable some debug logs for hardhat tests (#538) --- .github/workflows/hardhat-tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/hardhat-tests.yml b/.github/workflows/hardhat-tests.yml index 8ad622f93..1a0a0e64f 100644 --- a/.github/workflows/hardhat-tests.yml +++ b/.github/workflows/hardhat-tests.yml @@ -65,6 +65,7 @@ jobs: DO_NOT_SET_THIS_ENV_VAR____IS_HARDHAT_CI: true FORCE_COLOR: 3 NODE_OPTIONS: --max-old-space-size=4096 + DEBUG: "hardhat:core:hardhat-network:*" run: cd hardhat-tests && pnpm test:ci lint-hardhat-tests: name: Lint Hardhat tests From 048c0c0524ca785c0ea9b9f163887b3473903376 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Mon, 8 Jul 2024 12:06:49 +0200 Subject: [PATCH 07/54] Sync with recent Hardhat changes and deduplicate the Hardhat dep (#544) * chore: Explicitly depend on semver and fs-extra in hardhat-tests Appeases ESLint. These are de facto pulled by other dependencies but it's implicit. * refactor: Unify ts-node and use the one currently used by Hardhat Deduping the hardhat package makes it easier to patch it while working on the stack trace porting feature branch. * chore: Use the newest Hardhat 2.22.6 This will make patching the changes easier to review as we will sync with the upstream as it has some changes already related to the stack traces that we port. --- crates/tools/js/benchmark/package.json | 2 +- hardhat-tests/integration/smock/package.json | 2 +- hardhat-tests/package.json | 6 +- .../hardhat-network/stack-traces/execution.ts | 23 +-- .../hardhat-network/stack-traces/test.ts | 11 +- pnpm-lock.yaml | 180 ++++-------------- 6 files changed, 52 insertions(+), 172 deletions(-) diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index 923616f30..e8a4d916d 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -18,7 +18,7 @@ "devDependencies": { "argparse": "^2.0.1", "chai": "^4.2.0", - "hardhat": "2.22.5", + "hardhat": "2.22.6", "lodash": "^4.17.11", "mocha": "^10.0.0", "tsx": "^4.7.1" diff --git a/hardhat-tests/integration/smock/package.json b/hardhat-tests/integration/smock/package.json index ccd92b7f3..9d387a38b 100644 --- a/hardhat-tests/integration/smock/package.json +++ b/hardhat-tests/integration/smock/package.json @@ -12,7 +12,7 @@ "@nomiclabs/hardhat-ethers": "^2.2.3", "chai": "^4.3.6", "ethers": "5", - "hardhat": "2.22.5", + "hardhat": "2.22.6", "mocha": "^10.0.0" } } diff --git a/hardhat-tests/package.json b/hardhat-tests/package.json index 5b8200762..8933b039e 100644 --- a/hardhat-tests/package.json +++ b/hardhat-tests/package.json @@ -53,12 +53,14 @@ "eslint-plugin-prettier": "3.4.0", "ethereumjs-abi": "^0.6.8", "ethers": "^6.1.0", - "hardhat": "2.22.5", + "fs-extra": "^7.0.1", + "hardhat": "2.22.6", "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", "sinon": "^9.0.0", - "ts-node": "^9.1.1", + "semver": "^6.3.0", + "ts-node": "^10.8.0", "typescript": "~5.0.0", "undici": "^5.14.0" }, diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts b/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts index ee6c71ce0..24f9b4719 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts @@ -29,7 +29,7 @@ const senderAddress = bytesToHex(privateToAddress(toBuffer(senderPrivateKey))); export async function instantiateProvider( loggerConfig: LoggerConfig, tracingConfig: TracingConfig -): Promise<[EdrProviderWrapper, VMTracer]> { +): Promise { const config = { hardfork: "shanghai", chainId: 1, @@ -55,26 +55,13 @@ export async function instantiateProvider( enableTransientStorage: false, }; - const vmTracer = new VMTracer(false); - const provider = await EdrProviderWrapper.create( config, loggerConfig, - { - onStep: async (step) => { - await vmTracer.addStep(step); - }, - onAfterMessage: async (message) => { - await vmTracer.addAfterMessage(message); - }, - onBeforeMessage: async (message) => { - await vmTracer.addBeforeMessage(message); - }, - }, tracingConfig ); - return [provider, vmTracer]; + return provider; } export function encodeConstructorParams( @@ -116,9 +103,11 @@ interface TxData { export async function traceTransaction( provider: EdrProviderWrapper, - vmTracer: VMTracer, txData: TxData ): Promise { + const vmTracer = new VMTracer(); + provider.setVmTracer(vmTracer); + try { await provider.request({ method: "eth_sendTransaction", @@ -142,6 +131,6 @@ export async function traceTransaction( } return trace; } finally { - vmTracer.clearLastError(); + provider.setVmTracer(undefined); } } diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts b/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts index 7a746bf2d..6491bf474 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts @@ -24,7 +24,6 @@ import { } from "hardhat/internal/hardhat-network/stack-traces/solidity-stack-trace"; import { SolidityTracer } from "hardhat/internal/hardhat-network/stack-traces/solidityTracer"; import { VmTraceDecoder } from "hardhat/internal/hardhat-network/stack-traces/vm-trace-decoder"; -import { VMTracer } from "hardhat/internal/hardhat-network/stack-traces/vm-tracer"; import { SUPPORTED_SOLIDITY_VERSION_RANGE } from "hardhat/internal/hardhat-network/stack-traces/constants"; import { BuildInfo, @@ -481,7 +480,7 @@ async function runTest( const logger = new FakeModulesLogger(); const solidityTracer = new SolidityTracer(); - const [provider, vmTracer] = await instantiateProvider( + const provider = await instantiateProvider( { enabled: false, printLineFn: logger.printLineFn(), @@ -500,7 +499,6 @@ async function runTest( txIndex, tx, provider, - vmTracer, compilerOutput, txIndexToContract ); @@ -524,7 +522,6 @@ async function runTest( txIndex, tx, provider, - vmTracer, compilerOutput, contract! ); @@ -633,7 +630,6 @@ async function runDeploymentTransactionTest( txIndex: number, tx: DeploymentTransaction, provider: EdrProviderWrapper, - vmTracer: VMTracer, compilerOutput: CompilerOutput, txIndexToContract: Map ): Promise { @@ -665,7 +661,7 @@ async function runDeploymentTransactionTest( const data = Buffer.concat([deploymentBytecode, params]); - const trace = await traceTransaction(provider, vmTracer, { + const trace = await traceTransaction(provider, { value: tx.value !== undefined ? BigInt(tx.value) : undefined, data, gas: tx.gas !== undefined ? BigInt(tx.gas) : undefined, @@ -682,7 +678,6 @@ async function runCallTransactionTest( txIndex: number, tx: CallTransaction, provider: EdrProviderWrapper, - vmTracer: VMTracer, compilerOutput: CompilerOutput, contract: DeployedContract ): Promise { @@ -703,7 +698,7 @@ async function runCallTransactionTest( data = Buffer.from([]); } - const trace = await traceTransaction(provider, vmTracer, { + const trace = await traceTransaction(provider, { to: contract.address, value: tx.value !== undefined ? BigInt(tx.value) : undefined, data, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0fa07092d..6bec71d83 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -60,8 +60,8 @@ importers: specifier: ^4.2.0 version: 4.4.1 hardhat: - specifier: 2.22.5 - version: 2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.6 + version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash: specifier: ^4.17.11 version: 4.17.21 @@ -176,9 +176,12 @@ importers: ethers: specifier: ^6.1.0 version: 6.12.0 + fs-extra: + specifier: ^7.0.1 + version: 7.0.1 hardhat: - specifier: 2.22.5 - version: 2.22.5(ts-node@9.1.1(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.6 + version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -188,12 +191,15 @@ importers: rimraf: specifier: ^3.0.2 version: 3.0.2 + semver: + specifier: ^6.3.0 + version: 6.3.1 sinon: specifier: ^9.0.0 version: 9.2.4 ts-node: - specifier: ^9.1.1 - version: 9.1.1(typescript@5.0.4) + specifier: ^10.8.0 + version: 10.9.2(@types/node@18.15.13)(typescript@5.0.4) typescript: specifier: ~5.0.0 version: 5.0.4 @@ -205,10 +211,10 @@ importers: devDependencies: '@defi-wonderland/smock': specifier: ^2.4.0 - version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) '@nomiclabs/hardhat-ethers': specifier: ^2.2.3 - version: 2.2.3(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) chai: specifier: ^4.3.6 version: 4.4.1 @@ -216,8 +222,8 @@ importers: specifier: '5' version: 5.7.2 hardhat: - specifier: 2.22.5 - version: 2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.6 + version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -1226,8 +1232,9 @@ packages: command-exists@1.2.9: resolution: {integrity: sha512-LTQ/SGc+s0Xc0Fu5WaKnR0YiygZkm9eKFvyS+fRsU7/ZWFF8ykFM6Pc9aCVf1+xasOOZpO3BAVgVrKvsqKHV7w==} - commander@3.0.2: - resolution: {integrity: sha512-Gar0ASD4BDyKC4hl4DwHqDrmvjoxWKZigVnAbn5H1owvm4CxCPdb0HQDehwNYMJpla5+M2tPmPARzhtYuwpHow==} + commander@8.3.0: + resolution: {integrity: sha512-OkTL9umf+He2DZkUq8f8J9of7yL6RJKI24dVITBmNfZBmri9zYZQrKkuXiKhyfPSu8tUhnVBB1iKXevvnlR4Ww==} + engines: {node: '>= 12'} concat-map@0.0.1: resolution: {integrity: sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==} @@ -1627,9 +1634,6 @@ packages: fp-ts@1.19.3: resolution: {integrity: sha512-H5KQDspykdHuztLTg+ajGN0Z2qUjcEf3Ybxc6hLt0k7/zPkn29XnKnxlBPyW2XIddWrGaJBzBl4VLYOtk39yZg==} - fs-extra@0.30.0: - resolution: {integrity: sha512-UvSPKyhMn6LEd/WpUaV9C9t3zATuqoqfWc3QdPhPLb58prN9tqYPlPWi8Krxi44loBoUzlobqZ3+8tGpxxSzwA==} - fs-extra@7.0.1: resolution: {integrity: sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==} engines: {node: '>=6 <7 || >=8'} @@ -1717,8 +1721,8 @@ packages: resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==} engines: {node: '>=6'} - hardhat@2.22.5: - resolution: {integrity: sha512-9Zq+HonbXCSy6/a13GY1cgHglQRfh4qkzmj1tpPlhxJDwNVnhxlReV6K7hCWFKlOrV13EQwsdcD0rjcaQKWRZw==} + hardhat@2.22.6: + resolution: {integrity: sha512-abFEnd9QACwEtSvZZGSmzvw7N3zhQN1cDKz5SLHAupfG24qTHofCjqvD5kT5Wwsq5XOL0ON1Mq5rr4v0XX5ciw==} hasBin: true peerDependencies: ts-node: '*' @@ -1974,9 +1978,6 @@ packages: resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==} hasBin: true - jsonfile@2.4.0: - resolution: {integrity: sha512-PKllAqbgLgxHaj8TElYymKCAgrASebJrWpTnEkOaTowt23VKXXN0sUeriJ+eh7y6ufb/CC5ap11pz71/cM0hUw==} - jsonfile@4.0.0: resolution: {integrity: sha512-m6F1R3z8jjlf2imQHS2Qez5sjKWQzbuuhuJ/FKYFRZvPE3PuHcSMVZzfsLhGVOkfd20obL5SWEBew5ShlquNxg==} @@ -1994,9 +1995,6 @@ packages: resolution: {integrity: sha512-dcS1ul+9tmeD95T+x28/ehLgd9mENa3LsvDTtzm3vyBEO7RPptvAD+t44WVXaUjTBRcrpFeFlC8WCruUR456hw==} engines: {node: '>=0.10.0'} - klaw@1.3.1: - resolution: {integrity: sha512-TED5xi9gGQjGpNnvRWknrwAB1eL5GciPfVFOt3Vk1OJCVDQbzuSfrF3hkUQKlsgKrG1F+0t5W0m+Fje1jIt8rw==} - kleur@4.1.5: resolution: {integrity: sha512-o+NO+8WrRiQEE4/7nwRJhN1HWpVmJm511pBHUxPLtp0BUISzlBplORYSmTclCnJvQq2tKu/sgl3xVpkc7ZWuQQ==} engines: {node: '>=6'} @@ -2380,10 +2378,6 @@ packages: resolution: {integrity: sha512-fGxEI7+wsG9xrvdjsrlmL22OMTTiHRwAMroiEeMgq8gzoLC/PQr7RsRDSTLUg/bZAZtF+TVIkHc6/4RIKrui+Q==} engines: {node: '>=0.10.0'} - require-from-string@2.0.2: - resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==} - engines: {node: '>=0.10.0'} - require-main-filename@2.0.0: resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==} @@ -2409,11 +2403,6 @@ packages: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} - rimraf@2.7.1: - resolution: {integrity: sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==} - deprecated: Rimraf versions prior to v4 are no longer supported - hasBin: true - rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} hasBin: true @@ -2528,9 +2517,9 @@ packages: engines: {node: '>=6'} hasBin: true - solc@0.7.3: - resolution: {integrity: sha512-GAsWNAjGzIDg7VxzP6mPjdurby3IkGCjQcM8GFYZT6RyaoUZKmMU6Y7YwG+tFGhv7dwZ8rmR4iwFDrrD99JwqA==} - engines: {node: '>=8.0.0'} + solc@0.8.26: + resolution: {integrity: sha512-yiPQNVf5rBFHwN6SIf3TUUvVAFKcQqmSUFeq+fb6pNRCo0ZCgpYOZDi3BVoezCPIAcKrVYd/qXlBLUP9wVrZ9g==} + engines: {node: '>=10.0.0'} hasBin: true source-map-support@0.5.21: @@ -2660,13 +2649,6 @@ packages: '@swc/wasm': optional: true - ts-node@9.1.1: - resolution: {integrity: sha512-hPlt7ZACERQGf03M253ytLY3dHbGNGrAq9qIHWUY9XHYl1z7wYngSr3OQ5xmui8o2AaxsONxIzjafLUiWBo1Fg==} - engines: {node: '>=10.0.0'} - hasBin: true - peerDependencies: - typescript: '>=2.7' - tsconfig-paths@3.15.0: resolution: {integrity: sha512-2Ac2RgzDe/cn48GvOe3M+o82pEFewD3UPbyoUHHdKasHwJKjds4fLXWf/Ux5kATBKN20oaFGu+jbElp1pos0mg==} @@ -3095,16 +3077,16 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: '@ethersproject/abi': 5.7.0 '@ethersproject/abstract-provider': 5.7.0 '@ethersproject/abstract-signer': 5.7.0 '@nomicfoundation/ethereumjs-util': 9.0.4 - '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) diff: 5.0.0 ethers: 5.7.2 - hardhat: 2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash.isequal: 4.5.0 lodash.isequalwith: 4.4.0 rxjs: 7.8.1 @@ -3615,10 +3597,10 @@ snapshots: '@nomicfoundation/solidity-analyzer-win32-ia32-msvc': 0.1.1 '@nomicfoundation/solidity-analyzer-win32-x64-msvc': 0.1.1 - '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: ethers: 5.7.2 - hardhat: 2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) '@scure/base@1.1.5': {} @@ -4202,7 +4184,7 @@ snapshots: command-exists@1.2.9: {} - commander@3.0.2: {} + commander@8.3.0: {} concat-map@0.0.1: {} @@ -4781,14 +4763,6 @@ snapshots: fp-ts@1.19.3: {} - fs-extra@0.30.0: - dependencies: - graceful-fs: 4.2.11 - jsonfile: 2.4.0 - klaw: 1.3.1 - path-is-absolute: 1.0.1 - rimraf: 2.7.1 - fs-extra@7.0.1: dependencies: graceful-fs: 4.2.11 @@ -4893,61 +4867,7 @@ snapshots: hard-rejection@2.1.0: {} - hardhat@2.22.5(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4): - dependencies: - '@ethersproject/abi': 5.7.0 - '@metamask/eth-sig-util': 4.0.1 - '@nomicfoundation/edr': link:crates/edr_napi - '@nomicfoundation/ethereumjs-common': 4.0.4 - '@nomicfoundation/ethereumjs-tx': 5.0.4 - '@nomicfoundation/ethereumjs-util': 9.0.4 - '@nomicfoundation/solidity-analyzer': 0.1.1 - '@sentry/node': 5.30.0 - '@types/bn.js': 5.1.5 - '@types/lru-cache': 5.1.1 - adm-zip: 0.4.16 - aggregate-error: 3.1.0 - ansi-escapes: 4.3.2 - boxen: 5.1.2 - chalk: 2.4.2 - chokidar: 3.6.0 - ci-info: 2.0.0 - debug: 4.3.4(supports-color@8.1.1) - enquirer: 2.4.1 - env-paths: 2.2.1 - ethereum-cryptography: 1.2.0 - ethereumjs-abi: 0.6.8 - find-up: 2.1.0 - fp-ts: 1.19.3 - fs-extra: 7.0.1 - glob: 7.2.0 - immutable: 4.3.5 - io-ts: 1.10.4 - keccak: 3.0.4 - lodash: 4.17.21 - mnemonist: 0.38.5 - mocha: 10.3.0 - p-map: 4.0.0 - raw-body: 2.5.2 - resolve: 1.17.0 - semver: 6.3.1 - solc: 0.7.3(debug@4.3.4) - source-map-support: 0.5.21 - stacktrace-parser: 0.1.10 - tsort: 0.0.1 - undici: 5.28.3 - uuid: 8.3.2 - ws: 7.5.9 - optionalDependencies: - ts-node: 10.9.2(typescript@5.0.4) - typescript: 5.0.4 - transitivePeerDependencies: - - bufferutil - - c-kzg - - supports-color - - utf-8-validate - - hardhat@2.22.5(ts-node@9.1.1(typescript@5.0.4))(typescript@5.0.4): + hardhat@2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): dependencies: '@ethersproject/abi': 5.7.0 '@metamask/eth-sig-util': 4.0.1 @@ -4985,7 +4905,7 @@ snapshots: raw-body: 2.5.2 resolve: 1.17.0 semver: 6.3.1 - solc: 0.7.3(debug@4.3.4) + solc: 0.8.26(debug@4.3.4) source-map-support: 0.5.21 stacktrace-parser: 0.1.10 tsort: 0.0.1 @@ -4993,7 +4913,7 @@ snapshots: uuid: 8.3.2 ws: 7.5.9 optionalDependencies: - ts-node: 9.1.1(typescript@5.0.4) + ts-node: 10.9.2(@types/node@18.15.13)(typescript@5.0.4) typescript: 5.0.4 transitivePeerDependencies: - bufferutil @@ -5219,10 +5139,6 @@ snapshots: dependencies: minimist: 1.2.8 - jsonfile@2.4.0: - optionalDependencies: - graceful-fs: 4.2.11 - jsonfile@4.0.0: optionalDependencies: graceful-fs: 4.2.11 @@ -5241,10 +5157,6 @@ snapshots: kind-of@6.0.3: {} - klaw@1.3.1: - optionalDependencies: - graceful-fs: 4.2.11 - kleur@4.1.5: {} levn@0.4.1: @@ -5632,8 +5544,6 @@ snapshots: require-directory@2.1.1: {} - require-from-string@2.0.2: {} - require-main-filename@2.0.0: {} resolve-from@4.0.0: {} @@ -5654,10 +5564,6 @@ snapshots: reusify@1.0.4: {} - rimraf@2.7.1: - dependencies: - glob: 7.2.0 - rimraf@3.0.2: dependencies: glob: 7.2.0 @@ -5786,15 +5692,13 @@ snapshots: wcwidth: 1.0.1 yargs: 15.4.1 - solc@0.7.3(debug@4.3.4): + solc@0.8.26(debug@4.3.4): dependencies: command-exists: 1.2.9 - commander: 3.0.2 + commander: 8.3.0 follow-redirects: 1.15.5(debug@4.3.4) - fs-extra: 0.30.0 js-sha3: 0.8.0 memorystream: 0.3.1 - require-from-string: 2.0.2 semver: 5.7.2 tmp: 0.0.33 transitivePeerDependencies: @@ -5931,13 +5835,14 @@ snapshots: v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - ts-node@10.9.2(typescript@5.0.4): + ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.11 '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 + '@types/node': 18.15.13 acorn: 8.11.3 acorn-walk: 8.3.2 arg: 4.1.3 @@ -5947,17 +5852,6 @@ snapshots: typescript: 5.0.4 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - optional: true - - ts-node@9.1.1(typescript@5.0.4): - dependencies: - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - source-map-support: 0.5.21 - typescript: 5.0.4 - yn: 3.1.1 tsconfig-paths@3.15.0: dependencies: From e650c9e8fba905bfc9f8b1ebaf6a5d98f8bf45d7 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 9 Jul 2024 17:57:40 +0200 Subject: [PATCH 08/54] feat: upgrade revm dependencies (#546) * feat: upgrade revm dependencies * Create wild-phones-drum.md --- .changeset/wild-phones-drum.md | 5 ++ Cargo.lock | 87 ++++++++++--------- crates/edr_eth/Cargo.toml | 4 +- .../edr_eth/src/transaction/signed/eip155.rs | 3 - .../edr_eth/src/transaction/signed/eip1559.rs | 3 - .../edr_eth/src/transaction/signed/eip2930.rs | 3 - .../edr_eth/src/transaction/signed/eip4844.rs | 3 - .../edr_eth/src/transaction/signed/legacy.rs | 3 - crates/edr_evm/Cargo.toml | 2 +- crates/edr_evm/src/block/builder.rs | 4 + crates/edr_evm/src/debug_trace.rs | 78 +++++++---------- crates/edr_evm/src/state/diff.rs | 4 +- crates/edr_evm/src/state/trie/storage_trie.rs | 2 +- crates/edr_evm/src/trace.rs | 77 ++++++---------- crates/edr_evm/src/transaction.rs | 6 +- crates/edr_napi/src/result.rs | 23 ++++- crates/edr_provider/Cargo.toml | 2 +- crates/edr_provider/src/data.rs | 6 +- crates/edr_provider/src/error.rs | 2 +- 19 files changed, 146 insertions(+), 171 deletions(-) create mode 100644 .changeset/wild-phones-drum.md diff --git a/.changeset/wild-phones-drum.md b/.changeset/wild-phones-drum.md new file mode 100644 index 000000000..9adee4f3e --- /dev/null +++ b/.changeset/wild-phones-drum.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Upgraded revm to v37 diff --git a/Cargo.lock b/Cargo.lock index 6a8093aea..76fc909ef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -46,14 +46,14 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" [[package]] name = "alloy-dyn-abi" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8425a283510106b1a6ad25dd4bb648ecde7da3fd2baeb9400a85ad62f51ec90b" +checksum = "413902aa18a97569e60f679c23f46a18db1656d87ab4d4e49d0e1e52042f66df" dependencies = [ "alloy-json-abi", - "alloy-primitives 0.7.4", + "alloy-primitives 0.7.7", "alloy-sol-type-parser", - "alloy-sol-types 0.7.4", + "alloy-sol-types 0.7.7", "const-hex", "derive_more", "itoa", @@ -64,11 +64,11 @@ dependencies = [ [[package]] name = "alloy-json-abi" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e30946aa6173020259055a44971f5cf40a7d76c931d209caeb51b333263df4f" +checksum = "bc05b04ac331a9f07e3a4036ef7926e49a8bf84a99a1ccfc7e2ab55a5fcbb372" dependencies = [ - "alloy-primitives 0.7.4", + "alloy-primitives 0.7.7", "alloy-sol-type-parser", "serde", "serde_json", @@ -97,9 +97,9 @@ dependencies = [ [[package]] name = "alloy-primitives" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db8aa973e647ec336810a9356af8aea787249c9d00b1525359f3db29a68d231b" +checksum = "ccb3ead547f4532bc8af961649942f0b9c16ee9226e26caa3f38420651cc0bf4" dependencies = [ "alloy-rlp", "bytes", @@ -160,9 +160,9 @@ dependencies = [ [[package]] name = "alloy-sol-macro" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dbd17d67f3e89478c8a634416358e539e577899666c927bc3d2b1328ee9b6ca" +checksum = "2b40397ddcdcc266f59f959770f601ce1280e699a91fc1862f29cef91707cd09" dependencies = [ "alloy-sol-macro-expander", "alloy-sol-macro-input", @@ -174,27 +174,27 @@ dependencies = [ [[package]] name = "alloy-sol-macro-expander" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6da95adcf4760bb4b108fefa51d50096c5e5fdd29ee72fed3e86ee414f2e34" +checksum = "867a5469d61480fea08c7333ffeca52d5b621f5ca2e44f271b117ec1fc9a0525" dependencies = [ "alloy-sol-macro-input", "const-hex", - "heck 0.4.1", + "heck 0.5.0", "indexmap 2.2.6", "proc-macro-error", "proc-macro2", "quote", "syn 2.0.58", - "syn-solidity 0.7.4", + "syn-solidity 0.7.7", "tiny-keccak", ] [[package]] name = "alloy-sol-macro-input" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32c8da04c1343871fb6ce5a489218f9c85323c8340a36e9106b5fc98d4dd59d5" +checksum = "2e482dc33a32b6fadbc0f599adea520bd3aaa585c141a80b404d0a3e3fa72528" dependencies = [ "const-hex", "dunce", @@ -202,15 +202,16 @@ dependencies = [ "proc-macro2", "quote", "syn 2.0.58", - "syn-solidity 0.7.4", + "syn-solidity 0.7.7", ] [[package]] name = "alloy-sol-type-parser" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "368cae4dc052cad1d8f72eb2ae0c38027116933eeb49213c200a9e9875f208d7" +checksum = "cbcba3ca07cf7975f15d871b721fb18031eec8bce51103907f6dcce00b255d98" dependencies = [ + "serde", "winnow 0.6.8", ] @@ -228,12 +229,12 @@ dependencies = [ [[package]] name = "alloy-sol-types" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a64d2d2395c1ac636b62419a7b17ec39031d6b2367e66e9acbf566e6055e9c" +checksum = "a91ca40fa20793ae9c3841b83e74569d1cc9af29a2f5237314fd3452d51e38c7" dependencies = [ - "alloy-primitives 0.7.4", - "alloy-sol-macro 0.7.4", + "alloy-primitives 0.7.7", + "alloy-sol-macro 0.7.7", "const-hex", "serde", ] @@ -618,9 +619,9 @@ dependencies = [ [[package]] name = "c-kzg" -version = "1.0.0" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3130f3d8717cc02e668a896af24984d5d5d4e8bf12e278e982e0f1bd88a0f9af" +checksum = "cdf100c4cea8f207e883ff91ca886d621d8a166cb04971dfaa9bb8fd99ed95df" dependencies = [ "blst", "cc", @@ -2829,8 +2830,9 @@ dependencies = [ [[package]] name = "revm" -version = "8.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=aceb093#aceb0939b1712faa0e8f45c1f5621c11b81df94e" +version = "10.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "355bde4e21578c241f9379fbb344a73d254969b5007239115e094dda1511cd34" dependencies = [ "auto_impl", "cfg-if", @@ -2842,8 +2844,9 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "4.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=aceb093#aceb0939b1712faa0e8f45c1f5621c11b81df94e" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23dfd24faa3cbbd96e0976103d1e174d6559b8036730f70415488ee21870d578" dependencies = [ "revm-primitives", "serde", @@ -2851,8 +2854,9 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "6.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=aceb093#aceb0939b1712faa0e8f45c1f5621c11b81df94e" +version = "8.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c669c9b105dbb41133c17bf7f34d29368e358a7fee8fcc289e90dbfb024dfc4" dependencies = [ "aurora-engine-modexp", "c-kzg", @@ -2866,10 +2870,11 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "3.1.1" -source = "git+https://github.com/NomicFoundation/revm?rev=aceb093#aceb0939b1712faa0e8f45c1f5621c11b81df94e" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "902184a7a781550858d4b96707098da357429f1e4545806fd5b589f455555cf2" dependencies = [ - "alloy-primitives 0.7.4", + "alloy-primitives 0.7.7", "auto_impl", "bitflags 2.5.0", "bitvec", @@ -2924,9 +2929,9 @@ dependencies = [ [[package]] name = "ruint" -version = "1.12.1" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f308135fef9fc398342da5472ce7c484529df23743fb7c734e0f3d472971e62" +checksum = "2c3cc4c2511671f327125da14133d0c5c5d137f006a1017a16f557bc85b16286" dependencies = [ "alloy-rlp", "ark-ff 0.3.0", @@ -2948,9 +2953,9 @@ dependencies = [ [[package]] name = "ruint-macro" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f86854cf50259291520509879a5c294c3c9a4c334e9ff65071c51e42ef1e2343" +checksum = "48fd7bd8a6377e15ad9d42a8ec25371b94ddc67abe7c8b9127bec79bebaaae18" [[package]] name = "rustc-demangle" @@ -3348,9 +3353,9 @@ dependencies = [ [[package]] name = "syn-solidity" -version = "0.7.4" +version = "0.7.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b8db114c44cf843a8bacd37a146e37987a0b823a0e8bc4fdc610c9c72ab397a5" +checksum = "c837dc8852cb7074e46b444afb81783140dab12c58867b49fb3898fbafedf7ea" dependencies = [ "paste", "proc-macro2", diff --git a/crates/edr_eth/Cargo.toml b/crates/edr_eth/Cargo.toml index 51be60cea..eb66abb38 100644 --- a/crates/edr_eth/Cargo.toml +++ b/crates/edr_eth/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [dependencies] anyhow = "1.0.75" alloy-rlp = { version = "0.3", default-features = false, features = ["derive"] } -c-kzg = { version = "1.0.0", default-features = false } +c-kzg = { version = "1.0.2", default-features = false } hash-db = { version = "0.15.2", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "allocator-api2", "inline-more"] } @@ -15,7 +15,7 @@ itertools = { version = "0.10.5", default-features = false, features = ["use_all k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", ] } log = { version = "0.4.17", default-features = false } once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] } -revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "3.1", default-features = false, features = ["c-kzg", "hashbrown"] } +revm-primitives = { version = "5.0", default-features = false, features = ["c-kzg", "hashbrown"] } serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true } sha2 = { version = "0.10.8", default-features = false } sha3 = { version = "0.10.8", default-features = false } diff --git a/crates/edr_eth/src/transaction/signed/eip155.rs b/crates/edr_eth/src/transaction/signed/eip155.rs index 6f6c50f9d..16f06b126 100644 --- a/crates/edr_eth/src/transaction/signed/eip155.rs +++ b/crates/edr_eth/src/transaction/signed/eip155.rs @@ -1,7 +1,6 @@ use std::sync::OnceLock; use alloy_rlp::RlpEncodable; -use hashbrown::HashMap; use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; @@ -79,8 +78,6 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, - eof_initcodes: Vec::new(), - eof_initcodes_hashed: HashMap::new(), } } } diff --git a/crates/edr_eth/src/transaction/signed/eip1559.rs b/crates/edr_eth/src/transaction/signed/eip1559.rs index 50627f4c1..e2a67d5dd 100644 --- a/crates/edr_eth/src/transaction/signed/eip1559.rs +++ b/crates/edr_eth/src/transaction/signed/eip1559.rs @@ -1,7 +1,6 @@ use std::sync::OnceLock; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use hashbrown::HashMap; use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; @@ -69,8 +68,6 @@ impl From for TxEnv { gas_priority_fee: Some(value.max_priority_fee_per_gas), blob_hashes: Vec::new(), max_fee_per_blob_gas: None, - eof_initcodes: Vec::new(), - eof_initcodes_hashed: HashMap::new(), } } } diff --git a/crates/edr_eth/src/transaction/signed/eip2930.rs b/crates/edr_eth/src/transaction/signed/eip2930.rs index d90ad7be3..84d0a1af8 100644 --- a/crates/edr_eth/src/transaction/signed/eip2930.rs +++ b/crates/edr_eth/src/transaction/signed/eip2930.rs @@ -1,7 +1,6 @@ use std::sync::OnceLock; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use hashbrown::HashMap; use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; @@ -68,8 +67,6 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, - eof_initcodes: Vec::new(), - eof_initcodes_hashed: HashMap::new(), } } } diff --git a/crates/edr_eth/src/transaction/signed/eip4844.rs b/crates/edr_eth/src/transaction/signed/eip4844.rs index dd74df5d9..c0aaf48ae 100644 --- a/crates/edr_eth/src/transaction/signed/eip4844.rs +++ b/crates/edr_eth/src/transaction/signed/eip4844.rs @@ -1,7 +1,6 @@ use std::sync::OnceLock; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use hashbrown::HashMap; use revm_primitives::{keccak256, TransactTo, TxEnv, GAS_PER_BLOB}; use crate::{ @@ -79,8 +78,6 @@ impl From for TxEnv { gas_priority_fee: Some(value.max_priority_fee_per_gas), blob_hashes: value.blob_hashes, max_fee_per_blob_gas: Some(value.max_fee_per_blob_gas), - eof_initcodes: Vec::new(), - eof_initcodes_hashed: HashMap::new(), } } } diff --git a/crates/edr_eth/src/transaction/signed/legacy.rs b/crates/edr_eth/src/transaction/signed/legacy.rs index 9a1597840..7d61460a6 100644 --- a/crates/edr_eth/src/transaction/signed/legacy.rs +++ b/crates/edr_eth/src/transaction/signed/legacy.rs @@ -1,7 +1,6 @@ use std::sync::OnceLock; use alloy_rlp::{RlpDecodable, RlpEncodable}; -use hashbrown::HashMap; use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; @@ -58,8 +57,6 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, - eof_initcodes: Vec::new(), - eof_initcodes_hashed: HashMap::new(), } } } diff --git a/crates/edr_evm/Cargo.toml b/crates/edr_evm/Cargo.toml index 1e8251083..095eba061 100644 --- a/crates/edr_evm/Cargo.toml +++ b/crates/edr_evm/Cargo.toml @@ -19,7 +19,7 @@ parking_lot = { version = "0.12.1", default-features = false } edr_defaults = { version = "0.3.5", path = "../edr_defaults" } edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["rand", "serde"] } edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" } -revm = { git = "https://github.com/NomicFoundation/revm", rev = "aceb093", version = "8.0", default-features = false, features = ["c-kzg", "dev", "serde"] } +revm = { version = "10.0", default-features = false, features = ["c-kzg", "dev", "serde"] } rpds = { version = "1.1.0", default-features = false, features = ["std"] } serde = { version = "1.0.158", default-features = false, features = ["std"] } serde_json = { version = "1.0.94", default-features = false, features = ["std"] } diff --git a/crates/edr_evm/src/block/builder.rs b/crates/edr_evm/src/block/builder.rs index 8f87207ad..4e03d7a6d 100644 --- a/crates/edr_evm/src/block/builder.rs +++ b/crates/edr_evm/src/block/builder.rs @@ -70,6 +70,9 @@ pub enum BlockTransactionError { /// Corrupt transaction data #[error("Invalid transaction: {0:?}")] InvalidTransaction(InvalidTransaction), + /// Precompile errors + #[error("{0}")] + Precompile(String), /// State errors #[error(transparent)] State(SE), @@ -99,6 +102,7 @@ where error @ (InvalidHeader::ExcessBlobGasNotSet | InvalidHeader::PrevrandaoNotSet), ) => Self::Custom(error.to_string()), EVMError::Custom(error) => Self::Custom(error), + EVMError::Precompile(error) => Self::Precompile(error), } } } diff --git a/crates/edr_evm/src/debug_trace.rs b/crates/edr_evm/src/debug_trace.rs index e4f8c968f..4f97680e4 100644 --- a/crates/edr_evm/src/debug_trace.rs +++ b/crates/edr_evm/src/debug_trace.rs @@ -9,14 +9,14 @@ use revm::{ db::DatabaseComponents, handler::register::EvmHandler, interpreter::{ - opcode::{self, BoxedInstruction, InstructionTables, OpCode}, - InstructionResult, Interpreter, InterpreterResult, + opcode::{self, DynInstruction, OpCode}, + Interpreter, InterpreterResult, }, primitives::{ hex, Address, BlockEnv, Bytes, CfgEnvWithHandlerCfg, ExecutionResult, ResultAndState, SpecId, U256, }, - Database, Evm, EvmContext, JournalEntry, + Context, Database, Evm, EvmContext, JournalEntry, }; use crate::{ @@ -278,26 +278,10 @@ pub fn register_eip_3155_tracer_handles< ) { // Every instruction inside flat table that is going to be wrapped by tracer // calls. - let table = handler - .instruction_table - .take() - .expect("Handler must have instruction table"); - - let table = match table { - InstructionTables::Plain(table) => table - .into_iter() - .map(|i| instruction_handler(i)) - .collect::>(), - InstructionTables::Boxed(table) => table - .into_iter() - .map(|i| instruction_handler(i)) - .collect::>(), - }; + let table = &mut handler.instruction_table; - // cast vector to array. - handler.instruction_table = Some(InstructionTables::Boxed( - table.try_into().unwrap_or_else(|_| unreachable!()), - )); + // Update all instructions to call the instruction handler. + table.update_all(instruction_handler); // call outcome let old_handle = handler.execution.insert_call_outcome.clone(); @@ -319,37 +303,29 @@ pub fn register_eip_3155_tracer_handles< } /// Outer closure that calls tracer for every instruction. -fn instruction_handler< - 'a, +fn instruction_handler( + prev: &DynInstruction<'_, Context>, + interpreter: &mut Interpreter, + host: &mut Context, +) where ContextT: GetContextData, DatabaseT: Database, - Instruction: Fn(&mut Interpreter, &mut Evm<'a, ContextT, DatabaseT>) + 'a, ->( - instruction: Instruction, -) -> BoxedInstruction<'a, Evm<'a, ContextT, DatabaseT>> { - Box::new( - move |interpreter: &mut Interpreter, host: &mut Evm<'a, ContextT, DatabaseT>| { - // SAFETY: as the PC was already incremented we need to subtract 1 to preserve - // the old Inspector behavior. - interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.sub(1) }; - - host.context.external.get_context_data().step(interpreter); - if interpreter.instruction_result != InstructionResult::Continue { - return; - } +{ + // SAFETY: as the PC was already incremented we need to subtract 1 to preserve + // the old Inspector behavior. + interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.sub(1) }; - // return PC to old value - interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.add(1) }; + host.external.get_context_data().step(interpreter); - // execute instruction. - instruction(interpreter, host); + // Reset PC to previous value. + interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.add(1) }; - host.context - .external - .get_context_data() - .step_end(interpreter, &mut host.context.evm); - }, - ) + // Execute instruction. + prev(interpreter, host); + + host.external + .get_context_data() + .step_end(interpreter, &mut host.evm); } /// An EIP-3155 compatible EVM tracer. @@ -437,7 +413,11 @@ impl TracerEip3155 { .journal .last() .and_then(|v| v.last()); - if let Some(JournalEntry::StorageChange { address, key, .. }) = last_entry { + if let Some( + JournalEntry::StorageChanged { address, key, .. } + | JournalEntry::StorageWarmed { address, key }, + ) = last_entry + { let value = context.journaled_state.state[address].storage[key].present_value(); let contract_storage = self.storage.entry(self.contract_address).or_default(); contract_storage.insert(u256_to_padded_hex(key), u256_to_padded_hex(&value)); diff --git a/crates/edr_evm/src/state/diff.rs b/crates/edr_evm/src/state/diff.rs index 2238f63b8..1614bbece 100644 --- a/crates/edr_evm/src/state/diff.rs +++ b/crates/edr_evm/src/state/diff.rs @@ -1,5 +1,5 @@ use edr_eth::{Address, U256}; -use revm::primitives::{Account, AccountInfo, AccountStatus, HashMap, StorageSlot}; +use revm::primitives::{Account, AccountInfo, AccountStatus, EvmStorageSlot, HashMap}; /// The difference between two states, which can be applied to a state to get /// the new state using [`revm::db::DatabaseCommit::commit`]. @@ -34,7 +34,7 @@ impl StateDiff { &mut self, address: Address, index: U256, - slot: StorageSlot, + slot: EvmStorageSlot, account_info: Option, ) { self.inner diff --git a/crates/edr_evm/src/state/trie/storage_trie.rs b/crates/edr_evm/src/state/trie/storage_trie.rs index 189b6827b..cdd90d67c 100644 --- a/crates/edr_evm/src/state/trie/storage_trie.rs +++ b/crates/edr_evm/src/state/trie/storage_trie.rs @@ -76,7 +76,7 @@ pub(super) struct StorageTrieMutation<'a> { impl<'a> StorageTrieMutation<'a> { #[cfg_attr(feature = "tracing", tracing::instrument(skip(self)))] - pub fn set_storage_slots(&mut self, storage: &revm::primitives::Storage) { + pub fn set_storage_slots(&mut self, storage: &revm::primitives::EvmStorage) { storage.iter().for_each(|(index, value)| { self.set_storage_slot(index, &value.present_value); }); diff --git a/crates/edr_evm/src/trace.rs b/crates/edr_evm/src/trace.rs index ae0db95aa..946ef9d3b 100644 --- a/crates/edr_evm/src/trace.rs +++ b/crates/edr_evm/src/trace.rs @@ -4,12 +4,12 @@ use edr_eth::{Address, Bytes, U256}; use revm::{ handler::register::EvmHandler, interpreter::{ - opcode::{self, BoxedInstruction, InstructionTables}, + opcode::{self, DynInstruction}, return_revert, CallInputs, CallOutcome, CallValue, CreateInputs, CreateOutcome, InstructionResult, Interpreter, SuccessOrHalt, }, primitives::{Bytecode, EVMError, ExecutionResult, Output}, - Database, Evm, EvmContext, FrameOrResult, FrameResult, + Context, Database, EvmContext, FrameOrResult, FrameResult, }; use crate::debug::GetContextData; @@ -23,28 +23,10 @@ pub fn register_trace_collector_handles< ) where DatabaseT::Error: Debug, { - // Every instruction inside flat table that is going to be wrapped by tracer - // calls. - let table = handler - .instruction_table - .take() - .expect("Handler must have instruction table"); - - let table = match table { - InstructionTables::Plain(table) => table - .into_iter() - .map(|i| instruction_handler(i)) - .collect::>(), - InstructionTables::Boxed(table) => table - .into_iter() - .map(|i| instruction_handler(i)) - .collect::>(), - }; - - // cast vector to array. - handler.instruction_table = Some(InstructionTables::Boxed( - table.try_into().unwrap_or_else(|_| unreachable!()), - )); + let table = &mut handler.instruction_table; + + // Update all instructions to call the instruction handler. + table.update_all(instruction_handler); // call and create input stack shared between handlers. They are used to share // inputs in *_end Inspector calls. @@ -128,32 +110,27 @@ pub fn register_trace_collector_handles< } /// Outer closure that calls tracer for every instruction. -fn instruction_handler< - 'a, +fn instruction_handler( + prev: &DynInstruction<'_, Context>, + interpreter: &mut Interpreter, + host: &mut Context, +) where ContextT: GetContextData, DatabaseT: Database, - Instruction: Fn(&mut Interpreter, &mut Evm<'a, ContextT, DatabaseT>) + 'a, ->( - instruction: Instruction, -) -> BoxedInstruction<'a, Evm<'a, ContextT, DatabaseT>> { - Box::new( - move |interpreter: &mut Interpreter, host: &mut Evm<'a, ContextT, DatabaseT>| { - // SAFETY: as the PC was already incremented we need to subtract 1 to preserve - // the old Inspector behavior. - interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.sub(1) }; - - host.context - .external - .get_context_data() - .step(interpreter, &host.context.evm); - - // return PC to old value - interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.add(1) }; - - // execute instruction. - instruction(interpreter, host); - }, - ) +{ + // SAFETY: as the PC was already incremented we need to subtract 1 to preserve + // the old Inspector behavior. + interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.sub(1) }; + + host.external + .get_context_data() + .step(interpreter, &host.evm); + + // Reset PC to previous value. + interpreter.instruction_pointer = unsafe { interpreter.instruction_pointer.add(1) }; + + // Execute instruction. + prev(interpreter, host); } /// Stack tracing message @@ -415,7 +392,7 @@ impl TraceCollector { reason, gas_used: outcome.gas().limit(), }, - SuccessOrHalt::InternalContinue | SuccessOrHalt::InternalCallOrCreate => { + SuccessOrHalt::Internal(_) => { panic!("Internal error: {safe_ret:?}") } SuccessOrHalt::FatalExternalError => panic!("Fatal external error"), @@ -482,7 +459,7 @@ impl TraceCollector { reason, gas_used: outcome.gas().limit(), }, - SuccessOrHalt::InternalContinue | SuccessOrHalt::InternalCallOrCreate => { + SuccessOrHalt::Internal(_) => { panic!("Internal error: {safe_ret:?}") } SuccessOrHalt::FatalExternalError => panic!("Fatal external error"), diff --git a/crates/edr_evm/src/transaction.rs b/crates/edr_evm/src/transaction.rs index 99d1c796a..0e1f8fe83 100644 --- a/crates/edr_evm/src/transaction.rs +++ b/crates/edr_evm/src/transaction.rs @@ -34,6 +34,9 @@ pub enum TransactionError { /// config is on a post-merge hardfork. #[error("Post-merge transaction is missing prevrandao")] MissingPrevrandao, + /// Precompile errors + #[error("{0}")] + Precompile(String), /// State errors #[error(transparent)] State(SE), @@ -53,6 +56,7 @@ where EVMError::Database(DatabaseComponentError::State(e)) => Self::State(e), EVMError::Database(DatabaseComponentError::BlockHash(e)) => Self::Blockchain(e), EVMError::Custom(error) => Self::Custom(error), + EVMError::Precompile(error) => Self::Precompile(error), } } } @@ -107,8 +111,6 @@ pub fn initial_cost(transaction: &impl Transaction, spec_id: SpecId) -> u64 { access_list .as_ref() .map_or(&[], |access_list| access_list.as_slice()), - // TODO: https://github.com/NomicFoundation/edr/issues/427 - &[], ) } diff --git a/crates/edr_napi/src/result.rs b/crates/edr_napi/src/result.rs index 5fb11ef6f..6891e15dc 100644 --- a/crates/edr_napi/src/result.rs +++ b/crates/edr_napi/src/result.rs @@ -16,6 +16,7 @@ pub enum SuccessReason { Return, /// The opcode `SELFDESTRUCT` was called SelfDestruct, + EofReturnContract, } impl From for SuccessReason { @@ -24,6 +25,7 @@ impl From for SuccessReason { edr_evm::SuccessReason::Stop => Self::Stop, edr_evm::SuccessReason::Return => Self::Return, edr_evm::SuccessReason::SelfDestruct => Self::SelfDestruct, + edr_evm::SuccessReason::EofReturnContract => Self::EofReturnContract, } } } @@ -34,6 +36,7 @@ impl From for edr_evm::SuccessReason { SuccessReason::Stop => Self::Stop, SuccessReason::Return => Self::Return, SuccessReason::SelfDestruct => Self::SelfDestruct, + SuccessReason::EofReturnContract => Self::EofReturnContract, } } } @@ -82,7 +85,7 @@ pub struct RevertResult { pub enum ExceptionalHalt { OutOfGas, OpcodeNotFound, - InvalidFEOpcode, + InvalidEFOpcode, InvalidJump, NotActivated, StackUnderflow, @@ -97,6 +100,12 @@ pub enum ExceptionalHalt { CreateContractStartingWithEF, /// EIP-3860: Limit and meter initcode. Initcode size limit exceeded. CreateInitCodeSizeLimit, + /// Aux data overflow, new aux data is larger tha u16 max size. + EofAuxDataOverflow, + /// Aud data is smaller then already present data size. + EofAuxDataTooSmall, + /// EOF Subroutine stack overflow + EOFFunctionStackOverflow, } impl From for ExceptionalHalt { @@ -104,7 +113,7 @@ impl From for ExceptionalHalt { match halt { edr_evm::HaltReason::OutOfGas(..) => ExceptionalHalt::OutOfGas, edr_evm::HaltReason::OpcodeNotFound => ExceptionalHalt::OpcodeNotFound, - edr_evm::HaltReason::InvalidFEOpcode => ExceptionalHalt::InvalidFEOpcode, + edr_evm::HaltReason::InvalidEFOpcode => ExceptionalHalt::InvalidEFOpcode, edr_evm::HaltReason::InvalidJump => ExceptionalHalt::InvalidJump, edr_evm::HaltReason::NotActivated => ExceptionalHalt::NotActivated, edr_evm::HaltReason::StackUnderflow => ExceptionalHalt::StackUnderflow, @@ -122,6 +131,11 @@ impl From for ExceptionalHalt { edr_evm::HaltReason::CreateInitCodeSizeLimit => { ExceptionalHalt::CreateInitCodeSizeLimit } + edr_evm::HaltReason::EofAuxDataOverflow => ExceptionalHalt::EofAuxDataOverflow, + edr_evm::HaltReason::EofAuxDataTooSmall => ExceptionalHalt::EofAuxDataTooSmall, + edr_evm::HaltReason::EOFFunctionStackOverflow => { + ExceptionalHalt::EOFFunctionStackOverflow + } edr_evm::HaltReason::OverflowPayment | edr_evm::HaltReason::StateChangeDuringStaticCall | edr_evm::HaltReason::CallNotAllowedInsideStatic @@ -138,7 +152,7 @@ impl From for edr_evm::HaltReason { match value { ExceptionalHalt::OutOfGas => Self::OutOfGas(edr_evm::OutOfGasError::Basic), ExceptionalHalt::OpcodeNotFound => Self::OpcodeNotFound, - ExceptionalHalt::InvalidFEOpcode => Self::InvalidFEOpcode, + ExceptionalHalt::InvalidEFOpcode => Self::InvalidEFOpcode, ExceptionalHalt::InvalidJump => Self::InvalidJump, ExceptionalHalt::NotActivated => Self::NotActivated, ExceptionalHalt::StackUnderflow => Self::StackUnderflow, @@ -150,6 +164,9 @@ impl From for edr_evm::HaltReason { ExceptionalHalt::CreateContractSizeLimit => Self::CreateContractSizeLimit, ExceptionalHalt::CreateContractStartingWithEF => Self::CreateContractStartingWithEF, ExceptionalHalt::CreateInitCodeSizeLimit => Self::CreateInitCodeSizeLimit, + ExceptionalHalt::EofAuxDataOverflow => Self::EofAuxDataOverflow, + ExceptionalHalt::EofAuxDataTooSmall => Self::EofAuxDataTooSmall, + ExceptionalHalt::EOFFunctionStackOverflow => Self::EOFFunctionStackOverflow, } } } diff --git a/crates/edr_provider/Cargo.toml b/crates/edr_provider/Cargo.toml index 4f6d28f6b..25fd11889 100644 --- a/crates/edr_provider/Cargo.toml +++ b/crates/edr_provider/Cargo.toml @@ -4,7 +4,7 @@ version = "0.3.5" edition = "2021" [dependencies] -alloy-dyn-abi = { version = "0.7.4", features = ["eip712"] } +alloy-dyn-abi = { version = "0.7.6", features = ["eip712"] } alloy-sol-types = { version = "0.5.1", default-features = false, features = ["std"] } anyhow = { version = "1.0.75", optional = true } auto_impl = { version = "1.2", default-features = false } diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index 861145018..93f884e02 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -44,8 +44,8 @@ use edr_evm::{ transaction::{self, SignedTransaction as _}, Account, AccountInfo, BlobExcessGasAndPrice, Block as _, BlockAndTotalDifficulty, BlockEnv, Bytecode, CfgEnv, CfgEnvWithHandlerCfg, DebugContext, DebugTraceConfig, - DebugTraceResultWithTraces, Eip3155AndRawTracers, ExecutionResult, HashMap, HashSet, MemPool, - MineBlockResultAndState, OrderedTransaction, RandomHashGenerator, StorageSlot, SyncBlock, + DebugTraceResultWithTraces, Eip3155AndRawTracers, EvmStorageSlot, ExecutionResult, HashMap, + HashSet, MemPool, MineBlockResultAndState, OrderedTransaction, RandomHashGenerator, SyncBlock, TxEnv, KECCAK_EMPTY, }; use edr_rpc_eth::{ @@ -1756,7 +1756,7 @@ impl ProviderData, solidity_trace: Trace) -> Self { let reason = match halt { - HaltReason::OpcodeNotFound | HaltReason::InvalidFEOpcode => { + HaltReason::OpcodeNotFound | HaltReason::InvalidEFOpcode => { TransactionFailureReason::OpcodeNotFound } HaltReason::OutOfGas(error) => TransactionFailureReason::OutOfGas(error), From fe9e3b1a4158e40108b9d5233c839bdc054c9889 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 11 Jul 2024 13:59:19 +0200 Subject: [PATCH 09/54] edr-0.4.2 (#540) Co-authored-by: github-actions[bot] --- .changeset/big-boxes-drop.md | 5 ----- .changeset/wild-phones-drum.md | 5 ----- crates/edr_napi/CHANGELOG.md | 7 +++++++ crates/edr_napi/package.json | 2 +- 4 files changed, 8 insertions(+), 11 deletions(-) delete mode 100644 .changeset/big-boxes-drop.md delete mode 100644 .changeset/wild-phones-drum.md diff --git a/.changeset/big-boxes-drop.md b/.changeset/big-boxes-drop.md deleted file mode 100644 index 0b3cd7cda..000000000 --- a/.changeset/big-boxes-drop.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixes restriction to disallow remote blocks without a nonce diff --git a/.changeset/wild-phones-drum.md b/.changeset/wild-phones-drum.md deleted file mode 100644 index 9adee4f3e..000000000 --- a/.changeset/wild-phones-drum.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Upgraded revm to v37 diff --git a/crates/edr_napi/CHANGELOG.md b/crates/edr_napi/CHANGELOG.md index add82d2d1..1ec9b03dc 100644 --- a/crates/edr_napi/CHANGELOG.md +++ b/crates/edr_napi/CHANGELOG.md @@ -1,5 +1,12 @@ # @nomicfoundation/edr +## 0.4.2 + +### Patch Changes + +- b056511: Fixes restriction to disallow remote blocks without a nonce +- e650c9e: Upgraded revm to v37 + ## 0.4.1 ### Patch Changes diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index e69e944aa..84da2e6da 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/edr", - "version": "0.4.1", + "version": "0.4.2", "main": "index.js", "types": "index.d.ts", "files": [ From 83f3325b81481351de49326595a06add9bf96462 Mon Sep 17 00:00:00 2001 From: Agost Biro <5764438+agostbiro@users.noreply.github.com> Date: Thu, 11 Jul 2024 16:54:35 +0200 Subject: [PATCH 10/54] ci: remove path checks for benchmarks (#550) --- .github/workflows/edr-benchmark.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/edr-benchmark.yml b/.github/workflows/edr-benchmark.yml index 3c87812ec..2c2346a90 100644 --- a/.github/workflows/edr-benchmark.yml +++ b/.github/workflows/edr-benchmark.yml @@ -4,21 +4,9 @@ on: push: branches: - main - paths: - - ".github/workflows/edr-benchmark.yml" - - "rust-toolchain" - - "Cargo.lock" - - "Cargo.toml" - - "crates/**" pull_request: branches: - "**" - paths: - - ".github/workflows/edr-benchmark.yml" - - "rust-toolchain" - - "Cargo.lock" - - "Cargo.toml" - - "crates/**" workflow_dispatch: defaults: From caa4ac8ffa8a28c0bfb2b9d76d8ae45f53d36031 Mon Sep 17 00:00:00 2001 From: Agost Biro <5764438+agostbiro@users.noreply.github.com> Date: Thu, 11 Jul 2024 17:02:58 +0200 Subject: [PATCH 11/54] ci: remove path restrictions for EDR jobs (#551) --- .github/workflows/edr-ci.yml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index 4560aa548..64cd2874f 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -4,21 +4,9 @@ on: push: branches: - main - paths: - - ".github/workflows/edr-ci.yml" - - "rust-toolchain" - - "Cargo.lock" - - "Cargo.toml" - - "crates/**" pull_request: branches: - "**" - paths: - - ".github/workflows/edr-ci.yml" - - "rust-toolchain" - - "Cargo.lock" - - "Cargo.toml" - - "crates/**" workflow_dispatch: env: From 2d62afd8daae1936e43439879a01a5eef484330d Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Tue, 16 Jul 2024 12:10:53 +0200 Subject: [PATCH 12/54] ci: check that index.d.ts is up to date (#553) --- .github/workflows/edr-ci.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/.github/workflows/edr-ci.yml b/.github/workflows/edr-ci.yml index 64cd2874f..da1006ede 100644 --- a/.github/workflows/edr-ci.yml +++ b/.github/workflows/edr-ci.yml @@ -180,3 +180,26 @@ jobs: - name: Run prettier run: pnpm run prettier + + edr-napi-typings-file: + name: Check that edr_napi typings file is up to date + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: pnpm/action-setup@v4 + with: + version: 9 + - name: Install Node + uses: actions/setup-node@v2 + with: + node-version: ${{ matrix.node }} + cache: pnpm + + - name: Install package + run: pnpm install --frozen-lockfile --prefer-offline + + - name: Build edr_napi + run: cd crates/edr_napi && pnpm build + + - name: Check that there are no uncommitted changes + run: git diff --exit-code From 07c7667cd1c5a21e0def6dc6082ff7a71aa0de20 Mon Sep 17 00:00:00 2001 From: Wodann Date: Tue, 16 Jul 2024 23:43:21 -0500 Subject: [PATCH 13/54] feat: add support for RIP-7212 (#552) * feat: add support for RIP-7212 * misc: add changelog * fix: updated index.d.ts * fix: revert rename of InvalidFEOpcode * fix: set enableRip7212 in ProviderConfig * test: validate that disabling RIP-7212 works * refactor: use runtime variable instead of const * Path Hardhat dev dep to work with latest EDR changes EDR uses Hardhat as a dev dependency to run some javascript tests. The way this works is that the tests are run using Hardhat, but we use pnpm to override the EDR dependency in Hardhat with the local one. This works fine as long as there are no breaking changes in EDR. When there are, we have a circular dependency problem: we can't publish a new version of EDR until the tests pass, but for the tests to pass we need a version of Hardhat that works with the new version of EDR. A temporary workaround for this is to use `pnpm patch` to temporarily modify the Hardhat code in a way that works with the breaking change. In this case, this just means adding the new field when constructing the provider. --------- Co-authored-by: Franco Victorio --- .changeset/neat-actors-call.md | 5 + Cargo.lock | 166 +++++++++++++++--- crates/edr_eth/Cargo.toml | 3 +- crates/edr_eth/src/access_list.rs | 81 --------- crates/edr_eth/src/lib.rs | 5 +- crates/edr_eth/src/transaction.rs | 7 +- .../src/transaction/request/eip1559.rs | 3 +- .../src/transaction/request/eip2930.rs | 3 +- .../src/transaction/request/eip4844.rs | 3 +- crates/edr_eth/src/transaction/signed.rs | 18 +- .../edr_eth/src/transaction/signed/eip155.rs | 1 + .../edr_eth/src/transaction/signed/eip1559.rs | 6 +- .../edr_eth/src/transaction/signed/eip2930.rs | 6 +- .../edr_eth/src/transaction/signed/eip4844.rs | 4 +- .../edr_eth/src/transaction/signed/legacy.rs | 1 + crates/edr_evm/Cargo.toml | 3 +- crates/edr_evm/src/blockchain.rs | 3 - crates/edr_evm/src/blockchain/forked.rs | 5 +- crates/edr_evm/src/blockchain/local.rs | 5 +- crates/edr_evm/src/lib.rs | 1 + crates/edr_evm/src/precompiles.rs | 24 +++ crates/edr_evm/src/runtime.rs | 47 ++++- crates/edr_evm/src/transaction.rs | 14 +- crates/edr_napi/index.d.ts | 13 +- crates/edr_napi/src/provider/config.rs | 3 + crates/edr_napi/src/result.rs | 6 +- crates/edr_napi/test/provider.ts | 1 + crates/edr_provider/Cargo.toml | 2 + crates/edr_provider/src/config.rs | 1 + crates/edr_provider/src/data.rs | 26 ++- crates/edr_provider/src/data/call.rs | 8 +- crates/edr_provider/src/data/gas.rs | 13 +- crates/edr_provider/src/debugger.rs | 2 +- crates/edr_provider/src/error.rs | 2 +- crates/edr_provider/src/pending.rs | 4 +- .../src/requests/eth/transactions.rs | 10 +- .../edr_provider/src/requests/validation.rs | 3 +- crates/edr_provider/src/test_utils.rs | 1 + crates/edr_provider/tests/eip4844.rs | 21 ++- crates/edr_provider/tests/rip7212.rs | 79 +++++++++ crates/edr_rpc_eth/src/call_request.rs | 2 +- crates/edr_rpc_eth/src/transaction.rs | 3 +- package.json | 3 + patches/hardhat@2.22.6.patch | 24 +++ pnpm-lock.yaml | 27 +-- 45 files changed, 465 insertions(+), 203 deletions(-) create mode 100644 .changeset/neat-actors-call.md delete mode 100644 crates/edr_eth/src/access_list.rs create mode 100644 crates/edr_evm/src/precompiles.rs create mode 100644 crates/edr_provider/tests/rip7212.rs create mode 100644 patches/hardhat@2.22.6.patch diff --git a/.changeset/neat-actors-call.md b/.changeset/neat-actors-call.md new file mode 100644 index 000000000..8aeb49bcd --- /dev/null +++ b/.changeset/neat-actors-call.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": minor +--- + +Added support for RIP-7212 by enabling it in the provider configuration diff --git a/Cargo.lock b/Cargo.lock index 76fc909ef..22c57f851 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -62,6 +62,20 @@ dependencies = [ "winnow 0.6.8", ] +[[package]] +name = "alloy-eips" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f76ecab54890cdea1e4808fc0891c7e6cfcf71fe1a9fe26810c7280ef768f4ed" +dependencies = [ + "alloy-primitives 0.7.7", + "alloy-rlp", + "alloy-serde", + "c-kzg", + "once_cell", + "serde", +] + [[package]] name = "alloy-json-abi" version = "0.7.7" @@ -140,6 +154,17 @@ dependencies = [ "syn 2.0.58", ] +[[package]] +name = "alloy-serde" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9416c52959e66ead795a11f4a86c248410e9e368a0765710e57055b8a1774dd6" +dependencies = [ + "alloy-primitives 0.7.7", + "serde", + "serde_json", +] + [[package]] name = "alloy-sol-macro" version = "0.5.4" @@ -549,9 +574,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" dependencies = [ "serde", ] @@ -578,6 +603,19 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bls12_381" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7bc6d6292be3a19e6379786dac800f551e5865a5bb51ebbe3064ab80433f403" +dependencies = [ + "ff", + "group", + "pairing", + "rand_core", + "subtle", +] + [[package]] name = "blst" version = "0.3.11" @@ -1164,6 +1202,7 @@ dependencies = [ "parking_lot 0.12.1", "paste", "rand", + "revm-precompile", "rpds", "serde", "serde_json", @@ -1340,6 +1379,7 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ + "bitvec", "rand_core", "subtle", ] @@ -1909,6 +1949,21 @@ dependencies = [ "sha3-asm", ] +[[package]] +name = "kzg-rs" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd9920cd4460ce3cbca19c62f3bb9a9611562478a4dc9d2c556f4a7d049c5b6b" +dependencies = [ + "bls12_381", + "glob", + "hex", + "once_cell", + "serde", + "serde_derive", + "serde_yaml", +] + [[package]] name = "lazy_static" version = "1.4.0" @@ -1931,7 +1986,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.52.4", + "windows-targets 0.48.5", ] [[package]] @@ -2072,7 +2127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4ca998356d8ff9fba7a070dae4508a2298439c98c9f3bc9c07669538b999e8f" dependencies = [ "anyhow", - "bitflags 2.5.0", + "bitflags 2.6.0", "ctor", "napi-derive", "napi-sys", @@ -2273,7 +2328,7 @@ version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "cfg-if", "foreign-types", "libc", @@ -2333,6 +2388,27 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" +[[package]] +name = "p256" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9863ad85fa8f4460f9c48cb909d38a0d689dba1f6f6988a5e3e0d31071bcd4b" +dependencies = [ + "ecdsa", + "elliptic-curve", + "primeorder", + "sha2", +] + +[[package]] +name = "pairing" +version = "0.23.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81fec4625e73cf41ef4bb6846cafa6d44736525f442ba45e407c4a000a13996f" +dependencies = [ + "group", +] + [[package]] name = "parity-scale-codec" version = "3.6.9" @@ -2507,6 +2583,15 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +[[package]] +name = "primeorder" +version = "0.13.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "353e1ca18966c16d9deb1c69278edbc5f194139612772bd9537af60ac231e1e6" +dependencies = [ + "elliptic-curve", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -2568,7 +2653,7 @@ checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.5.0", + "bitflags 2.6.0", "lazy_static", "num-traits", "rand", @@ -2830,9 +2915,8 @@ dependencies = [ [[package]] name = "revm" -version = "10.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355bde4e21578c241f9379fbb344a73d254969b5007239115e094dda1511cd34" +version = "11.0.0" +source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" dependencies = [ "auto_impl", "cfg-if", @@ -2840,13 +2924,13 @@ dependencies = [ "revm-interpreter", "revm-precompile", "serde", + "serde_json", ] [[package]] name = "revm-interpreter" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23dfd24faa3cbbd96e0976103d1e174d6559b8036730f70415488ee21870d578" +version = "7.0.0" +source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" dependencies = [ "revm-primitives", "serde", @@ -2854,29 +2938,31 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "8.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c669c9b105dbb41133c17bf7f34d29368e358a7fee8fcc289e90dbfb024dfc4" +version = "9.0.0" +source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" dependencies = [ "aurora-engine-modexp", "c-kzg", + "cfg-if", "k256", "once_cell", + "p256", "revm-primitives", "ripemd", + "secp256k1", "sha2", "substrate-bn", ] [[package]] name = "revm-primitives" -version = "5.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "902184a7a781550858d4b96707098da357429f1e4545806fd5b589f455555cf2" +version = "6.0.0" +source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" dependencies = [ + "alloy-eips", "alloy-primitives 0.7.7", "auto_impl", - "bitflags 2.5.0", + "bitflags 2.6.0", "bitvec", "c-kzg", "cfg-if", @@ -2885,6 +2971,7 @@ dependencies = [ "enumn", "hashbrown 0.14.3", "hex", + "kzg-rs", "once_cell", "serde", ] @@ -2993,7 +3080,7 @@ version = "0.38.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", @@ -3065,6 +3152,25 @@ dependencies = [ "zeroize", ] +[[package]] +name = "secp256k1" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e0cc0f1cf93f4969faf3ea1c7d8a9faed25918d96affa959720823dfe86d4f3" +dependencies = [ + "rand", + "secp256k1-sys", +] + +[[package]] +name = "secp256k1-sys" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1433bd67156263443f14d603720b082dd3121779323fce20cba2aa07b874bc1b" +dependencies = [ + "cc", +] + [[package]] name = "security-framework" version = "2.10.0" @@ -3138,6 +3244,7 @@ version = "1.0.115" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" dependencies = [ + "indexmap 2.2.6", "itoa", "ryu", "serde", @@ -3164,6 +3271,19 @@ dependencies = [ "serde", ] +[[package]] +name = "serde_yaml" +version = "0.9.34+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" +dependencies = [ + "indexmap 2.2.6", + "itoa", + "ryu", + "serde", + "unsafe-libyaml", +] + [[package]] name = "serial_test" version = "2.0.0" @@ -3800,6 +3920,12 @@ version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e51733f11c9c4f72aa0c160008246859e340b00807569a0da0e7a1079b27ba85" +[[package]] +name = "unsafe-libyaml" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" + [[package]] name = "url" version = "2.5.0" diff --git a/crates/edr_eth/Cargo.toml b/crates/edr_eth/Cargo.toml index eb66abb38..f8a35de55 100644 --- a/crates/edr_eth/Cargo.toml +++ b/crates/edr_eth/Cargo.toml @@ -15,7 +15,8 @@ itertools = { version = "0.10.5", default-features = false, features = ["use_all k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", ] } log = { version = "0.4.17", default-features = false } once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] } -revm-primitives = { version = "5.0", default-features = false, features = ["c-kzg", "hashbrown"] } +# revm-primitives = { version = "5.0", default-features = false, features = ["c-kzg", "hashbrown"] } +revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "6.0", default-features = false, features = ["c-kzg", "hashbrown"] } serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true } sha2 = { version = "0.10.8", default-features = false } sha3 = { version = "0.10.8", default-features = false } diff --git a/crates/edr_eth/src/access_list.rs b/crates/edr_eth/src/access_list.rs deleted file mode 100644 index 9790b3ea6..000000000 --- a/crates/edr_eth/src/access_list.rs +++ /dev/null @@ -1,81 +0,0 @@ -// Part of this code was adapted from ethers-rs and is distributed under their -// license: -// - https://github.com/gakonst/ethers-rs/blob/cba6f071aedafb766e82e4c2f469ed5e4638337d/LICENSE-APACHE -// - https://github.com/gakonst/ethers-rs/blob/cba6f071aedafb766e82e4c2f469ed5e4638337d/LICENSE-MIT -// For the original context see: https://github.com/gakonst/ethers-rs/blob/3d9c3290d42b77c510e5b5d0b6f7a2f72913bfff/ethers-core/src/types/transaction/eip2930.rs - -use alloy_rlp::{RlpDecodable, RlpDecodableWrapper, RlpEncodable, RlpEncodableWrapper}; - -use crate::{Address, B256, U256}; - -/// Access list -// NB: Need to use `RlpEncodableWrapper` else we get an extra [] in the output -// https://github.com/gakonst/ethers-rs/pull/353#discussion_r680683869 -#[derive(Debug, Default, Clone, PartialEq, Eq, Hash, RlpDecodableWrapper, RlpEncodableWrapper)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct AccessList(pub Vec); - -impl From> for AccessList { - fn from(src: Vec) -> AccessList { - AccessList(src) - } -} - -impl From for Vec { - fn from(src: AccessList) -> Vec { - src.0 - } -} - -/// Access list item -#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, RlpDecodable, RlpEncodable)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))] -pub struct AccessListItem { - /// Accessed address - pub address: Address, - /// Accessed storage keys - // In JSON, we have to accept null as well for storage key, but we don't want to change the - // type to Option> as that's invalid in RLP. - #[cfg_attr( - feature = "serde", - serde(deserialize_with = "crate::serde::optional_to_default") - )] - pub storage_keys: Vec, -} - -impl From for (Address, Vec) { - fn from(value: AccessListItem) -> Self { - ( - value.address, - value - .storage_keys - .into_iter() - .map(|key| U256::from_be_bytes(key.0)) - .collect(), - ) - } -} - -impl From for Vec<(Address, Vec)> { - fn from(value: AccessList) -> Self { - value.0.into_iter().map(AccessListItem::into).collect() - } -} - -#[cfg(all(test, feature = "serde"))] -mod tests { - use serde_json::json; - - use super::*; - - #[test] - fn access_list_item() { - let item_json = json!( { - "address": "0x1234567890123456789012345678901234567890", - "storageKeys": null, - }); - - let _item: AccessListItem = serde_json::from_value(item_json).unwrap(); - } -} diff --git a/crates/edr_eth/src/lib.rs b/crates/edr_eth/src/lib.rs index e9bfb3cf5..2ba9e2fdb 100644 --- a/crates/edr_eth/src/lib.rs +++ b/crates/edr_eth/src/lib.rs @@ -5,8 +5,6 @@ //! Ethereum types as needed by EDR. In particular, they are based on the same //! primitive types as `revm`. -/// Ethereum access list types -pub mod access_list; /// Ethereum account types pub mod account; /// Parent beacon types and constants @@ -46,7 +44,8 @@ pub mod withdrawal; pub use c_kzg::{Blob, Bytes48, BYTES_PER_BLOB, BYTES_PER_COMMITMENT, BYTES_PER_PROOF}; pub use revm_primitives::{ alloy_primitives::{Bloom, BloomInput, B512, B64, U64}, - hex_literal, AccountInfo, Address, Bytecode, Bytes, HashMap, HashSet, SpecId, B256, U256, + hex_literal, AccessList, AccessListItem, AccountInfo, Address, Bytecode, Bytes, HashMap, + HashSet, SpecId, B256, U256, }; pub use self::block_spec::{BlockSpec, BlockTag, Eip1898BlockSpec, PreEip1898BlockSpec}; diff --git a/crates/edr_eth/src/transaction.rs b/crates/edr_eth/src/transaction.rs index 193706ded..6b3adf9c8 100644 --- a/crates/edr_eth/src/transaction.rs +++ b/crates/edr_eth/src/transaction.rs @@ -17,10 +17,7 @@ pub use revm_primitives::alloy_primitives::TxKind; use revm_primitives::B256; pub use self::r#type::TransactionType; -use crate::{ - access_list::{AccessList, AccessListItem}, - Address, Bytes, U256, -}; +use crate::{AccessListItem, Address, Bytes, U256}; pub const INVALID_TX_TYPE_ERROR_MESSAGE: &str = "invalid tx type"; @@ -63,7 +60,7 @@ pub trait SignedTransaction: Transaction { pub trait Transaction { /// Returns the access list of the transaction, if any. - fn access_list(&self) -> Option<&AccessList>; + fn access_list(&self) -> &[AccessListItem]; /// Returns the input data of the transaction. fn data(&self) -> &Bytes; diff --git a/crates/edr_eth/src/transaction/request/eip1559.rs b/crates/edr_eth/src/transaction/request/eip1559.rs index a72fad60a..670cbdfb3 100644 --- a/crates/edr_eth/src/transaction/request/eip1559.rs +++ b/crates/edr_eth/src/transaction/request/eip1559.rs @@ -5,11 +5,10 @@ use k256::SecretKey; use revm_primitives::keccak256; use crate::{ - access_list::AccessListItem, signature::{self, public_key_to_address, Fakeable, SignatureError}, transaction::{self, TxKind}, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessListItem, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, PartialEq, Eq, RlpDecodable, RlpEncodable)] diff --git a/crates/edr_eth/src/transaction/request/eip2930.rs b/crates/edr_eth/src/transaction/request/eip2930.rs index a200f36a7..26b2c53d9 100644 --- a/crates/edr_eth/src/transaction/request/eip2930.rs +++ b/crates/edr_eth/src/transaction/request/eip2930.rs @@ -5,11 +5,10 @@ use k256::SecretKey; use revm_primitives::keccak256; use crate::{ - access_list::AccessListItem, signature::{self, public_key_to_address, Fakeable, SignatureError}, transaction::{self, TxKind}, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessListItem, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, PartialEq, Eq, RlpEncodable)] diff --git a/crates/edr_eth/src/transaction/request/eip4844.rs b/crates/edr_eth/src/transaction/request/eip4844.rs index 46340e81a..da02ea17d 100644 --- a/crates/edr_eth/src/transaction/request/eip4844.rs +++ b/crates/edr_eth/src/transaction/request/eip4844.rs @@ -5,11 +5,10 @@ use k256::SecretKey; use revm_primitives::keccak256; use crate::{ - access_list::AccessListItem, signature::{self, public_key_to_address, Fakeable, SignatureError}, transaction, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessListItem, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, PartialEq, Eq, RlpEncodable)] diff --git a/crates/edr_eth/src/transaction/signed.rs b/crates/edr_eth/src/transaction/signed.rs index 5a9bd2385..786161d7d 100644 --- a/crates/edr_eth/src/transaction/signed.rs +++ b/crates/edr_eth/src/transaction/signed.rs @@ -5,7 +5,7 @@ mod eip4844; mod legacy; use alloy_rlp::{Buf, BufMut}; -use revm_primitives::{TransactTo, TxEnv}; +use revm_primitives::{AccessListItem, TransactTo, TxEnv}; pub use self::{ eip155::Eip155, @@ -17,9 +17,7 @@ pub use self::{ use super::{ Signed, SignedTransaction, Transaction, TransactionType, TxKind, INVALID_TX_TYPE_ERROR_MESSAGE, }; -use crate::{ - access_list::AccessList, signature::Signature, utils::enveloped, Address, Bytes, B256, U256, -}; +use crate::{signature::Signature, utils::enveloped, Address, Bytes, B256, U256}; /// Converts a `TxKind` to a `TransactTo`. fn kind_to_transact_to(kind: TxKind) -> TransactTo { @@ -219,12 +217,12 @@ impl SignedTransaction for Signed { } impl Transaction for Signed { - fn access_list(&self) -> Option<&AccessList> { + fn access_list(&self) -> &[AccessListItem] { match self { - Signed::PreEip155Legacy(_) | Signed::PostEip155Legacy(_) => None, - Signed::Eip2930(tx) => Some(&tx.access_list), - Signed::Eip1559(tx) => Some(&tx.access_list), - Signed::Eip4844(tx) => Some(&tx.access_list), + Signed::PreEip155Legacy(_) | Signed::PostEip155Legacy(_) => &[], + Signed::Eip2930(tx) => &tx.access_list, + Signed::Eip1559(tx) => &tx.access_list, + Signed::Eip4844(tx) => &tx.access_list, } } @@ -362,7 +360,7 @@ mod tests { use alloy_rlp::Decodable as _; use super::*; - use crate::{signature, transaction, Bytes}; + use crate::{signature, transaction, AccessList, Bytes}; #[test] fn can_recover_sender() { diff --git a/crates/edr_eth/src/transaction/signed/eip155.rs b/crates/edr_eth/src/transaction/signed/eip155.rs index 16f06b126..573d62d4a 100644 --- a/crates/edr_eth/src/transaction/signed/eip155.rs +++ b/crates/edr_eth/src/transaction/signed/eip155.rs @@ -78,6 +78,7 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, + authorization_list: None, } } } diff --git a/crates/edr_eth/src/transaction/signed/eip1559.rs b/crates/edr_eth/src/transaction/signed/eip1559.rs index e2a67d5dd..07cd9a2f7 100644 --- a/crates/edr_eth/src/transaction/signed/eip1559.rs +++ b/crates/edr_eth/src/transaction/signed/eip1559.rs @@ -5,11 +5,10 @@ use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; use crate::{ - access_list::AccessList, signature::{self, Fakeable}, transaction::{self, TxKind}, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessList, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, Eq, RlpEncodable)] @@ -68,6 +67,7 @@ impl From for TxEnv { gas_priority_fee: Some(value.max_priority_fee_per_gas), blob_hashes: Vec::new(), max_fee_per_blob_gas: None, + authorization_list: None, } } } @@ -151,8 +151,8 @@ mod tests { use super::*; use crate::{ - access_list::AccessListItem, signature::{secret_key_from_str, secret_key_to_address}, + AccessListItem, }; const DUMMY_SECRET_KEY: &str = diff --git a/crates/edr_eth/src/transaction/signed/eip2930.rs b/crates/edr_eth/src/transaction/signed/eip2930.rs index 84d0a1af8..8bdc1bf9a 100644 --- a/crates/edr_eth/src/transaction/signed/eip2930.rs +++ b/crates/edr_eth/src/transaction/signed/eip2930.rs @@ -5,11 +5,10 @@ use revm_primitives::{keccak256, TxEnv}; use super::kind_to_transact_to; use crate::{ - access_list::AccessList, signature::{self, Fakeable}, transaction::{self, TxKind}, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessList, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, Eq, RlpEncodable)] @@ -67,6 +66,7 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, + authorization_list: None, } } } @@ -145,7 +145,7 @@ mod tests { use k256::SecretKey; use super::*; - use crate::{access_list::AccessListItem, signature::secret_key_from_str}; + use crate::{signature::secret_key_from_str, AccessListItem}; fn dummy_request() -> transaction::request::Eip2930 { let to = Address::from_str("0xc014ba5ec014ba5ec014ba5ec014ba5ec014ba5e").unwrap(); diff --git a/crates/edr_eth/src/transaction/signed/eip4844.rs b/crates/edr_eth/src/transaction/signed/eip4844.rs index c0aaf48ae..136ebd9f6 100644 --- a/crates/edr_eth/src/transaction/signed/eip4844.rs +++ b/crates/edr_eth/src/transaction/signed/eip4844.rs @@ -4,11 +4,10 @@ use alloy_rlp::{RlpDecodable, RlpEncodable}; use revm_primitives::{keccak256, TransactTo, TxEnv, GAS_PER_BLOB}; use crate::{ - access_list::AccessList, signature::{self, Fakeable}, transaction, utils::envelop_bytes, - Address, Bytes, B256, U256, + AccessList, Address, Bytes, B256, U256, }; #[derive(Clone, Debug, Eq, RlpEncodable)] @@ -78,6 +77,7 @@ impl From for TxEnv { gas_priority_fee: Some(value.max_priority_fee_per_gas), blob_hashes: value.blob_hashes, max_fee_per_blob_gas: Some(value.max_fee_per_blob_gas), + authorization_list: None, } } } diff --git a/crates/edr_eth/src/transaction/signed/legacy.rs b/crates/edr_eth/src/transaction/signed/legacy.rs index 7d61460a6..1d4540c5a 100644 --- a/crates/edr_eth/src/transaction/signed/legacy.rs +++ b/crates/edr_eth/src/transaction/signed/legacy.rs @@ -57,6 +57,7 @@ impl From for TxEnv { gas_priority_fee: None, blob_hashes: Vec::new(), max_fee_per_blob_gas: None, + authorization_list: None, } } } diff --git a/crates/edr_evm/Cargo.toml b/crates/edr_evm/Cargo.toml index 095eba061..493d03ec0 100644 --- a/crates/edr_evm/Cargo.toml +++ b/crates/edr_evm/Cargo.toml @@ -19,7 +19,8 @@ parking_lot = { version = "0.12.1", default-features = false } edr_defaults = { version = "0.3.5", path = "../edr_defaults" } edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["rand", "serde"] } edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" } -revm = { version = "10.0", default-features = false, features = ["c-kzg", "dev", "serde"] } +# revm = { version = "10.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] } +revm = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "11.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] } rpds = { version = "1.1.0", default-features = false, features = ["std"] } serde = { version = "1.0.158", default-features = false, features = ["std"] } serde_json = { version = "1.0.94", default-features = false, features = ["std"] } diff --git a/crates/edr_evm/src/blockchain.rs b/crates/edr_evm/src/blockchain.rs index fa1d28b37..c044cc3ca 100644 --- a/crates/edr_evm/src/blockchain.rs +++ b/crates/edr_evm/src/blockchain.rs @@ -30,9 +30,6 @@ use crate::{ /// Combinatorial error for the blockchain API. #[derive(Debug, thiserror::Error)] pub enum BlockchainError { - /// Block number exceeds storage capacity (`usize::MAX`) - #[error("Block number exceeds storage capacity.")] - BlockNumberTooLarge, /// Forked blockchain error #[error(transparent)] Forked(#[from] ForkedBlockchainError), diff --git a/crates/edr_evm/src/blockchain/forked.rs b/crates/edr_evm/src/blockchain/forked.rs index 5b16f08f5..f18610cda 100644 --- a/crates/edr_evm/src/blockchain/forked.rs +++ b/crates/edr_evm/src/blockchain/forked.rs @@ -259,10 +259,7 @@ where type Error = BlockchainError; #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))] - fn block_hash(&self, number: U256) -> Result { - let number = - u64::try_from(number).map_err(|_error| BlockchainError::BlockNumberTooLarge)?; - + fn block_hash(&self, number: u64) -> Result { if number <= self.fork_block_number { tokio::task::block_in_place(move || { self.runtime().block_on(self.remote.block_by_number(number)) diff --git a/crates/edr_evm/src/blockchain/local.rs b/crates/edr_evm/src/blockchain/local.rs index 6dc6d1016..9ba25ce6c 100644 --- a/crates/edr_evm/src/blockchain/local.rs +++ b/crates/edr_evm/src/blockchain/local.rs @@ -413,10 +413,7 @@ where type Error = BlockchainError; #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))] - fn block_hash(&self, number: U256) -> Result { - let number = - u64::try_from(number).map_err(|_error| BlockchainError::BlockNumberTooLarge)?; - + fn block_hash(&self, number: u64) -> Result { self.storage .block_by_number(number)? .map(|block| *block.hash()) diff --git a/crates/edr_evm/src/lib.rs b/crates/edr_evm/src/lib.rs index 3290461dc..8da6201d3 100644 --- a/crates/edr_evm/src/lib.rs +++ b/crates/edr_evm/src/lib.rs @@ -40,6 +40,7 @@ mod debug_trace; /// Types for managing Ethereum mem pool pub mod mempool; mod miner; +mod precompiles; pub(crate) mod random; mod runtime; /// Utilities for testing diff --git a/crates/edr_evm/src/precompiles.rs b/crates/edr_evm/src/precompiles.rs new file mode 100644 index 000000000..4018f3f75 --- /dev/null +++ b/crates/edr_evm/src/precompiles.rs @@ -0,0 +1,24 @@ +use std::{fmt::Debug, sync::Arc}; + +use edr_eth::{Address, HashMap}; +use revm::ContextPrecompile; + +use crate::{db::Database, evm::EvmHandler}; + +/// Registers custom precompiles. +pub fn register_precompiles_handles( + handler: &mut EvmHandler<'_, ContextT, DatabaseT>, + precompiles: HashMap>, +) where + DatabaseT: Database, + DatabaseT::Error: Debug, +{ + let old_handle = handler.pre_execution.load_precompiles(); + handler.pre_execution.load_precompiles = Arc::new(move || { + let mut new_handle = old_handle.clone(); + + new_handle.extend(precompiles.clone()); + + new_handle + }); +} diff --git a/crates/edr_evm/src/runtime.rs b/crates/edr_evm/src/runtime.rs index a46db0aaa..7ceb67276 100644 --- a/crates/edr_evm/src/runtime.rs +++ b/crates/edr_evm/src/runtime.rs @@ -1,18 +1,20 @@ use std::fmt::Debug; +use edr_eth::{Address, HashMap}; use revm::{ db::{DatabaseComponents, StateRef}, primitives::{ - BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, ResultAndState, SpecId, - TxEnv, + BlockEnv, CfgEnvWithHandlerCfg, EnvWithHandlerCfg, ExecutionResult, Precompile, + ResultAndState, SpecId, TxEnv, }, - DatabaseCommit, Evm, + ContextPrecompile, DatabaseCommit, Evm, }; use crate::{ blockchain::SyncBlockchain, chain_spec::L1ChainSpec, debug::DebugContext, + precompiles::register_precompiles_handles, state::{StateOverrides, StateRefOverrider, SyncState}, transaction::TransactionError, }; @@ -26,7 +28,7 @@ pub type SyncDatabase<'blockchain, 'state, ChainSpecT, BlockchainErrorT, StateEr /// Runs a transaction without committing the state. // `DebugContext` cannot be simplified further -#[allow(clippy::type_complexity)] +#[allow(clippy::too_many_arguments, clippy::type_complexity)] #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))] pub fn dry_run<'blockchain, 'evm, 'overrides, 'state, DebugDataT, BlockchainErrorT, StateErrorT>( blockchain: &'blockchain dyn SyncBlockchain, @@ -35,6 +37,7 @@ pub fn dry_run<'blockchain, 'evm, 'overrides, 'state, DebugDataT, BlockchainErro cfg: CfgEnvWithHandlerCfg, transaction: TxEnv, block: BlockEnv, + custom_precompiles: &HashMap, debug_context: Option< DebugContext< 'evm, @@ -62,16 +65,30 @@ where block_hash: blockchain, }); + let precompiles: HashMap> = custom_precompiles + .iter() + .map(|(address, precompile)| (*address, ContextPrecompile::from(precompile.clone()))) + .collect(); + if let Some(debug_context) = debug_context { let mut evm = evm_builder .with_external_context(debug_context.data) .with_env_with_handler_cfg(env) .append_handler_register(debug_context.register_handles_fn) + .append_handler_register_box(Box::new(move |handler| { + register_precompiles_handles(handler, precompiles.clone()); + })) .build(); evm.transact() } else { - let mut evm = evm_builder.with_env_with_handler_cfg(env).build(); + let mut evm = evm_builder + .with_env_with_handler_cfg(env) + .append_handler_register_box(Box::new(move |handler| { + register_precompiles_handles(handler, precompiles.clone()); + })) + .build(); + evm.transact() } }; @@ -82,7 +99,7 @@ where /// Runs a transaction without committing the state, while disabling balance /// checks and creating accounts for new addresses. // `DebugContext` cannot be simplified further -#[allow(clippy::type_complexity)] +#[allow(clippy::too_many_arguments, clippy::type_complexity)] #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))] pub fn guaranteed_dry_run< 'blockchain, @@ -99,6 +116,7 @@ pub fn guaranteed_dry_run< mut cfg: CfgEnvWithHandlerCfg, mut transaction: TxEnv, block: BlockEnv, + custom_precompiles: &HashMap, debug_context: Option< DebugContext< 'evm, @@ -125,6 +143,7 @@ where cfg, transaction, block, + custom_precompiles, debug_context, ) } @@ -137,6 +156,7 @@ pub fn run<'blockchain, 'evm, BlockchainErrorT, DebugDataT, StateT>( cfg: CfgEnvWithHandlerCfg, transaction: TxEnv, block: BlockEnv, + custom_precompiles: &HashMap, debug_context: Option>, ) -> Result> where @@ -153,16 +173,29 @@ where block_hash: blockchain, }); + let precompiles: HashMap> = custom_precompiles + .iter() + .map(|(address, precompile)| (*address, ContextPrecompile::from(precompile.clone()))) + .collect(); + let result = if let Some(debug_context) = debug_context { let mut evm = evm_builder .with_external_context(debug_context.data) .with_env_with_handler_cfg(env) .append_handler_register(debug_context.register_handles_fn) + .append_handler_register_box(Box::new(move |handler| { + register_precompiles_handles(handler, precompiles.clone()); + })) .build(); evm.transact_commit() } else { - let mut evm = evm_builder.with_env_with_handler_cfg(env).build(); + let mut evm = evm_builder + .with_env_with_handler_cfg(env) + .append_handler_register_box(Box::new(move |handler| { + register_precompiles_handles(handler, precompiles.clone()); + })) + .build(); evm.transact_commit() }?; diff --git a/crates/edr_evm/src/transaction.rs b/crates/edr_evm/src/transaction.rs index 0e1f8fe83..a29a31540 100644 --- a/crates/edr_evm/src/transaction.rs +++ b/crates/edr_evm/src/transaction.rs @@ -6,7 +6,7 @@ use std::fmt::Debug; // Re-export the transaction types from `edr_eth`. pub use edr_eth::transaction::*; -use edr_eth::{Address, SpecId, U256}; +use edr_eth::{SpecId, U256}; use revm::{ db::DatabaseComponentError, interpreter::gas::validate_initial_tx_gas, @@ -99,24 +99,18 @@ pub fn validate( /// Calculates the initial cost of a transaction. pub fn initial_cost(transaction: &impl Transaction, spec_id: SpecId) -> u64 { - let access_list = transaction - .access_list() - .cloned() - .map(Vec::<(Address, Vec)>::from); - validate_initial_tx_gas( spec_id, transaction.data().as_ref(), transaction.kind() == TxKind::Create, - access_list - .as_ref() - .map_or(&[], |access_list| access_list.as_slice()), + transaction.access_list(), + 0, ) } #[cfg(test)] mod tests { - use edr_eth::{transaction, Bytes}; + use edr_eth::{transaction, Address, Bytes}; use super::*; diff --git a/crates/edr_napi/index.d.ts b/crates/edr_napi/index.d.ts index 616c64b5b..621ee25fd 100644 --- a/crates/edr_napi/index.d.ts +++ b/crates/edr_napi/index.d.ts @@ -223,6 +223,8 @@ export interface ProviderConfig { chains: Array /** The address of the coinbase */ coinbase: Buffer + /** Enables RIP-7212 */ + enableRip7212: boolean /** * The configuration for forking a blockchain. If not provided, a local * blockchain will be created @@ -260,7 +262,8 @@ export const enum SuccessReason { /** The opcode `RETURN` was called */ Return = 1, /** The opcode `SELFDESTRUCT` was called */ - SelfDestruct = 2 + SelfDestruct = 2, + EofReturnContract = 3 } export interface CallOutput { /** Return value */ @@ -313,7 +316,13 @@ export const enum ExceptionalHalt { /** Error on created contract that begins with EF */ CreateContractStartingWithEF = 12, /** EIP-3860: Limit and meter initcode. Initcode size limit exceeded. */ - CreateInitCodeSizeLimit = 13 + CreateInitCodeSizeLimit = 13, + /** Aux data overflow, new aux data is larger tha u16 max size. */ + EofAuxDataOverflow = 14, + /** Aud data is smaller then already present data size. */ + EofAuxDataTooSmall = 15, + /** EOF Subroutine stack overflow */ + EOFFunctionStackOverflow = 16 } /** The result when the EVM terminates due to an exceptional halt. */ export interface HaltResult { diff --git a/crates/edr_napi/src/provider/config.rs b/crates/edr_napi/src/provider/config.rs index f2a5aec2e..be7b1624e 100644 --- a/crates/edr_napi/src/provider/config.rs +++ b/crates/edr_napi/src/provider/config.rs @@ -100,6 +100,8 @@ pub struct ProviderConfig { pub chains: Vec, /// The address of the coinbase pub coinbase: Buffer, + /// Enables RIP-7212 + pub enable_rip_7212: bool, /// The configuration for forking a blockchain. If not provided, a local /// blockchain will be created pub fork: Option, @@ -261,6 +263,7 @@ impl TryFrom for edr_provider::ProviderConfig { chain_id: value.chain_id.try_cast()?, chains, coinbase: value.coinbase.try_cast()?, + enable_rip_7212: value.enable_rip_7212, fork: value.fork.map(TryInto::try_into).transpose()?, genesis_accounts: HashMap::new(), hardfork: value.hardfork.into(), diff --git a/crates/edr_napi/src/result.rs b/crates/edr_napi/src/result.rs index 6891e15dc..21ed2051d 100644 --- a/crates/edr_napi/src/result.rs +++ b/crates/edr_napi/src/result.rs @@ -85,7 +85,7 @@ pub struct RevertResult { pub enum ExceptionalHalt { OutOfGas, OpcodeNotFound, - InvalidEFOpcode, + InvalidFEOpcode, InvalidJump, NotActivated, StackUnderflow, @@ -113,7 +113,7 @@ impl From for ExceptionalHalt { match halt { edr_evm::HaltReason::OutOfGas(..) => ExceptionalHalt::OutOfGas, edr_evm::HaltReason::OpcodeNotFound => ExceptionalHalt::OpcodeNotFound, - edr_evm::HaltReason::InvalidEFOpcode => ExceptionalHalt::InvalidEFOpcode, + edr_evm::HaltReason::InvalidFEOpcode => ExceptionalHalt::InvalidFEOpcode, edr_evm::HaltReason::InvalidJump => ExceptionalHalt::InvalidJump, edr_evm::HaltReason::NotActivated => ExceptionalHalt::NotActivated, edr_evm::HaltReason::StackUnderflow => ExceptionalHalt::StackUnderflow, @@ -152,7 +152,7 @@ impl From for edr_evm::HaltReason { match value { ExceptionalHalt::OutOfGas => Self::OutOfGas(edr_evm::OutOfGasError::Basic), ExceptionalHalt::OpcodeNotFound => Self::OpcodeNotFound, - ExceptionalHalt::InvalidEFOpcode => Self::InvalidEFOpcode, + ExceptionalHalt::InvalidFEOpcode => Self::InvalidFEOpcode, ExceptionalHalt::InvalidJump => Self::InvalidJump, ExceptionalHalt::NotActivated => Self::NotActivated, ExceptionalHalt::StackUnderflow => Self::StackUnderflow, diff --git a/crates/edr_napi/test/provider.ts b/crates/edr_napi/test/provider.ts index 955194417..e2dd97a53 100644 --- a/crates/edr_napi/test/provider.ts +++ b/crates/edr_napi/test/provider.ts @@ -37,6 +37,7 @@ describe("Provider", () => { chainId: 123n, chains: [], coinbase: Buffer.from("0000000000000000000000000000000000000000", "hex"), + enableRip7212: false, genesisAccounts: [ { secretKey: diff --git a/crates/edr_provider/Cargo.toml b/crates/edr_provider/Cargo.toml index 25fd11889..fb21b9836 100644 --- a/crates/edr_provider/Cargo.toml +++ b/crates/edr_provider/Cargo.toml @@ -20,6 +20,8 @@ lazy_static = { version = "1.4.0", default-features = false } log = { version = "0.4.20", default-features = false } parking_lot = { version = "0.12.1", default-features = false } rand = { version = "0.8.5", default-features = false } +# revm-precompile = { version = "8.0", default-features = false, features = ["c-kzg", "secp256r1", "std"] } +revm-precompile = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "9.0", default-features = false, features = ["c-kzg", "secp256r1", "std"] } rpds = { version = "1.1.0", default-features = false, features = ["std"] } serde = { version = "1.0.147", default-features = false, features = ["derive"] } serde_json = { version = "1.0.89" } diff --git a/crates/edr_provider/src/config.rs b/crates/edr_provider/src/config.rs index 0fa99c485..4a12d9705 100644 --- a/crates/edr_provider/src/config.rs +++ b/crates/edr_provider/src/config.rs @@ -85,6 +85,7 @@ pub struct ProviderConfig { pub chain_id: ChainId, pub chains: HashMap, pub coinbase: Address, + pub enable_rip_7212: bool, pub fork: Option, // Genesis accounts in addition to accounts. Useful for adding impersonated accounts for tests. pub genesis_accounts: HashMap, diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index 93f884e02..339ba4e05 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -45,8 +45,8 @@ use edr_evm::{ Account, AccountInfo, BlobExcessGasAndPrice, Block as _, BlockAndTotalDifficulty, BlockEnv, Bytecode, CfgEnv, CfgEnvWithHandlerCfg, DebugContext, DebugTraceConfig, DebugTraceResultWithTraces, Eip3155AndRawTracers, EvmStorageSlot, ExecutionResult, HashMap, - HashSet, MemPool, MineBlockResultAndState, OrderedTransaction, RandomHashGenerator, SyncBlock, - TxEnv, KECCAK_EMPTY, + HashSet, MemPool, MineBlockResultAndState, OrderedTransaction, Precompile, RandomHashGenerator, + SyncBlock, TxEnv, KECCAK_EMPTY, }; use edr_rpc_eth::{ client::{EthRpcClient, HeaderMap, RpcClientError}, @@ -56,6 +56,7 @@ use gas::gas_used_ratio; use indexmap::IndexMap; use itertools::izip; use lru::LruCache; +use revm_precompile::secp256r1; use rpds::HashTrieMapSync; use tokio::runtime; @@ -168,6 +169,7 @@ pub struct ProviderData, dao_activation_block: Option, min_gas_price: U256, parent_beacon_block_root_generator: RandomHashGenerator, @@ -266,6 +268,17 @@ impl ProviderData ProviderData ProviderData ProviderData ProviderData ProviderData ProviderData ProviderData ProviderData ProviderData, // `DebugContext` cannot be simplified further #[allow(clippy::type_complexity)] pub debug_context: Option< @@ -51,6 +53,7 @@ where state_overrides, cfg_env, tx_env, + precompiles, debug_context, } = args; @@ -79,6 +82,7 @@ where cfg_env, tx_env, block, + precompiles, debug_context, ) .map_or_else( diff --git a/crates/edr_provider/src/data/gas.rs b/crates/edr_provider/src/data/gas.rs index 056889dbb..530b4af03 100644 --- a/crates/edr_provider/src/data/gas.rs +++ b/crates/edr_provider/src/data/gas.rs @@ -1,13 +1,16 @@ use core::fmt::Debug; use std::cmp; -use edr_eth::{block::Header, reward_percentile::RewardPercentile, transaction::Transaction, U256}; +use edr_eth::{ + block::Header, reward_percentile::RewardPercentile, transaction::Transaction, Address, HashMap, + U256, +}; use edr_evm::{ blockchain::{BlockchainError, SyncBlockchain}, chain_spec::L1ChainSpec, state::{StateError, StateOverrides, SyncState}, trace::{register_trace_collector_handles, TraceCollector}, - CfgEnvWithHandlerCfg, DebugContext, ExecutionResult, SyncBlock, TxEnv, + CfgEnvWithHandlerCfg, DebugContext, ExecutionResult, Precompile, SyncBlock, TxEnv, }; use itertools::Itertools; @@ -24,6 +27,7 @@ pub(super) struct CheckGasLimitArgs<'a> { pub cfg_env: CfgEnvWithHandlerCfg, pub tx_env: TxEnv, pub gas_limit: u64, + pub precompiles: &'a HashMap, pub trace_collector: &'a mut TraceCollector, } @@ -41,6 +45,7 @@ pub(super) fn check_gas_limit( cfg_env, mut tx_env, gas_limit, + precompiles, trace_collector, } = args; @@ -53,6 +58,7 @@ pub(super) fn check_gas_limit( state_overrides, cfg_env, tx_env, + precompiles, debug_context: Some(DebugContext { data: trace_collector, register_handles_fn: register_trace_collector_handles, @@ -71,6 +77,7 @@ pub(super) struct BinarySearchEstimationArgs<'a> { pub tx_env: TxEnv, pub lower_bound: u64, pub upper_bound: u64, + pub precompiles: &'a HashMap, pub trace_collector: &'a mut TraceCollector, } @@ -91,6 +98,7 @@ pub(super) fn binary_search_estimation( tx_env, mut lower_bound, mut upper_bound, + precompiles, trace_collector, } = args; @@ -113,6 +121,7 @@ pub(super) fn binary_search_estimation( cfg_env: cfg_env.clone(), tx_env: tx_env.clone(), gas_limit: mid, + precompiles, trace_collector, })?; diff --git a/crates/edr_provider/src/debugger.rs b/crates/edr_provider/src/debugger.rs index bc7a0613f..529ae2673 100644 --- a/crates/edr_provider/src/debugger.rs +++ b/crates/edr_provider/src/debugger.rs @@ -12,7 +12,7 @@ use crate::{ mock::{register_mocking_handles, Mocker}, }; -/// Registers the EIP-3155 tracer handles. +/// Registers debugger handles. pub fn register_debugger_handles( handler: &mut EvmHandler<'_, ContextT, DatabaseT>, ) where diff --git a/crates/edr_provider/src/error.rs b/crates/edr_provider/src/error.rs index d0aa1b991..2ebbdacc5 100644 --- a/crates/edr_provider/src/error.rs +++ b/crates/edr_provider/src/error.rs @@ -376,7 +376,7 @@ impl TransactionFailure { pub fn halt(halt: HaltReason, tx_hash: Option, solidity_trace: Trace) -> Self { let reason = match halt { - HaltReason::OpcodeNotFound | HaltReason::InvalidEFOpcode => { + HaltReason::OpcodeNotFound | HaltReason::InvalidFEOpcode => { TransactionFailureReason::OpcodeNotFound } HaltReason::OutOfGas(error) => TransactionFailureReason::OutOfGas(error), diff --git a/crates/edr_provider/src/pending.rs b/crates/edr_provider/src/pending.rs index 030eb4526..f7cfd420d 100644 --- a/crates/edr_provider/src/pending.rs +++ b/crates/edr_provider/src/pending.rs @@ -217,8 +217,8 @@ impl<'blockchain> BlockchainMut for BlockchainWithPending<'blockcha impl<'blockchain> BlockHashRef for BlockchainWithPending<'blockchain> { type Error = BlockchainError; - fn block_hash(&self, number: U256) -> Result { - if number == U256::from(self.pending_block.header().number) { + fn block_hash(&self, number: u64) -> Result { + if number == self.pending_block.header().number { Ok(*self.pending_block.hash()) } else { self.blockchain.block_hash(number) diff --git a/crates/edr_provider/src/requests/eth/transactions.rs b/crates/edr_provider/src/requests/eth/transactions.rs index 23c434e08..dad5dfd29 100644 --- a/crates/edr_provider/src/requests/eth/transactions.rs +++ b/crates/edr_provider/src/requests/eth/transactions.rs @@ -226,6 +226,12 @@ pub fn transaction_to_rpc_result( block_data.as_ref().map(|bd| bd.transaction_index) }; + let access_list = if transaction.transaction_type() >= TransactionType::Eip2930 { + Some(transaction.access_list().to_vec()) + } else { + None + }; + Ok(edr_rpc_eth::Transaction { hash: *transaction.transaction_hash(), nonce: transaction.nonce(), @@ -245,9 +251,7 @@ pub fn transaction_to_rpc_result( s: signature.s(), chain_id, transaction_type: transaction_type.map(u64::from), - access_list: transaction - .access_list() - .map(|access_list| access_list.clone().into()), + access_list, max_fee_per_gas: transaction.max_fee_per_gas(), max_priority_fee_per_gas: transaction.max_priority_fee_per_gas(), max_fee_per_blob_gas: transaction.max_fee_per_blob_gas(), diff --git a/crates/edr_provider/src/requests/validation.rs b/crates/edr_provider/src/requests/validation.rs index 9e88c98f8..91d3417fb 100644 --- a/crates/edr_provider/src/requests/validation.rs +++ b/crates/edr_provider/src/requests/validation.rs @@ -1,9 +1,8 @@ use core::fmt::Debug; use edr_eth::{ - access_list::AccessListItem, transaction::{self, EthTransactionRequest}, - Address, BlockSpec, BlockTag, PreEip1898BlockSpec, SpecId, B256, U256, + AccessListItem, Address, BlockSpec, BlockTag, PreEip1898BlockSpec, SpecId, B256, U256, }; use edr_evm::Bytes; use edr_rpc_eth::CallRequest; diff --git a/crates/edr_provider/src/test_utils.rs b/crates/edr_provider/src/test_utils.rs index 4ac720415..2367cca1b 100644 --- a/crates/edr_provider/src/test_utils.rs +++ b/crates/edr_provider/src/test_utils.rs @@ -65,6 +65,7 @@ pub fn create_test_config_with_fork(fork: Option) -> ProviderConfig chain_id: 123, chains: HashMap::new(), coinbase: Address::from(U160::from(1)), + enable_rip_7212: false, fork, genesis_accounts: HashMap::new(), hardfork: SpecId::LATEST, diff --git a/crates/edr_provider/tests/eip4844.rs b/crates/edr_provider/tests/eip4844.rs index 1ccd273a6..e68cadad1 100644 --- a/crates/edr_provider/tests/eip4844.rs +++ b/crates/edr_provider/tests/eip4844.rs @@ -8,6 +8,7 @@ use edr_eth::{ signature::{secret_key_from_str, secret_key_to_address}, transaction::{ self, pooled::PooledTransaction, EthTransactionRequest, SignedTransaction, Transaction, + TransactionType, }, AccountInfo, Address, Blob, Bytes, Bytes48, PreEip1898BlockSpec, SpecId, B256, BYTES_PER_BLOB, U256, @@ -149,6 +150,12 @@ fn fake_call_request() -> anyhow::Result { let transaction = transaction.into_payload(); let from = transaction.caller(); + let access_list = if transaction.transaction_type() >= TransactionType::Eip2930 { + Some(transaction.access_list().to_vec()) + } else { + None + }; + Ok(CallRequest { from: Some(*from), to: transaction.kind().to().copied(), @@ -157,9 +164,7 @@ fn fake_call_request() -> anyhow::Result { gas: Some(transaction.gas_limit()), value: Some(transaction.value()), data: Some(transaction.data().clone()), - access_list: transaction - .access_list() - .map(|access_list| access_list.0.clone()), + access_list, blobs, blob_hashes: transaction.blob_hashes(), ..CallRequest::default() @@ -178,6 +183,12 @@ fn fake_transaction_request() -> EthTransactionRequest { let transaction = transaction.into_payload(); let from = *transaction.caller(); + let access_list = if transaction.transaction_type() >= TransactionType::Eip2930 { + Some(transaction.access_list().to_vec()) + } else { + None + }; + EthTransactionRequest { from, to: transaction.kind().to().copied(), @@ -188,9 +199,7 @@ fn fake_transaction_request() -> EthTransactionRequest { data: Some(transaction.data().clone()), nonce: Some(transaction.nonce()), chain_id: transaction.chain_id(), - access_list: transaction - .access_list() - .map(|access_list| access_list.0.clone()), + access_list, transaction_type: Some(transaction.transaction_type().into()), blobs, blob_hashes: transaction.blob_hashes(), diff --git a/crates/edr_provider/tests/rip7212.rs b/crates/edr_provider/tests/rip7212.rs new file mode 100644 index 000000000..a2d7ab1d9 --- /dev/null +++ b/crates/edr_provider/tests/rip7212.rs @@ -0,0 +1,79 @@ +#![cfg(feature = "test-utils")] + +use edr_eth::Bytes; +use edr_evm::bytes; +use edr_provider::{ + test_utils::create_test_config, time::CurrentTime, MethodInvocation, NoopLogger, Provider, + ProviderRequest, +}; +use edr_rpc_eth::CallRequest; +use revm_precompile::secp256r1; +use tokio::runtime; + +// Example adapted from +// +static CALLDATA: Bytes = bytes!("4cee90eb86eaa050036147a12d49004b6b9c72bd725d39d4785011fe190f0b4da73bd4903f0ce3b639bbbf6e8e80d16931ff4bcf5993d58468e8fb19086e8cac36dbcd03009df8c59286b162af3bd7fcc0450c9aa81be5d10d312af6c66b1d604aebd3099c618202fcfe16ae7770b0c49ab5eadf74b754204a3bb6060e44eff37618b065f9832de4ca6ca971a7a1adc826d0f7c00181a5fb2ddf79ae00b4e10e"); + +#[tokio::test(flavor = "multi_thread")] +async fn rip7212_disabled() -> anyhow::Result<()> { + let mut config = create_test_config(); + config.enable_rip_7212 = false; + + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let response = provider.handle_request(ProviderRequest::Single(MethodInvocation::Call( + CallRequest { + to: Some(*secp256r1::P256VERIFY.address()), + data: Some(CALLDATA.clone()), + ..CallRequest::default() + }, + None, + None, + )))?; + + assert_eq!(response.result, "0x"); + + Ok(()) +} + +#[tokio::test(flavor = "multi_thread")] +async fn rip7212_enabled() -> anyhow::Result<()> { + let mut config = create_test_config(); + config.enable_rip_7212 = true; + + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let response = provider.handle_request(ProviderRequest::Single(MethodInvocation::Call( + CallRequest { + to: Some(*secp256r1::P256VERIFY.address()), + data: Some(CALLDATA.clone()), + ..CallRequest::default() + }, + None, + None, + )))?; + + // 1 gwei in hex + assert_eq!( + response.result, + "0x0000000000000000000000000000000000000000000000000000000000000001" + ); + + Ok(()) +} diff --git a/crates/edr_rpc_eth/src/call_request.rs b/crates/edr_rpc_eth/src/call_request.rs index 2965a5b1c..5e722d3aa 100644 --- a/crates/edr_rpc_eth/src/call_request.rs +++ b/crates/edr_rpc_eth/src/call_request.rs @@ -1,4 +1,4 @@ -use edr_eth::{access_list::AccessListItem, Address, Bytes, B256, U256}; +use edr_eth::{AccessListItem, Address, Bytes, B256, U256}; /// For specifying input to methods requiring a transaction object, like /// `eth_call` and `eth_estimateGas` diff --git a/crates/edr_rpc_eth/src/transaction.rs b/crates/edr_rpc_eth/src/transaction.rs index 73759d7c3..facf132fe 100644 --- a/crates/edr_rpc_eth/src/transaction.rs +++ b/crates/edr_rpc_eth/src/transaction.rs @@ -1,10 +1,9 @@ use std::sync::OnceLock; use edr_eth::{ - access_list::AccessListItem, signature, transaction::{self, TxKind}, - Address, Bytes, B256, U256, + AccessListItem, Address, Bytes, B256, U256, }; /// RPC transaction diff --git a/package.json b/package.json index 59af888f9..10560e8ea 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "pnpm": { "overrides": { "hardhat>@nomicfoundation/edr": "workspace:*" + }, + "patchedDependencies": { + "hardhat@2.22.6": "patches/hardhat@2.22.6.patch" } }, "engines": { diff --git a/patches/hardhat@2.22.6.patch b/patches/hardhat@2.22.6.patch new file mode 100644 index 000000000..ae789e07b --- /dev/null +++ b/patches/hardhat@2.22.6.patch @@ -0,0 +1,24 @@ +diff --git a/internal/hardhat-network/provider/provider.js b/internal/hardhat-network/provider/provider.js +index 6564b3c6687c6371e422eaacd76a6ef6e7fd8a36..c08257afe197482cd3b86f840364693a5a5943ae 100644 +--- a/internal/hardhat-network/provider/provider.js ++++ b/internal/hardhat-network/provider/provider.js +@@ -152,6 +152,7 @@ class EdrProviderWrapper extends events_1.EventEmitter { + }), + cacheDir: config.forkCachePath, + coinbase: Buffer.from(coinbase.slice(2), "hex"), ++ enableRip7212: false, + fork, + hardfork: (0, convertToEdr_1.ethereumsjsHardforkToEdrSpecId)(hardforkName), + genesisAccounts: config.genesisAccounts.map((account) => { +diff --git a/src/internal/hardhat-network/provider/provider.ts b/src/internal/hardhat-network/provider/provider.ts +index 4f1197ec3e27c8e0584276629b6783add9687573..e53dc2b3e13e900f04886187f970ed56d7a654dd 100644 +--- a/src/internal/hardhat-network/provider/provider.ts ++++ b/src/internal/hardhat-network/provider/provider.ts +@@ -256,6 +256,7 @@ export class EdrProviderWrapper + }), + cacheDir: config.forkCachePath, + coinbase: Buffer.from(coinbase.slice(2), "hex"), ++ enableRip7212: false, + fork, + hardfork: ethereumsjsHardforkToEdrSpecId(hardforkName), + genesisAccounts: config.genesisAccounts.map((account) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6bec71d83..173cf1aff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: hardhat>@nomicfoundation/edr: workspace:* +patchedDependencies: + hardhat@2.22.6: + hash: 46xqq2jqpyv7s7uwk7ku3nraji + path: patches/hardhat@2.22.6.patch + importers: .: @@ -61,7 +66,7 @@ importers: version: 4.4.1 hardhat: specifier: 2.22.6 - version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash: specifier: ^4.17.11 version: 4.17.21 @@ -181,7 +186,7 @@ importers: version: 7.0.1 hardhat: specifier: 2.22.6 - version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -211,10 +216,10 @@ importers: devDependencies: '@defi-wonderland/smock': specifier: ^2.4.0 - version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) '@nomiclabs/hardhat-ethers': specifier: ^2.2.3 - version: 2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) chai: specifier: ^4.3.6 version: 4.4.1 @@ -223,7 +228,7 @@ importers: version: 5.7.2 hardhat: specifier: 2.22.6 - version: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -3077,16 +3082,16 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: '@ethersproject/abi': 5.7.0 '@ethersproject/abstract-provider': 5.7.0 '@ethersproject/abstract-signer': 5.7.0 '@nomicfoundation/ethereumjs-util': 9.0.4 - '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) diff: 5.0.0 ethers: 5.7.2 - hardhat: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash.isequal: 4.5.0 lodash.isequalwith: 4.4.0 rxjs: 7.8.1 @@ -3597,10 +3602,10 @@ snapshots: '@nomicfoundation/solidity-analyzer-win32-ia32-msvc': 0.1.1 '@nomicfoundation/solidity-analyzer-win32-x64-msvc': 0.1.1 - '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: ethers: 5.7.2 - hardhat: 2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) '@scure/base@1.1.5': {} @@ -4867,7 +4872,7 @@ snapshots: hard-rejection@2.1.0: {} - hardhat@2.22.6(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): + hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): dependencies: '@ethersproject/abi': 5.7.0 '@metamask/eth-sig-util': 4.0.1 From 7aa2f61a3a1852cef7e812ec9ab9538752aa615b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 17 Jul 2024 14:45:22 +0200 Subject: [PATCH 14/54] edr-0.5.0 (#555) Co-authored-by: github-actions[bot] --- .changeset/neat-actors-call.md | 5 ----- crates/edr_napi/CHANGELOG.md | 6 ++++++ crates/edr_napi/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .changeset/neat-actors-call.md diff --git a/.changeset/neat-actors-call.md b/.changeset/neat-actors-call.md deleted file mode 100644 index 8aeb49bcd..000000000 --- a/.changeset/neat-actors-call.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": minor ---- - -Added support for RIP-7212 by enabling it in the provider configuration diff --git a/crates/edr_napi/CHANGELOG.md b/crates/edr_napi/CHANGELOG.md index 1ec9b03dc..5d3969b6a 100644 --- a/crates/edr_napi/CHANGELOG.md +++ b/crates/edr_napi/CHANGELOG.md @@ -1,5 +1,11 @@ # @nomicfoundation/edr +## 0.5.0 + +### Minor Changes + +- 07c7667: Added support for RIP-7212 by enabling it in the provider configuration + ## 0.4.2 ### Patch Changes diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 84da2e6da..32953ad90 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/edr", - "version": "0.4.2", + "version": "0.5.0", "main": "index.js", "types": "index.d.ts", "files": [ From e02eb227afb5b2096c6eee1637db1258d0881e94 Mon Sep 17 00:00:00 2001 From: Wodann Date: Thu, 18 Jul 2024 09:14:33 -0500 Subject: [PATCH 15/54] build: upgrade revm to v12 (#557) * build: upgrade revm to v12 * test: remove invalid test * misc: add changeset --- .changeset/thick-impalas-sparkle.md | 5 +++ Cargo.lock | 31 +++++++++-------- crates/edr_eth/Cargo.toml | 3 +- crates/edr_evm/Cargo.toml | 3 +- crates/edr_provider/Cargo.toml | 3 +- .../provider/modules/eth/hardforks.ts | 33 ------------------- 6 files changed, 26 insertions(+), 52 deletions(-) create mode 100644 .changeset/thick-impalas-sparkle.md diff --git a/.changeset/thick-impalas-sparkle.md b/.changeset/thick-impalas-sparkle.md new file mode 100644 index 000000000..940607e36 --- /dev/null +++ b/.changeset/thick-impalas-sparkle.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Fixed a bug in the JSON-RPC where we previously allowed a null value for storage keys of an access list diff --git a/Cargo.lock b/Cargo.lock index 22c57f851..fca0a7c21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -64,14 +64,15 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f76ecab54890cdea1e4808fc0891c7e6cfcf71fe1a9fe26810c7280ef768f4ed" +checksum = "d32a3e14fa0d152d00bd8daf605eb74ad397efb0f54bd7155585823dddb4401e" dependencies = [ "alloy-primitives 0.7.7", "alloy-rlp", "alloy-serde", "c-kzg", + "k256", "once_cell", "serde", ] @@ -156,9 +157,9 @@ dependencies = [ [[package]] name = "alloy-serde" -version = "0.1.4" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9416c52959e66ead795a11f4a86c248410e9e368a0765710e57055b8a1774dd6" +checksum = "15c5b9057acc02aee1b8aac2b5a0729cb0f73d080082c111313e5d1f92a96630" dependencies = [ "alloy-primitives 0.7.7", "serde", @@ -1986,7 +1987,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.4", ] [[package]] @@ -2915,8 +2916,9 @@ dependencies = [ [[package]] name = "revm" -version = "11.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" +version = "12.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6cfb48bce8ca2113e157bdbddbd5eeb09daac1c903d79ec17085897c38c7c91" dependencies = [ "auto_impl", "cfg-if", @@ -2929,8 +2931,9 @@ dependencies = [ [[package]] name = "revm-interpreter" -version = "7.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" +version = "8.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6b0daddea06fc6da5346acc39b32a357bbe3579e9e3d94117d9ae125cd596fc" dependencies = [ "revm-primitives", "serde", @@ -2938,8 +2941,9 @@ dependencies = [ [[package]] name = "revm-precompile" -version = "9.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" +version = "9.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef55228211251d7b6c7707c3ee13bb70dea4d2fd81ec4034521e4fe31010b2ea" dependencies = [ "aurora-engine-modexp", "c-kzg", @@ -2956,8 +2960,9 @@ dependencies = [ [[package]] name = "revm-primitives" -version = "6.0.0" -source = "git+https://github.com/NomicFoundation/revm?rev=be50b38#be50b38d386419595d82563f8e1cd2f62612ffc7" +version = "7.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2fc4311037ee093ec50ec734e1424fcb3e12d535c6cef683b75d1c064639630c" dependencies = [ "alloy-eips", "alloy-primitives 0.7.7", diff --git a/crates/edr_eth/Cargo.toml b/crates/edr_eth/Cargo.toml index f8a35de55..13678ba18 100644 --- a/crates/edr_eth/Cargo.toml +++ b/crates/edr_eth/Cargo.toml @@ -15,8 +15,7 @@ itertools = { version = "0.10.5", default-features = false, features = ["use_all k256 = { version = "0.13.1", default-features = false, features = ["arithmetic", "ecdsa", "pkcs8", ] } log = { version = "0.4.17", default-features = false } once_cell = { version = "1.18.0", default-features = false, features = ["alloc", "race", "std"] } -# revm-primitives = { version = "5.0", default-features = false, features = ["c-kzg", "hashbrown"] } -revm-primitives = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "6.0", default-features = false, features = ["c-kzg", "hashbrown"] } +revm-primitives = { version = "7.0", default-features = false, features = ["c-kzg", "hashbrown"] } serde = { version = "1.0.147", default-features = false, features = ["derive"], optional = true } sha2 = { version = "0.10.8", default-features = false } sha3 = { version = "0.10.8", default-features = false } diff --git a/crates/edr_evm/Cargo.toml b/crates/edr_evm/Cargo.toml index 493d03ec0..bf5b46232 100644 --- a/crates/edr_evm/Cargo.toml +++ b/crates/edr_evm/Cargo.toml @@ -19,8 +19,7 @@ parking_lot = { version = "0.12.1", default-features = false } edr_defaults = { version = "0.3.5", path = "../edr_defaults" } edr_eth = { version = "0.3.5", path = "../edr_eth", features = ["rand", "serde"] } edr_rpc_eth = { version = "0.3.5", path = "../edr_rpc_eth" } -# revm = { version = "10.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] } -revm = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "11.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] } +revm = { version = "12.0", default-features = false, features = ["c-kzg", "dev", "serde", "std"] } rpds = { version = "1.1.0", default-features = false, features = ["std"] } serde = { version = "1.0.158", default-features = false, features = ["std"] } serde_json = { version = "1.0.94", default-features = false, features = ["std"] } diff --git a/crates/edr_provider/Cargo.toml b/crates/edr_provider/Cargo.toml index fb21b9836..d37c34c86 100644 --- a/crates/edr_provider/Cargo.toml +++ b/crates/edr_provider/Cargo.toml @@ -20,8 +20,7 @@ lazy_static = { version = "1.4.0", default-features = false } log = { version = "0.4.20", default-features = false } parking_lot = { version = "0.12.1", default-features = false } rand = { version = "0.8.5", default-features = false } -# revm-precompile = { version = "8.0", default-features = false, features = ["c-kzg", "secp256r1", "std"] } -revm-precompile = { git = "https://github.com/NomicFoundation/revm", rev = "be50b38", version = "9.0", default-features = false, features = ["c-kzg", "secp256r1", "std"] } +revm-precompile = { version = "9.1", default-features = false, features = ["c-kzg", "secp256r1", "std"] } rpds = { version = "1.1.0", default-features = false, features = ["std"] } serde = { version = "1.0.147", default-features = false, features = ["derive"] } serde_json = { version = "1.0.89" } diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/hardforks.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/hardforks.ts index a20befa08..6e6c46ed3 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/hardforks.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/eth/hardforks.ts @@ -532,39 +532,6 @@ describe("Eth module - hardfork dependant tests", function () { ); assert.deepEqual(tx.accessList, accessList); }); - - it("Should accept access lists with null storageKeys", async function () { - const accessList = [ - { - address: "0x1234567890123456789012345678901234567890", - storageKeys: null, - }, - ]; - const [sender] = await this.provider.send("eth_accounts"); - const txHash = await this.provider.send("eth_sendTransaction", [ - { - from: sender, - to: sender, - accessList, - }, - ]); - - const tx = await this.provider.send("eth_getTransactionByHash", [ - txHash, - ]); - - assert.equal(tx.type, numberToRpcQuantity(1)); - assert.equal( - tx.chainId, - numberToRpcQuantity(this.common.chainId()) - ); - assert.deepEqual(tx.accessList, [ - { - address: "0x1234567890123456789012345678901234567890", - storageKeys: [], - }, - ]); - }); }); }); From 0bba027c0f9aeb80bad0c4c7d270fa38f2db98a0 Mon Sep 17 00:00:00 2001 From: Agost Biro <5764438+agostbiro@users.noreply.github.com> Date: Wed, 31 Jul 2024 09:34:48 +0200 Subject: [PATCH 16/54] fix: use remote chain id for pre-fork simulation (#567) * fix: use remote chain id for pre-fork simulation * Fix error message --- .changeset/fast-kings-search.md | 5 + crates/edr_evm/src/blockchain.rs | 8 ++ crates/edr_evm/src/blockchain/forked.rs | 12 ++ crates/edr_provider/src/data.rs | 110 ++++++++++++++---- crates/edr_provider/src/requests/eth/call.rs | 2 +- crates/edr_provider/tests/issues/issue_533.rs | 44 +++++++ crates/edr_provider/tests/issues/mod.rs | 1 + 7 files changed, 159 insertions(+), 23 deletions(-) create mode 100644 .changeset/fast-kings-search.md create mode 100644 crates/edr_provider/tests/issues/issue_533.rs diff --git a/.changeset/fast-kings-search.md b/.changeset/fast-kings-search.md new file mode 100644 index 000000000..422cdad82 --- /dev/null +++ b/.changeset/fast-kings-search.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Fixed a bug in fork mode where the locally overridden chain id was used instead of the remote chain id when simulating transactions in pre-fork blocks. diff --git a/crates/edr_evm/src/blockchain.rs b/crates/edr_evm/src/blockchain.rs index c044cc3ca..67221f913 100644 --- a/crates/edr_evm/src/blockchain.rs +++ b/crates/edr_evm/src/blockchain.rs @@ -124,6 +124,14 @@ where /// Retrieves the instances chain ID. fn chain_id(&self) -> u64; + /// Retrieves the chain ID of the block at the provided number. + /// The chain ID can be different in fork mode pre- and post-fork block + /// number. + fn chain_id_at_block_number(&self, _block_number: u64) -> Result { + // Chain id only depends on the block number in fork mode + Ok(self.chain_id()) + } + /// Retrieves the last block in the blockchain. fn last_block( &self, diff --git a/crates/edr_evm/src/blockchain/forked.rs b/crates/edr_evm/src/blockchain/forked.rs index f18610cda..302c617e9 100644 --- a/crates/edr_evm/src/blockchain/forked.rs +++ b/crates/edr_evm/src/blockchain/forked.rs @@ -345,6 +345,18 @@ where self.chain_id } + fn chain_id_at_block_number(&self, block_number: u64) -> Result { + if block_number > self.last_block_number() { + return Err(BlockchainError::UnknownBlockNumber); + } + + if block_number <= self.fork_block_number { + Ok(self.remote_chain_id()) + } else { + Ok(self.chain_id()) + } + } + #[cfg_attr(feature = "tracing", tracing::instrument(skip_all))] fn last_block( &self, diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index 339ba4e05..de47217a9 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -591,6 +591,20 @@ impl ProviderData Result> { + let block_number = self.block_number_by_block_spec(block_spec)?; + + let chain_id = if let Some(block_number) = block_number { + self.chain_id_at_block_number(block_number, block_spec)? + } else { + self.blockchain.chain_id() + }; + + Ok(chain_id) + } pub fn coinbase(&self) -> Address { self.beneficiary } @@ -607,9 +621,8 @@ impl ProviderData ProviderData Result> { - let cfg_env = self.create_evm_config(Some(block_spec))?; + let cfg_env = self.create_evm_config_at_block_spec(block_spec)?; let tx_env: TxEnv = transaction.into(); @@ -691,7 +704,7 @@ impl ProviderData Result> { - let cfg_env = self.create_evm_config(Some(block_spec))?; + let cfg_env = self.create_evm_config_at_block_spec(block_spec)?; // Minimum gas cost that is required for transaction to be included in // a block let minimum_cost = transaction::initial_cost(&transaction, self.spec_id()); @@ -1422,7 +1435,7 @@ impl ProviderData Result> { - let cfg_env = self.create_evm_config(Some(block_spec))?; + let cfg_env = self.create_evm_config_at_block_spec(block_spec)?; let tx_env = transaction.into(); let mut debugger = Debugger::with_mocker( @@ -1909,26 +1922,32 @@ impl ProviderData Result> { + self.blockchain + .chain_id_at_block_number(block_number) + .map_err(|err| match err { + BlockchainError::UnknownBlockNumber => ProviderError::InvalidBlockNumberOrHash { + block_spec: block_spec.clone(), + latest_block_number: self.blockchain.last_block_number(), + }, + _ => ProviderError::Blockchain(err), + }) + } + + /// Creates an EVM configuration with the provided hardfork and chain id fn create_evm_config( &self, - block_spec: Option<&BlockSpec>, + spec_id: SpecId, + chain_id: u64, ) -> Result> { - let block_number = block_spec - .map(|block_spec| self.block_number_by_block_spec(block_spec)) - .transpose()? - .flatten(); - - let spec_id = if let Some(block_number) = block_number { - self.blockchain.spec_at_block_number(block_number)? - } else { - self.blockchain.spec_id() - }; - let mut cfg_env = CfgEnv::default(); - cfg_env.chain_id = self.blockchain.chain_id(); + cfg_env.chain_id = chain_id; cfg_env.limit_contract_code_size = if self.allow_unlimited_contract_size { Some(usize::MAX) } else { @@ -1939,6 +1958,29 @@ impl ProviderData Result> { + let block_number = self.block_number_by_block_spec(block_spec)?; + + let spec_id = if let Some(block_number) = block_number { + self.spec_at_block_number(block_number, block_spec)? + } else { + self.blockchain.spec_id() + }; + + let chain_id = if let Some(block_number) = block_number { + self.chain_id_at_block_number(block_number, block_spec)? + } else { + self.blockchain.chain_id() + }; + + self.create_evm_config(spec_id, chain_id) + } + fn execute_in_block_context( &mut self, block_spec: Option<&BlockSpec>, @@ -1995,7 +2037,8 @@ impl ProviderData= SpecId::MERGE { options.mix_hash = Some(self.prev_randao_generator.next_value()); @@ -2228,6 +2271,24 @@ impl ProviderData Result> { + self.blockchain + .spec_at_block_number(block_number) + .map_err(|err| match err { + BlockchainError::UnknownBlockNumber => ProviderError::InvalidBlockNumberOrHash { + block_spec: block_spec.clone(), + latest_block_number: self.blockchain.last_block_number(), + }, + _ => ProviderError::Blockchain(err), + }) + } + pub fn sign_transaction_request( &self, transaction_request: TransactionRequestAndSender, @@ -2979,6 +3040,11 @@ mod tests { let chain_id = fixture.provider_data.chain_id(); assert_eq!(chain_id, fixture.config.chain_id); + let chain_id_at_block = fixture + .provider_data + .chain_id_at_block_spec(&BlockSpec::Number(1))?; + assert_eq!(chain_id_at_block, 1); + Ok(()) } diff --git a/crates/edr_provider/src/requests/eth/call.rs b/crates/edr_provider/src/requests/eth/call.rs index c9aead4bc..07405016e 100644 --- a/crates/edr_provider/src/requests/eth/call.rs +++ b/crates/edr_provider/src/requests/eth/call.rs @@ -103,7 +103,7 @@ pub(crate) fn resolve_call_request_inner anyhow::Result<()> { + let logger = Box::new(NoopLogger); + let subscriber = Box::new(|_event| {}); + + let mut config = create_test_config_with_fork(Some(ForkConfig { + json_rpc_url: get_alchemy_url(), + block_number: Some(20_384_300), + http_headers: None, + })); + + // The default chain id set by Hardhat + config.chain_id = 31337; + + let provider = Provider::new( + runtime::Handle::current(), + logger, + subscriber, + config, + CurrentTime, + )?; + + let transaction_hash = + B256::from_str("0x0537316f37627655b7fe5e50e23f71cd835b377d1cde4226443c94723d036e32")?; + + let result = provider.handle_request(ProviderRequest::Single( + MethodInvocation::DebugTraceTransaction(transaction_hash, None), + ))?; + + assert!(!result.traces.is_empty()); + + Ok(()) +} diff --git a/crates/edr_provider/tests/issues/mod.rs b/crates/edr_provider/tests/issues/mod.rs index 851af44a3..3dcc1a2d2 100644 --- a/crates/edr_provider/tests/issues/mod.rs +++ b/crates/edr_provider/tests/issues/mod.rs @@ -9,3 +9,4 @@ mod issue_361; mod issue_384; mod issue_407; mod issue_503; +mod issue_533; From 37e2737cc6b50cfb994942ccf02186187fed3319 Mon Sep 17 00:00:00 2001 From: Igor Matuszewski Date: Wed, 31 Jul 2024 10:44:47 +0200 Subject: [PATCH 17/54] chore: Bump hardhat to 2.22.7 (#571) * chore: Bump hardhat to 2.22.7 * fixup: Don't enable RIP-7212 in our tests * Adapt for NomicFoundation/hardhat#5411 --- crates/tools/js/benchmark/package.json | 2 +- hardhat-tests/integration/smock/package.json | 2 +- hardhat-tests/package.json | 2 +- .../hardhat-network/helpers/useProvider.ts | 1 + .../modules/debug/traceTransaction.ts | 2 + .../hardhat-network/stack-traces/execution.ts | 1 + .../hardhat-network/stack-traces/test.ts | 10 ++--- package.json | 3 -- patches/hardhat@2.22.6.patch | 24 ----------- pnpm-lock.yaml | 43 ++++++++++--------- 10 files changed, 34 insertions(+), 56 deletions(-) delete mode 100644 patches/hardhat@2.22.6.patch diff --git a/crates/tools/js/benchmark/package.json b/crates/tools/js/benchmark/package.json index e8a4d916d..a66072a39 100644 --- a/crates/tools/js/benchmark/package.json +++ b/crates/tools/js/benchmark/package.json @@ -18,7 +18,7 @@ "devDependencies": { "argparse": "^2.0.1", "chai": "^4.2.0", - "hardhat": "2.22.6", + "hardhat": "2.22.7", "lodash": "^4.17.11", "mocha": "^10.0.0", "tsx": "^4.7.1" diff --git a/hardhat-tests/integration/smock/package.json b/hardhat-tests/integration/smock/package.json index 9d387a38b..645f54f0f 100644 --- a/hardhat-tests/integration/smock/package.json +++ b/hardhat-tests/integration/smock/package.json @@ -12,7 +12,7 @@ "@nomiclabs/hardhat-ethers": "^2.2.3", "chai": "^4.3.6", "ethers": "5", - "hardhat": "2.22.6", + "hardhat": "2.22.7", "mocha": "^10.0.0" } } diff --git a/hardhat-tests/package.json b/hardhat-tests/package.json index 8933b039e..d010700f5 100644 --- a/hardhat-tests/package.json +++ b/hardhat-tests/package.json @@ -54,7 +54,7 @@ "ethereumjs-abi": "^0.6.8", "ethers": "^6.1.0", "fs-extra": "^7.0.1", - "hardhat": "2.22.6", + "hardhat": "2.22.7", "mocha": "^10.0.0", "prettier": "2.4.1", "rimraf": "^3.0.2", diff --git a/hardhat-tests/test/internal/hardhat-network/helpers/useProvider.ts b/hardhat-tests/test/internal/hardhat-network/helpers/useProvider.ts index ebc22185f..36682b8b6 100644 --- a/hardhat-tests/test/internal/hardhat-network/helpers/useProvider.ts +++ b/hardhat-tests/test/internal/hardhat-network/helpers/useProvider.ts @@ -101,6 +101,7 @@ export function useProvider({ coinbase, allowBlocksWithSameTimestamp, enableTransientStorage: false, + enableRip7212: false, }, { enabled: loggerEnabled, diff --git a/hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceTransaction.ts b/hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceTransaction.ts index e7598e7cf..a65250b6a 100644 --- a/hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceTransaction.ts +++ b/hardhat-tests/test/internal/hardhat-network/provider/modules/debug/traceTransaction.ts @@ -257,6 +257,7 @@ describe("Debug module", function () { forkCachePath: FORK_TESTS_CACHE_PATH, allowBlocksWithSameTimestamp: false, enableTransientStorage: false, + enableRip7212: false, }, { enabled: false, @@ -382,6 +383,7 @@ describe("Debug module", function () { forkCachePath: FORK_TESTS_CACHE_PATH, allowBlocksWithSameTimestamp: false, enableTransientStorage: false, + enableRip7212: false, }, { enabled: false, diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts b/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts index 24f9b4719..551f60c03 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/execution.ts @@ -53,6 +53,7 @@ export async function instantiateProvider( coinbase: "0x0000000000000000000000000000000000000000", initialBaseFeePerGas: 0, enableTransientStorage: false, + enableRip7212: false, }; const provider = await EdrProviderWrapper.create( diff --git a/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts b/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts index 6491bf474..fe1d57d61 100644 --- a/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts +++ b/hardhat-tests/test/internal/hardhat-network/stack-traces/test.ts @@ -6,7 +6,7 @@ import { EdrProviderWrapper } from "hardhat/internal/hardhat-network/provider/pr import { ReturnData } from "hardhat/internal/hardhat-network/provider/return-data"; import { ConsoleLogs, - consoleLogToString, + ConsoleLogger, } from "hardhat/internal/hardhat-network/stack-traces/consoleLogger"; import { printMessageTrace, @@ -93,7 +93,7 @@ interface DeploymentTransaction { }; stackTrace?: StackFrameDescription[]; // No stack trace === the tx MUST be successful imports?: string[]; // Imports needed for successful compilation - consoleLogs?: ConsoleLogs[]; + consoleLogs?: ConsoleLogs; gas?: number; } @@ -108,7 +108,7 @@ interface CallTransaction { // The second one is with function and parms function?: string; // Default: no data params?: Array; // Default: no param - consoleLogs?: ConsoleLogs[]; + consoleLogs?: ConsoleLogs; gas?: number; } @@ -437,7 +437,7 @@ function compareStackTraces( assert.lengthOf(trace, description.length); } -function compareConsoleLogs(logs: string[], expectedLogs?: ConsoleLogs[]) { +function compareConsoleLogs(logs: string[], expectedLogs?: ConsoleLogs) { if (expectedLogs === undefined) { return; } @@ -446,7 +446,7 @@ function compareConsoleLogs(logs: string[], expectedLogs?: ConsoleLogs[]) { for (let i = 0; i < logs.length; i++) { const actual = logs[i]; - const expected = consoleLogToString(expectedLogs[i]); + const expected = ConsoleLogger.format(expectedLogs[i]); assert.equal(actual, expected); } diff --git a/package.json b/package.json index 10560e8ea..59af888f9 100644 --- a/package.json +++ b/package.json @@ -16,9 +16,6 @@ "pnpm": { "overrides": { "hardhat>@nomicfoundation/edr": "workspace:*" - }, - "patchedDependencies": { - "hardhat@2.22.6": "patches/hardhat@2.22.6.patch" } }, "engines": { diff --git a/patches/hardhat@2.22.6.patch b/patches/hardhat@2.22.6.patch deleted file mode 100644 index ae789e07b..000000000 --- a/patches/hardhat@2.22.6.patch +++ /dev/null @@ -1,24 +0,0 @@ -diff --git a/internal/hardhat-network/provider/provider.js b/internal/hardhat-network/provider/provider.js -index 6564b3c6687c6371e422eaacd76a6ef6e7fd8a36..c08257afe197482cd3b86f840364693a5a5943ae 100644 ---- a/internal/hardhat-network/provider/provider.js -+++ b/internal/hardhat-network/provider/provider.js -@@ -152,6 +152,7 @@ class EdrProviderWrapper extends events_1.EventEmitter { - }), - cacheDir: config.forkCachePath, - coinbase: Buffer.from(coinbase.slice(2), "hex"), -+ enableRip7212: false, - fork, - hardfork: (0, convertToEdr_1.ethereumsjsHardforkToEdrSpecId)(hardforkName), - genesisAccounts: config.genesisAccounts.map((account) => { -diff --git a/src/internal/hardhat-network/provider/provider.ts b/src/internal/hardhat-network/provider/provider.ts -index 4f1197ec3e27c8e0584276629b6783add9687573..e53dc2b3e13e900f04886187f970ed56d7a654dd 100644 ---- a/src/internal/hardhat-network/provider/provider.ts -+++ b/src/internal/hardhat-network/provider/provider.ts -@@ -256,6 +256,7 @@ export class EdrProviderWrapper - }), - cacheDir: config.forkCachePath, - coinbase: Buffer.from(coinbase.slice(2), "hex"), -+ enableRip7212: false, - fork, - hardfork: ethereumsjsHardforkToEdrSpecId(hardforkName), - genesisAccounts: config.genesisAccounts.map((account) => { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 173cf1aff..68a57d357 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,11 +7,6 @@ settings: overrides: hardhat>@nomicfoundation/edr: workspace:* -patchedDependencies: - hardhat@2.22.6: - hash: 46xqq2jqpyv7s7uwk7ku3nraji - path: patches/hardhat@2.22.6.patch - importers: .: @@ -65,8 +60,8 @@ importers: specifier: ^4.2.0 version: 4.4.1 hardhat: - specifier: 2.22.6 - version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.7 + version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash: specifier: ^4.17.11 version: 4.17.21 @@ -185,8 +180,8 @@ importers: specifier: ^7.0.1 version: 7.0.1 hardhat: - specifier: 2.22.6 - version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.7 + version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -216,10 +211,10 @@ importers: devDependencies: '@defi-wonderland/smock': specifier: ^2.4.0 - version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) '@nomiclabs/hardhat-ethers': specifier: ^2.2.3 - version: 2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) chai: specifier: ^4.3.6 version: 4.4.1 @@ -227,8 +222,8 @@ importers: specifier: '5' version: 5.7.2 hardhat: - specifier: 2.22.6 - version: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + specifier: 2.22.7 + version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -577,6 +572,7 @@ packages: '@humanwhocodes/config-array@0.11.14': resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} engines: {node: '>=10.10.0'} + deprecated: Use @eslint/config-array instead '@humanwhocodes/module-importer@1.0.1': resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} @@ -584,6 +580,7 @@ packages: '@humanwhocodes/object-schema@2.0.3': resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} + deprecated: Use @eslint/object-schema instead '@jridgewell/resolve-uri@3.1.2': resolution: {integrity: sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==} @@ -1693,10 +1690,12 @@ packages: glob@7.2.0: resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} + deprecated: Glob versions prior to v9 are no longer supported glob@8.1.0: resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==} engines: {node: '>=12'} + deprecated: Glob versions prior to v9 are no longer supported globals@13.24.0: resolution: {integrity: sha512-AhO5QUcj8llrbG09iWhPU2B204J1xnPeL8kQmVorSsy+Sjj1sk8gIyh6cUocGmH4L0UuhAJy+hJMRA4mgA4mFQ==} @@ -1726,8 +1725,8 @@ packages: resolution: {integrity: sha512-VIZB+ibDhx7ObhAe7OVtoEbuP4h/MuOTHJ+J8h/eBXotJYl0fBgR72xDFCKgIh22OJZIOVNxBMWuhAr10r8HdA==} engines: {node: '>=6'} - hardhat@2.22.6: - resolution: {integrity: sha512-abFEnd9QACwEtSvZZGSmzvw7N3zhQN1cDKz5SLHAupfG24qTHofCjqvD5kT5Wwsq5XOL0ON1Mq5rr4v0XX5ciw==} + hardhat@2.22.7: + resolution: {integrity: sha512-nrXQAl+qUr75TsCLDo8P41YXLc+5U7qQMMCIrbbmy1/uQaVPncdjDrD5BR0CENvHRj7EBqO+JkofpozXoIfJKg==} hasBin: true peerDependencies: ts-node: '*' @@ -1825,6 +1824,7 @@ packages: inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -2410,6 +2410,7 @@ packages: rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} + deprecated: Rimraf versions prior to v4 are no longer supported hasBin: true ripemd160@2.0.2: @@ -3082,16 +3083,16 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: '@ethersproject/abi': 5.7.0 '@ethersproject/abstract-provider': 5.7.0 '@ethersproject/abstract-signer': 5.7.0 '@nomicfoundation/ethereumjs-util': 9.0.4 - '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) diff: 5.0.0 ethers: 5.7.2 - hardhat: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash.isequal: 4.5.0 lodash.isequalwith: 4.4.0 rxjs: 7.8.1 @@ -3602,10 +3603,10 @@ snapshots: '@nomicfoundation/solidity-analyzer-win32-ia32-msvc': 0.1.1 '@nomicfoundation/solidity-analyzer-win32-x64-msvc': 0.1.1 - '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: ethers: 5.7.2 - hardhat: 2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) '@scure/base@1.1.5': {} @@ -4872,7 +4873,7 @@ snapshots: hard-rejection@2.1.0: {} - hardhat@2.22.6(patch_hash=46xqq2jqpyv7s7uwk7ku3nraji)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): + hardhat@2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): dependencies: '@ethersproject/abi': 5.7.0 '@metamask/eth-sig-util': 4.0.1 From 8ae31b90584fd61c4073bf335ecb13c4550fa438 Mon Sep 17 00:00:00 2001 From: Wodann Date: Thu, 1 Aug 2024 08:27:18 -0500 Subject: [PATCH 18/54] fix: prevent crash when returning large JSON responses (#569) --- .changeset/two-starfishes-obey.md | 5 ++ crates/edr_napi/index.d.ts | 3 +- crates/edr_napi/package.json | 5 +- crates/edr_napi/src/provider.rs | 37 +++++++--- crates/edr_napi/test/helpers.ts | 17 +++++ crates/edr_napi/test/issues.ts | 109 +++++++++++++++++++++++++++++ crates/edr_napi/test/provider.ts | 25 +++---- crates/tools/js/benchmark/index.js | 28 ++++---- package.json | 3 + patches/hardhat@2.22.7.patch | 77 ++++++++++++++++++++ pnpm-lock.yaml | 36 +++++++--- 11 files changed, 293 insertions(+), 52 deletions(-) create mode 100644 .changeset/two-starfishes-obey.md create mode 100644 crates/edr_napi/test/issues.ts create mode 100644 patches/hardhat@2.22.7.patch diff --git a/.changeset/two-starfishes-obey.md b/.changeset/two-starfishes-obey.md new file mode 100644 index 000000000..629d241f5 --- /dev/null +++ b/.changeset/two-starfishes-obey.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Fixed crash when returning large JSON responses diff --git a/crates/edr_napi/index.d.ts b/crates/edr_napi/index.d.ts index 621ee25fd..d19f66225 100644 --- a/crates/edr_napi/index.d.ts +++ b/crates/edr_napi/index.d.ts @@ -418,7 +418,8 @@ export class Provider { setVerboseTracing(verboseTracing: boolean): void } export class Response { - get json(): string + /** Returns the response data as a JSON string or a JSON object. */ + get data(): string | any get solidityTrace(): RawTrace | null get traces(): Array } diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 32953ad90..a460e5bea 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -38,6 +38,7 @@ "@types/node": "^18.0.0", "chai": "^4.3.6", "chai-as-promised": "^7.1.1", + "json-stream-stringify": "^3.1.4", "mocha": "^10.0.0", "ts-node": "^10.8.0", "typescript": "~4.5.2" @@ -55,8 +56,8 @@ "universal": "napi universal", "version": "napi version", "pretest": "pnpm build", - "test": "pnpm tsc && mocha --recursive \"test/**/*.ts\"", - "testNoBuild": "pnpm tsc && mocha --recursive \"test/**/*.ts\"", + "test": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", + "testNoBuild": "pnpm tsc && node --max-old-space-size=8192 node_modules/mocha/bin/_mocha --recursive \"test/**/*.ts\"", "clean": "rm -rf @nomicfoundation/edr.node" } } diff --git a/crates/edr_napi/src/provider.rs b/crates/edr_napi/src/provider.rs index 7116b5091..062fb3fa4 100644 --- a/crates/edr_napi/src/provider.rs +++ b/crates/edr_napi/src/provider.rs @@ -4,7 +4,7 @@ use std::sync::Arc; use edr_provider::{time::CurrentTime, InvalidRequestReason}; use edr_rpc_eth::jsonrpc; -use napi::{tokio::runtime, Env, JsFunction, JsObject, Status}; +use napi::{tokio::runtime, Either, Env, JsFunction, JsObject, Status}; use napi_derive::napi; use self::config::ProviderConfig; @@ -120,9 +120,9 @@ impl Provider { format!("Invalid JSON `{json_request}` due to: {error}"), ) }) - .map(|json_response| Response { + .map(|json| Response { solidity_trace: None, - json: json_response, + data: Either::A(json), traces: Vec::new(), }); } @@ -168,10 +168,25 @@ impl Provider { let response = jsonrpc::ResponseData::from(response.map(|response| response.result)); serde_json::to_string(&response) - .map_err(|e| napi::Error::new(Status::GenericFailure, e.to_string())) - .map(|json_response| Response { + .and_then(|json| { + // We experimentally determined that 500_000_000 was the maximum string length + // that can be returned without causing the error: + // + // > Failed to convert rust `String` into napi `string` + // + // To be safe, we're limiting string lengths to half of that. + const MAX_STRING_LENGTH: usize = 250_000_000; + + if json.len() <= MAX_STRING_LENGTH { + Ok(Either::A(json)) + } else { + serde_json::to_value(response).map(Either::B) + } + }) + .map_err(|error| napi::Error::new(Status::GenericFailure, error.to_string())) + .map(|data| Response { solidity_trace, - json: json_response, + data, traces: traces.into_iter().map(Arc::new).collect(), }) } @@ -209,7 +224,10 @@ impl Provider { #[napi] pub struct Response { - json: String, + // N-API is known to be slow when marshalling `serde_json::Value`s, so we try to return a + // `String`. If the object is too large to be represented as a `String`, we return a `Buffer` + // instead. + data: Either, /// When a transaction fails to execute, the provider returns a trace of the /// transaction. solidity_trace: Option>, @@ -219,9 +237,10 @@ pub struct Response { #[napi] impl Response { + /// Returns the response data as a JSON string or a JSON object. #[napi(getter)] - pub fn json(&self) -> String { - self.json.clone() + pub fn data(&self) -> Either { + self.data.clone() } #[napi(getter)] diff --git a/crates/edr_napi/test/helpers.ts b/crates/edr_napi/test/helpers.ts index 537c93811..ba2b1aa81 100644 --- a/crates/edr_napi/test/helpers.ts +++ b/crates/edr_napi/test/helpers.ts @@ -1,5 +1,22 @@ import { TracingMessage, TracingMessageResult, TracingStep } from ".."; +function getEnv(key: string): string | undefined { + const variable = process.env[key]; + if (variable === undefined || variable === "") { + return undefined; + } + + const trimmed = variable.trim(); + + return trimmed.length === 0 ? undefined : trimmed; +} + +export const ALCHEMY_URL = getEnv("ALCHEMY_URL"); + +export function isCI(): boolean { + return getEnv("CI") === "true"; +} + /** * Given a trace, return only its steps. */ diff --git a/crates/edr_napi/test/issues.ts b/crates/edr_napi/test/issues.ts new file mode 100644 index 000000000..fa3fe82aa --- /dev/null +++ b/crates/edr_napi/test/issues.ts @@ -0,0 +1,109 @@ +import chai, { assert } from "chai"; +import { JsonStreamStringify } from "json-stream-stringify"; + +import { + ContractAndFunctionName, + EdrContext, + MineOrdering, + Provider, + SpecId, + SubscriptionEvent, +} from ".."; +import { ALCHEMY_URL, isCI } from "./helpers"; + +describe("Provider", () => { + const context = new EdrContext(); + const providerConfig = { + allowBlocksWithSameTimestamp: false, + allowUnlimitedContractSize: true, + bailOnCallFailure: false, + bailOnTransactionFailure: false, + blockGasLimit: 300_000_000n, + chainId: 1n, + chains: [], + coinbase: Buffer.from("0000000000000000000000000000000000000000", "hex"), + enableRip7212: false, + genesisAccounts: [ + { + secretKey: + "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80", + balance: 1000n * 10n ** 18n, + }, + ], + hardfork: SpecId.Latest, + initialBlobGas: { + gasUsed: 0n, + excessGas: 0n, + }, + initialParentBeaconBlockRoot: Buffer.from( + "0000000000000000000000000000000000000000000000000000000000000000", + "hex", + ), + minGasPrice: 0n, + mining: { + autoMine: true, + memPool: { + order: MineOrdering.Priority, + }, + }, + networkId: 123n, + }; + + const loggerConfig = { + enable: false, + decodeConsoleLogInputsCallback: (inputs: Buffer[]): string[] => { + return []; + }, + getContractAndFunctionNameCallback: ( + _code: Buffer, + _calldata?: Buffer, + ): ContractAndFunctionName => { + return { + contractName: "", + }; + }, + printLineCallback: (message: string, replace: boolean) => {}, + }; + + it("issue 543", async function () { + if (ALCHEMY_URL === undefined || !isCI()) { + this.skip(); + } + + // This test is slow because the debug_traceTransaction is performed on a large transaction. + this.timeout(240_000); + + const provider = await Provider.withConfig( + context, + { + fork: { + jsonRpcUrl: ALCHEMY_URL, + }, + initialBaseFeePerGas: 0n, + ...providerConfig, + }, + loggerConfig, + (_event: SubscriptionEvent) => {}, + ); + + const debugTraceTransaction = `{ + "jsonrpc": "2.0", + "method": "debug_traceTransaction", + "params": ["0x7e460f200343e5ab6653a8857cc5ef798e3f5bea6a517b156f90c77ef311a57c"], + "id": 1 + }`; + + const response = await provider.handleRequest(debugTraceTransaction); + + let responseData; + + if (typeof response.data === "string") { + responseData = JSON.parse(response.data); + } else { + responseData = response.data; + } + + // Validate that we can query the response data without crashing. + const _json = new JsonStreamStringify(responseData); + }); +}); diff --git a/crates/edr_napi/test/provider.ts b/crates/edr_napi/test/provider.ts index e2dd97a53..7a43e48b0 100644 --- a/crates/edr_napi/test/provider.ts +++ b/crates/edr_napi/test/provider.ts @@ -9,23 +9,10 @@ import { SpecId, SubscriptionEvent, } from ".."; -import { collectMessages, collectSteps } from "./helpers"; +import { collectMessages, collectSteps, ALCHEMY_URL } from "./helpers"; chai.use(chaiAsPromised); -function getEnv(key: string): string | undefined { - const variable = process.env[key]; - if (variable === undefined || variable === "") { - return undefined; - } - - const trimmed = variable.trim(); - - return trimmed.length === 0 ? undefined : trimmed; -} - -const ALCHEMY_URL = getEnv("ALCHEMY_URL"); - describe("Provider", () => { const context = new EdrContext(); const providerConfig = { @@ -350,7 +337,15 @@ describe("Provider", () => { }), ); - const txHash = JSON.parse(sendTxResponse.json).result; + let responseData; + + if (typeof sendTxResponse.data === "string") { + responseData = JSON.parse(sendTxResponse.data); + } else { + responseData = sendTxResponse.data; + } + + const txHash = responseData.result; const traceTransactionResponse = await provider.handleRequest( JSON.stringify({ diff --git a/crates/tools/js/benchmark/index.js b/crates/tools/js/benchmark/index.js index ee64fe488..df57cf853 100644 --- a/crates/tools/js/benchmark/index.js +++ b/crates/tools/js/benchmark/index.js @@ -90,10 +90,9 @@ async function report(benchmarkResultPath) { async function verify(benchmarkResultPath) { let success = true; const benchmarkResult = require(benchmarkResultPath); - const snapshotResult = require(path.join( - getScenariosDir(), - SCENARIO_SNAPSHOT_NAME - )); + const snapshotResult = require( + path.join(getScenariosDir(), SCENARIO_SNAPSHOT_NAME), + ); for (let scenarioName in snapshotResult) { // TODO https://github.com/NomicFoundation/edr/issues/365 @@ -107,7 +106,7 @@ async function verify(benchmarkResultPath) { if (ratio > NEPTUNE_MAX_MIN_FAILURES) { console.error( `Snapshot failure for ${scenarioName} with max/min failure ratio`, - ratio + ratio, ); success = false; } @@ -129,16 +128,16 @@ async function verify(benchmarkResultPath) { if (shouldFail.size > 0) { console.error( `Scenario ${scenarioName} should fail at indexes ${Array.from( - shouldFail - ).sort()}` + shouldFail, + ).sort()}`, ); } if (shouldNotFail.size > 0) { console.error( `Scenario ${scenarioName} should not fail at indexes ${Array.from( - shouldNotFail - ).sort()}` + shouldNotFail, + ).sort()}`, ); } } @@ -207,7 +206,7 @@ async function benchmarkAllScenarios(outPath, useAnvil) { console.error( `Total time ${ Math.round(100 * (totalTime / 1000)) / 100 - } seconds with ${totalFailures} failures.` + } seconds with ${totalFailures} failures.`, ); console.error(`Benchmark results written to ${outPath}`); @@ -275,7 +274,7 @@ async function benchmarkScenario(scenarioFileName, useAnvil) { console.error( `${name} finished in ${ Math.round(100 * (timeMs / 1000)) / 100 - } seconds with ${failures.length} failures.` + } seconds with ${failures.length} failures.`, ); const result = { @@ -331,11 +330,11 @@ function preprocessConfig(config) { config = removeNull(config); config.providerConfig.initialDate = new Date( - config.providerConfig.initialDate.secsSinceEpoch * 1000 + config.providerConfig.initialDate.secsSinceEpoch * 1000, ); config.providerConfig.hardfork = normalizeHardfork( - config.providerConfig.hardfork + config.providerConfig.hardfork, ); // "accounts" in EDR are "genesisAccounts" in Hardhat @@ -345,7 +344,7 @@ function preprocessConfig(config) { config.providerConfig.genesisAccounts = config.providerConfig.accounts.map( ({ balance, secretKey }) => { return { balance, privateKey: secretKey }; - } + }, ); delete config.providerConfig.accounts; @@ -380,6 +379,7 @@ function preprocessConfig(config) { } config.providerConfig.minGasPrice = BigInt(config.providerConfig.minGasPrice); + config.providerConfig.enableRip7212 = false; return config; } diff --git a/package.json b/package.json index 59af888f9..1baeb65d4 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,9 @@ "pnpm": { "overrides": { "hardhat>@nomicfoundation/edr": "workspace:*" + }, + "patchedDependencies": { + "hardhat@2.22.7": "patches/hardhat@2.22.7.patch" } }, "engines": { diff --git a/patches/hardhat@2.22.7.patch b/patches/hardhat@2.22.7.patch new file mode 100644 index 000000000..392e91d18 --- /dev/null +++ b/patches/hardhat@2.22.7.patch @@ -0,0 +1,77 @@ +diff --git a/internal/hardhat-network/provider/provider.js b/internal/hardhat-network/provider/provider.js +index 720cbe438e2a09b210db4135c0e87a4edb5b69f0..5954096feb5bc4ab1c546e6acc9d765bdfb7e95d 100644 +--- a/internal/hardhat-network/provider/provider.js ++++ b/internal/hardhat-network/provider/provider.js +@@ -215,7 +215,14 @@ class EdrProviderWrapper extends events_1.EventEmitter { + params, + }); + const responseObject = await this._provider.handleRequest(stringifiedArgs); +- const response = JSON.parse(responseObject.json); ++ ++ let response; ++ if (typeof responseObject.data === "string") { ++ response = JSON.parse(responseObject.data); ++ } else { ++ response = responseObject.data; ++ } ++ + const needsTraces = this._node._vm.evm.events.eventNames().length > 0 || + this._node._vm.events.eventNames().length > 0 || + this._vmTracer !== undefined; +diff --git a/internal/hardhat-network/provider/vm/minimal-vm.js b/internal/hardhat-network/provider/vm/minimal-vm.js +index 7308105d1718d54afac5a87402a6c2250ae8115c..5e054633ac9dcc7ec1872d1527e637a18a0db550 100644 +--- a/internal/hardhat-network/provider/vm/minimal-vm.js ++++ b/internal/hardhat-network/provider/vm/minimal-vm.js +@@ -26,7 +26,14 @@ function getMinimalEthereumJsVm(provider) { + method: "eth_getStorageAt", + params: [address.toString(), `0x${slotHash.toString("hex")}`], + })); +- const response = JSON.parse(responseObject.json); ++ ++ let response; ++ if (typeof responseObject.data === "string") { ++ response = JSON.parse(responseObject.data); ++ } else { ++ response = responseObject.data; ++ } ++ + return Buffer.from(response.result.slice(2), "hex"); + }, + putContractStorage: async (address, slotHash, slotValue) => { +diff --git a/src/internal/hardhat-network/provider/provider.ts b/src/internal/hardhat-network/provider/provider.ts +index 939ca6b3b7968e9b98cc2b4d1edfc906ef92897c..15418fdb0902728cefc6433dce152a08efc5ba70 100644 +--- a/src/internal/hardhat-network/provider/provider.ts ++++ b/src/internal/hardhat-network/provider/provider.ts +@@ -354,7 +354,13 @@ export class EdrProviderWrapper + const responseObject: Response = await this._provider.handleRequest( + stringifiedArgs + ); +- const response = JSON.parse(responseObject.json); ++ ++ let response; ++ if (typeof responseObject.data === "string") { ++ response = JSON.parse(responseObject.data); ++ } else { ++ response = responseObject.data; ++ } + + const needsTraces = + this._node._vm.evm.events.eventNames().length > 0 || +diff --git a/src/internal/hardhat-network/provider/vm/minimal-vm.ts b/src/internal/hardhat-network/provider/vm/minimal-vm.ts +index bf75d7d30adf1845201a8841fdc1c4db17e63d90..0c947e8a74c7dedcd8e6831773cbaaee432284dc 100644 +--- a/src/internal/hardhat-network/provider/vm/minimal-vm.ts ++++ b/src/internal/hardhat-network/provider/vm/minimal-vm.ts +@@ -82,7 +82,12 @@ export function getMinimalEthereumJsVm( + }) + ); + +- const response = JSON.parse(responseObject.json); ++ let response; ++ if (typeof responseObject.data === "string") { ++ response = JSON.parse(responseObject.data); ++ } else { ++ response = responseObject.data; ++ } + + return Buffer.from(response.result.slice(2), "hex"); + }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68a57d357..3ed6e43c1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,6 +7,11 @@ settings: overrides: hardhat>@nomicfoundation/edr: workspace:* +patchedDependencies: + hardhat@2.22.7: + hash: umhdsnfwxfqbbniyljx6a4ic5i + path: patches/hardhat@2.22.7.patch + importers: .: @@ -41,6 +46,9 @@ importers: chai-as-promised: specifier: ^7.1.1 version: 7.1.1(chai@4.4.1) + json-stream-stringify: + specifier: ^3.1.4 + version: 3.1.4 mocha: specifier: ^10.0.0 version: 10.3.0 @@ -61,7 +69,7 @@ importers: version: 4.4.1 hardhat: specifier: 2.22.7 - version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash: specifier: ^4.17.11 version: 4.17.21 @@ -181,7 +189,7 @@ importers: version: 7.0.1 hardhat: specifier: 2.22.7 - version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -211,10 +219,10 @@ importers: devDependencies: '@defi-wonderland/smock': specifier: ^2.4.0 - version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) '@nomiclabs/hardhat-ethers': specifier: ^2.2.3 - version: 2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + version: 2.2.3(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) chai: specifier: ^4.3.6 version: 4.4.1 @@ -223,7 +231,7 @@ importers: version: 5.7.2 hardhat: specifier: 2.22.7 - version: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + version: 2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) mocha: specifier: ^10.0.0 version: 10.3.0 @@ -1979,6 +1987,10 @@ packages: json-stable-stringify-without-jsonify@1.0.1: resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==} + json-stream-stringify@3.1.4: + resolution: {integrity: sha512-oGoz05ft577LolnXFQHD2CjnXDxXVA5b8lHwfEZgRXQUZeCMo6sObQQRq+NXuHQ3oTeMZHHmmPY2rjVwyqR62A==} + engines: {node: '>=7.10.1'} + json5@1.0.2: resolution: {integrity: sha512-g1MWMLBiz8FKi1e4w0UyVL3w+iJceWAFBAaBnnGKOpNa5f8TLktkbre1+s6oICydWAm+HRUGTmI+//xv2hvXYA==} hasBin: true @@ -3083,16 +3095,16 @@ snapshots: dependencies: '@jridgewell/trace-mapping': 0.3.9 - '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@defi-wonderland/smock@2.4.0(@ethersproject/abi@5.7.0)(@ethersproject/abstract-provider@5.7.0)(@ethersproject/abstract-signer@5.7.0)(@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)))(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: '@ethersproject/abi': 5.7.0 '@ethersproject/abstract-provider': 5.7.0 '@ethersproject/abstract-signer': 5.7.0 '@nomicfoundation/ethereumjs-util': 9.0.4 - '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) + '@nomiclabs/hardhat-ethers': 2.2.3(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4)) diff: 5.0.0 ethers: 5.7.2 - hardhat: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) lodash.isequal: 4.5.0 lodash.isequalwith: 4.4.0 rxjs: 7.8.1 @@ -3603,10 +3615,10 @@ snapshots: '@nomicfoundation/solidity-analyzer-win32-ia32-msvc': 0.1.1 '@nomicfoundation/solidity-analyzer-win32-x64-msvc': 0.1.1 - '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': + '@nomiclabs/hardhat-ethers@2.2.3(ethers@5.7.2)(hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(typescript@5.0.4))(typescript@5.0.4))': dependencies: ethers: 5.7.2 - hardhat: 2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) + hardhat: 2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4) '@scure/base@1.1.5': {} @@ -4873,7 +4885,7 @@ snapshots: hard-rejection@2.1.0: {} - hardhat@2.22.7(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): + hardhat@2.22.7(patch_hash=umhdsnfwxfqbbniyljx6a4ic5i)(ts-node@10.9.2(@types/node@18.15.13)(typescript@5.0.4))(typescript@5.0.4): dependencies: '@ethersproject/abi': 5.7.0 '@metamask/eth-sig-util': 4.0.1 @@ -5141,6 +5153,8 @@ snapshots: json-stable-stringify-without-jsonify@1.0.1: {} + json-stream-stringify@3.1.4: {} + json5@1.0.2: dependencies: minimist: 1.2.8 From c3241285fc4a0c7fbfc060c23d6243c5e774c5c4 Mon Sep 17 00:00:00 2001 From: Piotr Galar Date: Fri, 2 Aug 2024 13:10:46 +0100 Subject: [PATCH 19/54] ci: update collaborator check in the benchmarks workflow (#574) --- .github/workflows/edr-benchmark.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/edr-benchmark.yml b/.github/workflows/edr-benchmark.yml index 2c2346a90..2898e0bb6 100644 --- a/.github/workflows/edr-benchmark.yml +++ b/.github/workflows/edr-benchmark.yml @@ -24,7 +24,7 @@ jobs: environment: github-action-benchmark runs-on: self-hosted # Only run for trusted collaborators since third-parties could run malicious code on the self-hosted benchmark runner. - if: github.ref == 'refs/heads/main' || (github.event.pull_request.author_association == 'OWNER' || github.event.pull_request.author_association == 'MEMBER' || github.event.pull_request.author_association == 'COLLABORATOR') + if: github.ref == 'refs/heads/main' || github.repository == github.event.pull_request.head.repo.full_name steps: - uses: actions/checkout@v3 From cf5d7a1c76d5d45fe2eb70b5724f413e157a85f3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 16:04:20 +0200 Subject: [PATCH 20/54] edr-0.5.1 (#559) Co-authored-by: github-actions[bot] --- .changeset/fast-kings-search.md | 5 ----- .changeset/thick-impalas-sparkle.md | 5 ----- .changeset/two-starfishes-obey.md | 5 ----- crates/edr_napi/CHANGELOG.md | 8 ++++++++ crates/edr_napi/package.json | 2 +- 5 files changed, 9 insertions(+), 16 deletions(-) delete mode 100644 .changeset/fast-kings-search.md delete mode 100644 .changeset/thick-impalas-sparkle.md delete mode 100644 .changeset/two-starfishes-obey.md diff --git a/.changeset/fast-kings-search.md b/.changeset/fast-kings-search.md deleted file mode 100644 index 422cdad82..000000000 --- a/.changeset/fast-kings-search.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixed a bug in fork mode where the locally overridden chain id was used instead of the remote chain id when simulating transactions in pre-fork blocks. diff --git a/.changeset/thick-impalas-sparkle.md b/.changeset/thick-impalas-sparkle.md deleted file mode 100644 index 940607e36..000000000 --- a/.changeset/thick-impalas-sparkle.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixed a bug in the JSON-RPC where we previously allowed a null value for storage keys of an access list diff --git a/.changeset/two-starfishes-obey.md b/.changeset/two-starfishes-obey.md deleted file mode 100644 index 629d241f5..000000000 --- a/.changeset/two-starfishes-obey.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -Fixed crash when returning large JSON responses diff --git a/crates/edr_napi/CHANGELOG.md b/crates/edr_napi/CHANGELOG.md index 5d3969b6a..3d53cefb0 100644 --- a/crates/edr_napi/CHANGELOG.md +++ b/crates/edr_napi/CHANGELOG.md @@ -1,5 +1,13 @@ # @nomicfoundation/edr +## 0.5.1 + +### Patch Changes + +- 0bba027: Fixed a bug in fork mode where the locally overridden chain id was used instead of the remote chain id when simulating transactions in pre-fork blocks. +- e02eb22: Fixed a bug in the JSON-RPC where we previously allowed a null value for storage keys of an access list +- 8ae31b9: Fixed crash when returning large JSON responses + ## 0.5.0 ### Minor Changes diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index a460e5bea..7dc19243d 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/edr", - "version": "0.5.0", + "version": "0.5.1", "main": "index.js", "types": "index.d.ts", "files": [ From 66ca796c50154fb64bf55a5279a0bb7a3feed111 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Mon, 5 Aug 2024 17:11:58 +0200 Subject: [PATCH 21/54] fix: add json alias property in provider response (#582) * fix: add json alias property in provider response * Create empty-bobcats-refuse.md --- .changeset/empty-bobcats-refuse.md | 5 +++++ crates/edr_napi/index.d.ts | 1 + crates/edr_napi/src/provider.rs | 6 ++++++ 3 files changed, 12 insertions(+) create mode 100644 .changeset/empty-bobcats-refuse.md diff --git a/.changeset/empty-bobcats-refuse.md b/.changeset/empty-bobcats-refuse.md new file mode 100644 index 000000000..88fa92ad9 --- /dev/null +++ b/.changeset/empty-bobcats-refuse.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +fix: added `json` alias property in provider response to fix breaking change in v0.5.1 diff --git a/crates/edr_napi/index.d.ts b/crates/edr_napi/index.d.ts index d19f66225..a2d5334c5 100644 --- a/crates/edr_napi/index.d.ts +++ b/crates/edr_napi/index.d.ts @@ -420,6 +420,7 @@ export class Provider { export class Response { /** Returns the response data as a JSON string or a JSON object. */ get data(): string | any + get json(): string | any get solidityTrace(): RawTrace | null get traces(): Array } diff --git a/crates/edr_napi/src/provider.rs b/crates/edr_napi/src/provider.rs index 062fb3fa4..3397e8c8c 100644 --- a/crates/edr_napi/src/provider.rs +++ b/crates/edr_napi/src/provider.rs @@ -243,6 +243,12 @@ impl Response { self.data.clone() } + // Temporary alias for data to prevent breaking change + #[napi(getter)] + pub fn json(&self) -> Either { + self.data.clone() + } + #[napi(getter)] pub fn solidity_trace(&self) -> Option { self.solidity_trace From e90a194d19007af25b04c8f194dfb4409697402b Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Aug 2024 17:18:26 +0200 Subject: [PATCH 22/54] edr-0.5.2 (#583) Co-authored-by: github-actions[bot] --- .changeset/empty-bobcats-refuse.md | 5 ----- crates/edr_napi/CHANGELOG.md | 6 ++++++ crates/edr_napi/package.json | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) delete mode 100644 .changeset/empty-bobcats-refuse.md diff --git a/.changeset/empty-bobcats-refuse.md b/.changeset/empty-bobcats-refuse.md deleted file mode 100644 index 88fa92ad9..000000000 --- a/.changeset/empty-bobcats-refuse.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@nomicfoundation/edr": patch ---- - -fix: added `json` alias property in provider response to fix breaking change in v0.5.1 diff --git a/crates/edr_napi/CHANGELOG.md b/crates/edr_napi/CHANGELOG.md index 3d53cefb0..8c3444ca6 100644 --- a/crates/edr_napi/CHANGELOG.md +++ b/crates/edr_napi/CHANGELOG.md @@ -1,5 +1,11 @@ # @nomicfoundation/edr +## 0.5.2 + +### Patch Changes + +- 66ca796: fix: added `json` alias property in provider response to fix breaking change in v0.5.1 + ## 0.5.1 ### Patch Changes diff --git a/crates/edr_napi/package.json b/crates/edr_napi/package.json index 7dc19243d..89cedc17f 100644 --- a/crates/edr_napi/package.json +++ b/crates/edr_napi/package.json @@ -1,6 +1,6 @@ { "name": "@nomicfoundation/edr", - "version": "0.5.1", + "version": "0.5.2", "main": "index.js", "types": "index.d.ts", "files": [ From a417e19622e9887c401db433ce501943498d66eb Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Wed, 7 Aug 2024 17:02:13 +0200 Subject: [PATCH 23/54] breaking change: rename response.json to response.data (#584) * breaking change: rename response.json to response.data * Create sour-donkeys-draw.md * Update sour-donkeys-draw.md --- .changeset/sour-donkeys-draw.md | 5 +++++ crates/edr_napi/index.d.ts | 1 - crates/edr_napi/src/provider.rs | 6 ------ 3 files changed, 5 insertions(+), 7 deletions(-) create mode 100644 .changeset/sour-donkeys-draw.md diff --git a/.changeset/sour-donkeys-draw.md b/.changeset/sour-donkeys-draw.md new file mode 100644 index 000000000..6adc524ee --- /dev/null +++ b/.changeset/sour-donkeys-draw.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": minor +--- + +Renamed `json` field in response to `data` and changed its type to `string | object` (specified as `string | any` due to an napi-rs limitation). diff --git a/crates/edr_napi/index.d.ts b/crates/edr_napi/index.d.ts index a2d5334c5..d19f66225 100644 --- a/crates/edr_napi/index.d.ts +++ b/crates/edr_napi/index.d.ts @@ -420,7 +420,6 @@ export class Provider { export class Response { /** Returns the response data as a JSON string or a JSON object. */ get data(): string | any - get json(): string | any get solidityTrace(): RawTrace | null get traces(): Array } diff --git a/crates/edr_napi/src/provider.rs b/crates/edr_napi/src/provider.rs index 3397e8c8c..062fb3fa4 100644 --- a/crates/edr_napi/src/provider.rs +++ b/crates/edr_napi/src/provider.rs @@ -243,12 +243,6 @@ impl Response { self.data.clone() } - // Temporary alias for data to prevent breaking change - #[napi(getter)] - pub fn json(&self) -> Either { - self.data.clone() - } - #[napi(getter)] pub fn solidity_trace(&self) -> Option { self.solidity_trace From 2f1c1896196082a9f62164fa45c0134f52565d89 Mon Sep 17 00:00:00 2001 From: Agost Biro <5764438+agostbiro@users.noreply.github.com> Date: Wed, 21 Aug 2024 16:37:12 +0200 Subject: [PATCH 24/54] fix: improve error message and option to skip unsupported transaction type in debug trace (#606) * fix: improve error message and option to skip unsupported tx type in debug trace * Address code review feedback * Handle unsupported transaction type requested * Fix test setup --- .changeset/empty-cars-join.md | 5 + crates/edr_provider/src/data.rs | 208 +++++++++++++++--- crates/edr_provider/src/error.rs | 13 ++ crates/edr_provider/tests/issues/issue_570.rs | 119 ++++++++++ crates/edr_provider/tests/issues/mod.rs | 1 + crates/edr_rpc_eth/src/lib.rs | 2 +- crates/edr_rpc_eth/src/transaction.rs | 200 ++++++++++------- 7 files changed, 434 insertions(+), 114 deletions(-) create mode 100644 .changeset/empty-cars-join.md create mode 100644 crates/edr_provider/tests/issues/issue_570.rs diff --git a/.changeset/empty-cars-join.md b/.changeset/empty-cars-join.md new file mode 100644 index 000000000..0a3582eb1 --- /dev/null +++ b/.changeset/empty-cars-join.md @@ -0,0 +1,5 @@ +--- +"@nomicfoundation/edr": patch +--- + +Improved error message and added option to skip unsupported transaction type in `debug_traceTransaction`. Set `__EDR_UNSAFE_SKIP_UNSUPPORTED_TRANSACTION_TYPES=true` as an environment variable to enable this. diff --git a/crates/edr_provider/src/data.rs b/crates/edr_provider/src/data.rs index de47217a9..c8ee01bfa 100644 --- a/crates/edr_provider/src/data.rs +++ b/crates/edr_provider/src/data.rs @@ -16,7 +16,7 @@ use alloy_dyn_abi::eip712::TypedData; use edr_eth::{ block::{ calculate_next_base_fee_per_blob_gas, calculate_next_base_fee_per_gas, miner_reward, - BlobGas, BlockOptions, + BlobGas, BlockOptions, Header, }, fee_history::FeeHistoryResult, filter::{FilteredEvents, LogOutput, SubscriptionType}, @@ -24,15 +24,15 @@ use edr_eth::{ receipt::BlockReceipt, reward_percentile::RewardPercentile, signature::{self, RecoveryMessage}, - transaction::{request::TransactionRequestAndSender, Transaction, TransactionType}, + transaction::{request::TransactionRequestAndSender, Signed, Transaction, TransactionType}, Address, BlockSpec, BlockTag, Bytes, Eip1898BlockSpec, SpecId, B256, U256, }; use edr_evm::{ blockchain::{ - Blockchain, BlockchainError, ForkedBlockchain, ForkedCreationError, GenesisBlockOptions, - LocalBlockchain, LocalCreationError, SyncBlockchain, + Blockchain, BlockchainError, ForkedBlockchain, ForkedBlockchainError, ForkedCreationError, + GenesisBlockOptions, LocalBlockchain, LocalCreationError, SyncBlockchain, }, - chain_spec::L1ChainSpec, + chain_spec::{ChainSpec, L1ChainSpec}, db::StateRef, debug_trace_transaction, execution_result_to_debug_result, mempool, mine_block, mine_block_with_single_transaction, register_eip_3155_and_raw_tracers_handles, @@ -45,12 +45,13 @@ use edr_evm::{ Account, AccountInfo, BlobExcessGasAndPrice, Block as _, BlockAndTotalDifficulty, BlockEnv, Bytecode, CfgEnv, CfgEnvWithHandlerCfg, DebugContext, DebugTraceConfig, DebugTraceResultWithTraces, Eip3155AndRawTracers, EvmStorageSlot, ExecutionResult, HashMap, - HashSet, MemPool, MineBlockResultAndState, OrderedTransaction, Precompile, RandomHashGenerator, - SyncBlock, TxEnv, KECCAK_EMPTY, + HashSet, IntoRemoteBlock, MemPool, MineBlockResultAndState, OrderedTransaction, Precompile, + RandomHashGenerator, RemoteBlockCreationError, SyncBlock, TxEnv, KECCAK_EMPTY, }; use edr_rpc_eth::{ client::{EthRpcClient, HeaderMap, RpcClientError}, error::HttpError, + RpcTransactionType, }; use gas::gas_used_ratio; use indexmap::IndexMap; @@ -83,6 +84,9 @@ use crate::{ const DEFAULT_INITIAL_BASE_FEE_PER_GAS: u64 = 1_000_000_000; const EDR_MAX_CACHED_STATES_ENV_VAR: &str = "__EDR_MAX_CACHED_STATES"; const DEFAULT_MAX_CACHED_STATES: usize = 100_000; +const EDR_UNSAFE_SKIP_UNSUPPORTED_TRANSACTION_TYPES: &str = + "__EDR_UNSAFE_SKIP_UNSUPPORTED_TRANSACTION_TYPES"; +const DEFAULT_SKIP_UNSUPPORTED_TRANSACTION_TYPES: bool = false; /// The result of executing an `eth_call`. #[derive(Clone, Debug)] @@ -188,6 +192,8 @@ pub struct ProviderData, filters: HashMap, @@ -229,18 +235,7 @@ impl ProviderData { - Ok(NonZeroUsize::new(DEFAULT_MAX_CACHED_STATES).expect("constant is non-zero")) - } - std::env::VarError::NotUnicode(s) => Err(CreationError::InvalidMaxCachedStates(s)), - }, - |s| { - s.parse() - .map_err(|_err| CreationError::InvalidMaxCachedStates(s.into())) - }, - )?; + let max_cached_states = get_max_cached_states_from_env()?; let mut block_state_cache = LruCache::new(max_cached_states); let mut block_number_to_state_id = HashTrieMapSync::default(); @@ -255,6 +250,8 @@ impl ProviderData ProviderData ProviderData Result> { - let block = self - .blockchain - .block_by_transaction_hash(transaction_hash)? - .ok_or_else(|| ProviderError::InvalidTransactionHash(*transaction_hash))?; - - let header = block.header(); + let (header, transactions) = + self.block_data_for_debug_trace_transaction(transaction_hash)?; let cfg_env = self.create_evm_config_at_block_spec(&BlockSpec::Number(header.number))?; - let transactions = block.transactions().to_vec(); - - let prev_block_number = block.header().number - 1; + let prev_block_number = header.number - 1; let prev_block_spec = Some(BlockSpec::Number(prev_block_number)); let verbose_tracing = self.verbose_tracing; @@ -1922,6 +1914,146 @@ impl ProviderData Result<(Header, Vec), ProviderError> { + // HACK: This is a hack to make `debug_traceTransaction` return a helpful error + // message in fork mode if there is a transaction in the block whose + // type is not supported or skip that transaction if an environment + // variable is set. This hack is only necessary until proper multichain + // support. https://github.com/NomicFoundation/edr/issues/570 + self.rpc_client + .as_ref() + .and_then(|rpc_client| { + // Use `Result