-
Notifications
You must be signed in to change notification settings - Fork 685
[NIT-4075] Extract keccak for ZKVM precompile substitution #4001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pmikolajczyk41
wants to merge
23
commits into
master
Choose a base branch
from
pmikolajczyk/NIT-4075-keccak
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
03c2484
Create arbkeccak dummy package
pmikolajczyk41 879e77e
Remove Keccak512 (not used, avoid future collision)
pmikolajczyk41 45a8707
Move crypto.Keccak* to arbkeccak
pmikolajczyk41 b432bba
Copy the implementation for the wasm world (temporarily)
pmikolajczyk41 0e3a918
Do refactor
pmikolajczyk41 24ff162
JIT working!
pmikolajczyk41 d3b6472
Keep keccak implementation in jit
pmikolajczyk41 f4871f4
Add new wasm library (wip)
pmikolajczyk41 b2faa32
Revert "Keep keccak implementation in jit"
pmikolajczyk41 39786cc
Wasm library refer to caller-env
pmikolajczyk41 200d423
Makefile
pmikolajczyk41 0eb3642
Merge
pmikolajczyk41 597f04e
Merge remote-tracking branch 'origin/master' into pmikolajczyk/NIT-40…
pmikolajczyk41 0022541
fix
pmikolajczyk41 4c04594
Add keccak_wasm.go
pmikolajczyk41 636279c
Revert import
pmikolajczyk41 5dcb2ff
Lint
pmikolajczyk41 fea45e5
remove print
pmikolajczyk41 460c6b0
minor code adjustment
pmikolajczyk41 c587535
merge
pmikolajczyk41 395a162
minor refactor
pmikolajczyk41 19c7403
linter
pmikolajczyk41 26bc970
linter
pmikolajczyk41 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| use crate::{ExecEnv, GuestPtr, MemAccess}; | ||
| use core::mem::MaybeUninit; | ||
| use tiny_keccak::{Hasher, Keccak}; | ||
|
|
||
| pub fn keccak256<M: MemAccess, E: ExecEnv>( | ||
| mem: &mut M, | ||
| _env: &mut E, | ||
| in_buf_ptr: GuestPtr, | ||
| in_buf_len: u32, | ||
| out_buf_ptr: GuestPtr, | ||
| ) { | ||
| let input = mem.read_slice(in_buf_ptr, in_buf_len as usize); | ||
|
|
||
| let mut output = MaybeUninit::<[u8; 32]>::uninit(); | ||
| let mut hasher = Keccak::v256(); | ||
| hasher.update(input.as_ref()); | ||
|
|
||
| // SAFETY: finalize() writes 32 bytes | ||
| unsafe { | ||
| hasher.finalize(&mut *output.as_mut_ptr()); | ||
| mem.write_slice(out_buf_ptr, output.assume_init().as_slice()); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| use crate::caller_env::{JitEnv, JitExecEnv}; | ||
| use crate::machine::{MaybeEscape, WasmEnvMut}; | ||
| use caller_env::GuestPtr; | ||
|
|
||
| pub fn keccak256( | ||
| mut src: WasmEnvMut, | ||
| in_buf_ptr: GuestPtr, | ||
| in_buf_len: u32, | ||
| out_buf_ptr: GuestPtr, | ||
| ) -> MaybeEscape { | ||
| let (mut mem, wenv) = src.jit_env(); | ||
|
|
||
| caller_env::arbkeccak::keccak256( | ||
| &mut mem, | ||
| &mut JitExecEnv { wenv }, | ||
| in_buf_ptr, | ||
| in_buf_len, | ||
| out_buf_ptr, | ||
| ); | ||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| [workspace] | ||
| members = [ | ||
| "arbcompress", | ||
| "arbkeccak", | ||
| "wasi-stub", | ||
| "host-io", | ||
| "user-host", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "arbkeccak" | ||
| version = "0.1.0" | ||
| edition = "2021" | ||
| publish = false | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| caller-env = { path = "../../caller-env/", features = ["static_caller"] } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| // Copyright 2025, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| fn main() { | ||
| // Tell Cargo that if the given file changes, to rerun this build script. | ||
| println!("cargo:rustc-link-search=../../target/lib-wasm/"); | ||
| println!("cargo:rustc-link-search=../target/lib/"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| // Copyright 2025, Offchain Labs, Inc. | ||
| // For license information, see https://github.com/OffchainLabs/nitro/blob/master/LICENSE.md | ||
|
|
||
| #![allow(clippy::missing_safety_doc)] | ||
|
|
||
| use caller_env::{self, GuestPtr}; | ||
|
|
||
| #[no_mangle] | ||
| pub unsafe extern "C" fn arbkeccak__keccak256( | ||
| in_buf_ptr: GuestPtr, | ||
| in_buf_len: u32, | ||
| out_buf_ptr: GuestPtr, | ||
| ) { | ||
| caller_env::arbkeccak::keccak256( | ||
| &mut caller_env::static_caller::STATIC_MEM, | ||
| &mut caller_env::static_caller::STATIC_ENV, | ||
| in_buf_ptr, | ||
| in_buf_len, | ||
| out_buf_ptr, | ||
| ) | ||
| } |
Submodule go-ethereum
updated
3 files
| +1 −1 | crypto/keccak.go | |
| +54 −0 | crypto/keccak_wasm.go | |
| +1 −1 | crypto/keccak_ziren.go |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.