Skip to content

perf(sp1): fast path Reth precompiles - #61

Closed
figtracer wants to merge 6 commits into
eth-act:mainfrom
figtracer:fig/sp1-reth-modexp-fast-paths
Closed

perf(sp1): fast path Reth precompiles#61
figtracer wants to merge 6 commits into
eth-act:mainfrom
figtracer:fig/sp1-reth-modexp-fast-paths

Conversation

@figtracer

@figtracer figtracer commented Jul 7, 2026

Copy link
Copy Markdown

Summary

Adds SP1-only optimizations to the Reth guest's precompile provider before its existing zkVM syscall fallback:

  • specialized MODEXP paths for common bounded operands and exponents
  • exact one-entry input/output caches for repeated MODEXP and BLAKE2F calls
  • the merged stateless improvements from #30 and #31 via revision 3d2fc17

The Reth validation path still consumes and validates transaction public keys.

Ownership

This belongs in ere-guests because it selects SP1 syscall and cache policy in ERE's Reth crypto adapter. stateless remains zkVM-agnostic; generic MODEXP paths could move into SP1's libzkevm later so the Ethrex guest can use them too.

Correctness

The fast paths are checked against aurora-engine-modexp, including zero/modulus edge cases, U256, fixed-width, Montgomery/REDC, and repeated 248-bit chunk inputs. Both benchmark builds also produced the exact expected output for every fixture.

Full cycle benchmark

Paired SP1 run using zkevm-benchmark-workload at e0b6519, ERE v0.13.0, Reth v2.3.0, SP1 v6.3.1, and four workers. The same 1,077 Osaka 10M cases were converted to v0.13 canonical SSZ through ERE's legacy-to-canonical input bridge.

Build Total cycles Exact outputs
Same-base control (cffc3f1 + stateless@3d2fc17) 810,421,889,702 1,077 / 1,077
PR head (5770b2e) 185,706,351,828 1,077 / 1,077
Delta -624,715,537,874 (-77.085%) 0 mismatches

PR / control = 0.229

PR ELF SHA-256: 08052808b3aeef0f92ac0a83bc9caccf3ed33ef4d21f1043f4b2c3d14370677f

The Zilkworm article reports 159,156,117,864 cycles under the older legacy-input runner. That is useful historical context, but it is not the paired control for the v0.13 result above because the current guest also performs canonical SSZ input/output work.

Checks

  • .github/scripts/cargo-fetch-all.sh --locked
  • .github/scripts/cargo-fmt-all.sh --check
  • cargo clippy --all-targets -- -D warnings
  • cargo test --lib --no-fail-fast
  • cargo test --doc --no-fail-fast
  • SP1 and ZisK feature checks/clippy
  • SP1 RISC-V guest build

@figtracer figtracer changed the title perf(sp1): fast path Reth modexp perf(sp1): fast path Reth precompiles Jul 8, 2026
@figtracer
figtracer force-pushed the fig/sp1-reth-modexp-fast-paths branch from da4d5c4 to 5543f57 Compare July 13, 2026 08:44
@figtracer
figtracer marked this pull request as ready for review July 13, 2026 10:00
@figtracer
figtracer marked this pull request as draft July 13, 2026 15:43
@figtracer figtracer closed this Aug 3, 2026
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.

1 participant