Skip to content

Commit b02ab37

Browse files
committed
all: use vendored keccak package
1 parent 01cdf07 commit b02ab37

File tree

16 files changed

+41
-53
lines changed

16 files changed

+41
-53
lines changed

accounts/accounts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import (
2424
"github.com/ethereum/go-ethereum"
2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/core/types"
27+
"github.com/ethereum/go-ethereum/crypto/keccak"
2728
"github.com/ethereum/go-ethereum/event"
28-
"golang.org/x/crypto/sha3"
2929
)
3030

3131
// Account represents an Ethereum account located at a specific location defined
@@ -196,7 +196,7 @@ func TextHash(data []byte) []byte {
196196
// This gives context to the signed message and prevents signing of transactions.
197197
func TextAndHash(data []byte) ([]byte, string) {
198198
msg := fmt.Sprintf("\x19Ethereum Signed Message:\n%d%s", len(data), data)
199-
hasher := sha3.NewLegacyKeccak256()
199+
hasher := keccak.NewLegacyKeccak256()
200200
hasher.Write([]byte(msg))
201201
return hasher.Sum(nil), msg
202202
}

cmd/evm/internal/t8ntool/execution.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import (
3333
"github.com/ethereum/go-ethereum/core/tracing"
3434
"github.com/ethereum/go-ethereum/core/types"
3535
"github.com/ethereum/go-ethereum/core/vm"
36+
"github.com/ethereum/go-ethereum/crypto/keccak"
3637
"github.com/ethereum/go-ethereum/ethdb"
3738
"github.com/ethereum/go-ethereum/log"
3839
"github.com/ethereum/go-ethereum/params"
3940
"github.com/ethereum/go-ethereum/rlp"
4041
"github.com/ethereum/go-ethereum/trie"
4142
"github.com/ethereum/go-ethereum/triedb"
4243
"github.com/holiman/uint256"
43-
"golang.org/x/crypto/sha3"
4444
)
4545

4646
type Prestate struct {
@@ -415,7 +415,7 @@ func MakePreState(db ethdb.Database, accounts types.GenesisAlloc, isBintrie bool
415415
}
416416

417417
func rlpHash(x any) (h common.Hash) {
418-
hw := sha3.NewLegacyKeccak256()
418+
hw := keccak.NewLegacyKeccak256()
419419
rlp.Encode(hw, x)
420420
hw.Sum(h[:0])
421421
return h

common/types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"strings"
3131

3232
"github.com/ethereum/go-ethereum/common/hexutil"
33-
"golang.org/x/crypto/sha3"
33+
"github.com/ethereum/go-ethereum/crypto/keccak"
3434
)
3535

3636
// Lengths of hashes and addresses in bytes.
@@ -271,7 +271,7 @@ func (a *Address) checksumHex() []byte {
271271
buf := a.hex()
272272

273273
// compute checksum
274-
sha := sha3.NewLegacyKeccak256()
274+
sha := keccak.NewLegacyKeccak256()
275275
sha.Write(buf[2:])
276276
hash := sha.Sum(nil)
277277
for i := 2; i < len(buf); i++ {

consensus/clique/clique.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ import (
3737
"github.com/ethereum/go-ethereum/core/types"
3838
"github.com/ethereum/go-ethereum/core/vm"
3939
"github.com/ethereum/go-ethereum/crypto"
40+
"github.com/ethereum/go-ethereum/crypto/keccak"
4041
"github.com/ethereum/go-ethereum/ethdb"
4142
"github.com/ethereum/go-ethereum/log"
4243
"github.com/ethereum/go-ethereum/params"
4344
"github.com/ethereum/go-ethereum/rlp"
4445
"github.com/ethereum/go-ethereum/trie"
45-
"golang.org/x/crypto/sha3"
4646
)
4747

4848
const (
@@ -642,7 +642,7 @@ func (c *Clique) Close() error {
642642

643643
// SealHash returns the hash of a block prior to it being sealed.
644644
func SealHash(header *types.Header) (hash common.Hash) {
645-
hasher := sha3.NewLegacyKeccak256()
645+
hasher := keccak.NewLegacyKeccak256()
646646
encodeSigHeader(hasher, header)
647647
hasher.(crypto.KeccakState).Read(hash[:])
648648
return hash

consensus/ethash/consensus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ import (
3131
"github.com/ethereum/go-ethereum/core/tracing"
3232
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/core/vm"
34+
"github.com/ethereum/go-ethereum/crypto/keccak"
3435
"github.com/ethereum/go-ethereum/params"
3536
"github.com/ethereum/go-ethereum/rlp"
3637
"github.com/ethereum/go-ethereum/trie"
3738
"github.com/holiman/uint256"
38-
"golang.org/x/crypto/sha3"
3939
)
4040

4141
// Ethash proof-of-work protocol constants.
@@ -527,7 +527,7 @@ func (ethash *Ethash) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
527527

528528
// SealHash returns the hash of a block prior to it being sealed.
529529
func (ethash *Ethash) SealHash(header *types.Header) (hash common.Hash) {
530-
hasher := sha3.NewLegacyKeccak256()
530+
hasher := keccak.NewLegacyKeccak256()
531531

532532
enc := []interface{}{
533533
header.ParentHash,

core/rawdb/accessors_chain_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import (
2828
"github.com/ethereum/go-ethereum/common"
2929
"github.com/ethereum/go-ethereum/core/types"
3030
"github.com/ethereum/go-ethereum/crypto"
31+
"github.com/ethereum/go-ethereum/crypto/keccak"
3132
"github.com/ethereum/go-ethereum/params"
3233
"github.com/ethereum/go-ethereum/rlp"
33-
"golang.org/x/crypto/sha3"
3434
)
3535

3636
// Tests block header storage and retrieval operations.
@@ -52,10 +52,7 @@ func TestHeaderStorage(t *testing.T) {
5252
if entry := ReadHeaderRLP(db, header.Hash(), header.Number.Uint64()); entry == nil {
5353
t.Fatalf("Stored header RLP not found")
5454
} else {
55-
hasher := sha3.NewLegacyKeccak256()
56-
hasher.Write(entry)
57-
58-
if hash := common.BytesToHash(hasher.Sum(nil)); hash != header.Hash() {
55+
if hash := crypto.Keccak256Hash(entry); hash != header.Hash() {
5956
t.Fatalf("Retrieved RLP header mismatch: have %v, want %v", entry, header)
6057
}
6158
}
@@ -72,8 +69,7 @@ func TestBodyStorage(t *testing.T) {
7269

7370
// Create a test body to move around the database and make sure it's really new
7471
body := &types.Body{Uncles: []*types.Header{{Extra: []byte("test header")}}}
75-
76-
hasher := sha3.NewLegacyKeccak256()
72+
hasher := keccak.NewLegacyKeccak256()
7773
rlp.Encode(hasher, body)
7874
hash := common.BytesToHash(hasher.Sum(nil))
7975

@@ -90,10 +86,7 @@ func TestBodyStorage(t *testing.T) {
9086
if entry := ReadBodyRLP(db, hash, 0); entry == nil {
9187
t.Fatalf("Stored body RLP not found")
9288
} else {
93-
hasher := sha3.NewLegacyKeccak256()
94-
hasher.Write(entry)
95-
96-
if calc := common.BytesToHash(hasher.Sum(nil)); calc != hash {
89+
if calc := crypto.Keccak256Hash(entry); calc != hash {
9790
t.Fatalf("Retrieved RLP body mismatch: have %v, want %v", entry, body)
9891
}
9992
}

core/rlp_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
"github.com/ethereum/go-ethereum/consensus/ethash"
2626
"github.com/ethereum/go-ethereum/core/types"
2727
"github.com/ethereum/go-ethereum/crypto"
28+
"github.com/ethereum/go-ethereum/crypto/keccak"
2829
"github.com/ethereum/go-ethereum/params"
2930
"github.com/ethereum/go-ethereum/rlp"
30-
"golang.org/x/crypto/sha3"
3131
)
3232

3333
func getBlock(transactions int, uncles int, dataSize int) *types.Block {
@@ -147,7 +147,7 @@ func BenchmarkHashing(b *testing.B) {
147147
blockRlp, _ = rlp.EncodeToBytes(block)
148148
}
149149
var got common.Hash
150-
var hasher = sha3.NewLegacyKeccak256()
150+
var hasher = keccak.NewLegacyKeccak256()
151151
b.Run("iteratorhashing", func(b *testing.B) {
152152
for b.Loop() {
153153
var hash common.Hash

core/state/snapshot/generate_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/ethereum/go-ethereum/common"
2626
"github.com/ethereum/go-ethereum/core/rawdb"
2727
"github.com/ethereum/go-ethereum/core/types"
28+
"github.com/ethereum/go-ethereum/crypto"
2829
"github.com/ethereum/go-ethereum/ethdb"
2930
"github.com/ethereum/go-ethereum/log"
3031
"github.com/ethereum/go-ethereum/rlp"
@@ -34,16 +35,10 @@ import (
3435
"github.com/ethereum/go-ethereum/triedb/hashdb"
3536
"github.com/ethereum/go-ethereum/triedb/pathdb"
3637
"github.com/holiman/uint256"
37-
"golang.org/x/crypto/sha3"
3838
)
3939

4040
func hashData(input []byte) common.Hash {
41-
var hasher = sha3.NewLegacyKeccak256()
42-
var hash common.Hash
43-
hasher.Reset()
44-
hasher.Write(input)
45-
hasher.Sum(hash[:0])
46-
return hash
41+
return crypto.Keccak256Hash(input)
4742
}
4843

4944
// Tests that snapshot generation from an empty database.

core/state_processor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ import (
3131
"github.com/ethereum/go-ethereum/core/rawdb"
3232
"github.com/ethereum/go-ethereum/core/types"
3333
"github.com/ethereum/go-ethereum/crypto"
34+
"github.com/ethereum/go-ethereum/crypto/keccak"
3435
"github.com/ethereum/go-ethereum/params"
3536
"github.com/ethereum/go-ethereum/trie"
3637
"github.com/holiman/uint256"
37-
"golang.org/x/crypto/sha3"
3838
)
3939

4040
func u64(val uint64) *uint64 { return &val }
@@ -398,7 +398,7 @@ func GenerateBadBlock(parent *types.Block, engine consensus.Engine, txs types.Tr
398398
var receipts []*types.Receipt
399399
// The post-state result doesn't need to be correct (this is a bad block), but we do need something there
400400
// Preferably something unique. So let's use a combo of blocknum + txhash
401-
hasher := sha3.NewLegacyKeccak256()
401+
hasher := keccak.NewLegacyKeccak256()
402402
hasher.Write(header.Number.Bytes())
403403
var cumulativeGas uint64
404404
var nBlobs int

eth/protocols/snap/sync_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/ethereum/go-ethereum/core/rawdb"
3333
"github.com/ethereum/go-ethereum/core/types"
3434
"github.com/ethereum/go-ethereum/crypto"
35+
"github.com/ethereum/go-ethereum/crypto/keccak"
3536
"github.com/ethereum/go-ethereum/ethdb"
3637
"github.com/ethereum/go-ethereum/internal/testrand"
3738
"github.com/ethereum/go-ethereum/log"
@@ -41,7 +42,6 @@ import (
4142
"github.com/ethereum/go-ethereum/triedb"
4243
"github.com/ethereum/go-ethereum/triedb/pathdb"
4344
"github.com/holiman/uint256"
44-
"golang.org/x/crypto/sha3"
4545
)
4646

4747
func TestHashing(t *testing.T) {
@@ -55,7 +55,7 @@ func TestHashing(t *testing.T) {
5555
}
5656
var want, got string
5757
var old = func() {
58-
hasher := sha3.NewLegacyKeccak256()
58+
hasher := keccak.NewLegacyKeccak256()
5959
for i := 0; i < len(bytecodes); i++ {
6060
hasher.Reset()
6161
hasher.Write(bytecodes[i])
@@ -88,7 +88,7 @@ func BenchmarkHashing(b *testing.B) {
8888
bytecodes[i] = buf
8989
}
9090
var old = func() {
91-
hasher := sha3.NewLegacyKeccak256()
91+
hasher := keccak.NewLegacyKeccak256()
9292
for i := 0; i < len(bytecodes); i++ {
9393
hasher.Reset()
9494
hasher.Write(bytecodes[i])

0 commit comments

Comments
 (0)