fix(crypto): remove keccak_ziren.go (#2113)

This commit is contained in:
Daniel Liu 2026-03-03 11:15:42 +08:00 committed by GitHub
parent b991bd8aa7
commit e250435851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 0 additions and 125 deletions

View file

@ -1,122 +0,0 @@
// 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/XinFinOrg/XDPoSChain/common"
)
// zirenKeccakState implements the KeccakState interface using the Ziren zkvm_runtime.
// It accumulates data written to it and uses the zkvm's Keccak256 system call for hashing.
type zirenKeccakState struct {
buf []byte // accumulated data
result []byte // cached result
dirty bool // whether new data has been written since last hash
}
func newZirenKeccakState() KeccakState {
return &zirenKeccakState{
buf: make([]byte, 0, 512), // pre-allocate reasonable capacity
}
}
func (s *zirenKeccakState) Write(p []byte) (n int, err error) {
s.buf = append(s.buf, p...)
s.dirty = true
return len(p), nil
}
func (s *zirenKeccakState) Sum(b []byte) []byte {
s.computeHashIfNeeded()
return append(b, s.result...)
}
func (s *zirenKeccakState) Reset() {
s.buf = s.buf[:0]
s.result = nil
s.dirty = false
}
func (s *zirenKeccakState) Size() int {
return 32
}
func (s *zirenKeccakState) BlockSize() int {
return 136 // Keccak256 rate
}
func (s *zirenKeccakState) Read(p []byte) (n int, err error) {
s.computeHashIfNeeded()
if len(p) == 0 {
return 0, nil
}
// After computeHashIfNeeded(), s.result is always a 32-byte slice
n = copy(p, s.result)
return n, nil
}
func (s *zirenKeccakState) computeHashIfNeeded() {
if s.dirty || s.result == nil {
// Use the zkvm_runtime Keccak256 which uses SyscallKeccakSponge
hashArray := zkvm_runtime.Keccak256(s.buf)
s.result = hashArray[:]
s.dirty = false
}
}
// NewKeccakState creates a new KeccakState
// This uses a Ziren-optimized implementation that leverages the zkvm_runtime.Keccak256 system call.
func NewKeccakState() KeccakState {
return newZirenKeccakState()
}
// 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.BytesToHash(Keccak256(data...))
}

1
go.mod
View file

@ -33,7 +33,6 @@ require (
require (
github.com/Microsoft/go-winio v0.6.2
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260124092617-829590d2c921
github.com/btcsuite/btcd/btcec/v2 v2.2.0
github.com/consensys/gnark-crypto v0.10.0
github.com/deckarep/golang-set/v2 v2.7.0

2
go.sum
View file

@ -1,7 +1,5 @@
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260124092617-829590d2c921 h1:NxRnjiL8BBFLCnsDv18a20vb1d34TUiiZtdJGqpj3xs=
github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20260124092617-829590d2c921/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI=
github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA=
github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8=
github.com/VictoriaMetrics/fastcache v1.12.2 h1:N0y9ASrJ0F6h0QaC3o6uJb3NIZ9VKLjCM7NQbSmF7WI=