-
Notifications
You must be signed in to change notification settings - Fork 21.5k
cmd/keeper: use the ziren keccak precompile #32816
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
Merged
gballet
merged 6 commits into
ethereum:master
from
gballet:keeper-ziren-keccak-precompile
Oct 20, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
90beffb
core/vm, crypto: add crypto package for hashing
gballet c14034a
rework to replace the module
gballet cbf86b4
use my keccak PR
gballet b26b3e8
update ziren ref + use tags for crypto module
gballet 561495d
fix linter `go mod tidy` issue
gballet cad8721
factor some code in
gballet 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
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
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,63 @@ | ||
| // Copyright 2025 The go-ethereum Authors | ||
| // This file is part of the go-ethereum library. | ||
| // | ||
| // The go-ethereum library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The go-ethereum library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //go:build !ziren | ||
|
|
||
| package crypto | ||
|
|
||
| import ( | ||
| "sync" | ||
|
|
||
| "github.com/ethereum/go-ethereum/common" | ||
| "golang.org/x/crypto/sha3" | ||
| ) | ||
|
|
||
| // NewKeccakState creates a new KeccakState | ||
| func NewKeccakState() KeccakState { | ||
| return sha3.NewLegacyKeccak256().(KeccakState) | ||
| } | ||
|
|
||
| var hasherPool = sync.Pool{ | ||
| New: func() any { | ||
| return sha3.NewLegacyKeccak256().(KeccakState) | ||
| }, | ||
| } | ||
|
|
||
| // Keccak256 calculates and returns the Keccak256 hash of the input data. | ||
| func Keccak256(data ...[]byte) []byte { | ||
| b := make([]byte, 32) | ||
| d := hasherPool.Get().(KeccakState) | ||
| d.Reset() | ||
| for _, b := range data { | ||
| d.Write(b) | ||
| } | ||
| d.Read(b) | ||
| hasherPool.Put(d) | ||
| return b | ||
| } | ||
|
|
||
| // Keccak256Hash calculates and returns the Keccak256 hash of the input data, | ||
| // converting it to an internal Hash data structure. | ||
| func Keccak256Hash(data ...[]byte) (h common.Hash) { | ||
| d := hasherPool.Get().(KeccakState) | ||
| d.Reset() | ||
| for _, b := range data { | ||
| d.Write(b) | ||
| } | ||
| d.Read(h[:]) | ||
| hasherPool.Put(d) | ||
| return h | ||
| } |
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,64 @@ | ||
| // Copyright 2025 The go-ethereum Authors | ||
| // This file is part of the go-ethereum library. | ||
| // | ||
| // The go-ethereum library is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU Lesser General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // The go-ethereum library is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU Lesser General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. | ||
|
|
||
| //go:build ziren | ||
|
|
||
| package crypto | ||
|
|
||
| import ( | ||
| "github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime" | ||
| "github.com/ethereum/go-ethereum/common" | ||
| "golang.org/x/crypto/sha3" | ||
| ) | ||
|
|
||
| // NewKeccakState creates a new KeccakState | ||
| // For now, we fallback to the original implementation for the stateful interface. | ||
| // TODO: Implement a stateful wrapper around zkvm_runtime.Keccak256 if needed. | ||
| func NewKeccakState() KeccakState { | ||
| return sha3.NewLegacyKeccak256().(KeccakState) | ||
| } | ||
|
|
||
| // Keccak256 calculates and returns the Keccak256 hash using the Ziren zkvm_runtime implementation. | ||
| func Keccak256(data ...[]byte) []byte { | ||
| // For multiple data chunks, concatenate them | ||
| if len(data) == 0 { | ||
| result := zkvm_runtime.Keccak256(nil) | ||
| return result[:] | ||
| } | ||
| if len(data) == 1 { | ||
| result := zkvm_runtime.Keccak256(data[0]) | ||
| return result[:] | ||
| } | ||
|
|
||
| // Concatenate multiple data chunks | ||
| var totalLen int | ||
| for _, d := range data { | ||
| totalLen += len(d) | ||
| } | ||
|
|
||
| combined := make([]byte, 0, totalLen) | ||
| for _, d := range data { | ||
| combined = append(combined, d...) | ||
| } | ||
|
|
||
| result := zkvm_runtime.Keccak256(combined) | ||
| return result[:] | ||
| } | ||
|
|
||
| // Keccak256Hash calculates and returns the Keccak256 hash as a Hash using the Ziren zkvm_runtime implementation. | ||
| func Keccak256Hash(data ...[]byte) common.Hash { | ||
| return common.Hash(Keccak256(data...)) | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use
NewKeccakStatein the trie hashing. Isn't it a critical you want to replace with thezkvm_runtime?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Next pr