Skip to content

fix(core): fix Trie::verify_range for proof of absences.#3146

Merged
azteca1998 merged 2 commits into
mainfrom
fix-verify_range-proof-of-absence
Jun 17, 2025
Merged

fix(core): fix Trie::verify_range for proof of absences.#3146
azteca1998 merged 2 commits into
mainfrom
fix-verify_range-proof-of-absence

Conversation

@azteca1998

Copy link
Copy Markdown
Contributor

Motivation

Description

Closes #issue_number

@github-actions

github-actions Bot commented Jun 12, 2025

Copy link
Copy Markdown

Lines of code report

Total lines added: 1436
Total lines removed: 833
Total lines changed: 2269

Detailed view
+-----------------------------------------------------------------+-------+------+
| File                                                            | Lines | Diff |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/blockchain/test_runner.rs                   | 167   | -44  |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/levm_runner.rs                 | 381   | -1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ef_tests/state/runner/revm_runner.rs                 | 528   | -3   |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/cli.rs                                        | 437   | -7   |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex/l2/command.rs                                 | 354   | -14  |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/cache.rs                           | 50    | +28  |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/constants.rs                       | 55    | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/fetcher.rs                         | 95    | +26  |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/rpc/db.rs                          | 481   | +481 |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/rpc/mod.rs                         | 249   | +146 |
+-----------------------------------------------------------------+-------+------+
| ethrex/cmd/ethrex_replay/src/run.rs                             | 60    | -7   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/blockchain.rs                          | 503   | -170 |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/error.rs                               | 111   | -2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/blockchain/payload.rs                             | 563   | -2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/common/common.rs                                  | 7     | -1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/common/trie/trie.rs                               | 865   | -37  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/common/trie/verify_range.rs                       | 501   | +32  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/common/types/mod.rs                               | 23    | -1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/src/execution.rs         | 318   | -23  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/src/io.rs                | 76    | -2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/src/lib.rs               | 4     | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/prover/zkvm/interface/src/trie.rs              | 121   | +121 |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/block_producer.rs                    | 131   | -44  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/errors.rs                            | 250   | -4   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/mod.rs                               | 112   | -5   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/sequencer/proof_coordinator.rs                 | 503   | -10  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/utils/prover/db.rs                             | 224   | +224 |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/l2/utils/prover/mod.rs                            | 4     | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/kademlia.rs                        | 501   | -112 |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/peer_handler.rs                    | 643   | -25  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/sync.rs                            | 572   | +5   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/engine/payload.rs                  | 665   | -4   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/eth/block.rs                       | 356   | -81  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/networking/rpc/rpc.rs                             | 586   | -2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/api.rs                                    | 270   | +2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/error.rs                                  | 51    | -2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                                  | 1292  | -67  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/in_memory.rs                     | 624   | -37  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/libmdbx.rs                       | 1406  | -51  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/redb.rs                          | 1250  | -41  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/db.rs                            | 138   | +2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/backends/levm/mod.rs                           | 508   | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/errors.rs                                      | 121   | -8   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/call_frame.rs                         | 217   | +9   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/error.rs                           | 6     | +6   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/gen_db.rs                          | 250   | -17  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/db/mod.rs                             | 18    | +2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/errors.rs                             | 230   | +54  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/execution_handlers.rs                 | 245   | +7   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/gas_cost.rs                           | 867   | +40  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/default_hook.rs                 | 352   | +35  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/hooks/l2_hook.rs                      | 129   | +5   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/memory.rs                             | 190   | +9   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/arithmetic.rs         | 217   | +10  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/bitwise_comparison.rs | 215   | +10  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/block.rs              | 123   | +2   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/push.rs               | 42    | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs                        | 1289  | -9   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/tracing.rs                            | 165   | +5   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                              | 478   | +26  |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/lib.rs                                         | 14    | +1   |
+-----------------------------------------------------------------+-------+------+
| ethrex/crates/vm/prover_db.rs                                   | 143   | +143 |
+-----------------------------------------------------------------+-------+------+

@github-actions

Copy link
Copy Markdown

Benchmark for 3bb9b68

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 35.5±0.42ms 35.9±0.44ms +1.13%
Trie/cita-trie insert 1k 3.7±0.04ms 3.8±0.21ms +2.70%
Trie/ethrex-trie insert 10k 55.8±0.31ms 56.2±0.72ms +0.72%
Trie/ethrex-trie insert 1k 6.5±0.02ms 6.5±0.03ms 0.00%

@azteca1998 azteca1998 changed the title fix(core): Fix Trie::verify_range for proof of absences. fix(core): fix Trie::verify_range for proof of absences. Jun 12, 2025
@azteca1998 azteca1998 linked an issue Jun 12, 2025 that may be closed by this pull request
@github-actions

Copy link
Copy Markdown

Benchmark for 3ad3a11

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 37.2±0.88ms 38.1±1.84ms +2.42%
Trie/cita-trie insert 1k 3.8±0.05ms 3.7±0.03ms -2.63%
Trie/ethrex-trie insert 10k 60.2±2.39ms 57.1±0.42ms -5.15%
Trie/ethrex-trie insert 1k 6.7±0.09ms 6.7±0.34ms 0.00%

@azteca1998 azteca1998 marked this pull request as ready for review June 12, 2025 15:58
@azteca1998 azteca1998 requested a review from a team as a code owner June 12, 2025 15:58

@Arkenan Arkenan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

proof,
root.into(),
(*first_key, Some(*last_key)),
Some(*keys.first().unwrap()),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: maybe this can be improved if instead of unwrapping we do something like

if let [key] = keys.as_slice() {
  if first_key != *key {
    return Err(TrieError::Verify(
                "correct proof but invalid key".to_string(),
            ));
  }
  // ...
}

this way we avoid the unwrap, plus the last_key is also guaranteed to be "key" if it exists.

@azteca1998 azteca1998 added this pull request to the merge queue Jun 17, 2025
Merged via the queue into main with commit e053c95 Jun 17, 2025
21 checks passed
@azteca1998 azteca1998 deleted the fix-verify_range-proof-of-absence branch June 17, 2025 14:36
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
…ss#3146)

**Motivation**

<!-- Why does this pull request exist? What are its goals? -->

**Description**

<!-- A clear and concise general description of the changes this PR
introduces -->

<!-- Link to issues: Resolves lambdaclass#111, Resolves lambdaclass#222 -->

Closes #issue_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sync snap test is flaky

3 participants