Skip to content

Conversation

@iovoid
Copy link
Contributor

@iovoid iovoid commented Nov 10, 2025

Caution

This changes the serialization of Code, and thus requires re-syncing.

Motivation

While executing the state tests in debug mode, a debug assert was triggered.

The calculation of valid jumpdests assumes the code will be less than 2^16 bytes in length, however this isn't true before Shanghai.

Description

This PR adds support for up to 2^32 bytes of initcode.

@github-actions
Copy link

github-actions bot commented Nov 10, 2025

Lines of code report

Total lines added: 2
Total lines removed: 1
Total lines changed: 3

Detailed view
+------------------------------------------------------------------------+-------+------+
| File                                                                   | Lines | Diff |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/rocksdb.rs                              | 1603  | -1   |
+------------------------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/stack_memory_storage_flow.rs | 250   | +2   |
+------------------------------------------------------------------------+-------+------+


for (code_hash, code) in update_batch.code_updates {
let mut buf = Vec::with_capacity(6 + code.bytecode.len() + 2 * code.jump_targets.len());
let mut buf = Vec::with_capacity(6 + code.bytecode.len() + 4 * code.jump_targets.len());
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to use size_of to avoid hard-coding this lenght

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Improved in 9d129ce

.chunks_exact(2)
.map(|c| u16::from_le_bytes([c[0], c[1]]))
.chunks_exact(4)
.map(|c| u32::from_le_bytes([c[0], c[1], c[2], c[3]]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Talking with @Oppen, we think that it's better to encode the jump_target in RLP, which will be smaller than 32 bits for the common case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Better is a strong word for any use of RLP. But in the tradeoff IO probably wins, and RLP is better for IO than always using all the bytes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 084c8e2

@github-actions
Copy link

github-actions bot commented Nov 10, 2025

Benchmark Results Comparison

No significant difference was registered for any benchmark run.

Detailed Results

Benchmark Results: BubbleSort

Command Mean [s] Min [s] Max [s] Relative
main_revm_BubbleSort 2.962 ± 0.020 2.939 2.988 1.00 ± 0.01
main_levm_BubbleSort 3.248 ± 0.082 3.202 3.467 1.10 ± 0.03
pr_revm_BubbleSort 2.954 ± 0.019 2.937 3.000 1.00
pr_levm_BubbleSort 3.233 ± 0.021 3.203 3.272 1.09 ± 0.01

Benchmark Results: ERC20Approval

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Approval 960.3 ± 5.8 951.7 968.4 1.00
main_levm_ERC20Approval 1137.5 ± 10.8 1123.7 1158.8 1.18 ± 0.01
pr_revm_ERC20Approval 970.9 ± 9.7 960.9 987.4 1.01 ± 0.01
pr_levm_ERC20Approval 1140.9 ± 5.6 1130.9 1150.4 1.19 ± 0.01

Benchmark Results: ERC20Mint

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Mint 132.6 ± 2.3 130.8 138.4 1.00
main_levm_ERC20Mint 168.7 ± 5.8 165.0 184.8 1.27 ± 0.05
pr_revm_ERC20Mint 133.7 ± 2.1 131.7 138.3 1.01 ± 0.02
pr_levm_ERC20Mint 168.6 ± 1.4 167.2 172.0 1.27 ± 0.02

Benchmark Results: ERC20Transfer

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ERC20Transfer 230.5 ± 3.8 225.7 237.2 1.00 ± 0.02
main_levm_ERC20Transfer 285.5 ± 3.1 280.2 288.8 1.24 ± 0.02
pr_revm_ERC20Transfer 230.1 ± 2.6 227.4 234.8 1.00
pr_levm_ERC20Transfer 288.6 ± 5.5 285.0 304.0 1.25 ± 0.03

Benchmark Results: Factorial

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Factorial 225.3 ± 2.5 223.4 231.7 1.01 ± 0.01
main_levm_Factorial 264.0 ± 1.9 262.4 268.9 1.18 ± 0.01
pr_revm_Factorial 223.5 ± 0.9 222.3 225.2 1.00
pr_levm_Factorial 263.1 ± 1.7 260.9 265.8 1.18 ± 0.01

Benchmark Results: FactorialRecursive

Command Mean [s] Min [s] Max [s] Relative
main_revm_FactorialRecursive 1.607 ± 0.042 1.543 1.661 1.00
main_levm_FactorialRecursive 8.248 ± 0.029 8.193 8.287 5.13 ± 0.14
pr_revm_FactorialRecursive 1.650 ± 0.019 1.615 1.675 1.03 ± 0.03
pr_levm_FactorialRecursive 8.282 ± 0.045 8.206 8.349 5.15 ± 0.14

Benchmark Results: Fibonacci

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Fibonacci 205.7 ± 1.9 202.5 210.1 1.00 ± 0.02
main_levm_Fibonacci 249.2 ± 3.1 247.0 257.0 1.22 ± 0.03
pr_revm_Fibonacci 205.0 ± 3.4 202.8 214.4 1.00
pr_levm_Fibonacci 250.1 ± 3.3 246.5 256.5 1.22 ± 0.03

Benchmark Results: FibonacciRecursive

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_FibonacciRecursive 829.1 ± 11.0 815.8 849.1 1.11 ± 0.02
main_levm_FibonacciRecursive 744.4 ± 6.8 737.1 756.3 1.00
pr_revm_FibonacciRecursive 859.7 ± 9.4 841.2 872.2 1.15 ± 0.02
pr_levm_FibonacciRecursive 745.3 ± 7.5 738.3 759.2 1.00 ± 0.01

Benchmark Results: ManyHashes

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_ManyHashes 8.2 ± 0.1 8.2 8.3 1.00
main_levm_ManyHashes 9.6 ± 0.1 9.4 9.8 1.16 ± 0.01
pr_revm_ManyHashes 8.3 ± 0.1 8.2 8.6 1.00 ± 0.01
pr_levm_ManyHashes 9.5 ± 0.1 9.5 9.6 1.15 ± 0.01

Benchmark Results: MstoreBench

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_MstoreBench 264.1 ± 4.7 260.9 274.4 1.08 ± 0.02
main_levm_MstoreBench 243.5 ± 3.2 238.9 249.6 1.00
pr_revm_MstoreBench 264.2 ± 3.7 261.3 273.0 1.09 ± 0.02
pr_levm_MstoreBench 245.4 ± 1.8 243.5 248.8 1.01 ± 0.02

Benchmark Results: Push

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_Push 290.9 ± 1.0 289.2 292.5 1.00
main_levm_Push 298.0 ± 1.4 295.8 300.1 1.02 ± 0.01
pr_revm_Push 290.9 ± 1.3 289.7 294.2 1.00 ± 0.01
pr_levm_Push 299.0 ± 2.6 296.6 304.5 1.03 ± 0.01

Benchmark Results: SstoreBench_no_opt

Command Mean [ms] Min [ms] Max [ms] Relative
main_revm_SstoreBench_no_opt 166.7 ± 3.7 161.1 170.7 1.86 ± 0.07
main_levm_SstoreBench_no_opt 89.5 ± 2.7 87.5 95.8 1.00
pr_revm_SstoreBench_no_opt 167.3 ± 5.0 161.4 178.2 1.87 ± 0.08
pr_levm_SstoreBench_no_opt 90.1 ± 2.0 87.9 94.1 1.01 ± 0.04

pub bytecode: Bytes,
// TODO: Consider using Arc<[u16]> (needs to enable serde rc feature)
pub jump_targets: Vec<u16>,
// TODO: Consider using Arc<[u32]> (needs to enable serde rc feature)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add a comment here or anywhere you consider convenient about the reason why we use 32 bits? So nobody changes it to u16 back again
If you want you can link EIP-3860 but it's not necessary

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it would be a good idea to link to the EIP. Also to the failing EEST test.

Copy link
Contributor

Choose a reason for hiding this comment

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

When in doubt, overcommenting is better than undercommenting. Don't let school tell you otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment in da77868

@iovoid iovoid marked this pull request as ready for review November 11, 2025 18:58
@iovoid iovoid requested a review from a team as a code owner November 11, 2025 18:58
@jrchatruc jrchatruc enabled auto-merge November 11, 2025 19:45
@jrchatruc jrchatruc added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit 8089824 Nov 11, 2025
51 checks passed
@jrchatruc jrchatruc deleted the jumpdest_large_initcode branch November 11, 2025 20:45
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.

7 participants