Skip to content

Conversation

JereSalo
Copy link
Contributor

Motivation

Description

Execution with eth_getProof had some caveats regarding the trie. For making it work we need to do 2 things:

  1. Pre-inject possible nodes to the trie
  2. Make a modification to the MPT in case we don't find a missing node.

The 1 was already done in the code but wasn't working properly, the problem was just that the root node wasn't being inserted into the nodes that were used for building the trie that's used for getting potential child nodes.

The 2 is a modification that we don't want in our MPT so we didn't carry along with that. However, in execution without zkVM we have the possibility of inserting arbitrary nodes with the hashes that we want and RLP content that doesn't necessarily match to that hash, so we can "deceive" the trie into thinking it has some nodes when in fact they are just dummy nodes.
How can we use it to our advantage? We insert dummy branch nodes in every single place where a storage node is being referenced but it's missing. This way, if we want to do a trie restructuring we will find the node that otherwise we wouldn't have found, and the good thing is that we don't care about the contents of this node because they won't change, in this particular case the node will be referenced by a one nibble extension node. For more info read https://github.com/kkrt-labs/zk-pig/blob/main/docs/modified-mpt.md#modified-mpt-implementation

Closes #issue_number

@Copilot Copilot AI review requested due to automatic review settings September 23, 2025 18:34
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes execution with eth_getProof by addressing issues with the trie implementation when nodes are missing. The solution involves pre-injecting nodes into the trie and adding dummy nodes to handle missing references.

Key changes:

  • Pre-inject root nodes into the state trie to ensure they're available for child node discovery
  • Extract trie traversal logic into a helper function for code reusability
  • Insert dummy branch nodes for missing storage node references to prevent execution failures

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/common/trie/node/branch.rs Add Default trait to BranchNode to enable creation of dummy nodes
cmd/ethrex_replay/src/rpc/db.rs Fix root node injection by ensuring it's added to state_nodes collection
cmd/ethrex_replay/src/lib.rs Add helpers module to lib exports
cmd/ethrex_replay/src/helpers.rs New helper function to extract referenced hashes from trie nodes
cmd/ethrex_replay/src/cli.rs Refactor trie handling to use helper function and add dummy node injection for storage tries

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link

Benchmark for 8085d49

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.5±1.40ms 35.9±1.89ms +1.13%
Trie/cita-trie insert 1k 3.6±0.02ms 3.6±0.18ms 0.00%
Trie/ethrex-trie insert 10k 55.2±0.61ms 55.1±0.77ms -0.18%
Trie/ethrex-trie insert 1k 6.2±0.08ms 6.2±0.04ms 0.00%

Node::Branch(node) => {
for choice in &node.choices {
let NodeRef::Hash(hash) = *choice else {
unreachable!()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Return errors instead of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@tomip01 tomip01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! just one comment

Copy link

Benchmark for 5dc4763

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.1±0.17ms 35.1±0.32ms 0.00%
Trie/cita-trie insert 1k 3.6±0.03ms 3.7±0.15ms +2.78%
Trie/ethrex-trie insert 10k 55.3±2.31ms 55.3±0.67ms 0.00%
Trie/ethrex-trie insert 1k 6.1±0.02ms 6.1±0.02ms 0.00%

Copy link

Benchmark for 48c2cd0

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 36.0±0.94ms 35.5±0.52ms -1.39%
Trie/cita-trie insert 1k 3.6±0.02ms 3.6±0.07ms 0.00%
Trie/ethrex-trie insert 10k 55.4±0.83ms 55.9±0.78ms +0.90%
Trie/ethrex-trie insert 1k 6.3±0.18ms 6.2±0.15ms -1.59%

@JereSalo JereSalo enabled auto-merge September 24, 2025 21:10
@JereSalo JereSalo added this pull request to the merge queue Sep 24, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 24, 2025
@JereSalo JereSalo enabled auto-merge September 24, 2025 21:29
Copy link

Benchmark for d43e64c

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 34.1±1.11ms 39.0±2.04ms +14.37%
Trie/cita-trie insert 1k 3.6±0.04ms 3.7±0.19ms +2.78%
Trie/ethrex-trie insert 10k 57.3±1.21ms 56.8±1.60ms -0.87%
Trie/ethrex-trie insert 1k 6.2±0.03ms 6.1±0.13ms -1.61%

@JereSalo JereSalo added this pull request to the merge queue Sep 24, 2025
auto-merge was automatically disabled September 24, 2025 22:23

Pull Request is not mergeable

@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Sep 24, 2025
Copy link

Benchmark for 72c30cd

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.1±0.23ms 34.9±0.43ms -0.57%
Trie/cita-trie insert 1k 3.6±0.03ms 3.7±0.25ms +2.78%
Trie/ethrex-trie insert 10k 54.7±0.32ms 55.2±0.39ms +0.91%
Trie/ethrex-trie insert 1k 6.2±0.03ms 6.1±0.01ms -1.61%

@JereSalo JereSalo enabled auto-merge September 25, 2025 15:24
Copy link

Benchmark for 14c6871

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.3±0.67ms 35.3±0.46ms 0.00%
Trie/cita-trie insert 1k 3.6±0.02ms 3.6±0.06ms 0.00%
Trie/ethrex-trie insert 10k 55.2±0.38ms 54.9±0.62ms -0.54%
Trie/ethrex-trie insert 1k 6.1±0.02ms 6.2±0.22ms +1.64%

@JereSalo JereSalo added this pull request to the merge queue Sep 25, 2025
Merged via the queue into main with commit 316b9f3 Sep 25, 2025
36 checks passed
@JereSalo JereSalo deleted the debugging_eth_getProof branch September 25, 2025 16:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants