Skip to content

Commit afb097e

Browse files
authored
params: remove dependency on crypto (#22788)
* params: remove dependency on crypto Package params should not depend on package crypto because building crypto requires cgo. Since build/ci.go needs package params to get the go-ethereum version number, C code must be compiled in order to run the build tool, which is annoying for certain cross-compilation setups. * params: add SectionHead
1 parent ca9c576 commit afb097e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

params/config.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"math/big"
2323

2424
"github.com/ethereum/go-ethereum/common"
25-
"github.com/ethereum/go-ethereum/crypto"
25+
"golang.org/x/crypto/sha3"
2626
)
2727

2828
// Genesis hashes to enforce below configs on.
@@ -278,12 +278,18 @@ func (c *TrustedCheckpoint) HashEqual(hash common.Hash) bool {
278278

279279
// Hash returns the hash of checkpoint's four key fields(index, sectionHead, chtRoot and bloomTrieRoot).
280280
func (c *TrustedCheckpoint) Hash() common.Hash {
281-
buf := make([]byte, 8+3*common.HashLength)
282-
binary.BigEndian.PutUint64(buf, c.SectionIndex)
283-
copy(buf[8:], c.SectionHead.Bytes())
284-
copy(buf[8+common.HashLength:], c.CHTRoot.Bytes())
285-
copy(buf[8+2*common.HashLength:], c.BloomRoot.Bytes())
286-
return crypto.Keccak256Hash(buf)
281+
var sectionIndex [8]byte
282+
binary.BigEndian.PutUint64(sectionIndex[:], c.SectionIndex)
283+
284+
w := sha3.NewLegacyKeccak256()
285+
w.Write(sectionIndex[:])
286+
w.Write(c.SectionHead[:])
287+
w.Write(c.CHTRoot[:])
288+
w.Write(c.BloomRoot[:])
289+
290+
var h common.Hash
291+
w.Sum(h[:0])
292+
return h
287293
}
288294

289295
// Empty returns an indicator whether the checkpoint is regarded as empty.

0 commit comments

Comments
 (0)