mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-22 20:56:42 +00:00
cmd: use stateless keccak
This commit is contained in:
parent
4c753498b2
commit
5c631f6206
4 changed files with 7 additions and 26 deletions
|
|
@ -900,16 +900,12 @@ func (s *Suite) snapGetByteCodes(t *utesting.T, tc *byteCodesTest) error {
|
|||
// that the serving node is missing
|
||||
var (
|
||||
bytecodes = res.Codes
|
||||
hasher = crypto.NewKeccakState()
|
||||
hash = make([]byte, 32)
|
||||
codes = make([][]byte, len(req.Hashes))
|
||||
)
|
||||
|
||||
for i, j := 0, 0; i < len(bytecodes); i++ {
|
||||
// Find the next hash that we've been served, leaving misses with nils
|
||||
hasher.Reset()
|
||||
hasher.Write(bytecodes[i])
|
||||
hasher.Read(hash)
|
||||
hash := crypto.Keccak256(bytecodes[i])
|
||||
|
||||
for j < len(req.Hashes) && !bytes.Equal(hash, req.Hashes[j][:]) {
|
||||
j++
|
||||
|
|
@ -959,16 +955,12 @@ func (s *Suite) snapGetTrieNodes(t *utesting.T, tc *trieNodesTest) error {
|
|||
|
||||
// Cross reference the requested trienodes with the response to find gaps
|
||||
// that the serving node is missing
|
||||
hasher := crypto.NewKeccakState()
|
||||
hash := make([]byte, 32)
|
||||
trienodes := res.Nodes
|
||||
if got, want := len(trienodes), len(tc.expHashes); got != want {
|
||||
return fmt.Errorf("wrong trienode count, got %d, want %d", got, want)
|
||||
}
|
||||
for i, trienode := range trienodes {
|
||||
hasher.Reset()
|
||||
hasher.Write(trienode)
|
||||
hasher.Read(hash)
|
||||
hash := crypto.Keccak256(trienode[:])
|
||||
if got, want := hash, tc.expHashes[i]; !bytes.Equal(got, want[:]) {
|
||||
t.Logf(" hash %d wrong, got %#x, want %#x\n", i, got, want)
|
||||
err = fmt.Errorf("hash %d wrong, got %#x, want %#x", i, got, want)
|
||||
|
|
|
|||
|
|
@ -354,8 +354,6 @@ func checkStateContent(ctx *cli.Context) error {
|
|||
defer db.Close()
|
||||
var (
|
||||
it = rawdb.NewKeyLengthIterator(db.NewIterator(prefix, start), 32)
|
||||
hasher = crypto.NewKeccakState()
|
||||
got = make([]byte, 32)
|
||||
errs int
|
||||
count int
|
||||
startTime = time.Now()
|
||||
|
|
@ -365,9 +363,7 @@ func checkStateContent(ctx *cli.Context) error {
|
|||
count++
|
||||
k := it.Key()
|
||||
v := it.Value()
|
||||
hasher.Reset()
|
||||
hasher.Write(v)
|
||||
hasher.Read(got)
|
||||
got := crypto.Keccak256(v)
|
||||
if !bytes.Equal(k, got) {
|
||||
errs++
|
||||
fmt.Printf("Error at %#x\n", k)
|
||||
|
|
|
|||
|
|
@ -430,8 +430,6 @@ func traverseRawState(ctx *cli.Context) error {
|
|||
codes int
|
||||
lastReport time.Time
|
||||
start = time.Now()
|
||||
hasher = crypto.NewKeccakState()
|
||||
got = make([]byte, 32)
|
||||
)
|
||||
accIter, err := t.NodeIterator(nil)
|
||||
if err != nil {
|
||||
|
|
@ -455,9 +453,7 @@ func traverseRawState(ctx *cli.Context) error {
|
|||
log.Error("Missing trie node(account)", "hash", node)
|
||||
return errors.New("missing account")
|
||||
}
|
||||
hasher.Reset()
|
||||
hasher.Write(blob)
|
||||
hasher.Read(got)
|
||||
got := crypto.Keccak256(blob)
|
||||
if !bytes.Equal(got, node.Bytes()) {
|
||||
log.Error("Invalid trie node(account)", "hash", node.Hex(), "value", blob)
|
||||
return errors.New("invalid account node")
|
||||
|
|
@ -496,9 +492,7 @@ func traverseRawState(ctx *cli.Context) error {
|
|||
log.Error("Missing trie node(storage)", "hash", node)
|
||||
return errors.New("missing storage")
|
||||
}
|
||||
hasher.Reset()
|
||||
hasher.Write(blob)
|
||||
hasher.Read(got)
|
||||
got := crypto.Keccak256(blob)
|
||||
if !bytes.Equal(got, node.Bytes()) {
|
||||
log.Error("Invalid trie node(storage)", "hash", node.Hex(), "value", blob)
|
||||
return errors.New("invalid storage node")
|
||||
|
|
|
|||
|
|
@ -132,9 +132,8 @@ func generateHistoryTests(clictx *cli.Context) error {
|
|||
}
|
||||
|
||||
func calcReceiptsHash(rcpt []*types.Receipt) common.Hash {
|
||||
h := crypto.NewKeccakState()
|
||||
rlp.Encode(h, rcpt)
|
||||
return common.Hash(h.Sum(nil))
|
||||
encoded, _ := rlp.EncodeToBytes(rcpt)
|
||||
return crypto.Keccak256Hash(encoded)
|
||||
}
|
||||
|
||||
func writeJSON(fileName string, value any) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue