Skip to content

sha2: succinct patch for 0.11.0 - #10

Closed
sebastianst wants to merge 2 commits into
sp1-patches:patch-sha3-v0.11.0from
ethereum-optimism:patch-sha2-v0.11.0
Closed

sebastianst wants to merge 2 commits into
sp1-patches:patch-sha3-v0.11.0from
ethereum-optimism:patch-sha2-v0.11.0

Conversation

@sebastianst

@sebastianst sebastianst commented Sep 14, 2026 •

Copy link
Copy Markdown

This branch is one commit on top of upstream tag sha2-v0.11.0 (ffe0939) and is meant to be tagged patch-sha2-0.11.0-sp1-6.2.0 (alias -sp1-6.0.0), not merged — same shape as patch-sha3-0.11.0-sp1-6.0.0. The PR targets patch-sha3-v0.11.0 only because it is the one branch here that already contains sha2-v0.11.0, so the diff shows just this commit (2 files, +80/−1): ethereum-optimism@12e493aecbe2

Why

revm-precompile 42 (revm 42, reth v2.5.0) requires sha2 = "0.11". A [patch.crates-io] entry pointing at patch-sha2-0.10.9-sp1-6.2.0 does not apply to it — cargo only warns:

warning: patch `sha2 v0.10.9 (…?tag=patch-sha2-0.10.9-sp1-6.2.0)` was not used in the crate graph

and resolves sha2 0.11.0 from crates.io unpatched. So every SP1 program executing a current revm runs SHA-256 in software, silently. In our guest lockfile both copies are present side by side: the patched 0.10.9 for k256/p256/kzg-rs/sp1-zkvm/alloy-eips, and an unpatched 0.11.0 whose only dependent is revm-precompile 42.0.1.

Tracking issue: ethereum-optimism/optimism#22890

What

Forward-port of patch-sha2-0.10.9-sp1-6.2.0 onto upstream sha2-v0.11.0: same cfg gate (all(target_os = "zkvm", target_vendor = "succinct")), same raw extern "C" syscall declarations, same compress body — the signature is unchanged in 0.11 (fn compress(state: &mut [u32; 8], blocks: &[[u8; 64]])), 0.11 just dropped the GenericArray wrapper that the 0.10 patch had to unwrap.

Adaptations: unsafe extern "C" for edition 2024, pub(super) visibility to match the other 0.11 backends, and one cfg_if! arm ahead of 0.11's new backend selection (which moved from cargo features to the sha2_backend / sha2_256_backend cfgs).

No Cargo.toml change and no sp1-lib dependency — same shape as patch-sha3-0.11.0-sp1-6.0.0. 2 files, +80/−1.

Verification

Host cargo check -p sha2 and cargo test -p sha2 pass (14 tests + 2 doctests: KAT, serialization, rand vectors). succinct.rs was type-checked separately for edition 2024, since the host build cfgs it out.

This has not been run in the zkVM. Please add a sha2-v0-11-0 entry to patch-testing/sha/ and run it — roughly 30 lines: an optional dep, a feature, a [[bin]], and a [patch.crates-io] entry, mirroring the existing v0-10-9 wiring. Worth covering empty input, multi-block input, and an unaligned first block (the aligned fast path reinterprets the block as *const u64, so it is the one thing a host check cannot prove).

Judgement calls / open questions

Best guess taken in the code, happy to change any of these:

  1. Dispatch shape. Kept the 0.10 structure — a first cfg_if! arm — so zkvm wins over an explicitly requested sha2_256_backend. The alternative is a dispatch helper like sha3's permute. sha2 has a single compress binding so the extra indirection did not seem to earn its place, but if you prefer the sha3 shape for consistency I will restructure.
  2. unexpected_cfgs warning. sha2 0.11 sets [lints.rust.unexpected_cfgs] level = "warn", so target_vendor = "succinct" produces a warning on host builds (sha3 0.11 has no [lints] section, which is why its patch is warning-free). Harmless downstream — cargo caps lints for git deps — but you may want to allow it in Cargo.toml.
  3. sha512 stays unaccelerated, as in the 0.10 patch.
  4. Hotness not measured. I did not benchmark how much SHA-256 the precompile path actually executes in a revm guest, so the cycle-count win is unquantified here.

🤖 Co-created with Claude Fable 5.1

Forward-port of patch-sha2-0.10.9-sp1-6.2.0 onto upstream sha2-v0.11.0.
On target_os = "zkvm" / target_vendor = "succinct", SHA-256 compression routes
to the syscall_sha256_extend + syscall_sha256_compress precompiles; every other
target keeps the stock 0.11 backend selection unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@sebastianst

Copy link
Copy Markdown
Author

🤖 Claude Fable 5.1 says: zkVM validation done, and the patch-testing coverage is up as succinctlabs/sp1#2971 (a sha2_v0_11_0 case mirroring sha2_v0_10_9, currently pointing at the fork branch; switch it to the tag once cut).

Run locally with the sp1up toolchain (cargo-prove sp1 58c4aea), CPU executor, no proving: cargo test --manifest-path patch-testing/Cargo.toml -p sha --release → 6 passed, including the new 0.11 case (1,335,157 cycles) and the 0.10.9 control (1,351,494). An extra corpus covering the empty input, one-block, multi-block and inputs sliced at offsets 1/3/7 (the unaligned-first-block branch) gave byte-identical digests to host sha2 0.11 and identical syscall counts for 0.11 and 0.10.9: SHA_COMPRESS = 117, SHA_EXTEND = 117.

@sebastianst

Copy link
Copy Markdown
Author

🤖 Claude Fable 5.1 says: Thanks for cutting patch-sha2-0.11.0-sp1-6.2.0. Adopted on our side in ethereum-optimism/optimism#22495, and succinctlabs/sp1#2971 now points its patch-testing sources at the tag (re-validated against it: same digests, same syscall counts). This PR can be closed as superseded by the tag.

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