feat: upgrade zktrie version to v0.5.0 (#214)

* upgrade zktrie version to v0.5.0

* update go.sum
This commit is contained in:
Haichen Shen 2023-02-12 21:16:43 -08:00 committed by GitHub
parent bb26fa3e39
commit e3e0078d1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 18 deletions

2
go.mod
View file

@ -49,7 +49,7 @@ require (
github.com/prometheus/tsdb v0.7.1
github.com/rjeczalik/notify v0.9.1
github.com/rs/cors v1.7.0
github.com/scroll-tech/zktrie v0.4.3
github.com/scroll-tech/zktrie v0.5.0
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4
github.com/stretchr/testify v1.7.0

4
go.sum
View file

@ -380,8 +380,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/scroll-tech/zktrie v0.4.3 h1:RyhusIu8F8u5ITmzqZjkAwlL6jdC9TK9i6tfuJoZcpk=
github.com/scroll-tech/zktrie v0.4.3/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
github.com/scroll-tech/zktrie v0.5.0 h1:dABDR6lMZq6Hs+fWQSiHbX8s3AOX6hY+5nkhSYm5rmU=
github.com/scroll-tech/zktrie v0.5.0/go.mod h1:XvNo7vAk8yxNyTjBDj5WIiFzYW4bx/gJ78+NK6Zn6Uk=
github.com/segmentio/kafka-go v0.1.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/segmentio/kafka-go v0.2.0/go.mod h1:X6itGqS9L4jDletMsxZ7Dz+JFWxM6JHfPOCvTvk+EJo=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=

View file

@ -175,7 +175,7 @@ func (t *ZkTrie) NodeIterator(start []byte) NodeIterator {
// with the node that proves the absence of the key.
func (t *ZkTrie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter) error {
err := t.ZkTrie.Prove(key, fromLevel, func(n *zktrie.Node) error {
key, err := n.Key()
nodeHash, err := n.NodeHash()
if err != nil {
return err
}
@ -188,7 +188,7 @@ func (t *ZkTrie) Prove(key []byte, fromLevel uint, proofDb ethdb.KeyValueWriter)
//return fmt.Errorf("key preimage not found for [%x] ref %x", n.NodeKey.Bytes(), k.Bytes())
}
}
return proofDb.Put(key[:], n.Value())
return proofDb.Put(nodeHash[:], n.Value())
})
if err != nil {
return err

View file

@ -48,12 +48,12 @@ func resumeProofs(proof []hexutil.Bytes, db *memorydb.Database) *zktrie.Node {
if err != nil {
log.Warn("decode proof string fail", "error", err)
} else if n != nil {
k, err := n.Key()
hash, err := n.NodeHash()
if err != nil {
log.Warn("node has no valid key", "error", err)
log.Warn("node has no valid node hash", "error", err)
} else {
//notice: must consistent with trie/merkletree.go
bt := k[:]
bt := hash[:]
db.Put(bt, buf)
if n.Type == zktrie.NodeTypeLeaf || n.Type == zktrie.NodeTypeEmpty {
return n
@ -81,23 +81,23 @@ func decodeProofForMPTPath(proof proofList, path *SMTPath) {
if err != nil {
log.Warn("decode proof string fail", "error", err)
} else if n != nil {
k, err := n.Key()
hash, err := n.NodeHash()
if err != nil {
log.Warn("node has no valid key", "error", err)
log.Warn("node has no valid node hash", "error", err)
return
}
if lastNode == nil {
//notice: use little-endian represent inside Hash ([:] or Bytes2())
path.Root = k[:]
// notice: use little-endian represent inside Hash ([:] or Byte32())
path.Root = hash[:]
} else {
if bytes.Equal(k[:], lastNode.ChildL[:]) {
if bytes.Equal(hash[:], lastNode.ChildL[:]) {
path.Path = append(path.Path, SMTPathNode{
Value: k[:],
Value: hash[:],
Sibling: lastNode.ChildR[:],
})
} else if bytes.Equal(k[:], lastNode.ChildR[:]) {
} else if bytes.Equal(hash[:], lastNode.ChildR[:]) {
path.Path = append(path.Path, SMTPathNode{
Value: k[:],
Value: hash[:],
Sibling: lastNode.ChildL[:],
})
keyPath.Add(keyPath, keyCounter)
@ -107,10 +107,10 @@ func decodeProofForMPTPath(proof proofList, path *SMTPath) {
keyCounter.Mul(keyCounter, big.NewInt(2))
}
switch n.Type {
case zktrie.NodeTypeMiddle:
case zktrie.NodeTypeParent:
lastNode = n
case zktrie.NodeTypeLeaf:
vhash, _ := n.ValueKey()
vhash, _ := n.ValueHash()
path.Leaf = &SMTPathNode{
//here we just return the inner represent of hash (little endian, reversed byte order to common hash)
Value: vhash[:],