Skip to content

Conversation

@edg-l
Copy link
Contributor

@edg-l edg-l commented Nov 10, 2025

Replace sha3 keccak to an assembly version using ffi

@github-actions
Copy link

github-actions bot commented Nov 10, 2025

Lines of code report

Total lines added: 308
Total lines removed: 98
Total lines changed: 406

Detailed view
+-------------------------------------------------------+-------+------+
| File                                                  | Lines | Diff |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/constants.rs                     | 39    | -1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/crypto/keccak/mod.rs             | 301   | +301 |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/crypto/lib.rs                    | 3     | +1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/evm.rs                           | 8     | -2   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/types/account.rs                 | 222   | -3   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/types/block_execution_witness.rs | 424   | -4   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/types/transaction.rs             | 2852  | -2   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/common/utils.rs                         | 68    | +5   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/discv4/messages.rs       | 921   | -1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/connection/codec.rs | 254   | -64  |
+-------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/rlpx/error.rs            | 120   | +1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/types.rs                 | 505   | -1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs                        | 1509  | -11  |
+-------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/opcode_handlers/keccak.rs   | 27    | -1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/precompiles.rs              | 1651  | -1   |
+-------------------------------------------------------+-------+------+
| ethrex/crates/vm/levm/src/utils.rs                    | 496   | -7   |
+-------------------------------------------------------+-------+------+

@github-actions
Copy link

Benchmark for c5c879e

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 47.8±13.61ms 32.9±8.78ms -31.17%
Trie/cita-trie insert 1k 2.9±0.05ms 2.8±0.03ms -3.45%
Trie/ethrex-trie insert 10k 25.9±1.78ms 24.0±0.42ms -7.34%
Trie/ethrex-trie insert 1k 2.2±0.02ms 2.2±0.36ms 0.00%

@github-actions
Copy link

Benchmark for 5ffb6bd

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 34.2±3.33ms 34.0±1.57ms -0.58%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.18ms 0.00%
Trie/ethrex-trie insert 10k 27.4±1.11ms 26.9±1.47ms -1.82%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.1±0.02ms -4.55%

@github-actions
Copy link

Benchmark for a6f1fad

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.0±1.17ms 28.5±1.52ms +1.79%
Trie/cita-trie insert 1k 2.9±0.02ms 2.9±0.12ms 0.00%
Trie/ethrex-trie insert 10k 26.0±0.99ms 24.8±1.19ms -4.62%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.1±0.04ms -4.55%

Comment on lines +35 to +43
impl Default for Keccak256 {
fn default() -> Self {
Self {
state: State::default(),
tail_buf: [0; BLOCK_SIZE],
tail_len: 0,
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be derived in the declaration of the struct. All the fields are taking their default value.

Copy link
Contributor

Choose a reason for hiding this comment

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

Rust let go of our hands. It can't be done because arrays only implement default up to a certain number less than 136.

Comment on lines 48 to 52
Self {
state: State::default(),
tail_buf: [0; BLOCK_SIZE],
tail_len: 0,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

you can call default() here.

@jrchatruc jrchatruc enabled auto-merge November 11, 2025 20:32
@github-actions
Copy link

Benchmark for a22c1fa

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.3±1.14ms 28.0±0.34ms -1.06%
Trie/cita-trie insert 1k 2.9±0.03ms 2.9±0.18ms 0.00%
Trie/ethrex-trie insert 10k 24.6±0.66ms 25.1±0.64ms +2.03%
Trie/ethrex-trie insert 1k 2.3±0.02ms 2.2±0.01ms -4.35%

@github-actions
Copy link

Benchmark for 21eb90e

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 30.1±1.91ms 29.9±1.34ms -0.66%
Trie/cita-trie insert 1k 2.9±0.01ms 3.0±0.18ms +3.45%
Trie/ethrex-trie insert 10k 26.4±1.16ms 27.1±0.96ms +2.65%
Trie/ethrex-trie insert 1k 2.2±0.02ms 2.2±0.02ms 0.00%

Co-authored-by: Tomás Grüner <47506558+MegaRedHand@users.noreply.github.com>
Comment on lines 36 to 40
// Hash value for an empty trie, equal to keccak(RLP_NULL)
pub static ref EMPTY_TRIE_HASH: H256 = H256::from_slice(
&Keccak256::digest([RLP_NULL]),
pub static ref EMPTY_TRIE_HASH: H256 = H256(
keccak_hash([RLP_NULL]),
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

we should refactorize the use of this lazy_static! and use std LazyLock/LazyCell.

Copy link
Contributor

Choose a reason for hiding this comment

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

I will file an issue with this task.

Copy link
Collaborator

Choose a reason for hiding this comment

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

We should move the EMPTY_KECCACK_HASH constant to this module too. (and fix that horrible typo too)

@@ -0,0 +1,855 @@
// Modified:
// - Ran `cpp` to substitute constants.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should paste the full command here.

@github-actions
Copy link

Benchmark for b2647eb

Click to view benchmark
Test Base PR %
Trie/cita-trie insert 10k 28.6±1.17ms 30.3±1.54ms +5.94%
Trie/cita-trie insert 1k 2.9±0.01ms 2.9±0.01ms 0.00%
Trie/ethrex-trie insert 10k 26.0±1.05ms 25.5±1.79ms -1.92%
Trie/ethrex-trie insert 1k 2.2±0.01ms 2.2±0.05ms 0.00%

@jrchatruc jrchatruc added this pull request to the merge queue Nov 11, 2025
Merged via the queue into main with commit 85ef3d3 Nov 11, 2025
58 checks passed
@jrchatruc jrchatruc deleted the perf/asm_ffi_keccak branch November 11, 2025 21:43
@github-project-automation github-project-automation bot moved this from In review to Done in ethrex_performance Nov 11, 2025
@github-project-automation github-project-automation bot moved this from In Review to Done in ethrex_l1 Nov 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

L1 Ethereum client performance

Projects

Status: Done
Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants