From 2f70c44d1fc7448f9d7b9fe555797b406a648924 Mon Sep 17 00:00:00 2001 From: Gabriel Rocheleau Date: Mon, 7 Oct 2024 05:11:34 -0400 Subject: [PATCH] trie: trie package renaming to mpt (#3719) * trie: trie package renaming to mpt * adjust ci with mpt * trie: trie package renaming to mpt * adjust ci with mpt * mpt: update version * trie: renaming to mpt for clarity * mpt: rename * trie: adjust proof naming scheme * trie: fix isRawMPTNode import * trie: don't export internally used verifyRangeProof * mpt: minor adjustments * mpt: fix example script --- .github/workflows/build.yml | 28 ++-- .../{trie-build.yml => mpt-build.yml} | 22 +-- .github/workflows/node-versions.yml | 4 +- package-lock.json | 66 ++++++--- packages/block/package.json | 2 +- packages/block/src/block/block.ts | 2 +- packages/block/src/block/constructors.ts | 2 +- packages/block/src/helpers.ts | 2 +- packages/block/tsconfig.prod.cjs.json | 2 +- packages/block/tsconfig.prod.esm.json | 2 +- packages/blockchain/package.json | 2 +- packages/blockchain/src/helpers.ts | 4 +- packages/blockchain/test/utils.spec.ts | 4 +- .../libp2p/net/package.json.browser.deps | 2 +- packages/client/package.json | 2 +- packages/client/src/execution/vmexecution.ts | 4 +- .../client/src/sync/fetcher/accountfetcher.ts | 8 +- .../client/src/sync/fetcher/storagefetcher.ts | 8 +- .../src/sync/fetcher/trienodefetcher.ts | 12 +- packages/client/src/util/debug.ts | 2 +- .../test/net/protocol/snapprotocol.spec.ts | 8 +- .../test/rpc/engine/withdrawals.spec.ts | 2 +- .../test/sync/fetcher/accountfetcher.spec.ts | 4 +- .../test/sync/fetcher/storagefetcher.spec.ts | 4 +- .../test/sync/fetcher/trienodefetcher.spec.ts | 6 +- packages/client/tsconfig.prod.esm.json | 2 +- packages/evm/tsconfig.prod.cjs.json | 2 +- packages/evm/tsconfig.prod.esm.json | 2 +- packages/genesis/package.json | 2 +- packages/genesis/test/index.spec.ts | 4 +- packages/{trie => mpt}/.c8rc.json | 0 packages/{trie => mpt}/.eslintrc.cjs | 0 packages/{trie => mpt}/.gitignore | 0 packages/{trie => mpt}/.gitmodules | 0 packages/{trie => mpt}/.npmignore | 0 packages/{trie => mpt}/.prettierignore | 0 packages/{trie => mpt}/CHANGELOG.md | 0 packages/{trie => mpt}/README.md | 138 +++++++++--------- packages/{trie => mpt}/UPGRADING.md | 0 .../{trie => mpt}/benchmarks/engines/level.ts | 0 packages/{trie => mpt}/benchmarks/index.ts | 0 packages/{trie => mpt}/benchmarks/keys.ts | 0 packages/{trie => mpt}/benchmarks/suite.ts | 0 packages/{trie => mpt}/docs/README.md | 0 .../{trie => mpt}/docs/classes/BranchNode.md | 0 .../docs/classes/CheckpointDB.md | 0 .../docs/classes/ExtensionNode.md | 0 .../{trie => mpt}/docs/classes/LeafNode.md | 0 .../docs/classes/PrioritizedTaskExecutor.md | 0 packages/{trie => mpt}/docs/classes/Trie.md | 0 .../docs/classes/TrieReadStream.md | 0 .../docs/classes/WalkController.md | 0 .../docs/interfaces/CheckpointDBOpts.md | 0 .../docs/interfaces/CommonInterface.md | 0 .../{trie => mpt}/docs/interfaces/Path.md | 0 .../{trie => mpt}/docs/interfaces/TrieOpts.md | 0 .../docs/interfaces/TrieShallowCopyOpts.md | 0 packages/{trie => mpt}/examples/README.md | 0 packages/{trie => mpt}/examples/basicUsage.ts | 4 +- packages/{trie => mpt}/examples/browser.html | 4 +- .../{trie => mpt}/examples/createFromProof.ts | 12 +- .../{trie => mpt}/examples/customLevelDB.ts | 2 +- .../{trie => mpt}/examples/level-legacy.js | 0 packages/{trie => mpt}/examples/level.js | 0 packages/{trie => mpt}/examples/lmdb.js | 2 +- packages/{trie => mpt}/examples/logDemo.ts | 4 +- .../examples/merkle_patricia_trees/README.md | 0 .../merkle_patricia_trees/example1a.js | 0 .../merkle_patricia_trees/example1b.js | 0 .../merkle_patricia_trees/example1c.js | 0 .../merkle_patricia_trees/example1d.js | 0 .../merkle_patricia_trees/example2a.js | 0 .../merkle_patricia_trees/example2b.js | 0 .../merkle_patricia_trees/example2c.js | 0 .../merkle_patricia_trees/example2d.js | 0 .../merkle_patricia_trees/example3a.js | 0 .../merkle_patricia_trees/example3b.js | 0 .../merkle_patricia_trees/example4a.js | 0 .../merkle_patricia_trees/example4b.js | 0 .../merkle_patricia_trees/infura_endpoint.js | 0 packages/{trie => mpt}/examples/proofs.ts | 8 +- .../{trie => mpt}/examples/rootPersistence.ts | 4 +- .../{trie => mpt}/examples/trieWalking.ts | 4 +- packages/{trie => mpt}/package.json | 10 +- .../{trie => mpt}/recipes/level-legacy.ts | 0 packages/{trie => mpt}/recipes/level.ts | 2 +- packages/{trie => mpt}/recipes/lmdb.ts | 2 +- packages/{trie => mpt}/scripts/view.ts | 0 packages/{trie => mpt}/scripts/walkDemo.ts | 0 packages/{trie => mpt}/src/constructors.ts | 9 +- packages/{trie => mpt}/src/db/checkpoint.ts | 0 packages/{trie => mpt}/src/db/index.ts | 0 packages/{trie => mpt}/src/index.ts | 2 +- packages/{trie/src/trie.ts => mpt/src/mpt.ts} | 36 +++-- packages/{trie => mpt}/src/node/branch.ts | 6 +- packages/{trie => mpt}/src/node/extension.ts | 0 .../src/node/extensionOrLeafNodeBase.ts | 0 packages/{trie => mpt}/src/node/index.ts | 0 packages/{trie => mpt}/src/node/leaf.ts | 0 packages/{trie => mpt}/src/node/util.ts | 10 +- packages/{trie => mpt}/src/proof/index.ts | 22 +-- packages/{trie => mpt}/src/proof/range.ts | 15 +- packages/{trie => mpt}/src/types.ts | 4 +- packages/{trie => mpt}/src/util/asyncWalk.ts | 2 +- packages/{trie => mpt}/src/util/encoding.ts | 4 +- .../{trie => mpt}/src/util/genesisState.ts | 4 +- packages/{trie => mpt}/src/util/hex.ts | 0 packages/{trie => mpt}/src/util/index.ts | 0 packages/{trie => mpt}/src/util/nibbles.ts | 0 .../{trie => mpt}/src/util/walkController.ts | 2 +- .../{trie => mpt}/test/db/checkpoint.spec.ts | 0 packages/{trie => mpt}/test/db/db.spec.ts | 0 packages/{trie => mpt}/test/encoding.spec.ts | 0 .../test/fixtures/gethGenesisKiln.ts | 0 .../test/fixtures/hexEncodedSecureTrieTest.ts | 0 .../test/fixtures/trieAnyOrder.ts | 0 .../test/fixtures/trieAnyOrderSecureTrie.ts | 0 .../{trie => mpt}/test/fixtures/trieTest.ts | 0 .../test/fixtures/trieTestNextPrev.ts | 0 .../test/fixtures/trieTestSecureTrie.ts | 0 packages/{trie => mpt}/test/index.spec.ts | 0 packages/{trie => mpt}/test/official.spec.ts | 0 packages/{trie => mpt}/test/proof.spec.ts | 14 +- .../{trie => mpt}/test/proof/range.spec.ts | 6 +- .../test/trie/checkpoint.spec.ts | 4 +- .../test/trie/checkpointing.spec.ts | 0 .../{trie => mpt}/test/trie/findPath.spec.ts | 0 .../{trie => mpt}/test/trie/prune.spec.ts | 8 +- .../{trie => mpt}/test/trie/secure.spec.ts | 0 packages/{trie => mpt}/test/trie/trie.spec.ts | 44 +++--- .../{trie => mpt}/test/util/asyncWalk.spec.ts | 4 +- .../test/util/encodingUtils.spec.ts | 0 .../test/util/genesisState.spec.ts | 6 +- packages/{trie => mpt}/test/util/log.spec.ts | 8 +- .../{trie => mpt}/tsconfig.benchmarks.json | 0 packages/{trie => mpt}/tsconfig.json | 0 packages/{trie => mpt}/tsconfig.lint.json | 0 packages/{trie => mpt}/tsconfig.prod.cjs.json | 0 packages/{trie => mpt}/tsconfig.prod.esm.json | 0 packages/{trie => mpt}/typedoc.cjs | 0 .../{trie => mpt}/vitest.config.browser.mts | 0 packages/statemanager/package.json | 2 +- .../statemanager/src/merkleStateManager.ts | 4 +- packages/statemanager/src/proofs/merkle.ts | 14 +- packages/statemanager/src/types.ts | 2 +- .../test/proofStateManager.spec.ts | 4 +- .../statemanager/test/rpcStateManager.spec.ts | 2 +- .../test/stateManager.code.spec.ts | 4 +- .../statemanager/test/stateManager.spec.ts | 6 +- packages/statemanager/tsconfig.prod.cjs.json | 2 +- packages/statemanager/tsconfig.prod.esm.json | 2 +- packages/verkle/src/node/util.ts | 8 +- packages/verkle/src/verkleTree.ts | 6 +- packages/verkle/test/internalNode.spec.ts | 11 +- packages/verkle/test/leafNode.spec.ts | 6 +- packages/verkle/test/verkle.spec.ts | 4 +- packages/vm/package.json | 2 +- packages/vm/src/buildBlock.ts | 2 +- packages/vm/src/runBlock.ts | 2 +- .../tester/runners/BlockchainTestsRunner.ts | 2 +- .../tester/runners/GeneralStateTestsRunner.ts | 2 +- packages/vm/tsconfig.prod.cjs.json | 2 +- packages/vm/tsconfig.prod.esm.json | 2 +- 163 files changed, 376 insertions(+), 337 deletions(-) rename .github/workflows/{trie-build.yml => mpt-build.yml} (90%) rename packages/{trie => mpt}/.c8rc.json (100%) rename packages/{trie => mpt}/.eslintrc.cjs (100%) rename packages/{trie => mpt}/.gitignore (100%) rename packages/{trie => mpt}/.gitmodules (100%) rename packages/{trie => mpt}/.npmignore (100%) rename packages/{trie => mpt}/.prettierignore (100%) rename packages/{trie => mpt}/CHANGELOG.md (100%) rename packages/{trie => mpt}/README.md (64%) rename packages/{trie => mpt}/UPGRADING.md (100%) rename packages/{trie => mpt}/benchmarks/engines/level.ts (100%) rename packages/{trie => mpt}/benchmarks/index.ts (100%) rename packages/{trie => mpt}/benchmarks/keys.ts (100%) rename packages/{trie => mpt}/benchmarks/suite.ts (100%) rename packages/{trie => mpt}/docs/README.md (100%) rename packages/{trie => mpt}/docs/classes/BranchNode.md (100%) rename packages/{trie => mpt}/docs/classes/CheckpointDB.md (100%) rename packages/{trie => mpt}/docs/classes/ExtensionNode.md (100%) rename packages/{trie => mpt}/docs/classes/LeafNode.md (100%) rename packages/{trie => mpt}/docs/classes/PrioritizedTaskExecutor.md (100%) rename packages/{trie => mpt}/docs/classes/Trie.md (100%) rename packages/{trie => mpt}/docs/classes/TrieReadStream.md (100%) rename packages/{trie => mpt}/docs/classes/WalkController.md (100%) rename packages/{trie => mpt}/docs/interfaces/CheckpointDBOpts.md (100%) rename packages/{trie => mpt}/docs/interfaces/CommonInterface.md (100%) rename packages/{trie => mpt}/docs/interfaces/Path.md (100%) rename packages/{trie => mpt}/docs/interfaces/TrieOpts.md (100%) rename packages/{trie => mpt}/docs/interfaces/TrieShallowCopyOpts.md (100%) rename packages/{trie => mpt}/examples/README.md (100%) rename packages/{trie => mpt}/examples/basicUsage.ts (74%) rename packages/{trie => mpt}/examples/browser.html (96%) rename packages/{trie => mpt}/examples/createFromProof.ts (72%) rename packages/{trie => mpt}/examples/customLevelDB.ts (98%) rename packages/{trie => mpt}/examples/level-legacy.js (100%) rename packages/{trie => mpt}/examples/level.js (100%) rename packages/{trie => mpt}/examples/lmdb.js (97%) rename packages/{trie => mpt}/examples/logDemo.ts (78%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/README.md (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example1a.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example1b.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example1c.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example1d.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example2a.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example2b.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example2c.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example2d.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example3a.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example3b.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example4a.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/example4b.js (100%) rename packages/{trie => mpt}/examples/merkle_patricia_trees/infura_endpoint.js (100%) rename packages/{trie => mpt}/examples/proofs.ts (69%) rename packages/{trie => mpt}/examples/rootPersistence.ts (79%) rename packages/{trie => mpt}/examples/trieWalking.ts (79%) rename packages/{trie => mpt}/package.json (92%) rename packages/{trie => mpt}/recipes/level-legacy.ts (100%) rename packages/{trie => mpt}/recipes/level.ts (99%) rename packages/{trie => mpt}/recipes/lmdb.ts (96%) rename packages/{trie => mpt}/scripts/view.ts (100%) rename packages/{trie => mpt}/scripts/walkDemo.ts (100%) rename packages/{trie => mpt}/src/constructors.ts (82%) rename packages/{trie => mpt}/src/db/checkpoint.ts (100%) rename packages/{trie => mpt}/src/db/index.ts (100%) rename packages/{trie => mpt}/src/index.ts (87%) rename packages/{trie/src/trie.ts => mpt/src/mpt.ts} (97%) rename packages/{trie => mpt}/src/node/branch.ts (85%) rename packages/{trie => mpt}/src/node/extension.ts (100%) rename packages/{trie => mpt}/src/node/extensionOrLeafNodeBase.ts (100%) rename packages/{trie => mpt}/src/node/index.ts (100%) rename packages/{trie => mpt}/src/node/leaf.ts (100%) rename packages/{trie => mpt}/src/node/util.ts (76%) rename packages/{trie => mpt}/src/proof/index.ts (91%) rename packages/{trie => mpt}/src/proof/range.ts (97%) rename packages/{trie => mpt}/src/types.ts (96%) rename packages/{trie => mpt}/src/util/asyncWalk.ts (97%) rename packages/{trie => mpt}/src/util/encoding.ts (98%) rename packages/{trie => mpt}/src/util/genesisState.ts (93%) rename packages/{trie => mpt}/src/util/hex.ts (100%) rename packages/{trie => mpt}/src/util/index.ts (100%) rename packages/{trie => mpt}/src/util/nibbles.ts (100%) rename packages/{trie => mpt}/src/util/walkController.ts (98%) rename packages/{trie => mpt}/test/db/checkpoint.spec.ts (100%) rename packages/{trie => mpt}/test/db/db.spec.ts (100%) rename packages/{trie => mpt}/test/encoding.spec.ts (100%) rename packages/{trie => mpt}/test/fixtures/gethGenesisKiln.ts (100%) rename packages/{trie => mpt}/test/fixtures/hexEncodedSecureTrieTest.ts (100%) rename packages/{trie => mpt}/test/fixtures/trieAnyOrder.ts (100%) rename packages/{trie => mpt}/test/fixtures/trieAnyOrderSecureTrie.ts (100%) rename packages/{trie => mpt}/test/fixtures/trieTest.ts (100%) rename packages/{trie => mpt}/test/fixtures/trieTestNextPrev.ts (100%) rename packages/{trie => mpt}/test/fixtures/trieTestSecureTrie.ts (100%) rename packages/{trie => mpt}/test/index.spec.ts (100%) rename packages/{trie => mpt}/test/official.spec.ts (100%) rename packages/{trie => mpt}/test/proof.spec.ts (95%) rename packages/{trie => mpt}/test/proof/range.spec.ts (98%) rename packages/{trie => mpt}/test/trie/checkpoint.spec.ts (97%) rename packages/{trie => mpt}/test/trie/checkpointing.spec.ts (100%) rename packages/{trie => mpt}/test/trie/findPath.spec.ts (100%) rename packages/{trie => mpt}/test/trie/prune.spec.ts (96%) rename packages/{trie => mpt}/test/trie/secure.spec.ts (100%) rename packages/{trie => mpt}/test/trie/trie.spec.ts (84%) rename packages/{trie => mpt}/test/util/asyncWalk.spec.ts (97%) rename packages/{trie => mpt}/test/util/encodingUtils.spec.ts (100%) rename packages/{trie => mpt}/test/util/genesisState.spec.ts (81%) rename packages/{trie => mpt}/test/util/log.spec.ts (77%) rename packages/{trie => mpt}/tsconfig.benchmarks.json (100%) rename packages/{trie => mpt}/tsconfig.json (100%) rename packages/{trie => mpt}/tsconfig.lint.json (100%) rename packages/{trie => mpt}/tsconfig.prod.cjs.json (100%) rename packages/{trie => mpt}/tsconfig.prod.esm.json (100%) rename packages/{trie => mpt}/typedoc.cjs (100%) rename packages/{trie => mpt}/vitest.config.browser.mts (100%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1ed240126c..5c98ad2a11 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -36,8 +36,8 @@ jobs: with: path: ${{github.workspace}}/packages/ethereum-tests key: submodule-${{ steps.create-cache-key.outputs.submodule-cache-key}} - - outputs: + + outputs: submodule-cache-key: submodule-${{ steps.create-cache-key.outputs.submodule-cache-key}} build: @@ -51,7 +51,7 @@ jobs: with: path: ${{github.workspace}}/node_modules key: npm-${{ hashFiles('package-lock.json') }} - + - name: Use Node.js 20 uses: actions/setup-node@v4 with: @@ -60,7 +60,7 @@ jobs: - run: npm ci working-directory: ${{github.workspace}} - + - name: Cache dependencies uses: actions/cache/save@v4 with: @@ -73,7 +73,7 @@ jobs: path: ${{github.workspace}} key: npm-${{ hashFiles('package-lock.json') }}-${{ github.run_id }} - outputs: + outputs: dep-cache-key: ${{ steps.dep-cache.outputs.cache-primary-key }}-${{ github.run_id }} block: @@ -82,7 +82,7 @@ jobs: with: dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} submodule-cache-key: ${{ needs.checkout-submodules.outputs.submodule-cache-key }} - + blockchain: needs: build uses: ./.github/workflows/blockchain-build.yml @@ -139,6 +139,12 @@ jobs: with: dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} + mpt: + needs: build + uses: ./.github/workflows/mpt-build.yml + with: + dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} + rlp: needs: build uses: ./.github/workflows/rlp-build.yml @@ -151,12 +157,6 @@ jobs: with: dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} - trie: - needs: build - uses: ./.github/workflows/trie-build.yml - with: - dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} - tx: needs: [build, checkout-submodules] uses: ./.github/workflows/tx-build.yml @@ -188,7 +188,7 @@ jobs: uses: ./.github/workflows/wallet-build.yml with: dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} - + lint: needs: build uses: ./.github/workflows/lint.yml @@ -201,5 +201,3 @@ jobs: with: dep-cache-key: ${{ needs.build.outputs.dep-cache-key }} submodule-cache-key: ${{ needs.checkout-submodules.outputs.submodule-cache-key }} - - \ No newline at end of file diff --git a/.github/workflows/trie-build.yml b/.github/workflows/mpt-build.yml similarity index 90% rename from .github/workflows/trie-build.yml rename to .github/workflows/mpt-build.yml index 051e96effd..e41e2c8d2a 100644 --- a/.github/workflows/trie-build.yml +++ b/.github/workflows/mpt-build.yml @@ -1,4 +1,4 @@ -name: Trie +name: MPT on: workflow_call: inputs: @@ -15,18 +15,18 @@ on: default: 'none' env: - cwd: ${{github.workspace}}/packages/trie + cwd: ${{github.workspace}}/packages/mpt defaults: run: - working-directory: packages/trie + working-directory: packages/mpt concurrency: - group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-trie + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}-mpt cancel-in-progress: true jobs: - test-trie: + test-mpt: runs-on: ubuntu-latest steps: @@ -35,7 +35,7 @@ jobs: uses: actions/checkout@v4 # We restore the code/deps from cache if triggered from workflow_call (i.e. have valid cache key) - - if: inputs.dep-cache-key != 'none' + - if: inputs.dep-cache-key != 'none' uses: actions/cache/restore@v4 id: dep-cache with: @@ -50,16 +50,16 @@ jobs: - name: Install Dependencies (if not restored from cache) if: steps.dep-cache.outputs.cache-hit != 'true' - run: npm ci + run: npm ci working-directory: ${{ github.workspace }} - + - run: npm run coverage - uses: codecov/codecov-action@v3 with: files: ${{ env.cwd }}/coverage/lcov.info - flags: trie + flags: mpt - # trie-benchmarks: + # mpt-benchmarks: # runs-on: ubuntu-latest # steps: # - uses: actions/checkout@v4 @@ -85,7 +85,7 @@ jobs: # # Where the output from the benchmark tool is stored # output-file-path: ${{ env.cwd }}/output.txt # # Location of data in gh-pages branch - # benchmark-data-dir-path: dev/bench/trie + # benchmark-data-dir-path: dev/bench/mpt # # GitHub API token to make a commit comment # github-token: ${{ secrets.GITHUB_TOKEN }} # # Push and deploy to GitHub pages branch automatically (if on master) diff --git a/.github/workflows/node-versions.yml b/.github/workflows/node-versions.yml index d85e908c6b..d5c50677e3 100644 --- a/.github/workflows/node-versions.yml +++ b/.github/workflows/node-versions.yml @@ -53,9 +53,9 @@ jobs: run: npm run test:node working-directory: packages/evm - - name: Test Trie + - name: Test MPT run: npm run test:node - working-directory: packages/trie + working-directory: packages/mpt - name: Test Tx run: npm run test:node diff --git a/package-lock.json b/package-lock.json index 2249398bdf..2ea4922bc6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1532,6 +1532,10 @@ "resolved": "packages/genesis", "link": true }, + "node_modules/@ethereumjs/mpt": { + "resolved": "packages/mpt", + "link": true + }, "node_modules/@ethereumjs/rlp": { "resolved": "packages/rlp", "link": true @@ -1540,10 +1544,6 @@ "resolved": "packages/statemanager", "link": true }, - "node_modules/@ethereumjs/trie": { - "resolved": "packages/trie", - "link": true - }, "node_modules/@ethereumjs/tx": { "resolved": "packages/tx", "link": true @@ -17253,8 +17253,8 @@ "license": "MPL-2.0", "dependencies": { "@ethereumjs/common": "^4.4.0", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "ethereum-cryptography": "^3.0.0" @@ -17274,8 +17274,8 @@ "dependencies": { "@ethereumjs/block": "^5.3.0", "@ethereumjs/common": "^4.4.0", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "debug": "^4.3.3", @@ -17310,9 +17310,9 @@ "@ethereumjs/ethash": "3.0.4", "@ethereumjs/evm": "3.1.0", "@ethereumjs/genesis": "0.2.3", + "@ethereumjs/mpt": "6.2.2", "@ethereumjs/rlp": "5.0.2", "@ethereumjs/statemanager": "2.4.0", - "@ethereumjs/trie": "6.2.1", "@ethereumjs/tx": "5.4.0", "@ethereumjs/util": "9.1.0", "@ethereumjs/verkle": "^0.1.0", @@ -17630,12 +17630,49 @@ "@ethereumjs/util": "^9.1.0" }, "devDependencies": { - "@ethereumjs/trie": "^6.2.1" + "@ethereumjs/mpt": "^6.2.2" }, "engines": { "node": ">=18" } }, + "packages/mpt": { + "name": "@ethereumjs/mpt", + "version": "6.2.2", + "license": "MPL-2.0", + "dependencies": { + "@ethereumjs/rlp": "^5.0.2", + "@ethereumjs/util": "^9.1.0", + "@types/readable-stream": "^2.3.13", + "debug": "^4.3.4", + "ethereum-cryptography": "^3.0.0", + "lru-cache": "10.1.0" + }, + "devDependencies": { + "@ethereumjs/genesis": "^0.2.3", + "@types/benchmark": "^1.0.33", + "abstract-level": "^1.0.3", + "level": "^8.0.0", + "level-legacy": "npm:level@^7.0.0", + "level-mem": "^6.0.1", + "levelup": "^5.1.1", + "lmdb": "^2.5.3", + "memory-level": "^1.0.0", + "micro-bmark": "0.2.0" + }, + "engines": { + "node": ">=18" + } + }, + "packages/mpt/node_modules/lru-cache": { + "version": "10.1.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz", + "integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==", + "license": "ISC", + "engines": { + "node": "14 || >=16.14" + } + }, "packages/rlp": { "name": "@ethereumjs/rlp", "version": "5.0.2", @@ -17656,8 +17693,8 @@ "license": "MPL-2.0", "dependencies": { "@ethereumjs/common": "^4.4.0", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", "@ethereumjs/util": "^9.1.0", "@ethereumjs/verkle": "^0.1.0", "@js-sdsl/ordered-map": "^4.4.2", @@ -17684,6 +17721,7 @@ "packages/trie": { "name": "@ethereumjs/trie", "version": "6.2.1", + "extraneous": true, "license": "MPL-2.0", "dependencies": { "@ethereumjs/rlp": "^5.0.2", @@ -17709,14 +17747,6 @@ "node": ">=18" } }, - "packages/trie/node_modules/lru-cache": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.1.0.tgz", - "integrity": "sha512-/1clY/ui8CzjKFyjdvwPWJUYKiFVXG2I2cY0ssG7h4+hwk+XOIX7ZSG9Q7TW8TW3Kp3BUSqgFWBLgL4PJ+Blag==", - "engines": { - "node": "14 || >=16.14" - } - }, "packages/tx": { "name": "@ethereumjs/tx", "version": "5.4.0", @@ -17789,9 +17819,9 @@ "@ethereumjs/block": "^5.3.0", "@ethereumjs/common": "^4.4.0", "@ethereumjs/evm": "^3.1.0", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/statemanager": "^2.4.0", - "@ethereumjs/trie": "^6.2.1", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "debug": "^4.3.3", diff --git a/packages/block/package.json b/packages/block/package.json index acf20c791d..e4eec3634a 100644 --- a/packages/block/package.json +++ b/packages/block/package.json @@ -49,7 +49,7 @@ "dependencies": { "@ethereumjs/common": "^4.4.0", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "ethereum-cryptography": "^3.0.0" diff --git a/packages/block/src/block/block.ts b/packages/block/src/block/block.ts index 35d42dcfab..f1867d6849 100644 --- a/packages/block/src/block/block.ts +++ b/packages/block/src/block/block.ts @@ -1,6 +1,6 @@ import { ConsensusType } from '@ethereumjs/common' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { Blob4844Tx, Capability } from '@ethereumjs/tx' import { BIGINT_0, diff --git a/packages/block/src/block/constructors.ts b/packages/block/src/block/constructors.ts index 530885769d..0bc2b45182 100644 --- a/packages/block/src/block/constructors.ts +++ b/packages/block/src/block/constructors.ts @@ -1,5 +1,5 @@ +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { type TxOptions, createTx, diff --git a/packages/block/src/helpers.ts b/packages/block/src/helpers.ts index d772d2a6a0..9fc406788b 100644 --- a/packages/block/src/helpers.ts +++ b/packages/block/src/helpers.ts @@ -1,5 +1,5 @@ +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { Blob4844Tx } from '@ethereumjs/tx' import { BIGINT_0, BIGINT_1, TypeOutput, isHexString, toType } from '@ethereumjs/util' diff --git a/packages/block/tsconfig.prod.cjs.json b/packages/block/tsconfig.prod.cjs.json index 466aadd816..0609082dc3 100644 --- a/packages/block/tsconfig.prod.cjs.json +++ b/packages/block/tsconfig.prod.cjs.json @@ -10,7 +10,7 @@ "references": [ { "path": "../common/tsconfig.prod.cjs.json" }, { "path": "../rlp/tsconfig.prod.cjs.json" }, - { "path": "../trie/tsconfig.prod.cjs.json" }, + { "path": "../mpt/tsconfig.prod.cjs.json" }, { "path": "../tx/tsconfig.prod.cjs.json" }, { "path": "../util/tsconfig.prod.cjs.json" } ] diff --git a/packages/block/tsconfig.prod.esm.json b/packages/block/tsconfig.prod.esm.json index 837a6d99cf..7d1e56ebff 100644 --- a/packages/block/tsconfig.prod.esm.json +++ b/packages/block/tsconfig.prod.esm.json @@ -10,7 +10,7 @@ "references": [ { "path": "../common/tsconfig.prod.esm.json" }, { "path": "../rlp/tsconfig.prod.esm.json" }, - { "path": "../trie/tsconfig.prod.esm.json" }, + { "path": "../mpt/tsconfig.prod.esm.json" }, { "path": "../tx/tsconfig.prod.esm.json" }, { "path": "../util/tsconfig.prod.esm.json" } ] diff --git a/packages/blockchain/package.json b/packages/blockchain/package.json index d6b4b43e5a..0abcc64586 100644 --- a/packages/blockchain/package.json +++ b/packages/blockchain/package.json @@ -50,7 +50,7 @@ "@ethereumjs/block": "^5.3.0", "@ethereumjs/common": "^4.4.0", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "debug": "^4.3.3", diff --git a/packages/blockchain/src/helpers.ts b/packages/blockchain/src/helpers.ts index fc21c891fd..b6529c26d2 100644 --- a/packages/blockchain/src/helpers.ts +++ b/packages/blockchain/src/helpers.ts @@ -1,5 +1,5 @@ import { ChainGenesis } from '@ethereumjs/common' -import { genesisStateRoot as genMerkleGenesisStateRoot } from '@ethereumjs/trie' +import { genesisMPTStateRoot } from '@ethereumjs/mpt' import type { Chain, Common } from '@ethereumjs/common' import type { GenesisState } from '@ethereumjs/util' @@ -29,7 +29,7 @@ export async function genGenesisStateRoot( if (genCommon.isActivatedEIP(6800)) { throw Error(`Verkle tree state not yet supported`) } else { - return genMerkleGenesisStateRoot(genesisState) + return genesisMPTStateRoot(genesisState) } } diff --git a/packages/blockchain/test/utils.spec.ts b/packages/blockchain/test/utils.spec.ts index cc9bf619ea..4b08430727 100644 --- a/packages/blockchain/test/utils.spec.ts +++ b/packages/blockchain/test/utils.spec.ts @@ -1,5 +1,5 @@ import { createCommonFromGethGenesis } from '@ethereumjs/common' -import { genesisStateRoot } from '@ethereumjs/trie' +import { genesisMPTStateRoot } from '@ethereumjs/mpt' import { bytesToHex, parseGethGenesisState } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -22,7 +22,7 @@ async function getBlockchain(gethGenesis: any): Promise { describe('[Utils/Parse]', () => { it('should properly parse genesis state from gethGenesis', async () => { const genesisState = parseGethGenesisState(postMergeData) - const stateRoot = await genesisStateRoot(genesisState) + const stateRoot = await genesisMPTStateRoot(genesisState) assert.equal( bytesToHex(stateRoot), '0xca3149fa9e37db08d1cd49c9061db1002ef1cd58db2210f2115c8c989b2bdf45', diff --git a/packages/client/archive/libp2p/net/package.json.browser.deps b/packages/client/archive/libp2p/net/package.json.browser.deps index eecd9f43ba..1709ad80bd 100644 --- a/packages/client/archive/libp2p/net/package.json.browser.deps +++ b/packages/client/archive/libp2p/net/package.json.browser.deps @@ -65,7 +65,7 @@ "@ethereumjs/evm": "2.1.0", "@ethereumjs/rlp": "5.0.1", "@ethereumjs/statemanager": "2.1.0", - "@ethereumjs/trie": "6.0.1", + "@ethereumjs/mpt": "6.2.2", "@ethereumjs/tx": "5.1.0", "@ethereumjs/util": "9.0.1", "@ethereumjs/vm": "7.1.0", diff --git a/packages/client/package.json b/packages/client/package.json index 3aecd89777..0ff4708a4a 100644 --- a/packages/client/package.json +++ b/packages/client/package.json @@ -64,7 +64,7 @@ "@ethereumjs/genesis": "0.2.3", "@ethereumjs/rlp": "5.0.2", "@ethereumjs/statemanager": "2.4.0", - "@ethereumjs/trie": "6.2.1", + "@ethereumjs/mpt": "6.2.2", "@ethereumjs/tx": "5.4.0", "@ethereumjs/util": "9.1.0", "@ethereumjs/verkle": "^0.1.0", diff --git a/packages/client/src/execution/vmexecution.ts b/packages/client/src/execution/vmexecution.ts index 37c063747a..0becfd70f1 100644 --- a/packages/client/src/execution/vmexecution.ts +++ b/packages/client/src/execution/vmexecution.ts @@ -7,13 +7,13 @@ import { import { ConsensusType, Hardfork } from '@ethereumjs/common' import { MCLBLS, RustBN254 } from '@ethereumjs/evm' import { getGenesis } from '@ethereumjs/genesis' +import { createMPT } from '@ethereumjs/mpt' import { CacheType, Caches, MerkleStateManager, StatelessVerkleStateManager, } from '@ethereumjs/statemanager' -import { createTrie } from '@ethereumjs/trie' import { BIGINT_0, BIGINT_1, @@ -147,7 +147,7 @@ export class VMExecution extends Execution { if (this.merkleVM !== undefined) { return } - const trie = await createTrie({ + const trie = await createMPT({ db: new LevelDB(this.stateDB), useKeyHashing: true, common: this.config.chainCommon, diff --git a/packages/client/src/sync/fetcher/accountfetcher.ts b/packages/client/src/sync/fetcher/accountfetcher.ts index 1b0e8823aa..c54c8908b5 100644 --- a/packages/client/src/sync/fetcher/accountfetcher.ts +++ b/packages/client/src/sync/fetcher/accountfetcher.ts @@ -1,5 +1,5 @@ +import { verifyMerkleRangeProof } from '@ethereumjs/mpt' import { MerkleStateManager } from '@ethereumjs/statemanager' -import { verifyMPTRangeProof } from '@ethereumjs/trie' import { BIGINT_0, BIGINT_1, @@ -33,7 +33,7 @@ import type { AccountData } from '../../net/protocol/snapprotocol.js' import type { FetcherOptions } from './fetcher.js' import type { StorageRequest } from './storagefetcher.js' import type { Job, SnapFetcherDoneFlags } from './types.js' -import type { MerklePatriciaTrie } from '@ethereumjs/trie' +import type { MerklePatriciaTrie } from '@ethereumjs/mpt' import type { Debugger } from 'debug' type AccountDataResponse = AccountData[] & { completed?: boolean } @@ -324,7 +324,7 @@ export class AccountFetcher extends Fetcher const keys = accounts.map((acc: any) => acc.hash) const values = accounts.map((acc: any) => accountBodyToRLP(acc.body)) // convert the request to the right values - return verifyMPTRangeProof(stateRoot, origin, keys[keys.length - 1], keys, values, proof, { + return verifyMerkleRangeProof(stateRoot, origin, keys[keys.length - 1], keys, values, proof, { common: this.config.chainCommon, useKeyHashingFunction: this.config.chainCommon?.customCrypto?.keccak256 ?? keccak256, }) @@ -405,7 +405,7 @@ export class AccountFetcher extends Fetcher // check zero-element proof if (rangeResult.proof.length > 0) { try { - const isMissingRightRange = await verifyMPTRangeProof( + const isMissingRightRange = await verifyMerkleRangeProof( this.root, origin, null, diff --git a/packages/client/src/sync/fetcher/storagefetcher.ts b/packages/client/src/sync/fetcher/storagefetcher.ts index f0a6c56d08..863541af24 100644 --- a/packages/client/src/sync/fetcher/storagefetcher.ts +++ b/packages/client/src/sync/fetcher/storagefetcher.ts @@ -1,5 +1,5 @@ +import { verifyMerkleRangeProof } from '@ethereumjs/mpt' import { MerkleStateManager } from '@ethereumjs/statemanager' -import { verifyMPTRangeProof } from '@ethereumjs/trie' import { BIGINT_0, BIGINT_1, @@ -128,7 +128,7 @@ export class StorageFetcher extends Fetcher slot.hash) const values = slots.map((slot: any) => slot.body) - return await verifyMPTRangeProof( + return await verifyMerkleRangeProof( stateRoot, origin, keys[keys.length - 1], @@ -280,7 +280,7 @@ export class StorageFetcher extends Fetcher 0) { try { - const isMissingRightRange = await verifyMPTRangeProof( + const isMissingRightRange = await verifyMerkleRangeProof( task.storageRequests[0].storageRoot, origin, null, @@ -337,7 +337,7 @@ export class StorageFetcher extends Fetcher try { // process received node data and request unknown child nodes for (const nodeData of result[0]) { - const node = decodeNode(nodeData as unknown as Uint8Array) + const node = decodeMPTNode(nodeData as unknown as Uint8Array) const nodeHash = bytesToHex(this.keccakFunction(nodeData as unknown as Uint8Array)) const pathString = this.requestedNodeToPath.get(nodeHash) ?? '' const [accountPath, storagePath] = pathString.split('/') @@ -340,7 +340,7 @@ export class TrieNodeFetcher extends Fetcher const { nodeData, path, pathToStorageNode } = data // add account node data to account trie - const node = decodeNode(nodeData) + const node = decodeMPTNode(nodeData) if (node instanceof LeafMPTNode) { const key = bytesToHex(pathToHexKey(path, node.key(), 'keybyte')) ops.push({ @@ -358,7 +358,7 @@ export class TrieNodeFetcher extends Fetcher const storageTrieOps: BatchDBOp[] = [] if (pathToStorageNode !== undefined && pathToStorageNode.size > 0) { for (const [path, data] of pathToStorageNode) { - const storageNode = decodeNode(data) + const storageNode = decodeMPTNode(data) if (storageNode instanceof LeafMPTNode) { const storageKey = bytesToHex(pathToHexKey(path, storageNode.key(), 'keybyte')) storageTrieOps.push({ diff --git a/packages/client/src/util/debug.ts b/packages/client/src/util/debug.ts index c277bb665e..2969adb378 100644 --- a/packages/client/src/util/debug.ts +++ b/packages/client/src/util/debug.ts @@ -29,7 +29,7 @@ import { Level } from 'level'; import { Common } from '@ethereumjs/common' import { Block } from '@ethereumjs/block' import { VM, runBlock, createVM } from './src' -import { MerklePatriciaTrie } from '@ethereumjs/trie' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { MerkleStateManager } from './src/state' import { Blockchain } from '@ethereumjs/blockchain' diff --git a/packages/client/test/net/protocol/snapprotocol.spec.ts b/packages/client/test/net/protocol/snapprotocol.spec.ts index 84004da898..f4c297ec76 100644 --- a/packages/client/test/net/protocol/snapprotocol.spec.ts +++ b/packages/client/test/net/protocol/snapprotocol.spec.ts @@ -1,5 +1,5 @@ +import { decodeMPTNode, verifyMerkleRangeProof } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { decodeNode, verifyMPTRangeProof } from '@ethereumjs/trie' import { KECCAK256_NULL, KECCAK256_RLP, @@ -191,7 +191,7 @@ describe('[SnapProtocol]', () => { try { const keys = accounts.map((acc: any) => acc.hash) const values = accounts.map((acc: any) => accountBodyToRLP(acc.body)) - await verifyMPTRangeProof(stateRoot, keys[0], keys[keys.length - 1], keys, values, proof, { + await verifyMerkleRangeProof(stateRoot, keys[0], keys[keys.length - 1], keys, values, proof, { useKeyHashingFunction: keccak256, }) } catch (e) { @@ -324,7 +324,7 @@ describe('[SnapProtocol]', () => { try { const keys = lastAccountSlots.map((acc: any) => acc.hash) const values = lastAccountSlots.map((acc: any) => acc.body) - await verifyMPTRangeProof( + await verifyMerkleRangeProof( lastAccountStorageRoot, keys[0], keys[keys.length - 1], @@ -486,7 +486,7 @@ describe('[SnapProtocol]', () => { for (let i = 0; i < nodes.length; i++) { const node: Uint8Array = nodes[i] if (node !== null) { - assert.ok(decodeNode(node), 'raw node data should decode without error') + assert.ok(decodeMPTNode(node), 'raw node data should decode without error') } } diff --git a/packages/client/test/rpc/engine/withdrawals.spec.ts b/packages/client/test/rpc/engine/withdrawals.spec.ts index 58ec76b93d..3d8f1b9a5b 100644 --- a/packages/client/test/rpc/engine/withdrawals.spec.ts +++ b/packages/client/test/rpc/engine/withdrawals.spec.ts @@ -1,5 +1,5 @@ import { genWithdrawalsTrieRoot } from '@ethereumjs/block' -import { MerklePatriciaTrie } from '@ethereumjs/trie' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { bigIntToHex, bytesToHex, createWithdrawal, intToHex } from '@ethereumjs/util' import { assert, it } from 'vitest' diff --git a/packages/client/test/sync/fetcher/accountfetcher.spec.ts b/packages/client/test/sync/fetcher/accountfetcher.spec.ts index 86a9da8c1b..0e952be898 100644 --- a/packages/client/test/sync/fetcher/accountfetcher.spec.ts +++ b/packages/client/test/sync/fetcher/accountfetcher.spec.ts @@ -1,5 +1,5 @@ +import { createMPTFromProof } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { createTrieFromProof } from '@ethereumjs/trie' import { bytesToBigInt, hexToBytes } from '@ethereumjs/util' import * as td from 'testdouble' import { assert, describe, it, vi } from 'vitest' @@ -289,7 +289,7 @@ describe('[AccountFetcher]', async () => { const pool = new PeerPool() as any // calculate new root with a key all the way to the right of the trie - const trie = await createTrieFromProof(_zeroElementProof) + const trie = await createMPTFromProof(_zeroElementProof) await trie.put(hexToBytes(`0x${'F'.repeat(32)}`), hexToBytes('0x123'), true) const newRoot = trie.root() diff --git a/packages/client/test/sync/fetcher/storagefetcher.spec.ts b/packages/client/test/sync/fetcher/storagefetcher.spec.ts index a1cb73eac4..ed77a2dcfa 100644 --- a/packages/client/test/sync/fetcher/storagefetcher.spec.ts +++ b/packages/client/test/sync/fetcher/storagefetcher.spec.ts @@ -1,5 +1,5 @@ +import { createMPTFromProof } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { createTrieFromProof } from '@ethereumjs/trie' import { hexToBytes } from '@ethereumjs/util' import { utf8ToBytes } from 'ethereum-cryptography/utils' import { assert, describe, it, vi } from 'vitest' @@ -362,7 +362,7 @@ describe('[StorageFetcher]', async () => { const pool = new PeerPool() as any // calculate new root with a key all the way to the right of the trie - const trie = await createTrieFromProof(_zeroElementProof) + const trie = await createMPTFromProof(_zeroElementProof) await trie.put(hexToBytes(`0x${'F'.repeat(32)}`), hexToBytes('0x123'), true) const newRoot = trie.root() diff --git a/packages/client/test/sync/fetcher/trienodefetcher.spec.ts b/packages/client/test/sync/fetcher/trienodefetcher.spec.ts index d4e2c46203..7cd83ca8ce 100644 --- a/packages/client/test/sync/fetcher/trienodefetcher.spec.ts +++ b/packages/client/test/sync/fetcher/trienodefetcher.spec.ts @@ -1,5 +1,5 @@ +import { decodeMPTNode } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { decodeNode } from '@ethereumjs/trie' import { bytesToHex, hexToBytes } from '@ethereumjs/util' import { OrderedMap } from '@js-sdsl/ordered-map' import { assert, describe, it, vi } from 'vitest' @@ -9,7 +9,7 @@ import { Config } from '../../../src/config.js' import { SnapProtocol } from '../../../src/net/protocol/index.js' import { wait } from '../../integration/util.js' -import type { BranchMPTNode } from '@ethereumjs/trie' +import type { BranchMPTNode } from '@ethereumjs/mpt' // Collected from Sepolia: // getTrieNodes({ @@ -165,7 +165,7 @@ describe('[TrieNodeFetcher]', async () => { await fetcher.store(requestResult) - const rootNode = decodeNode(nodes[0] as unknown as Uint8Array) as BranchMPTNode + const rootNode = decodeMPTNode(nodes[0] as unknown as Uint8Array) as BranchMPTNode const children = rootNode.getChildren() assert.equal( children.length, diff --git a/packages/client/tsconfig.prod.esm.json b/packages/client/tsconfig.prod.esm.json index baf85d72af..a8c3f98a15 100644 --- a/packages/client/tsconfig.prod.esm.json +++ b/packages/client/tsconfig.prod.esm.json @@ -13,7 +13,7 @@ { "path": "../common/tsconfig.prod.esm.json" }, { "path": "../devp2p/tsconfig.prod.esm.json" }, { "path": "../rlp/tsconfig.prod.esm.json" }, - { "path": "../trie/tsconfig.prod.esm.json" }, + { "path": "../mpt/tsconfig.prod.esm.json" }, { "path": "../tx/tsconfig.prod.esm.json" }, { "path": "../util/tsconfig.prod.esm.json" }, { "path": "../vm/tsconfig.prod.esm.json" } diff --git a/packages/evm/tsconfig.prod.cjs.json b/packages/evm/tsconfig.prod.cjs.json index 492f78ea66..92345f08fd 100644 --- a/packages/evm/tsconfig.prod.cjs.json +++ b/packages/evm/tsconfig.prod.cjs.json @@ -10,7 +10,7 @@ { "path": "../common/tsconfig.prod.cjs.json" }, { "path": "../rlp/tsconfig.prod.cjs.json" }, { "path": "../statemanager/tsconfig.prod.cjs.json" }, - { "path": "../trie/tsconfig.prod.cjs.json" }, + { "path": "../mpt/tsconfig.prod.cjs.json" }, { "path": "../tx/tsconfig.prod.cjs.json" }, { "path": "../util/tsconfig.prod.cjs.json" } ] diff --git a/packages/evm/tsconfig.prod.esm.json b/packages/evm/tsconfig.prod.esm.json index bd50460631..61dfc1698b 100644 --- a/packages/evm/tsconfig.prod.esm.json +++ b/packages/evm/tsconfig.prod.esm.json @@ -10,7 +10,7 @@ { "path": "../common/tsconfig.prod.esm.json" }, { "path": "../rlp/tsconfig.prod.esm.json" }, { "path": "../statemanager/tsconfig.prod.esm.json" }, - { "path": "../trie/tsconfig.prod.esm.json" }, + { "path": "../mpt/tsconfig.prod.esm.json" }, { "path": "../tx/tsconfig.prod.esm.json" }, { "path": "../util/tsconfig.prod.esm.json" } ] diff --git a/packages/genesis/package.json b/packages/genesis/package.json index e77e8d9a14..5ae0af7113 100644 --- a/packages/genesis/package.json +++ b/packages/genesis/package.json @@ -66,6 +66,6 @@ "node": ">=18" }, "devDependencies": { - "@ethereumjs/trie": "^6.2.1" + "@ethereumjs/mpt": "^6.2.2" } } diff --git a/packages/genesis/test/index.spec.ts b/packages/genesis/test/index.spec.ts index f321627034..75743c3a55 100644 --- a/packages/genesis/test/index.spec.ts +++ b/packages/genesis/test/index.spec.ts @@ -1,5 +1,5 @@ import { Chain, ChainGenesis } from '@ethereumjs/common' -import { genesisStateRoot as genGenesisStateRoot } from '@ethereumjs/trie' +import { genesisMPTStateRoot } from '@ethereumjs/mpt' import { bytesToHex, equalsBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' @@ -20,7 +20,7 @@ describe('genesis test', () => { `network=${name} chainId=${chainId} genesis should be found`, ) - const stateRoot = await genGenesisStateRoot(genesisState!) + const stateRoot = await genesisMPTStateRoot(genesisState!) assert.ok( equalsBytes(expectedRoot, stateRoot), `network=${name} chainId=${chainId} stateRoot should match expected=${bytesToHex( diff --git a/packages/trie/.c8rc.json b/packages/mpt/.c8rc.json similarity index 100% rename from packages/trie/.c8rc.json rename to packages/mpt/.c8rc.json diff --git a/packages/trie/.eslintrc.cjs b/packages/mpt/.eslintrc.cjs similarity index 100% rename from packages/trie/.eslintrc.cjs rename to packages/mpt/.eslintrc.cjs diff --git a/packages/trie/.gitignore b/packages/mpt/.gitignore similarity index 100% rename from packages/trie/.gitignore rename to packages/mpt/.gitignore diff --git a/packages/trie/.gitmodules b/packages/mpt/.gitmodules similarity index 100% rename from packages/trie/.gitmodules rename to packages/mpt/.gitmodules diff --git a/packages/trie/.npmignore b/packages/mpt/.npmignore similarity index 100% rename from packages/trie/.npmignore rename to packages/mpt/.npmignore diff --git a/packages/trie/.prettierignore b/packages/mpt/.prettierignore similarity index 100% rename from packages/trie/.prettierignore rename to packages/mpt/.prettierignore diff --git a/packages/trie/CHANGELOG.md b/packages/mpt/CHANGELOG.md similarity index 100% rename from packages/trie/CHANGELOG.md rename to packages/mpt/CHANGELOG.md diff --git a/packages/trie/README.md b/packages/mpt/README.md similarity index 64% rename from packages/trie/README.md rename to packages/mpt/README.md index cc35cfd8d4..2ff0685083 100644 --- a/packages/trie/README.md +++ b/packages/mpt/README.md @@ -1,27 +1,27 @@ -# @ethereumjs/trie +# @ethereumjs/mpt -[![NPM Package][trie-npm-badge]][trie-npm-link] -[![GitHub Issues][trie-issues-badge]][trie-issues-link] -[![Actions Status][trie-actions-badge]][trie-actions-link] -[![Code Coverage][trie-coverage-badge]][trie-coverage-link] +[![NPM Package][mpt-npm-badge]][mpt-npm-link] +[![GitHub Issues][mpt-issues-badge]][mpt-issues-link] +[![Actions Status][mpt-actions-badge]][mpt-actions-link] +[![Code Coverage][mpt-coverage-badge]][mpt-coverage-link] [![Discord][discord-badge]][discord-link] -| Implementation of the [Modified Merkle Patricia Trie](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/) as specified in the [Ethereum Yellow Paper](http://gavwood.com/Paper.pdf) | -| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Implementation of the [Modified Merkle Patricia Trie](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-mpt/) as specified in the [Ethereum Yellow Paper](http://gavwood.com/Paper.pdf) | +| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -> The modified Merkle Patricia tree (trie) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the trie, and its sole requirement in terms of the protocol specification, is to provide a single 32-byte value that identifies a given set of key-value pairs. +> The modified Merkle Patricia tree (mpt) provides a persistent data structure to map between arbitrary-length binary data (byte arrays). It is defined in terms of a mutable data structure to map between 256-bit binary fragments and arbitrary-length binary data. The core of the mpt, and its sole requirement in terms of the protocol specification, is to provide a single 32-byte value that identifies a given set of key-value pairs. ## Installation To obtain the latest version, simply require the project using `npm`: ```shell -npm install @ethereumjs/trie +npm install @ethereumjs/mpt ``` ## Usage -This class implements the basic [Modified Merkle Patricia Trie](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-trie/) in the `Trie` base class, which you can use with the `useKeyHashing` option set to `true` to create a trie which stores values under the `keccak256` hash of its keys (this is the Trie flavor which is used in Ethereum production systems). +This class implements the basic [Modified Merkle Patricia Trie](https://ethereum.org/en/developers/docs/data-structures-and-encoding/patricia-merkle-mpt/) in the `Trie` base class, which you can use with the `useKeyHashing` option set to `true` to create a Merkle Patricia Trie which stores values under the `keccak256` hash of its keys (this is the Trie flavor which is used in Ethereum production systems). Checkpointing functionality to `Trie` through the methods `checkpoint`, `commit` and `revert`. @@ -32,11 +32,11 @@ It is best to select the variant that is most appropriate for your unique use ca ```ts // ./examples/basicUsage.ts -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { MapDB, bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' async function test() { - const trie = await createTrie({ db: new MapDB() }) + const trie = await createMPT({ db: new MapDB() }) await trie.put(utf8ToBytes('test'), utf8ToBytes('one')) const value = await trie.get(utf8ToBytes('test')) console.log(value ? bytesToUtf8(value) : 'not found') // 'one' @@ -56,7 +56,7 @@ Tries can be instantiated using standalone constructor functions: ```ts // ./examples/basicUsage.ts#L5-L6 -const trie = await createTrie({ db: new MapDB() }) +const trie = await createMPT({ db: new MapDB() }) await trie.put(utf8ToBytes('test'), utf8ToBytes('one')) ``` @@ -66,7 +66,7 @@ Tries can also be instantiated from a merkle proof: // ./examples/createFromProof.ts#L17-L19 const proof = await createMerkleProof(someOtherTrie, k1) -const trie = await createTrieFromProof(proof, { useKeyHashing: true }) +const trie = await createMPTFromProof(proof, { useKeyHashing: true }) const otherProof = await createMerkleProof(someOtherTrie, k2) ``` @@ -75,11 +75,11 @@ const otherProof = await createMerkleProof(someOtherTrie, k2) ```ts // ./examples/basicUsage.ts -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { MapDB, bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' async function test() { - const trie = await createTrie({ db: new MapDB() }) + const trie = await createMPT({ db: new MapDB() }) await trie.put(utf8ToBytes('test'), utf8ToBytes('one')) const value = await trie.get(utf8ToBytes('test')) console.log(value ? bytesToUtf8(value) : 'not found') // 'one' @@ -88,13 +88,13 @@ async function test() { void test() ``` -When the `createTrie` constructor is used without any options, the `trie` object is instantiated with defaults configured to match the Ethereum production spec (i.e. keys are hashed using SHA256). It also persists the state root of the tree on each write operation, ensuring that your trie remains in the state you left it when you start your application the next time. +When the `createMPT` constructor is used without any options, the `MerklePatriciaTrie` object is instantiated with defaults configured to match the Ethereum production spec (i.e. keys are hashed using SHA256). It also persists the state root of the tree on each write operation, ensuring that your Merkle Patricia Trie remains in the state you left it when you start your application the next time. #### Create from a Proof -The trie library supports basic creation of [EIP-1186](https://eips.ethereum.org/EIPS/eip-1186) proofs as well as the instantiation of new tries from an existing proof. +The MPT library supports basic creation of [EIP-1186](https://eips.ethereum.org/EIPS/eip-1186) proofs as well as the instantiation of new MPTs from an existing proof. -The following is an example for using the `createTrieFromProof()` constructor. This instantiates a new partial trie based only on the branch of the trie contained in the provided proof. +The following is an example for using the `createMPTFromProof()` constructor. This instantiates a new partial Merkle Patricia Trie based only on the branch of the MPT contained in the provided proof. ```ts // ./examples/createFromProof.ts @@ -102,9 +102,9 @@ The following is an example for using the `createTrieFromProof()` constructor. T import { Trie, createMerkleProof, - createTrieFromProof, - updateTrieFromMerkleProof, -} from '@ethereumjs/trie' + createMPTFromProof, + updateMPTFromMerkleProof, +} from '@ethereumjs/mpt' import { bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' async function main() { @@ -116,11 +116,11 @@ async function main() { await someOtherTrie.put(k2, utf8ToBytes('valueTwo')) const proof = await createMerkleProof(someOtherTrie, k1) - const trie = await createTrieFromProof(proof, { useKeyHashing: true }) + const trie = await createMPTFromProof(proof, { useKeyHashing: true }) const otherProof = await createMerkleProof(someOtherTrie, k2) - // To add more proofs to the trie, use `updateTrieFromMerkleProof` - await updateTrieFromMerkleProof(trie, otherProof) + // To add more proofs to the mpt, use `updateMPTFromMerkleProof` + await updateMPTFromMerkleProof(trie, otherProof) const value = await trie.get(k1) console.log(bytesToUtf8(value!)) // valueOne @@ -142,11 +142,11 @@ The new walk functionality can be used like the following: ```ts // ./examples/trieWalking.ts -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { utf8ToBytes } from '@ethereumjs/util' async function main() { - const trie = await createTrie() + const trie = await createMPT() await trie.put(utf8ToBytes('key'), utf8ToBytes('val')) const walk = trie.walkTrieIterable(trie.root()) @@ -158,11 +158,11 @@ async function main() { void main() ``` -### `Trie` Configuration Options +### `MerklePatriciaTrie` Configuration Options #### Database Options -The `DB` opt in the `TrieOpts` allows you to use any database that conforms to the `DB` interface to store the trie data in. We provide several [examples](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples) for database implementations. The [level.js](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples/level.js) example is used in the `ethereumjs client` while [lmdb.js](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples/lmdb.js) is an alternative implementation that uses the popular [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) as its underlying database. +The `DB` opt in the `MPTOpts` allows you to use any database that conforms to the `DB` interface to store the trie data in. We provide several [examples](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples) for database implementations. The [level.js](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples/level.js) example is used in the `ethereumjs client` while [lmdb.js](https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie/examples/lmdb.js) is an alternative implementation that uses the popular [LMDB](https://en.wikipedia.org/wiki/Lightning_Memory-Mapped_Database) as its underlying database. If no `db` option is provided, an in-memory database powered by [a Javascript Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) will fulfill this role (imported from `@ethereumjs/util`, see [mapDB](https://github.com/ethereumjs/ethereumjs-monorepo/blob/master/packages/util/src/mapDB.ts) module). @@ -187,16 +187,16 @@ By default, the deletion of trie nodes from the underlying database does not occ #### Root Persistence -You can enable persistence by setting the `useRootPersistence` option to `true` when constructing a trie through the `createTrie` function. As such, this value is preserved when creating copies of the trie and is incapable of being modified once a trie is instantiated. +You can enable persistence by setting the `useRootPersistence` option to `true` when constructing a trie through the `createMPT` function. As such, this value is preserved when creating copies of the trie and is incapable of being modified once a trie is instantiated. ```ts // ./examples/rootPersistence.ts -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { bytesToHex } from '@ethereumjs/util' async function main() { - const trie = await createTrie({ + const trie = await createMPT({ useRootPersistence: true, }) @@ -262,7 +262,7 @@ try { ### Range Proofs -You may use the `verifyTrieRangeProof()` function to confirm if the given leaf nodes and edge proof possess the capacity to prove that the given trie leaves' range matches the specific root (which is useful for snap sync, for instance). +You may use the `verifyMPTRangeProof()` function to confirm if the given leaf nodes and edge proof possess the capacity to prove that the given trie leaves' range matches the specific root (which is useful for snap sync, for instance). ## Examples @@ -341,69 +341,69 @@ The `Trie` class features optional debug logging. Individual debug selections ca The following options are available: -| Logger | Description | -| --------------------------------- | -------------------------------------------------------------------- | -| `trie:#` | minimal info logging for all trie methods | -| `trie:#:put` | a trie put operation has occurred | -| `trie:#:get` | a trie get operation has occurred | -| `trie:#:del` | a trie del operation has occurred | -| `trie:#:find_path` | a node is being searched for | -| `trie:#:find_path:branch_node` | a branch node has been found during a node search | -| `trie:#:find_path:extension_node` | an extension node has been found during a node search | -| `trie:#:lookup_node` | node lookup operations | -| `trie:#:lookup_node:raw_node` | node lookup operations that have hit a raw node | -| `trie:#:lookup_node:by_hash` | node lookup operations that have hit a node hash | -| `trie:#:persist_root` | operations writing the state root to the disk | -| `trie:#:checkpoint` | checkpoint operations | -| `trie:#:commit` | operations committing checkpoints to the disk | -| `trie:#:revert:before` | the stateRoot before reverting committed checkpoints | -| `trie:#:revert:after` | the stateRoot after reverting committed checkpoints | -| `trie:#:flush_checkpoints` | checkpoints are being flushed | -| `trie:#:from_proof` | a trie has been updated from a proof using updateTrieFromMerkleProof | -| `trie:#:create_proof` | a merkle proof has been created using updateTrieFromMerkleProof | +| Logger | Description | +| -------------------------------- | ------------------------------------------------------------------ | +| `mpt:#` | minimal info logging for all mpt methods | +| `mpt:#:put` | a mpt put operation has occurred | +| `mpt:#:get` | a mpt get operation has occurred | +| `mpt:#:del` | a mpt del operation has occurred | +| `mpt:#:find_path` | a node is being searched for | +| `mpt:#:find_path:branch_node` | a branch node has been found during a node search | +| `mpt:#:find_path:extension_node` | an extension node has been found during a node search | +| `mpt:#:lookup_node` | node lookup operations | +| `mpt:#:lookup_node:raw_node` | node lookup operations that have hit a raw node | +| `mpt:#:lookup_node:by_hash` | node lookup operations that have hit a node hash | +| `mpt:#:persist_root` | operations writing the state root to the disk | +| `mpt:#:checkpoint` | checkpoint operations | +| `mpt:#:commit` | operations committing checkpoints to the disk | +| `mpt:#:revert:before` | the stateRoot before reverting committed checkpoints | +| `mpt:#:revert:after` | the stateRoot after reverting committed checkpoints | +| `mpt:#:flush_checkpoints` | checkpoints are being flushed | +| `mpt:#:from_proof` | a mpt has been updated from a proof using updateMPTFromMerkleProof | +| `mpt:#:create_proof` | a merkle proof has been created using updateMPTFromMerkleProof | To observe the logging in action at different levels: Run with minimal logging: ```shell -DEBUG=ethjs,trie npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt npx vitest test/util/log.spec.ts ``` Run with **put** method logging: ```shell -DEBUG=ethjs,trie:put npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt:put npx vitest test/util/log.spec.ts ``` -Run with **trie** + **put**/**get**/**del** logging: +Run with **mpt** + **put**/**get**/**del** logging: ```shell -DEBUG=ethjs,trie,trie:put,trie:get,trie:del npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt,mpt:put,mpt:get,mpt:del npx vitest test/util/log.spec.ts ``` Run with **findPath** debug logging: ```shell -DEBUG=ethjs,trie:find_path npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt:find_path npx vitest test/util/log.spec.ts ``` Run with **findPath** verbose logging: ```shell -DEBUG=ethjs,trie:find_path:* npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt:find_path:* npx vitest test/util/log.spec.ts ``` Run with max logging: ```shell -DEBUG=ethjs,trie:* npx vitest test/util/log.spec.ts +DEBUG=ethjs,mpt:* npx vitest test/util/log.spec.ts ``` `ethjs` **must** be included in the `DEBUG` environment variables to enable **any** logs. Additional log selections can be added with a comma separated list (no spaces). Logs with extensions can be enabled with a colon `:`, and `*` can be used to include all extensions. -`DEBUG=ethjs,trie:put,trie:find_path:* npx vitest test/proof.spec.ts` +`DEBUG=ethjs,mpt:put,mpt:find_path:* npx vitest test/proof.spec.ts` ## References @@ -426,11 +426,11 @@ See our organizational [documentation](https://ethereumjs.readthedocs.io) for an [discord-badge]: https://img.shields.io/static/v1?logo=discord&label=discord&message=Join&color=blue [discord-link]: https://discord.gg/TNwARpR -[trie-npm-badge]: https://img.shields.io/npm/v/@ethereumjs/trie.svg -[trie-npm-link]: https://www.npmjs.com/package/@ethereumjs/trie -[trie-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20trie?label=issues -[trie-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+trie" -[trie-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Trie/badge.svg -[trie-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Trie%22 -[trie-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=trie -[trie-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie +[mpt-npm-badge]: https://img.shields.io/npm/v/@ethereumjs/mpt.svg +[mpt-npm-link]: https://www.npmjs.com/package/@ethereumjs/mpt +[mpt-issues-badge]: https://img.shields.io/github/issues/ethereumjs/ethereumjs-monorepo/package:%20mpt?label=issues +[mpt-issues-link]: https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aopen+is%3Aissue+label%3A"package%3A+mpt" +[mpt-actions-badge]: https://github.com/ethereumjs/ethereumjs-monorepo/workflows/Trie/badge.svg +[mpt-actions-link]: https://github.com/ethereumjs/ethereumjs-monorepo/actions?query=workflow%3A%22Trie%22 +[mpt-coverage-badge]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/branch/master/graph/badge.svg?flag=mpt +[mpt-coverage-link]: https://codecov.io/gh/ethereumjs/ethereumjs-monorepo/tree/master/packages/mpt diff --git a/packages/trie/UPGRADING.md b/packages/mpt/UPGRADING.md similarity index 100% rename from packages/trie/UPGRADING.md rename to packages/mpt/UPGRADING.md diff --git a/packages/trie/benchmarks/engines/level.ts b/packages/mpt/benchmarks/engines/level.ts similarity index 100% rename from packages/trie/benchmarks/engines/level.ts rename to packages/mpt/benchmarks/engines/level.ts diff --git a/packages/trie/benchmarks/index.ts b/packages/mpt/benchmarks/index.ts similarity index 100% rename from packages/trie/benchmarks/index.ts rename to packages/mpt/benchmarks/index.ts diff --git a/packages/trie/benchmarks/keys.ts b/packages/mpt/benchmarks/keys.ts similarity index 100% rename from packages/trie/benchmarks/keys.ts rename to packages/mpt/benchmarks/keys.ts diff --git a/packages/trie/benchmarks/suite.ts b/packages/mpt/benchmarks/suite.ts similarity index 100% rename from packages/trie/benchmarks/suite.ts rename to packages/mpt/benchmarks/suite.ts diff --git a/packages/trie/docs/README.md b/packages/mpt/docs/README.md similarity index 100% rename from packages/trie/docs/README.md rename to packages/mpt/docs/README.md diff --git a/packages/trie/docs/classes/BranchNode.md b/packages/mpt/docs/classes/BranchNode.md similarity index 100% rename from packages/trie/docs/classes/BranchNode.md rename to packages/mpt/docs/classes/BranchNode.md diff --git a/packages/trie/docs/classes/CheckpointDB.md b/packages/mpt/docs/classes/CheckpointDB.md similarity index 100% rename from packages/trie/docs/classes/CheckpointDB.md rename to packages/mpt/docs/classes/CheckpointDB.md diff --git a/packages/trie/docs/classes/ExtensionNode.md b/packages/mpt/docs/classes/ExtensionNode.md similarity index 100% rename from packages/trie/docs/classes/ExtensionNode.md rename to packages/mpt/docs/classes/ExtensionNode.md diff --git a/packages/trie/docs/classes/LeafNode.md b/packages/mpt/docs/classes/LeafNode.md similarity index 100% rename from packages/trie/docs/classes/LeafNode.md rename to packages/mpt/docs/classes/LeafNode.md diff --git a/packages/trie/docs/classes/PrioritizedTaskExecutor.md b/packages/mpt/docs/classes/PrioritizedTaskExecutor.md similarity index 100% rename from packages/trie/docs/classes/PrioritizedTaskExecutor.md rename to packages/mpt/docs/classes/PrioritizedTaskExecutor.md diff --git a/packages/trie/docs/classes/Trie.md b/packages/mpt/docs/classes/Trie.md similarity index 100% rename from packages/trie/docs/classes/Trie.md rename to packages/mpt/docs/classes/Trie.md diff --git a/packages/trie/docs/classes/TrieReadStream.md b/packages/mpt/docs/classes/TrieReadStream.md similarity index 100% rename from packages/trie/docs/classes/TrieReadStream.md rename to packages/mpt/docs/classes/TrieReadStream.md diff --git a/packages/trie/docs/classes/WalkController.md b/packages/mpt/docs/classes/WalkController.md similarity index 100% rename from packages/trie/docs/classes/WalkController.md rename to packages/mpt/docs/classes/WalkController.md diff --git a/packages/trie/docs/interfaces/CheckpointDBOpts.md b/packages/mpt/docs/interfaces/CheckpointDBOpts.md similarity index 100% rename from packages/trie/docs/interfaces/CheckpointDBOpts.md rename to packages/mpt/docs/interfaces/CheckpointDBOpts.md diff --git a/packages/trie/docs/interfaces/CommonInterface.md b/packages/mpt/docs/interfaces/CommonInterface.md similarity index 100% rename from packages/trie/docs/interfaces/CommonInterface.md rename to packages/mpt/docs/interfaces/CommonInterface.md diff --git a/packages/trie/docs/interfaces/Path.md b/packages/mpt/docs/interfaces/Path.md similarity index 100% rename from packages/trie/docs/interfaces/Path.md rename to packages/mpt/docs/interfaces/Path.md diff --git a/packages/trie/docs/interfaces/TrieOpts.md b/packages/mpt/docs/interfaces/TrieOpts.md similarity index 100% rename from packages/trie/docs/interfaces/TrieOpts.md rename to packages/mpt/docs/interfaces/TrieOpts.md diff --git a/packages/trie/docs/interfaces/TrieShallowCopyOpts.md b/packages/mpt/docs/interfaces/TrieShallowCopyOpts.md similarity index 100% rename from packages/trie/docs/interfaces/TrieShallowCopyOpts.md rename to packages/mpt/docs/interfaces/TrieShallowCopyOpts.md diff --git a/packages/trie/examples/README.md b/packages/mpt/examples/README.md similarity index 100% rename from packages/trie/examples/README.md rename to packages/mpt/examples/README.md diff --git a/packages/trie/examples/basicUsage.ts b/packages/mpt/examples/basicUsage.ts similarity index 74% rename from packages/trie/examples/basicUsage.ts rename to packages/mpt/examples/basicUsage.ts index 5a008b3b8b..add95dacd5 100644 --- a/packages/trie/examples/basicUsage.ts +++ b/packages/mpt/examples/basicUsage.ts @@ -1,8 +1,8 @@ -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { MapDB, bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' async function test() { - const trie = await createTrie({ db: new MapDB() }) + const trie = await createMPT({ db: new MapDB() }) await trie.put(utf8ToBytes('test'), utf8ToBytes('one')) const value = await trie.get(utf8ToBytes('test')) console.log(value ? bytesToUtf8(value) : 'not found') // 'one' diff --git a/packages/trie/examples/browser.html b/packages/mpt/examples/browser.html similarity index 96% rename from packages/trie/examples/browser.html rename to packages/mpt/examples/browser.html index 56b51fb3de..d6c4c18835 100644 --- a/packages/trie/examples/browser.html +++ b/packages/mpt/examples/browser.html @@ -8,7 +8,7 @@ -

Trie | @ethereumjs/trie

+

MPT | @ethereumjs/mpt

Basic usage of this library in the browser (using Vite)

Run the Example

@@ -30,4 +30,4 @@

Interactive CLI

- \ No newline at end of file + diff --git a/packages/trie/examples/createFromProof.ts b/packages/mpt/examples/createFromProof.ts similarity index 72% rename from packages/trie/examples/createFromProof.ts rename to packages/mpt/examples/createFromProof.ts index f252f7440f..a6e464fc1d 100644 --- a/packages/trie/examples/createFromProof.ts +++ b/packages/mpt/examples/createFromProof.ts @@ -1,9 +1,9 @@ import { MerklePatriciaTrie, + createMPTFromProof, createMerkleProof, - createTrieFromProof, - updateTrieFromMerkleProof, -} from '@ethereumjs/trie' + updateMPTFromMerkleProof, +} from '@ethereumjs/mpt' import { bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' async function main() { @@ -15,11 +15,11 @@ async function main() { await someOtherTrie.put(k2, utf8ToBytes('valueTwo')) const proof = await createMerkleProof(someOtherTrie, k1) - const trie = await createTrieFromProof(proof, { useKeyHashing: true }) + const trie = await createMPTFromProof(proof, { useKeyHashing: true }) const otherProof = await createMerkleProof(someOtherTrie, k2) - // To add more proofs to the trie, use `updateTrieFromMerkleProof` - await updateTrieFromMerkleProof(trie, otherProof) + // To add more proofs to the trie, use `updateMPTFromMerkleProof` + await updateMPTFromMerkleProof(trie, otherProof) const value = await trie.get(k1) console.log(bytesToUtf8(value!)) // valueOne diff --git a/packages/trie/examples/customLevelDB.ts b/packages/mpt/examples/customLevelDB.ts similarity index 98% rename from packages/trie/examples/customLevelDB.ts rename to packages/mpt/examples/customLevelDB.ts index 038c00a650..e1b0c26f69 100644 --- a/packages/trie/examples/customLevelDB.ts +++ b/packages/mpt/examples/customLevelDB.ts @@ -1,4 +1,4 @@ -import { MerklePatriciaTrie } from '@ethereumjs/trie' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { KeyEncoding, ValueEncoding } from '@ethereumjs/util' import { Level } from 'level' import { MemoryLevel } from 'memory-level' diff --git a/packages/trie/examples/level-legacy.js b/packages/mpt/examples/level-legacy.js similarity index 100% rename from packages/trie/examples/level-legacy.js rename to packages/mpt/examples/level-legacy.js diff --git a/packages/trie/examples/level.js b/packages/mpt/examples/level.js similarity index 100% rename from packages/trie/examples/level.js rename to packages/mpt/examples/level.js diff --git a/packages/trie/examples/lmdb.js b/packages/mpt/examples/lmdb.js similarity index 97% rename from packages/trie/examples/lmdb.js rename to packages/mpt/examples/lmdb.js index 07c851ba6f..9e3ef974af 100644 --- a/packages/trie/examples/lmdb.js +++ b/packages/mpt/examples/lmdb.js @@ -8,7 +8,7 @@ class LMDB { this.path = path this.database = open({ compression: true, - name: '@ethereumjs/trie', + name: '@ethereumjs/mpt', path, }) } diff --git a/packages/trie/examples/logDemo.ts b/packages/mpt/examples/logDemo.ts similarity index 78% rename from packages/trie/examples/logDemo.ts rename to packages/mpt/examples/logDemo.ts index d224f43cb1..04eb2ac575 100644 --- a/packages/trie/examples/logDemo.ts +++ b/packages/mpt/examples/logDemo.ts @@ -1,7 +1,7 @@ /** * Run with DEBUG=ethjs,trie:* to see debug log output */ -import { MerklePatriciaTrie, createMerkleProof, verifyMerkleProof } from '@ethereumjs/trie' +import { MerklePatriciaTrie, createMerkleProof, verifyMPTWithMerkleProof } from '@ethereumjs/mpt' import { utf8ToBytes } from '@ethereumjs/util' const trie_entries: [string, string | null][] = [ @@ -23,7 +23,7 @@ const main = async () => { await trie.put(utf8ToBytes(key), value === null ? Uint8Array.from([]) : utf8ToBytes(value)) } const proof = await createMerkleProof(trie, utf8ToBytes('doge')) - const valid = await verifyMerkleProof(trie, trie.root(), utf8ToBytes('doge'), proof) + const valid = await verifyMPTWithMerkleProof(trie, trie.root(), utf8ToBytes('doge'), proof) console.log('valid', valid) } diff --git a/packages/trie/examples/merkle_patricia_trees/README.md b/packages/mpt/examples/merkle_patricia_trees/README.md similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/README.md rename to packages/mpt/examples/merkle_patricia_trees/README.md diff --git a/packages/trie/examples/merkle_patricia_trees/example1a.js b/packages/mpt/examples/merkle_patricia_trees/example1a.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example1a.js rename to packages/mpt/examples/merkle_patricia_trees/example1a.js diff --git a/packages/trie/examples/merkle_patricia_trees/example1b.js b/packages/mpt/examples/merkle_patricia_trees/example1b.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example1b.js rename to packages/mpt/examples/merkle_patricia_trees/example1b.js diff --git a/packages/trie/examples/merkle_patricia_trees/example1c.js b/packages/mpt/examples/merkle_patricia_trees/example1c.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example1c.js rename to packages/mpt/examples/merkle_patricia_trees/example1c.js diff --git a/packages/trie/examples/merkle_patricia_trees/example1d.js b/packages/mpt/examples/merkle_patricia_trees/example1d.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example1d.js rename to packages/mpt/examples/merkle_patricia_trees/example1d.js diff --git a/packages/trie/examples/merkle_patricia_trees/example2a.js b/packages/mpt/examples/merkle_patricia_trees/example2a.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example2a.js rename to packages/mpt/examples/merkle_patricia_trees/example2a.js diff --git a/packages/trie/examples/merkle_patricia_trees/example2b.js b/packages/mpt/examples/merkle_patricia_trees/example2b.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example2b.js rename to packages/mpt/examples/merkle_patricia_trees/example2b.js diff --git a/packages/trie/examples/merkle_patricia_trees/example2c.js b/packages/mpt/examples/merkle_patricia_trees/example2c.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example2c.js rename to packages/mpt/examples/merkle_patricia_trees/example2c.js diff --git a/packages/trie/examples/merkle_patricia_trees/example2d.js b/packages/mpt/examples/merkle_patricia_trees/example2d.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example2d.js rename to packages/mpt/examples/merkle_patricia_trees/example2d.js diff --git a/packages/trie/examples/merkle_patricia_trees/example3a.js b/packages/mpt/examples/merkle_patricia_trees/example3a.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example3a.js rename to packages/mpt/examples/merkle_patricia_trees/example3a.js diff --git a/packages/trie/examples/merkle_patricia_trees/example3b.js b/packages/mpt/examples/merkle_patricia_trees/example3b.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example3b.js rename to packages/mpt/examples/merkle_patricia_trees/example3b.js diff --git a/packages/trie/examples/merkle_patricia_trees/example4a.js b/packages/mpt/examples/merkle_patricia_trees/example4a.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example4a.js rename to packages/mpt/examples/merkle_patricia_trees/example4a.js diff --git a/packages/trie/examples/merkle_patricia_trees/example4b.js b/packages/mpt/examples/merkle_patricia_trees/example4b.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/example4b.js rename to packages/mpt/examples/merkle_patricia_trees/example4b.js diff --git a/packages/trie/examples/merkle_patricia_trees/infura_endpoint.js b/packages/mpt/examples/merkle_patricia_trees/infura_endpoint.js similarity index 100% rename from packages/trie/examples/merkle_patricia_trees/infura_endpoint.js rename to packages/mpt/examples/merkle_patricia_trees/infura_endpoint.js diff --git a/packages/trie/examples/proofs.ts b/packages/mpt/examples/proofs.ts similarity index 69% rename from packages/trie/examples/proofs.ts rename to packages/mpt/examples/proofs.ts index 34e0495dc8..3b69002cf9 100644 --- a/packages/trie/examples/proofs.ts +++ b/packages/mpt/examples/proofs.ts @@ -1,4 +1,4 @@ -import { MerklePatriciaTrie, createMerkleProof, verifyMerkleProof } from '@ethereumjs/trie' +import { MerklePatriciaTrie, createMerkleProof, verifyMPTWithMerkleProof } from '@ethereumjs/mpt' import { bytesToUtf8, utf8ToBytes } from '@ethereumjs/util' const trie = new MerklePatriciaTrie() @@ -12,14 +12,14 @@ async function main() { // proof-of-inclusion await trie.put(k1, v1) let proof = await createMerkleProof(trie, k1) - let value = await verifyMerkleProof(trie, trie.root(), k1, proof) + let value = await verifyMPTWithMerkleProof(trie, trie.root(), k1, proof) console.log(value ? bytesToUtf8(value) : 'not found') // 'one' // proof-of-exclusion await trie.put(k1, v1) await trie.put(k2, v2) proof = await createMerkleProof(trie, utf8ToBytes('key3')) - value = await verifyMerkleProof(trie, trie.root(), utf8ToBytes('key3'), proof) + value = await verifyMPTWithMerkleProof(trie, trie.root(), utf8ToBytes('key3'), proof) console.log(value ? bytesToUtf8(value) : 'null') // null // invalid proof @@ -28,7 +28,7 @@ async function main() { proof = await createMerkleProof(trie, k2) proof[0].reverse() try { - const _value = await verifyMerkleProof(trie, trie.root(), k2, proof) // results in error + const _value = await verifyMPTWithMerkleProof(trie, trie.root(), k2, proof) // results in error } catch (err) { console.log(err) } diff --git a/packages/trie/examples/rootPersistence.ts b/packages/mpt/examples/rootPersistence.ts similarity index 79% rename from packages/trie/examples/rootPersistence.ts rename to packages/mpt/examples/rootPersistence.ts index e22841a585..7cf597115a 100644 --- a/packages/trie/examples/rootPersistence.ts +++ b/packages/mpt/examples/rootPersistence.ts @@ -1,8 +1,8 @@ -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { bytesToHex } from '@ethereumjs/util' async function main() { - const trie = await createTrie({ + const trie = await createMPT({ useRootPersistence: true, }) diff --git a/packages/trie/examples/trieWalking.ts b/packages/mpt/examples/trieWalking.ts similarity index 79% rename from packages/trie/examples/trieWalking.ts rename to packages/mpt/examples/trieWalking.ts index a384fa661f..4a2233cf8b 100644 --- a/packages/trie/examples/trieWalking.ts +++ b/packages/mpt/examples/trieWalking.ts @@ -1,8 +1,8 @@ -import { createTrie } from '@ethereumjs/trie' +import { createMPT } from '@ethereumjs/mpt' import { utf8ToBytes } from '@ethereumjs/util' async function main() { - const trie = await createTrie() + const trie = await createMPT() await trie.put(utf8ToBytes('key'), utf8ToBytes('val')) const walk = trie.walkTrieIterable(trie.root()) diff --git a/packages/trie/package.json b/packages/mpt/package.json similarity index 92% rename from packages/trie/package.json rename to packages/mpt/package.json index df0ccb7497..6e9e3c11a6 100644 --- a/packages/trie/package.json +++ b/packages/mpt/package.json @@ -1,6 +1,6 @@ { - "name": "@ethereumjs/trie", - "version": "6.2.1", + "name": "@ethereumjs/mpt", + "version": "6.2.2", "description": "Implementation of the modified merkle patricia tree as specified in Ethereum's yellow paper.", "keywords": [ "merkle", @@ -8,9 +8,9 @@ "trie", "ethereum" ], - "homepage": "https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/trie#readme", + "homepage": "https://github.com/ethereumjs/ethereumjs-monorepo/tree/master/packages/mpt#readme", "bugs": { - "url": "https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aissue+label%3A%22package%3A+trie%22" + "url": "https://github.com/ethereumjs/ethereumjs-monorepo/issues?q=is%3Aissue+label%3A%22package%3A+mpt%22" }, "repository": { "type": "git", @@ -41,7 +41,7 @@ "clean": "../../config/cli/clean-package.sh", "coverage": "DEBUG=ethjs npx vitest run --coverage.enabled --coverage.reporter=lcov", "docs:build": "typedoc --options typedoc.cjs", - "examples": "tsx ../../scripts/examples-runner.ts -- trie", + "examples": "tsx ../../scripts/examples-runner.ts -- mpt", "examples:build": "npx embedme README.md", "lint": "../../config/cli/lint.sh", "lint:diff": "../../config/cli/lint-diff.sh", diff --git a/packages/trie/recipes/level-legacy.ts b/packages/mpt/recipes/level-legacy.ts similarity index 100% rename from packages/trie/recipes/level-legacy.ts rename to packages/mpt/recipes/level-legacy.ts diff --git a/packages/trie/recipes/level.ts b/packages/mpt/recipes/level.ts similarity index 99% rename from packages/trie/recipes/level.ts rename to packages/mpt/recipes/level.ts index 68b78e03f3..449e79fa71 100644 --- a/packages/trie/recipes/level.ts +++ b/packages/mpt/recipes/level.ts @@ -17,7 +17,7 @@ export class LevelDB implements DB { string | Uint8Array | Uint8Array, string | Uint8Array, string | Uint8Array - > | null + > | null, ) { this._leveldb = leveldb ?? new MemoryLevel(ENCODING_OPTS) } diff --git a/packages/trie/recipes/lmdb.ts b/packages/mpt/recipes/lmdb.ts similarity index 96% rename from packages/trie/recipes/lmdb.ts rename to packages/mpt/recipes/lmdb.ts index f9e9315a2e..1e59780be4 100644 --- a/packages/trie/recipes/lmdb.ts +++ b/packages/mpt/recipes/lmdb.ts @@ -10,7 +10,7 @@ export class LMDB implements DB { this._path = path this._database = open({ compression: true, - name: '@ethereumjs/trie', + name: '@ethereumjs/mpt', path, }) } diff --git a/packages/trie/scripts/view.ts b/packages/mpt/scripts/view.ts similarity index 100% rename from packages/trie/scripts/view.ts rename to packages/mpt/scripts/view.ts diff --git a/packages/trie/scripts/walkDemo.ts b/packages/mpt/scripts/walkDemo.ts similarity index 100% rename from packages/trie/scripts/walkDemo.ts rename to packages/mpt/scripts/walkDemo.ts diff --git a/packages/trie/src/constructors.ts b/packages/mpt/src/constructors.ts similarity index 82% rename from packages/trie/src/constructors.ts rename to packages/mpt/src/constructors.ts index 5bb8c57a90..ba157d982d 100644 --- a/packages/trie/src/constructors.ts +++ b/packages/mpt/src/constructors.ts @@ -7,11 +7,11 @@ import { import { keccak256 } from 'ethereum-cryptography/keccak' import { concatBytes } from 'ethereum-cryptography/utils' -import { MerklePatriciaTrie, ROOT_DB_KEY, updateTrieFromMerkleProof } from './index.js' +import { MerklePatriciaTrie, ROOT_DB_KEY, updateMPTFromMerkleProof } from './index.js' import type { MPTOpts, Proof } from './index.js' -export async function createTrie(opts?: MPTOpts) { +export async function createMPT(opts?: MPTOpts) { const keccakFunction = opts?.common?.customCrypto.keccak256 ?? opts?.useKeyHashingFunction ?? keccak256 let key = ROOT_DB_KEY @@ -56,14 +56,13 @@ export async function createTrie(opts?: MPTOpts) { * Create a trie from a given (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof. A proof contains the encoded trie nodes * from the root node to the leaf node storing state data. * @param proof an EIP-1186 proof to create trie from - * @param shouldVerifyRoot If `true`, verifies that the root key of the proof matches the trie root. Throws if this is not the case. * @param trieOpts trie opts to be applied to returned trie * @returns new trie created from given proof */ -export async function createTrieFromProof(proof: Proof, trieOpts?: MPTOpts) { +export async function createMPTFromProof(proof: Proof, trieOpts?: MPTOpts) { const shouldVerifyRoot = trieOpts?.root !== undefined const trie = new MerklePatriciaTrie(trieOpts) - const root = await updateTrieFromMerkleProof(trie, proof, shouldVerifyRoot) + const root = await updateMPTFromMerkleProof(trie, proof, shouldVerifyRoot) trie.root(root) await trie.persistRoot() return trie diff --git a/packages/trie/src/db/checkpoint.ts b/packages/mpt/src/db/checkpoint.ts similarity index 100% rename from packages/trie/src/db/checkpoint.ts rename to packages/mpt/src/db/checkpoint.ts diff --git a/packages/trie/src/db/index.ts b/packages/mpt/src/db/index.ts similarity index 100% rename from packages/trie/src/db/index.ts rename to packages/mpt/src/db/index.ts diff --git a/packages/trie/src/index.ts b/packages/mpt/src/index.ts similarity index 87% rename from packages/trie/src/index.ts rename to packages/mpt/src/index.ts index ed566d8a3c..fe0867b4f6 100644 --- a/packages/trie/src/index.ts +++ b/packages/mpt/src/index.ts @@ -1,7 +1,7 @@ export * from './constructors.js' export * from './db/index.js' +export * from './mpt.js' export * from './node/index.js' export * from './proof/index.js' -export * from './trie.js' export * from './types.js' export * from './util/index.js' diff --git a/packages/trie/src/trie.ts b/packages/mpt/src/mpt.ts similarity index 97% rename from packages/trie/src/trie.ts rename to packages/mpt/src/mpt.ts index e6944c9490..4d61ca1b24 100644 --- a/packages/trie/src/trie.ts +++ b/packages/mpt/src/mpt.ts @@ -24,9 +24,9 @@ import { BranchMPTNode, ExtensionMPTNode, LeafMPTNode, - decodeNode, - decodeRawNode, - isRawNode, + decodeMPTNode, + decodeRawMPTNode, + isRawMPTNode, } from './node/index.js' import { ROOT_DB_KEY } from './types.js' import { _walkTrie } from './util/asyncWalk.js' @@ -40,7 +40,7 @@ import type { MPTOpts, MPTOptsWithDefaults, Nibbles, - NodeReferenceOrRawNode, + NodeReferenceOrRawMPTNode, Path, TrieShallowCopyOpts, } from './types.js' @@ -49,7 +49,7 @@ import type { BatchDBOp, DB } from '@ethereumjs/util' import type { Debugger } from 'debug' /** - * The basic trie interface, use with `import { MerklePatriciaTrie } from '@ethereumjs/trie'`. + * The basic trie interface, use with `import { MerklePatriciaTrie } from '@ethereumjs/mpt'`. */ export class MerklePatriciaTrie { protected readonly _opts: MPTOptsWithDefaults = { @@ -80,7 +80,7 @@ export class MerklePatriciaTrie { * Creates a new trie. * @param opts Options for instantiating the trie * - * Note: in most cases, {@link createTrie} constructor should be used. It uses the same API but provides sensible defaults + * Note: in most cases, {@link createMPT} constructor should be used. It uses the same API but provides sensible defaults */ constructor(opts?: MPTOpts) { let valueEncoding: ValueEncoding @@ -510,8 +510,8 @@ export class MerklePatriciaTrie { * Retrieves a node from db by hash. */ async lookupNode(node: Uint8Array | Uint8Array[]): Promise { - if (isRawNode(node)) { - const decoded = decodeRawNode(node) + if (isRawMPTNode(node)) { + const decoded = decodeRawMPTNode(node) this.DEBUG && this.debug(`${decoded.constructor.name}`, ['lookup_node', 'raw_node']) return decoded } @@ -520,11 +520,11 @@ export class MerklePatriciaTrie { const value = (await this._db.get(key)) ?? null if (value === null) { - // Dev note: this error message text is used for error checking in `checkRoot`, `verifyMerkleProof`, and `findPath` + // Dev note: this error message text is used for error checking in `checkRoot`, `verifyMPTWithMerkleProof`, and `findPath` throw new Error('Missing node in DB') } - const decoded = decodeNode(value) + const decoded = decodeMPTNode(value) this.DEBUG && this.debug(`${decoded.constructor.name} found in DB`, ['lookup_node', 'by_hash']) return decoded } @@ -612,7 +612,11 @@ export class MerklePatriciaTrie { if (lastKey.length !== 0 || lastNode instanceof LeafMPTNode) { // shrinking extension or leaf lastNode.key(lastKey) - const formattedNode = this._formatNode(lastNode, false, toSave) as NodeReferenceOrRawNode + const formattedNode = this._formatNode( + lastNode, + false, + toSave, + ) as NodeReferenceOrRawMPTNode newBranchMPTNode.setBranch(branchKey, formattedNode) } else { // remove extension or attaching @@ -731,7 +735,7 @@ export class MerklePatriciaTrie { // nodes on the branch // count the number of nodes on the branch - const branchNodes: [number, NodeReferenceOrRawNode][] = lastNode.getChildren() + const branchNodes: [number, NodeReferenceOrRawMPTNode][] = lastNode.getChildren() // if there is only one branch node left, collapse the branch node if (branchNodes.length === 1) { @@ -750,7 +754,7 @@ export class MerklePatriciaTrie { // In that case, we need to serialize and hash it into a Uint8Array, otherwise the operation will throw opStack.push({ type: 'del', - key: isRawNode(branchNode) ? this.appliedKey(RLP.encode(branchNode)) : branchNode, + key: isRawMPTNode(branchNode) ? this.appliedKey(RLP.encode(branchNode)) : branchNode, }) } @@ -820,7 +824,7 @@ export class MerklePatriciaTrie { topLevel: boolean, opStack: BatchDBOp[], remove: boolean = false, - ): Uint8Array | NodeReferenceOrRawNode | BranchMPTNodeBranchValue[] { + ): Uint8Array | NodeReferenceOrRawMPTNode | BranchMPTNodeBranchValue[] { const encoded = node.serialize() if (encoded.length >= 32 || topLevel) { @@ -906,7 +910,7 @@ export class MerklePatriciaTrie { if ( item !== null && bytesToUnprefixedHex( - isRawNode(item) ? controller.trie.appliedKey(RLP.encode(item)) : item, + isRawMPTNode(item) ? controller.trie.appliedKey(RLP.encode(item)) : item, ) === dbkey ) { found = true @@ -988,7 +992,7 @@ export class MerklePatriciaTrie { */ protected async _findDbNodes(onFound: FoundNodeFunction): Promise { const outerOnFound: FoundNodeFunction = async (nodeRef, node, key, walkController) => { - if (isRawNode(nodeRef)) { + if (isRawMPTNode(nodeRef)) { if (node !== null) { walkController.allChildren(node, key) } diff --git a/packages/trie/src/node/branch.ts b/packages/mpt/src/node/branch.ts similarity index 85% rename from packages/trie/src/node/branch.ts rename to packages/mpt/src/node/branch.ts index ee0d2e9f87..ddb0d1e618 100644 --- a/packages/trie/src/node/branch.ts +++ b/packages/mpt/src/node/branch.ts @@ -1,6 +1,6 @@ import { RLP } from '@ethereumjs/rlp' -import type { BranchMPTNodeBranchValue, NodeReferenceOrRawNode } from '../types.js' +import type { BranchMPTNodeBranchValue, NodeReferenceOrRawMPTNode } from '../types.js' export class BranchMPTNode { _branches: BranchMPTNodeBranchValue[] @@ -47,8 +47,8 @@ export class BranchMPTNode { } } - getChildren(): [number, NodeReferenceOrRawNode][] { - const children: [number, NodeReferenceOrRawNode][] = [] + getChildren(): [number, NodeReferenceOrRawMPTNode][] { + const children: [number, NodeReferenceOrRawMPTNode][] = [] for (let i = 0; i < 16; i++) { const b = this._branches[i] if (b !== null && b.length > 0) { diff --git a/packages/trie/src/node/extension.ts b/packages/mpt/src/node/extension.ts similarity index 100% rename from packages/trie/src/node/extension.ts rename to packages/mpt/src/node/extension.ts diff --git a/packages/trie/src/node/extensionOrLeafNodeBase.ts b/packages/mpt/src/node/extensionOrLeafNodeBase.ts similarity index 100% rename from packages/trie/src/node/extensionOrLeafNodeBase.ts rename to packages/mpt/src/node/extensionOrLeafNodeBase.ts diff --git a/packages/trie/src/node/index.ts b/packages/mpt/src/node/index.ts similarity index 100% rename from packages/trie/src/node/index.ts rename to packages/mpt/src/node/index.ts diff --git a/packages/trie/src/node/leaf.ts b/packages/mpt/src/node/leaf.ts similarity index 100% rename from packages/trie/src/node/leaf.ts rename to packages/mpt/src/node/leaf.ts diff --git a/packages/trie/src/node/util.ts b/packages/mpt/src/node/util.ts similarity index 76% rename from packages/trie/src/node/util.ts rename to packages/mpt/src/node/util.ts index c4662f58b4..dd4d1c5421 100644 --- a/packages/trie/src/node/util.ts +++ b/packages/mpt/src/node/util.ts @@ -9,7 +9,7 @@ import { LeafMPTNode } from './leaf.js' import type { NestedUint8Array } from '@ethereumjs/util' -export function decodeRawNode(raw: Uint8Array[]) { +export function decodeRawMPTNode(raw: Uint8Array[]) { if (raw.length === 17) { return BranchMPTNode.fromArray(raw) } else if (raw.length === 2) { @@ -23,14 +23,14 @@ export function decodeRawNode(raw: Uint8Array[]) { } } -export function isRawNode(n: Uint8Array | NestedUint8Array): n is Uint8Array[] { +export function isRawMPTNode(n: Uint8Array | NestedUint8Array): n is Uint8Array[] { return Array.isArray(n) && !(n instanceof Uint8Array) } -export function decodeNode(node: Uint8Array) { +export function decodeMPTNode(node: Uint8Array) { const decodedNode = RLP.decode(Uint8Array.from(node)) - if (!isRawNode(decodedNode)) { + if (!isRawMPTNode(decodedNode)) { throw new Error('Invalid node') } - return decodeRawNode(decodedNode) + return decodeRawMPTNode(decodedNode) } diff --git a/packages/trie/src/proof/index.ts b/packages/mpt/src/proof/index.ts similarity index 91% rename from packages/trie/src/proof/index.ts rename to packages/mpt/src/proof/index.ts index d530a536ef..9ac3d43cac 100644 --- a/packages/trie/src/proof/index.ts +++ b/packages/mpt/src/proof/index.ts @@ -1,10 +1,12 @@ import { bytesToHex, concatBytes, equalsBytes } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak' -import { createTrieFromProof } from '../constructors.js' -import { MerklePatriciaTrie, verifyRangeProof } from '../index.js' +import { createMPTFromProof } from '../constructors.js' +import { MerklePatriciaTrie } from '../index.js' import { bytesToNibbles } from '../util/nibbles.js' +import { verifyRangeProof } from './range.js' + import type { MPTOpts, Proof } from '../index.js' import type { PutBatch } from '@ethereumjs/util' @@ -24,7 +26,7 @@ export async function verifyMPTProof( opts?: MPTOpts, ): Promise { try { - const proofTrie = await createTrieFromProof(proof, opts) + const proofTrie = await createMPTFromProof(proof, opts) const value = await proofTrie.get(key, true) return value } catch (err: any) { @@ -45,7 +47,7 @@ export async function verifyMPTProof( // * @param opts - optional, the opts may include a custom hashing function to use with the trie for proof verification // * @returns a flag to indicate whether there exists more trie node in the trie // */ -export function verifyMPTRangeProof( +export function verifyMerkleRangeProof( rootHash: Uint8Array, firstKey: Uint8Array | null, lastKey: Uint8Array | null, @@ -66,7 +68,7 @@ export function verifyMPTRangeProof( } /** - * Creates a proof from a trie and key that can be verified using {@link verifyMPTProof}. An (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof contains + * Creates a proof from a trie and key that can be verified using {@link verifyMPTWithMerkleProof}. An (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof contains * the encoded trie nodes from the root node to the leaf node storing state data. The returned proof will be in the format of an array that contains Uint8Arrays of * serialized branch, extension, and/or leaf nodes. * @param key key to create a proof for @@ -85,11 +87,12 @@ export async function createMerkleProof(trie: MerklePatriciaTrie, key: Uint8Arra * Updates a trie from a proof by putting all the nodes in the proof into the trie. Pass {@param shouldVerifyRoot} as true to check * that root key of proof matches root of trie and throw if not. * An (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof contains the encoded trie nodes from the root node to the leaf node storing state data. + * @param trie The trie to update from the proof. * @param proof An (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof to update the trie from. * @param shouldVerifyRoot - defaults to false. If `true`, verifies that the root key of the proof matches the trie root and throws if not (i.e invalid proof). * @returns The root of the proof */ -export async function updateTrieFromMerkleProof( +export async function updateMPTFromMerkleProof( trie: MerklePatriciaTrie, proof: Proof, shouldVerifyRoot: boolean = false, @@ -122,13 +125,14 @@ export async function updateTrieFromMerkleProof( /** * Verifies a proof by putting all of its nodes into a trie and attempting to get the proven key. An (EIP-1186)[https://eips.ethereum.org/EIPS/eip-1186] proof * contains the encoded trie nodes from the root node to the leaf node storing state data. + * @param trie The trie to verify the proof against * @param rootHash Root hash of the trie that this proof was created from and is being verified for * @param key Key that is being verified and that the proof is created for * @param proof an EIP-1186 proof to verify the key against * @throws If proof is found to be invalid. * @returns The value from the key, or null if valid proof of non-existence. */ -export async function verifyMerkleProof( +export async function verifyMPTWithMerkleProof( trie: MerklePatriciaTrie, rootHash: Uint8Array, key: Uint8Array, @@ -148,7 +152,7 @@ export async function verifyMerkleProof( common: trie['_opts'].common, }) try { - await updateTrieFromMerkleProof(proofTrie, proof, true) + await updateMPTFromMerkleProof(proofTrie, proof, true) } catch (e: any) { throw new Error('Invalid proof nodes given') } @@ -168,5 +172,3 @@ export async function verifyMerkleProof( } } } - -export * from './range.js' diff --git a/packages/trie/src/proof/range.ts b/packages/mpt/src/proof/range.ts similarity index 97% rename from packages/trie/src/proof/range.ts rename to packages/mpt/src/proof/range.ts index 2ae184ffb1..9a69f1959c 100644 --- a/packages/trie/src/proof/range.ts +++ b/packages/mpt/src/proof/range.ts @@ -1,8 +1,8 @@ import { equalsBytes } from '@ethereumjs/util' -import { createTrieFromProof } from '../index.js' +import { createMPTFromProof } from '../index.js' +import { MerklePatriciaTrie } from '../mpt.js' import { BranchMPTNode, ExtensionMPTNode, LeafMPTNode } from '../node/index.js' -import { MerklePatriciaTrie } from '../trie.js' import { nibblesCompare, nibblesTypeToPackedBytes } from '../util/nibbles.js' import type { HashKeysFunction, MPTNode, Nibbles } from '../types.js' @@ -321,13 +321,13 @@ async function unsetInternal( * @throws If proof is found to be invalid. * @returns The value from the key, or null if valid proof of non-existence. */ -async function verifyMerkleProof( +async function verifyMPTWithMerkleProof( rootHash: Uint8Array, key: Uint8Array, proof: Uint8Array[], useKeyHashingFunction: HashKeysFunction, ): Promise<{ value: Uint8Array | null; trie: MerklePatriciaTrie }> { - const proofTrie = await createTrieFromProof(proof, { + const proofTrie = await createMPTFromProof(proof, { root: rootHash, useKeyHashingFunction, }) @@ -388,6 +388,7 @@ async function hasRightElement(trie: MerklePatriciaTrie, key: Nibbles): Promise< /** * verifyRangeProof checks whether the given leaf nodes and edge proof * can prove the given trie leaves range is matched with the specific root. + * Used internally by the verifyMerkleRangeProof wrapper function. * * There are four situations: * @@ -454,7 +455,7 @@ export async function verifyRangeProof( if (proof !== null && firstKey !== null && lastKey === null) { // Zero element proof if (keys.length === 0) { - const { trie, value } = await verifyMerkleProof( + const { trie, value } = await verifyMPTWithMerkleProof( rootHash, nibblesTypeToPackedBytes(firstKey), proof, @@ -477,7 +478,7 @@ export async function verifyRangeProof( // One element proof if (keys.length === 1 && nibblesCompare(firstKey, lastKey) === 0) { - const { trie, value } = await verifyMerkleProof( + const { trie, value } = await verifyMPTWithMerkleProof( rootHash, nibblesTypeToPackedBytes(firstKey), proof, @@ -504,7 +505,7 @@ export async function verifyRangeProof( ) } - const trie = await createTrieFromProof(proof, { + const trie = await createMPTFromProof(proof, { useKeyHashingFunction, root: rootHash, }) diff --git a/packages/trie/src/types.ts b/packages/mpt/src/types.ts similarity index 96% rename from packages/trie/src/types.ts rename to packages/mpt/src/types.ts index e8857aa8c6..e1324febcc 100644 --- a/packages/trie/src/types.ts +++ b/packages/mpt/src/types.ts @@ -17,9 +17,9 @@ export type RawLeafMPTNode = [Uint8Array, Uint8Array] // Branch and extension nodes might store // hash to next node, or a raw node if its length < 32 -export type NodeReferenceOrRawNode = Uint8Array | RawExtensionMPTNode | RawLeafMPTNode +export type NodeReferenceOrRawMPTNode = Uint8Array | RawExtensionMPTNode | RawLeafMPTNode -export type BranchMPTNodeBranchValue = NodeReferenceOrRawNode | null +export type BranchMPTNodeBranchValue = NodeReferenceOrRawMPTNode | null export type Proof = Uint8Array[] diff --git a/packages/trie/src/util/asyncWalk.ts b/packages/mpt/src/util/asyncWalk.ts similarity index 97% rename from packages/trie/src/util/asyncWalk.ts rename to packages/mpt/src/util/asyncWalk.ts index bec6b3f45f..ba310017f1 100644 --- a/packages/trie/src/util/asyncWalk.ts +++ b/packages/mpt/src/util/asyncWalk.ts @@ -4,7 +4,7 @@ import { bytesToHex, equalsBytes } from '@ethereumjs/util' import { BranchMPTNode } from '../node/branch.js' import { ExtensionMPTNode } from '../node/extension.js' -import type { MerklePatriciaTrie } from '../trie.js' +import type { MerklePatriciaTrie } from '../mpt.js' import type { MPTNode } from '../types.js' export type NodeFilter = (node: MPTNode, key: number[]) => Promise diff --git a/packages/trie/src/util/encoding.ts b/packages/mpt/src/util/encoding.ts similarity index 98% rename from packages/trie/src/util/encoding.ts rename to packages/mpt/src/util/encoding.ts index 6068284dd6..0059382d7a 100644 --- a/packages/trie/src/util/encoding.ts +++ b/packages/mpt/src/util/encoding.ts @@ -26,11 +26,11 @@ import type { Nibbles } from '../types.js' /** * - * @param s byte sequence + * @param nibbles byte sequence * @returns boolean indicating if input hex nibble sequence has terminator indicating leaf-node * terminator is represented with 16 because a nibble ranges from 0 - 15(f) */ -export const hasTerminator = (nibbles: Uint8Array) => { +const hasTerminator = (nibbles: Uint8Array) => { return nibbles.length > 0 && nibbles[nibbles.length - 1] === 16 } diff --git a/packages/trie/src/util/genesisState.ts b/packages/mpt/src/util/genesisState.ts similarity index 93% rename from packages/trie/src/util/genesisState.ts rename to packages/mpt/src/util/genesisState.ts index 4afb3caa9b..784e595d51 100644 --- a/packages/trie/src/util/genesisState.ts +++ b/packages/mpt/src/util/genesisState.ts @@ -8,14 +8,14 @@ import { } from '@ethereumjs/util' import { keccak256 } from 'ethereum-cryptography/keccak.js' -import { MerklePatriciaTrie } from '../trie.js' +import { MerklePatriciaTrie } from '../mpt.js' import type { AccountState, GenesisState } from '@ethereumjs/util' /** * Derives the stateRoot of the genesis block based on genesis allocations */ -export async function genesisStateRoot(genesisState: GenesisState) { +export async function genesisMPTStateRoot(genesisState: GenesisState) { const trie = new MerklePatriciaTrie({ useKeyHashing: true }) for (const [key, value] of Object.entries(genesisState)) { const address = isHexString(key) ? hexToBytes(key) : unprefixedHexToBytes(key) diff --git a/packages/trie/src/util/hex.ts b/packages/mpt/src/util/hex.ts similarity index 100% rename from packages/trie/src/util/hex.ts rename to packages/mpt/src/util/hex.ts diff --git a/packages/trie/src/util/index.ts b/packages/mpt/src/util/index.ts similarity index 100% rename from packages/trie/src/util/index.ts rename to packages/mpt/src/util/index.ts diff --git a/packages/trie/src/util/nibbles.ts b/packages/mpt/src/util/nibbles.ts similarity index 100% rename from packages/trie/src/util/nibbles.ts rename to packages/mpt/src/util/nibbles.ts diff --git a/packages/trie/src/util/walkController.ts b/packages/mpt/src/util/walkController.ts similarity index 98% rename from packages/trie/src/util/walkController.ts rename to packages/mpt/src/util/walkController.ts index dd63e9dee5..81c6dd0239 100644 --- a/packages/trie/src/util/walkController.ts +++ b/packages/mpt/src/util/walkController.ts @@ -2,7 +2,7 @@ import { PrioritizedTaskExecutor } from '@ethereumjs/util' import { BranchMPTNode, ExtensionMPTNode, LeafMPTNode } from '../node/index.js' -import type { MerklePatriciaTrie } from '../trie.js' +import type { MerklePatriciaTrie } from '../mpt.js' import type { FoundNodeFunction, MPTNode, Nibbles } from '../types.js' /** diff --git a/packages/trie/test/db/checkpoint.spec.ts b/packages/mpt/test/db/checkpoint.spec.ts similarity index 100% rename from packages/trie/test/db/checkpoint.spec.ts rename to packages/mpt/test/db/checkpoint.spec.ts diff --git a/packages/trie/test/db/db.spec.ts b/packages/mpt/test/db/db.spec.ts similarity index 100% rename from packages/trie/test/db/db.spec.ts rename to packages/mpt/test/db/db.spec.ts diff --git a/packages/trie/test/encoding.spec.ts b/packages/mpt/test/encoding.spec.ts similarity index 100% rename from packages/trie/test/encoding.spec.ts rename to packages/mpt/test/encoding.spec.ts diff --git a/packages/trie/test/fixtures/gethGenesisKiln.ts b/packages/mpt/test/fixtures/gethGenesisKiln.ts similarity index 100% rename from packages/trie/test/fixtures/gethGenesisKiln.ts rename to packages/mpt/test/fixtures/gethGenesisKiln.ts diff --git a/packages/trie/test/fixtures/hexEncodedSecureTrieTest.ts b/packages/mpt/test/fixtures/hexEncodedSecureTrieTest.ts similarity index 100% rename from packages/trie/test/fixtures/hexEncodedSecureTrieTest.ts rename to packages/mpt/test/fixtures/hexEncodedSecureTrieTest.ts diff --git a/packages/trie/test/fixtures/trieAnyOrder.ts b/packages/mpt/test/fixtures/trieAnyOrder.ts similarity index 100% rename from packages/trie/test/fixtures/trieAnyOrder.ts rename to packages/mpt/test/fixtures/trieAnyOrder.ts diff --git a/packages/trie/test/fixtures/trieAnyOrderSecureTrie.ts b/packages/mpt/test/fixtures/trieAnyOrderSecureTrie.ts similarity index 100% rename from packages/trie/test/fixtures/trieAnyOrderSecureTrie.ts rename to packages/mpt/test/fixtures/trieAnyOrderSecureTrie.ts diff --git a/packages/trie/test/fixtures/trieTest.ts b/packages/mpt/test/fixtures/trieTest.ts similarity index 100% rename from packages/trie/test/fixtures/trieTest.ts rename to packages/mpt/test/fixtures/trieTest.ts diff --git a/packages/trie/test/fixtures/trieTestNextPrev.ts b/packages/mpt/test/fixtures/trieTestNextPrev.ts similarity index 100% rename from packages/trie/test/fixtures/trieTestNextPrev.ts rename to packages/mpt/test/fixtures/trieTestNextPrev.ts diff --git a/packages/trie/test/fixtures/trieTestSecureTrie.ts b/packages/mpt/test/fixtures/trieTestSecureTrie.ts similarity index 100% rename from packages/trie/test/fixtures/trieTestSecureTrie.ts rename to packages/mpt/test/fixtures/trieTestSecureTrie.ts diff --git a/packages/trie/test/index.spec.ts b/packages/mpt/test/index.spec.ts similarity index 100% rename from packages/trie/test/index.spec.ts rename to packages/mpt/test/index.spec.ts diff --git a/packages/trie/test/official.spec.ts b/packages/mpt/test/official.spec.ts similarity index 100% rename from packages/trie/test/official.spec.ts rename to packages/mpt/test/official.spec.ts diff --git a/packages/trie/test/proof.spec.ts b/packages/mpt/test/proof.spec.ts similarity index 95% rename from packages/trie/test/proof.spec.ts rename to packages/mpt/test/proof.spec.ts index 82153fda56..776da2ccec 100644 --- a/packages/trie/test/proof.spec.ts +++ b/packages/mpt/test/proof.spec.ts @@ -4,9 +4,9 @@ import { assert, describe, it } from 'vitest' import { MerklePatriciaTrie, + createMPTFromProof, createMerkleProof, - createTrieFromProof, - updateTrieFromMerkleProof, + updateMPTFromMerkleProof, verifyMPTProof, } from '../src/index.js' @@ -74,7 +74,7 @@ describe('simple merkle proofs generation and verification', () => { // now make the key non-null so the exclusion proof becomes invalid await trie.put(myKey, utf8ToBytes('thisIsaValue')) try { - await createTrieFromProof(proof, { root: trie.root() }) + await createMPTFromProof(proof, { root: trie.root() }) assert.fail(`expected error: 'The provided proof does not have the expected trie root'`) } catch (e: any) { assert.equal(e.message, 'The provided proof does not have the expected trie root') @@ -167,14 +167,14 @@ describe('simple merkle proofs generation and verification', () => { await trie.put(key3, encodedValue3) const proof = await createMerkleProof(trie, key) - const newTrie = await createTrieFromProof(proof, { useKeyHashing: true }) + const newTrie = await createMPTFromProof(proof, { useKeyHashing: true }) const trieValue = await newTrie.get(key) assert.ok(equalsBytes(trieValue!, encodedValue), 'trie value successfully copied') assert.ok(equalsBytes(trie.root(), newTrie.root()), 'root set correctly') const proof2 = await createMerkleProof(trie, key2) - await updateTrieFromMerkleProof(newTrie, proof2) + await updateMPTFromMerkleProof(newTrie, proof2) const trieValue2 = await newTrie.get(key2) assert.ok(equalsBytes(trieValue2!, encodedValue2), 'trie value successfully updated') @@ -191,13 +191,13 @@ describe('simple merkle proofs generation and verification', () => { const safeProof = await createMerkleProof(safeTrie, safeKey) try { - await updateTrieFromMerkleProof(newTrie, safeProof, true) + await updateMPTFromMerkleProof(newTrie, safeProof, true) assert.fail('cannot reach this') } catch (e) { assert.ok(true, 'throws on unmatching proof') } - await updateTrieFromMerkleProof(newTrie, safeProof) + await updateMPTFromMerkleProof(newTrie, safeProof) assert.ok(equalsBytes(trie.root(), newTrie.root()), 'root set correctly') const newSafeValue = await newTrie.get(safeKey) diff --git a/packages/trie/test/proof/range.spec.ts b/packages/mpt/test/proof/range.spec.ts similarity index 98% rename from packages/trie/test/proof/range.spec.ts rename to packages/mpt/test/proof/range.spec.ts index 6e4b8f4ce2..114d6db2d5 100644 --- a/packages/trie/test/proof/range.spec.ts +++ b/packages/mpt/test/proof/range.spec.ts @@ -9,7 +9,7 @@ import { } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { MerklePatriciaTrie, createMerkleProof, verifyMPTRangeProof } from '../../src/index.js' +import { MerklePatriciaTrie, createMerkleProof, verifyMerkleRangeProof } from '../../src/index.js' import type { DB } from '@ethereumjs/util' @@ -88,7 +88,7 @@ async function verify( startKey = startKey ?? entries[start][0] endKey = endKey ?? entries[end][0] const targetRange = entries.slice(start, end + 1) - return verifyMPTRangeProof( + return verifyMerkleRangeProof( trie.root(), startKey, endKey, @@ -211,7 +211,7 @@ describe('simple merkle range proofs generation and verification', () => { const { trie, entries } = await randomTrie(new MapDB()) assert.equal( - await verifyMPTRangeProof( + await verifyMerkleRangeProof( trie.root(), null, null, diff --git a/packages/trie/test/trie/checkpoint.spec.ts b/packages/mpt/test/trie/checkpoint.spec.ts similarity index 97% rename from packages/trie/test/trie/checkpoint.spec.ts rename to packages/mpt/test/trie/checkpoint.spec.ts index bf349b44c8..7b35676ce4 100644 --- a/packages/trie/test/trie/checkpoint.spec.ts +++ b/packages/mpt/test/trie/checkpoint.spec.ts @@ -10,7 +10,7 @@ import { keccak256 } from 'ethereum-cryptography/keccak.js' import { sha256 } from 'ethereum-cryptography/sha256.js' import { assert, describe, it } from 'vitest' -import { MerklePatriciaTrie, ROOT_DB_KEY, createTrie } from '../../src/index.js' +import { MerklePatriciaTrie, ROOT_DB_KEY, createMPT } from '../../src/index.js' describe('testing checkpoints', () => { let trie: MerklePatriciaTrie @@ -93,7 +93,7 @@ describe('testing checkpoints', () => { const KEY_ROOT = keccak256(ROOT_DB_KEY) // Initialize State - const CommittedState = await createTrie({ + const CommittedState = await createMPT({ useKeyHashing: true, useNodePruning: true, useRootPersistence: true, diff --git a/packages/trie/test/trie/checkpointing.spec.ts b/packages/mpt/test/trie/checkpointing.spec.ts similarity index 100% rename from packages/trie/test/trie/checkpointing.spec.ts rename to packages/mpt/test/trie/checkpointing.spec.ts diff --git a/packages/trie/test/trie/findPath.spec.ts b/packages/mpt/test/trie/findPath.spec.ts similarity index 100% rename from packages/trie/test/trie/findPath.spec.ts rename to packages/mpt/test/trie/findPath.spec.ts diff --git a/packages/trie/test/trie/prune.spec.ts b/packages/mpt/test/trie/prune.spec.ts similarity index 96% rename from packages/trie/test/trie/prune.spec.ts rename to packages/mpt/test/trie/prune.spec.ts index c2e2468c24..d2197352ca 100644 --- a/packages/trie/test/trie/prune.spec.ts +++ b/packages/mpt/test/trie/prune.spec.ts @@ -1,7 +1,7 @@ import { KECCAK256_RLP, equalsBytes, hexToBytes, randomBytes, utf8ToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { MerklePatriciaTrie, createTrie, isRawNode } from '../../src/index.js' +import { MerklePatriciaTrie, createMPT, isRawMPTNode } from '../../src/index.js' import type { BranchMPTNode } from '../../src/index.js' @@ -172,8 +172,8 @@ describe('Pruned trie tests', () => { const path = await trie.findPath(utf8ToBytes('key1')) const parentBranchMPTNode = path.stack[1] as BranchMPTNode // Hex ASCII value for for `1` is 31, and for `2` is 32. We should expect a branching out at indexes 1 an 2. - assert.ok(isRawNode(parentBranchMPTNode._branches[1]!), 'key1 node is not a rawNode') - assert.ok(isRawNode(parentBranchMPTNode._branches[2]!), 'key2 node is not a rawNode') + assert.ok(isRawMPTNode(parentBranchMPTNode._branches[1]!), 'key1 node is not a rawNode') + assert.ok(isRawMPTNode(parentBranchMPTNode._branches[2]!), 'key2 node is not a rawNode') assert.notOk(equalsBytes(trie.root(), initialRoot), 'Root should have changed') @@ -207,7 +207,7 @@ describe('Pruned trie tests', () => { it('should prune when keys are updated or deleted (with `useRootPersistence` enabled)', async () => { for (let testID = 0; testID < 1; testID++) { - const trie = await createTrie({ useNodePruning: true, useRootPersistence: true }) + const trie = await createMPT({ useNodePruning: true, useRootPersistence: true }) const keys: Uint8Array[] = [] for (let i = 0; i < 100; i++) { keys.push(randomBytes(32)) diff --git a/packages/trie/test/trie/secure.spec.ts b/packages/mpt/test/trie/secure.spec.ts similarity index 100% rename from packages/trie/test/trie/secure.spec.ts rename to packages/mpt/test/trie/secure.spec.ts diff --git a/packages/trie/test/trie/trie.spec.ts b/packages/mpt/test/trie/trie.spec.ts similarity index 84% rename from packages/trie/test/trie/trie.spec.ts rename to packages/mpt/test/trie/trie.spec.ts index 3219dff449..09943d9e79 100644 --- a/packages/trie/test/trie/trie.spec.ts +++ b/packages/mpt/test/trie/trie.spec.ts @@ -12,7 +12,7 @@ import { import { keccak256 } from 'ethereum-cryptography/keccak.js' import { assert, describe, it } from 'vitest' -import { ROOT_DB_KEY as BASE_DB_KEY, MerklePatriciaTrie, createTrie } from '../../src/index.js' +import { ROOT_DB_KEY as BASE_DB_KEY, MerklePatriciaTrie, createMPT } from '../../src/index.js' for (const { constructor, defaults, title } of [ { @@ -44,20 +44,20 @@ for (const { constructor, defaults, title } of [ } describe(`${title} (Persistence)`, () => { - it('creates an instance via createTrie and defaults to `false` with a database', async () => { + it('creates an instance via createMPT and defaults to `false` with a database', async () => { assert.isFalse( - (await createTrie({ ...defaults, db: new MapDB() }))['_opts'].useRootPersistence, + (await createMPT({ ...defaults, db: new MapDB() }))['_opts'].useRootPersistence, ) }) - it('creates an instance via createTrie and defaults to `false` without a database', async () => { - assert.isFalse((await createTrie({ ...defaults }))['_opts'].useRootPersistence) + it('creates an instance via createMPT and defaults to `false` without a database', async () => { + assert.isFalse((await createMPT({ ...defaults }))['_opts'].useRootPersistence) }) - it('creates an instance via createTrie and respects the `useRootPersistence` option with a database', async () => { + it('creates an instance via createMPT and respects the `useRootPersistence` option with a database', async () => { assert.isFalse( ( - await createTrie({ + await createMPT({ ...defaults, db: new MapDB(), useRootPersistence: false, @@ -67,7 +67,7 @@ for (const { constructor, defaults, title } of [ }) it('persist the root if the `useRootPersistence` option is `true`', async () => { - const trie = await createTrie({ + const trie = await createMPT({ ...defaults, db: new MapDB(), useRootPersistence: true, @@ -81,7 +81,7 @@ for (const { constructor, defaults, title } of [ }) it('persist the root if the `root` option is given', async () => { - const trie = await createTrie({ + const trie = await createMPT({ ...defaults, db: new MapDB(), root: KECCAK256_RLP, @@ -96,7 +96,7 @@ for (const { constructor, defaults, title } of [ }) it('does not persist the root if the `useRootPersistence` option is `false`', async () => { - const trie = await createTrie({ + const trie = await createMPT({ ...defaults, db: new MapDB(), useRootPersistence: false, @@ -110,7 +110,7 @@ for (const { constructor, defaults, title } of [ }) it('persists the root if the `db` option is not provided', async () => { - const trie = await createTrie({ ...defaults, useRootPersistence: true }) + const trie = await createMPT({ ...defaults, useRootPersistence: true }) assert.equal(await trie['_db'].get(ROOT_DB_KEY), undefined) @@ -122,17 +122,17 @@ for (const { constructor, defaults, title } of [ it('persist and restore the root', async () => { const db = new MapDB() - const trie = await createTrie({ ...defaults, db, useRootPersistence: true }) + const trie = await createMPT({ ...defaults, db, useRootPersistence: true }) assert.equal(await trie['_db'].get(ROOT_DB_KEY), undefined) await trie.put(utf8ToBytes('foo'), utf8ToBytes('bar')) assert.equal(bytesToHex((await trie['_db'].get(ROOT_DB_KEY))!), EXPECTED_ROOTS) // Using the same database as `trie` so we should have restored the root - const copy = await createTrie({ ...defaults, db, useRootPersistence: true }) + const copy = await createMPT({ ...defaults, db, useRootPersistence: true }) assert.equal(bytesToHex((await copy['_db'].get(ROOT_DB_KEY))!), EXPECTED_ROOTS) // New trie with a new database so we shouldn't find a root to restore - const empty = await createTrie({ + const empty = await createMPT({ ...defaults, db: new MapDB(), useRootPersistence: true, @@ -158,7 +158,7 @@ for (const { constructor, defaults, title } of [ const value = randomBytes(10) return { key, value } }) - const trie = await createTrie({ + const trie = await createMPT({ ...defaults, db: new MapDB(), }) @@ -182,7 +182,7 @@ for (const { constructor, defaults, title } of [ } }) it('should return false for all keys if trie is empty', async () => { - const emptyTrie = await createTrie({ + const emptyTrie = await createMPT({ ...defaults, db: new MapDB(), }) @@ -203,7 +203,7 @@ for (const { constructor, defaults, title } of [ } }) it('Should throw on unrelated errors', async () => { - const emptyTrie = await createTrie({ + const emptyTrie = await createMPT({ ...defaults, db: new MapDB(), useRootPersistence: true, @@ -235,8 +235,8 @@ describe('keyHashingFunction', async () => { }, } - const trieWithHashFunction = await createTrie({ useKeyHashingFunction: keyHashingFunction }) - const trieWithCommon = await createTrie({ common: c }) + const trieWithHashFunction = await createMPT({ useKeyHashingFunction: keyHashingFunction }) + const trieWithCommon = await createMPT({ common: c }) assert.equal( bytesToHex(trieWithHashFunction.root()), @@ -256,9 +256,9 @@ describe('keyHashingFunction', async () => { }, } - const trieWithHashFunction = await createTrie({ useKeyHashingFunction: keyHashingFunction }) + const trieWithHashFunction = await createMPT({ useKeyHashingFunction: keyHashingFunction }) const trieWithHashFunctionCopy = trieWithHashFunction.shallowCopy() - const trieWithCommon = await createTrie({ common: c }) + const trieWithCommon = await createMPT({ common: c }) const trieWithCommonCopy = trieWithCommon.shallowCopy() assert.equal( @@ -272,7 +272,7 @@ describe('keyHashingFunction', async () => { describe('getValueMap', () => { it('should return a map of all hashed keys and values', async () => { - const trie = await createTrie({}) + const trie = await createMPT({}) const entries: [Uint8Array, string][] = [ [bigIntToBytes(1n), '0x' + '0a'.repeat(32)], [bigIntToBytes(2n), '0x' + '0b'.repeat(32)], diff --git a/packages/trie/test/util/asyncWalk.spec.ts b/packages/mpt/test/util/asyncWalk.spec.ts similarity index 97% rename from packages/trie/test/util/asyncWalk.spec.ts rename to packages/mpt/test/util/asyncWalk.spec.ts index 3c06c7dfb7..455781ac36 100644 --- a/packages/trie/test/util/asyncWalk.spec.ts +++ b/packages/mpt/test/util/asyncWalk.spec.ts @@ -4,8 +4,8 @@ import { assert, describe, it } from 'vitest' import { LeafMPTNode, MerklePatriciaTrie, + createMPTFromProof, createMerkleProof, - createTrieFromProof, verifyMPTProof, } from '../../src/index.js' import { _walkTrie } from '../../src/util/asyncWalk.js' @@ -91,7 +91,7 @@ describe('walk a sparse trie', async () => { assert.ok(await verifyMPTProof(proofKey, proof)) // Build a sparse trie from the proof - const fromProof = await createTrieFromProof(proof, { root: trie.root() }) + const fromProof = await createMPTFromProof(proof, { root: trie.root() }) // Walk the sparse trie const walker = fromProof.walkTrieIterable(fromProof.root()) diff --git a/packages/trie/test/util/encodingUtils.spec.ts b/packages/mpt/test/util/encodingUtils.spec.ts similarity index 100% rename from packages/trie/test/util/encodingUtils.spec.ts rename to packages/mpt/test/util/encodingUtils.spec.ts diff --git a/packages/trie/test/util/genesisState.spec.ts b/packages/mpt/test/util/genesisState.spec.ts similarity index 81% rename from packages/trie/test/util/genesisState.spec.ts rename to packages/mpt/test/util/genesisState.spec.ts index aa25ace310..8b479b7347 100644 --- a/packages/trie/test/util/genesisState.spec.ts +++ b/packages/mpt/test/util/genesisState.spec.ts @@ -2,7 +2,7 @@ import { getGenesis } from '@ethereumjs/genesis' import { bytesToHex, parseGethGenesisState } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { genesisStateRoot } from '../../src/util/genesisState.js' +import { genesisMPTStateRoot } from '../../src/util/genesisState.js' // kiln genesis with deposit contract storage set import { gethGenesisKilnData } from '../fixtures/gethGenesisKiln.js' @@ -11,7 +11,7 @@ import type { GenesisState } from '@ethereumjs/util' describe('[Util/genesisStateRoot]', () => { it('should properly generate stateRoot from gethGenesis', async () => { const genesisState = parseGethGenesisState(gethGenesisKilnData) - const stateRoot = await genesisStateRoot(genesisState) + const stateRoot = await genesisMPTStateRoot(genesisState) assert.equal( bytesToHex(stateRoot), '0x52e628c7f35996ba5a0402d02b34535993c89ff7fc4c430b2763ada8554bee62', @@ -21,7 +21,7 @@ describe('[Util/genesisStateRoot]', () => { }) it('should correctly derive mainnet stateRoot from ethereumjs genesis', async () => { - const stateRoot = await genesisStateRoot(getGenesis(1) as GenesisState) + const stateRoot = await genesisMPTStateRoot(getGenesis(1) as GenesisState) assert.equal( bytesToHex(stateRoot), '0xd7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544', diff --git a/packages/trie/test/util/log.spec.ts b/packages/mpt/test/util/log.spec.ts similarity index 77% rename from packages/trie/test/util/log.spec.ts rename to packages/mpt/test/util/log.spec.ts index 2bc664d8a2..ee530a4df2 100644 --- a/packages/trie/test/util/log.spec.ts +++ b/packages/mpt/test/util/log.spec.ts @@ -1,8 +1,8 @@ import { utf8ToBytes } from '@ethereumjs/util' import { assert, describe, it } from 'vitest' -import { createMerkleProof, createTrieFromProof, verifyMerkleProof } from '../../src/index.js' -import { MerklePatriciaTrie } from '../../src/trie.js' +import { createMPTFromProof, createMerkleProof, verifyMPTWithMerkleProof } from '../../src/index.js' +import { MerklePatriciaTrie } from '../../src/mpt.js' describe('Run MerklePatriciaTrie script with DEBUG enabled', async () => { const trie_entries: [string, string | null][] = [ @@ -21,7 +21,7 @@ describe('Run MerklePatriciaTrie script with DEBUG enabled', async () => { } const proof = await createMerkleProof(trie, utf8ToBytes('doge')) - const valid = await verifyMerkleProof(trie, trie.root(), utf8ToBytes('doge'), proof) + const valid = await verifyMPTWithMerkleProof(trie, trie.root(), utf8ToBytes('doge'), proof) it('should be valid', async () => { assert.deepEqual(valid, utf8ToBytes('coin')) @@ -33,7 +33,7 @@ describe('Run MerklePatriciaTrie script with DEBUG enabled', async () => { trie.checkpoint() await trie.revert() process.env.DEBUG = '' - const trie2 = await createTrieFromProof(proof) + const trie2 = await createMPTFromProof(proof) trie2['DEBUG'] = true it('tries should share root', async () => { assert.deepEqual(trie.root(), trie2.root()) diff --git a/packages/trie/tsconfig.benchmarks.json b/packages/mpt/tsconfig.benchmarks.json similarity index 100% rename from packages/trie/tsconfig.benchmarks.json rename to packages/mpt/tsconfig.benchmarks.json diff --git a/packages/trie/tsconfig.json b/packages/mpt/tsconfig.json similarity index 100% rename from packages/trie/tsconfig.json rename to packages/mpt/tsconfig.json diff --git a/packages/trie/tsconfig.lint.json b/packages/mpt/tsconfig.lint.json similarity index 100% rename from packages/trie/tsconfig.lint.json rename to packages/mpt/tsconfig.lint.json diff --git a/packages/trie/tsconfig.prod.cjs.json b/packages/mpt/tsconfig.prod.cjs.json similarity index 100% rename from packages/trie/tsconfig.prod.cjs.json rename to packages/mpt/tsconfig.prod.cjs.json diff --git a/packages/trie/tsconfig.prod.esm.json b/packages/mpt/tsconfig.prod.esm.json similarity index 100% rename from packages/trie/tsconfig.prod.esm.json rename to packages/mpt/tsconfig.prod.esm.json diff --git a/packages/trie/typedoc.cjs b/packages/mpt/typedoc.cjs similarity index 100% rename from packages/trie/typedoc.cjs rename to packages/mpt/typedoc.cjs diff --git a/packages/trie/vitest.config.browser.mts b/packages/mpt/vitest.config.browser.mts similarity index 100% rename from packages/trie/vitest.config.browser.mts rename to packages/mpt/vitest.config.browser.mts diff --git a/packages/statemanager/package.json b/packages/statemanager/package.json index fd7e4810a9..5db96d65f1 100644 --- a/packages/statemanager/package.json +++ b/packages/statemanager/package.json @@ -52,7 +52,7 @@ "dependencies": { "@ethereumjs/common": "^4.4.0", "@ethereumjs/rlp": "^5.0.2", - "@ethereumjs/trie": "^6.2.1", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/util": "^9.1.0", "@ethereumjs/verkle": "^0.1.0", "@js-sdsl/ordered-map": "^4.4.2", diff --git a/packages/statemanager/src/merkleStateManager.ts b/packages/statemanager/src/merkleStateManager.ts index 1e765ab399..d7aca0bd89 100644 --- a/packages/statemanager/src/merkleStateManager.ts +++ b/packages/statemanager/src/merkleStateManager.ts @@ -1,6 +1,6 @@ import { Common, Mainnet } from '@ethereumjs/common' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { Account, bytesToUnprefixedHex, @@ -52,7 +52,7 @@ export const CODEHASH_PREFIX = utf8ToBytes('c') * and storage slots. * * The default state manager implementation uses a - * `@ethereumjs/trie` trie as a data backend. + * `@ethereumjs/mpt` trie as a data backend. * * Note that there is a `SimpleStateManager` dependency-free state * manager implementation available shipped with the `@ethereumjs/statemanager` diff --git a/packages/statemanager/src/proofs/merkle.ts b/packages/statemanager/src/proofs/merkle.ts index 6aca81156b..d8da4b27fd 100644 --- a/packages/statemanager/src/proofs/merkle.ts +++ b/packages/statemanager/src/proofs/merkle.ts @@ -1,10 +1,10 @@ -import { RLP } from '@ethereumjs/rlp' import { + createMPTFromProof, createMerkleProof, - createTrieFromProof, - updateTrieFromMerkleProof, + updateMPTFromMerkleProof, verifyMPTProof, -} from '@ethereumjs/trie' +} from '@ethereumjs/mpt' +import { RLP } from '@ethereumjs/rlp' import { KECCAK256_NULL, KECCAK256_NULL_S, @@ -96,7 +96,7 @@ export async function addMerkleStateStorageProof( const trie = sm['_getStorageTrie'](address) trie.root(hexToBytes(storageHash)) for (let i = 0; i < storageProof.length; i++) { - await updateTrieFromMerkleProof( + await updateMPTFromMerkleProof( trie, storageProof[i].proof.map((e) => hexToBytes(e)), safe, @@ -123,7 +123,7 @@ export async function fromMerkleStateProof( } else { const trie = opts.trie ?? - (await createTrieFromProof( + (await createMPTFromProof( proof[0].accountProof.map((e) => hexToBytes(e)), { useKeyHashing: true }, )) @@ -161,7 +161,7 @@ export async function addMerkleStateProofData( ) { if (Array.isArray(proof)) { for (let i = 0; i < proof.length; i++) { - await updateTrieFromMerkleProof( + await updateMPTFromMerkleProof( sm['_trie'], proof[i].accountProof.map((e) => hexToBytes(e)), safe, diff --git a/packages/statemanager/src/types.ts b/packages/statemanager/src/types.ts index 12b42a464f..3952757bd4 100644 --- a/packages/statemanager/src/types.ts +++ b/packages/statemanager/src/types.ts @@ -2,7 +2,7 @@ import { type PrefixedHexString } from '@ethereumjs/util' import type { AccessWitness, Caches } from './index.js' import type { Common } from '@ethereumjs/common' -import type { MerklePatriciaTrie } from '@ethereumjs/trie' +import type { MerklePatriciaTrie } from '@ethereumjs/mpt' import type { VerkleCrypto } from '@ethereumjs/util' import type { VerkleTree } from '@ethereumjs/verkle' /** diff --git a/packages/statemanager/test/proofStateManager.spec.ts b/packages/statemanager/test/proofStateManager.spec.ts index a18345aa65..9cf3753ccd 100644 --- a/packages/statemanager/test/proofStateManager.spec.ts +++ b/packages/statemanager/test/proofStateManager.spec.ts @@ -1,4 +1,4 @@ -import { MerklePatriciaTrie, createTrie } from '@ethereumjs/trie' +import { MerklePatriciaTrie, createMPT } from '@ethereumjs/mpt' import { Account, Address, @@ -116,7 +116,7 @@ describe('ProofStateManager', () => { // Account: 0xc626553e7c821d0f8308c28d56c60e3c15f8d55a // Storage slots: empty list const address = createAddressFromString('0xc626553e7c821d0f8308c28d56c60e3c15f8d55a') - const trie = await createTrie({ useKeyHashing: true }) + const trie = await createMPT({ useKeyHashing: true }) const stateManager = new MerkleStateManager({ trie }) // Dump all the account proof data in the DB let stateRoot: Uint8Array | undefined diff --git a/packages/statemanager/test/rpcStateManager.spec.ts b/packages/statemanager/test/rpcStateManager.spec.ts index 0ca5e84191..2691461f85 100644 --- a/packages/statemanager/test/rpcStateManager.spec.ts +++ b/packages/statemanager/test/rpcStateManager.spec.ts @@ -1,7 +1,7 @@ import { createBlockFromJSONRPCProvider, createBlockFromRPC } from '@ethereumjs/block' import { Common, Hardfork, Mainnet } from '@ethereumjs/common' import { type EVMRunCallOpts, createEVM } from '@ethereumjs/evm' -import { verifyMPTProof } from '@ethereumjs/trie' +import { verifyMPTProof } from '@ethereumjs/mpt' import { createFeeMarket1559Tx, createTxFromRPC } from '@ethereumjs/tx' import { Address, diff --git a/packages/statemanager/test/stateManager.code.spec.ts b/packages/statemanager/test/stateManager.code.spec.ts index b1e1df410d..8b9e3af62e 100644 --- a/packages/statemanager/test/stateManager.code.spec.ts +++ b/packages/statemanager/test/stateManager.code.spec.ts @@ -21,10 +21,10 @@ describe('StateManager -> Code', () => { This test is mostly an example of why a code prefix is necessary I an address, we put two storage values. The preimage of the (storage trie) root hash is known This preimage is used as codeHash - + NOTE: Currently, the only problem which this code prefix fixes, is putting 0x80 as contract code -> This hashes to the empty trie node hash (0x80 = RLP([])), so keccak256(0x80) = empty trie node hash - -> Therefore, each empty state trie now points to 0x80, which is not a valid trie node, which crashes @ethereumjs/trie + -> Therefore, each empty state trie now points to 0x80, which is not a valid trie node, which crashes @ethereumjs/mpt */ // Setup diff --git a/packages/statemanager/test/stateManager.spec.ts b/packages/statemanager/test/stateManager.spec.ts index e1fd5d46b1..aa0a1ea330 100644 --- a/packages/statemanager/test/stateManager.spec.ts +++ b/packages/statemanager/test/stateManager.spec.ts @@ -1,4 +1,4 @@ -import { MerklePatriciaTrie, createTrie, createTrieFromProof } from '@ethereumjs/trie' +import { MerklePatriciaTrie, createMPT, createMPTFromProof } from '@ethereumjs/mpt' import { Account, KECCAK256_RLP, @@ -312,7 +312,7 @@ describe('StateManager -> General', () => { it.skipIf(isBrowser() === true)( 'should create a statemanager fromProof with opts preserved', async () => { - const trie = await createTrie({ useKeyHashing: false }) + const trie = await createMPT({ useKeyHashing: false }) const sm = new MerkleStateManager({ trie }) const pk = hexToBytes('0x9f12aab647a25a81f821a5a0beec3330cd057b2346af4fb09d7a807e896701ea') const pk2 = hexToBytes('0x8724f27e2ce3714af01af3220478849db68a03c0f84edf1721d73d9a6139ad1c') @@ -331,7 +331,7 @@ describe('StateManager -> General', () => { keys.map((key) => hexToBytes(key)), ) const proof2 = await getMerkleStateProof(sm, address2) - const newTrie = await createTrieFromProof( + const newTrie = await createMPTFromProof( proof.accountProof.map((e) => hexToBytes(e)), { useKeyHashing: false }, ) diff --git a/packages/statemanager/tsconfig.prod.cjs.json b/packages/statemanager/tsconfig.prod.cjs.json index 1310ffb7a9..e67458c722 100644 --- a/packages/statemanager/tsconfig.prod.cjs.json +++ b/packages/statemanager/tsconfig.prod.cjs.json @@ -8,7 +8,7 @@ "include": ["src/**/*.ts"], "references": [ { "path": "../common/tsconfig.prod.cjs.json" }, - { "path": "../trie/tsconfig.prod.cjs.json" }, + { "path": "../mpt/tsconfig.prod.cjs.json" }, { "path": "../util/tsconfig.prod.cjs.json" }, { "path": "../verkle/tsconfig.prod.cjs.json" } ] diff --git a/packages/statemanager/tsconfig.prod.esm.json b/packages/statemanager/tsconfig.prod.esm.json index e43dc97915..bd600796ea 100644 --- a/packages/statemanager/tsconfig.prod.esm.json +++ b/packages/statemanager/tsconfig.prod.esm.json @@ -8,7 +8,7 @@ "include": ["src/**/*.ts"], "references": [ { "path": "../common/tsconfig.prod.esm.json" }, - { "path": "../trie/tsconfig.prod.esm.json" }, + { "path": "../mpt/tsconfig.prod.esm.json" }, { "path": "../util/tsconfig.prod.esm.json" }, { "path": "../verkle/tsconfig.prod.esm.json" } ] diff --git a/packages/verkle/src/node/util.ts b/packages/verkle/src/node/util.ts index 2374952c92..da2c6b8c85 100644 --- a/packages/verkle/src/node/util.ts +++ b/packages/verkle/src/node/util.ts @@ -7,7 +7,7 @@ import { LeafVerkleNodeValue, type VerkleNode, VerkleNodeType } from './types.js import type { VerkleCrypto } from '@ethereumjs/util' -export function decodeRawNode(raw: Uint8Array[], verkleCrypto: VerkleCrypto): VerkleNode { +export function decodeRawVerkleNode(raw: Uint8Array[], verkleCrypto: VerkleCrypto): VerkleNode { const nodeType = raw[0][0] switch (nodeType) { case VerkleNodeType.Internal: @@ -19,15 +19,15 @@ export function decodeRawNode(raw: Uint8Array[], verkleCrypto: VerkleCrypto): Ve } } -export function decodeNode(raw: Uint8Array, verkleCrypto: VerkleCrypto) { +export function decodeVerkleNode(raw: Uint8Array, verkleCrypto: VerkleCrypto) { const decoded = RLP.decode(Uint8Array.from(raw)) as Uint8Array[] if (!Array.isArray(decoded)) { throw new Error('Invalid node') } - return decodeRawNode(decoded, verkleCrypto) + return decodeRawVerkleNode(decoded, verkleCrypto) } -export function isRawNode(node: Uint8Array | Uint8Array[]): node is Uint8Array[] { +export function isRawVerkleNode(node: Uint8Array | Uint8Array[]): node is Uint8Array[] { return Array.isArray(node) && !(node instanceof Uint8Array) } diff --git a/packages/verkle/src/verkleTree.ts b/packages/verkle/src/verkleTree.ts index 1e10860f07..f3ebcb412f 100644 --- a/packages/verkle/src/verkleTree.ts +++ b/packages/verkle/src/verkleTree.ts @@ -12,7 +12,7 @@ import { CheckpointDB } from './db/checkpoint.js' import { InternalVerkleNode } from './node/internalNode.js' import { LeafVerkleNode } from './node/leafNode.js' import { LeafVerkleNodeValue, type VerkleNode } from './node/types.js' -import { createDeletedLeafVerkleValue, decodeNode, isLeafVerkleNode } from './node/util.js' +import { createDeletedLeafVerkleValue, decodeVerkleNode, isLeafVerkleNode } from './node/util.js' import { type Proof, ROOT_DB_KEY, @@ -384,7 +384,7 @@ export class VerkleTree { let rawNode = await this._db.get(this.root()) if (rawNode === undefined) throw new Error('root node should exist') - const rootNode = decodeNode(rawNode, this.verkleCrypto) as InternalVerkleNode + const rootNode = decodeVerkleNode(rawNode, this.verkleCrypto) as InternalVerkleNode this.DEBUG && this.debug(`Starting with Root Node: [${bytesToHex(this.root())}]`, ['find_path']) result.stack.push([rootNode, this.root()]) @@ -401,7 +401,7 @@ export class VerkleTree { rawNode = await this._db.get(this.verkleCrypto.hashCommitment(child.commitment)) // We should always find the node if the path is specified in child.path if (rawNode === undefined) throw new Error(`missing node at ${bytesToHex(child.path)}`) - const decodedNode = decodeNode(rawNode, this.verkleCrypto) + const decodedNode = decodeVerkleNode(rawNode, this.verkleCrypto) // Calculate the index of the last matching byte in the key const matchingKeyLength = matchingBytesLength(key, child.path) diff --git a/packages/verkle/test/internalNode.spec.ts b/packages/verkle/test/internalNode.spec.ts index 07bf62fa7b..2de245d06f 100644 --- a/packages/verkle/test/internalNode.spec.ts +++ b/packages/verkle/test/internalNode.spec.ts @@ -2,7 +2,12 @@ import { type VerkleCrypto, equalsBytes, randomBytes } from '@ethereumjs/util' import { loadVerkleCrypto } from 'verkle-cryptography-wasm' import { assert, beforeAll, describe, it } from 'vitest' -import { NODE_WIDTH, VerkleNodeType, decodeNode, isInternalVerkleNode } from '../src/node/index.js' +import { + NODE_WIDTH, + VerkleNodeType, + decodeVerkleNode, + isInternalVerkleNode, +} from '../src/node/index.js' import { InternalVerkleNode } from '../src/node/internalNode.js' describe('verkle node - internal', () => { @@ -56,7 +61,7 @@ describe('verkle node - internal', () => { commitment: verkleCrypto.zeroCommitment, }) const serialized = node.serialize() - const decoded = decodeNode(serialized, verkleCrypto) + const decoded = decodeVerkleNode(serialized, verkleCrypto) assert.deepEqual((decoded as InternalVerkleNode).children[0].commitment, child.commitment) }) @@ -66,7 +71,7 @@ describe('verkle node - internal', () => { commitment: verkleCrypto.zeroCommitment, }) const serialized = node.serialize() - const decoded = decodeNode(serialized, verkleCrypto) + const decoded = decodeVerkleNode(serialized, verkleCrypto) assert.equal((decoded as InternalVerkleNode).children[0], null) }) }) diff --git a/packages/verkle/test/leafNode.spec.ts b/packages/verkle/test/leafNode.spec.ts index 5135e437cd..54b5436f7b 100644 --- a/packages/verkle/test/leafNode.spec.ts +++ b/packages/verkle/test/leafNode.spec.ts @@ -6,7 +6,7 @@ import { LeafVerkleNodeValue, VerkleNodeType, createCValues, - decodeNode, + decodeVerkleNode, isLeafVerkleNode, } from '../src/node/index.js' import { LeafVerkleNode } from '../src/node/leafNode.js' @@ -90,12 +90,12 @@ describe('verkle node - leaf', () => { const values = new Array(256).fill(new Uint8Array(32)) const node = await LeafVerkleNode.create(stem, verkleCrypto, values) const serialized = node.serialize() - const decodedNode = decodeNode(serialized, verkleCrypto) + const decodedNode = decodeVerkleNode(serialized, verkleCrypto) assert.deepEqual(node, decodedNode) const defaultNode = await LeafVerkleNode.create(randomBytes(31), verkleCrypto) - assert.deepEqual(defaultNode, decodeNode(defaultNode.serialize(), verkleCrypto)) + assert.deepEqual(defaultNode, decodeVerkleNode(defaultNode.serialize(), verkleCrypto)) }) }) diff --git a/packages/verkle/test/verkle.spec.ts b/packages/verkle/test/verkle.spec.ts index 2967aead41..2fa4929f67 100644 --- a/packages/verkle/test/verkle.spec.ts +++ b/packages/verkle/test/verkle.spec.ts @@ -8,7 +8,7 @@ import { LeafVerkleNodeValue, VerkleNodeType, createVerkleTree, - decodeNode, + decodeVerkleNode, } from '../src/index.js' import type { VerkleNode } from '../src/index.js' @@ -139,7 +139,7 @@ describe('Verkle tree', () => { // Pull root node from DB const rawNode = await trie['_db'].get(trie.root()) - const rootNode = decodeNode(rawNode!, verkleCrypto) as InternalVerkleNode + const rootNode = decodeVerkleNode(rawNode!, verkleCrypto) as InternalVerkleNode // Update root node with commitment from leaf node rootNode.setChild(stem1[0], { commitment: leafNode1.commitment, path: stem1 }) trie.root(verkleCrypto.serializeCommitment(rootNode.commitment)) diff --git a/packages/vm/package.json b/packages/vm/package.json index 065e46bb4c..32934c073e 100644 --- a/packages/vm/package.json +++ b/packages/vm/package.json @@ -69,7 +69,7 @@ "@ethereumjs/evm": "^3.1.0", "@ethereumjs/rlp": "^5.0.2", "@ethereumjs/statemanager": "^2.4.0", - "@ethereumjs/trie": "^6.2.1", + "@ethereumjs/mpt": "^6.2.2", "@ethereumjs/tx": "^5.4.0", "@ethereumjs/util": "^9.1.0", "debug": "^4.3.3", diff --git a/packages/vm/src/buildBlock.ts b/packages/vm/src/buildBlock.ts index 1d00b7b279..b95fec859d 100644 --- a/packages/vm/src/buildBlock.ts +++ b/packages/vm/src/buildBlock.ts @@ -6,8 +6,8 @@ import { genWithdrawalsTrieRoot, } from '@ethereumjs/block' import { ConsensusType, Hardfork } from '@ethereumjs/common' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { Blob4844Tx, createMinimal4844TxFromNetworkWrapper } from '@ethereumjs/tx' import { Address, diff --git a/packages/vm/src/runBlock.ts b/packages/vm/src/runBlock.ts index ad1bea1bc0..41589f1d8c 100644 --- a/packages/vm/src/runBlock.ts +++ b/packages/vm/src/runBlock.ts @@ -1,8 +1,8 @@ import { createBlock, genRequestsTrieRoot } from '@ethereumjs/block' import { ConsensusType, Hardfork } from '@ethereumjs/common' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' import { StatelessVerkleStateManager, verifyVerkleStateProof } from '@ethereumjs/statemanager' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { TransactionType } from '@ethereumjs/tx' import { Account, diff --git a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts index 94f450dbbd..cf7b6e4a32 100644 --- a/packages/vm/test/tester/runners/BlockchainTestsRunner.ts +++ b/packages/vm/test/tester/runners/BlockchainTestsRunner.ts @@ -2,9 +2,9 @@ import { createBlock, createBlockFromRLP } from '@ethereumjs/block' import { EthashConsensus, createBlockchain } from '@ethereumjs/blockchain' import { ConsensusAlgorithm } from '@ethereumjs/common' import { Ethash } from '@ethereumjs/ethash' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { RLP } from '@ethereumjs/rlp' import { Caches, MerkleStateManager } from '@ethereumjs/statemanager' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { createTxFromRLP } from '@ethereumjs/tx' import { MapDB, diff --git a/packages/vm/test/tester/runners/GeneralStateTestsRunner.ts b/packages/vm/test/tester/runners/GeneralStateTestsRunner.ts index 9d495b2138..10e9e3bbca 100644 --- a/packages/vm/test/tester/runners/GeneralStateTestsRunner.ts +++ b/packages/vm/test/tester/runners/GeneralStateTestsRunner.ts @@ -1,8 +1,8 @@ import { Block } from '@ethereumjs/block' import { createBlockchain } from '@ethereumjs/blockchain' import { type InterpreterStep } from '@ethereumjs/evm' +import { MerklePatriciaTrie } from '@ethereumjs/mpt' import { Caches, MerkleStateManager } from '@ethereumjs/statemanager' -import { MerklePatriciaTrie } from '@ethereumjs/trie' import { Account, bytesToHex, diff --git a/packages/vm/tsconfig.prod.cjs.json b/packages/vm/tsconfig.prod.cjs.json index 5940c1cbd7..5a8b3e254a 100644 --- a/packages/vm/tsconfig.prod.cjs.json +++ b/packages/vm/tsconfig.prod.cjs.json @@ -13,7 +13,7 @@ { "path": "../evm/tsconfig.prod.cjs.json" }, { "path": "../rlp/tsconfig.prod.cjs.json" }, { "path": "../statemanager/tsconfig.prod.cjs.json" }, - { "path": "../trie/tsconfig.prod.cjs.json" }, + { "path": "../mpt/tsconfig.prod.cjs.json" }, { "path": "../tx/tsconfig.prod.cjs.json" }, { "path": "../util/tsconfig.prod.cjs.json" } ] diff --git a/packages/vm/tsconfig.prod.esm.json b/packages/vm/tsconfig.prod.esm.json index 73305489ec..e1c74cefcc 100644 --- a/packages/vm/tsconfig.prod.esm.json +++ b/packages/vm/tsconfig.prod.esm.json @@ -13,7 +13,7 @@ { "path": "../evm/tsconfig.prod.esm.json" }, { "path": "../rlp/tsconfig.prod.esm.json" }, { "path": "../statemanager/tsconfig.prod.esm.json" }, - { "path": "../trie/tsconfig.prod.esm.json" }, + { "path": "../mpt/tsconfig.prod.esm.json" }, { "path": "../tx/tsconfig.prod.esm.json" }, { "path": "../util/tsconfig.prod.esm.json" } ]