Skip to content

refactor: make sha3 exterior interface unmodified in patch#9

Merged
gdmlcjs merged 5 commits into
openvm/sha3-v0.10.8from
chore/sha3-v0.10.8-patch
Apr 29, 2026
Merged

refactor: make sha3 exterior interface unmodified in patch#9
gdmlcjs merged 5 commits into
openvm/sha3-v0.10.8from
chore/sha3-v0.10.8-patch

Conversation

@gdmlcjs
Copy link
Copy Markdown
Collaborator

@gdmlcjs gdmlcjs commented Apr 18, 2026

Refactors the sha3 patch to use the lower level openvm-keccak256-guest crate instead of the openvm-keccak256 crate.
The internal implementations are swapped to use the openvm functions for the zkvm target. The native_keccakf and native_xorin functions are used everywhere in all of the sha3 hashes (Sha3, Keccak, Shake, TurboShake, CShake) except for the 12-round permutation in TurboShake.
The hashing structs and traits are now untouched so that the interface of the patched version is equivalent to the upstream version.

@gdmlcjs gdmlcjs requested a review from jonathanpwang April 18, 2026 01:55
@gdmlcjs gdmlcjs self-assigned this Apr 18, 2026
@gdmlcjs gdmlcjs force-pushed the chore/sha3-v0.10.8-patch branch from e10bc81 to f8daa2a Compare April 18, 2026 02:43
@gdmlcjs gdmlcjs marked this pull request as ready for review April 18, 2026 02:52
Comment thread sha3/src/state.rs
Comment on lines +24 to +33
fn p1600(state: &mut [u64; PLEN], round_count: usize) {
#[cfg(target_os = "zkvm")]
if round_count == DEFAULT_ROUND_COUNT {
unsafe {
openvm_keccak256_guest::native_keccakf(state.as_mut_ptr() as *mut u8);
}
return;
}
keccak::p1600(state, round_count);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📝 Info: p1600 cfg pattern: native acceleration only for 24-round keccak-f

The p1600 function at sha3/src/state.rs:24-33 uses #[cfg(target_os = "zkvm")] on the if statement only, meaning the keccak::p1600(state, round_count) call at line 32 is compiled on ALL targets. On zkvm, when round_count == DEFAULT_ROUND_COUNT (24), it uses native_keccakf and returns early; otherwise it falls through to the software keccak::p1600. This correctly handles TurboSHAKE (12 rounds) by falling back to software, and is not a bug — but the pattern is subtle. A future maintainer adding a new cfg branch or reordering could easily break the fallthrough semantics. A comment explaining the intentional fallthrough would improve maintainability.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

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

LGTM but please add the comment explaining the p1600 function's conditional compilation as Devin suggested.

Also same note about follow-up PR to add zkvm CI.

@gdmlcjs
Copy link
Copy Markdown
Collaborator Author

gdmlcjs commented Apr 29, 2026

okay, just added the comment.

also made a linear ticket for the CI

@gdmlcjs gdmlcjs merged commit 528d97d into openvm/sha3-v0.10.8 Apr 29, 2026
84 of 176 checks passed
@gdmlcjs gdmlcjs deleted the chore/sha3-v0.10.8-patch branch April 29, 2026 21:08
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