Skip to content

perf(guest): route all guest keccak through the chip via a vendored t… - #885

Open
diegokingston wants to merge 2 commits into
mainfrom
perf/guest-keccak-ecall
Open

perf(guest): route all guest keccak through the chip via a vendored t…#885
diegokingston wants to merge 2 commits into
mainfrom
perf/guest-keccak-ecall

Conversation

@diegokingston

Copy link
Copy Markdown
Collaborator

…iny-keccak patch

ethrex's free-fn keccak_hash path (trie/RLP/tx hashing) bypasses the Crypto trait, so ~6% of a 20-tx block ran tiny_keccak's pure-Rust keccakf in the guest despite the keccak chip. Vendor tiny-keccak 2.0.2 under crypto/tiny-keccak with a one-hunk patch: on riscv64, keccakf calls the keccak_permute ecall; host keeps the software impl. Activated via [patch.crates-io] in the ethrex guest workspace.

Measured vs origin/main (same fixtures, deterministic):
transfers_20 8,732,213 -> 8,461,843 (-270,370, -3.1%)
erc20_20 10,328,222 -> 9,929,487 (-398,735, -3.9%)
mixed_20 9,817,444 -> 9,450,857 (-366,587, -3.7%)
software tiny_keccak::keccakf in the guest flamegraph: 397k -> 0 (erc20_20).

Verified: test_prove_ethrex_empty_block (prove+verify) passes.

…iny-keccak patch

ethrex's free-fn keccak_hash path (trie/RLP/tx hashing) bypasses the Crypto
trait, so ~6% of a 20-tx block ran tiny_keccak's pure-Rust keccakf in the
guest despite the keccak chip. Vendor tiny-keccak 2.0.2 under
crypto/tiny-keccak with a one-hunk patch: on riscv64, keccakf calls the
keccak_permute ecall; host keeps the software impl. Activated via
[patch.crates-io] in the ethrex guest workspace (same pattern as
sp1-patches/tiny-keccak).

Measured vs origin/main (same fixtures, deterministic):
  transfers_20  8,732,213 -> 8,461,843  (-270,370, -3.1%)
  erc20_20     10,328,222 -> 9,929,487  (-398,735, -3.9%)
  mixed_20      9,817,444 -> 9,450,857  (-366,587, -3.7%)
software tiny_keccak::keccakf in the guest flamegraph: 397k -> 0 (erc20_20).

Verified: test_prove_ethrex_empty_block (prove+verify) passes.
@diegokingston

Copy link
Copy Markdown
Collaborator Author

/bench

@github-actions

github-actions Bot commented Jul 31, 2026

Copy link
Copy Markdown

Benchmark — real block (ethrex_mainnet_25368371.bin) (median of 3)

continuations · epoch 2^22 · 12 epochs

Metric main PR Δ
Peak heap 51856 MB 52175 MB +319 MB (+0.6%) ⚪
Prove time 159.217s 153.339s -5.878s (-3.7%) ⚪

-3.7% — beyond what 3 runs resolve. Use /bench-abba for a paired test.

Prove-time spread 0.7% (153.339s / 154.133s / 153.024s)

Commit: ce43d51 · Baseline: cached · Runner: self-hosted bench

@diegokingston
diegokingston marked this pull request as ready for review July 31, 2026 21:24
@MauroToscano

Copy link
Copy Markdown
Contributor

/bench

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.

2 participants