From e3e0078d1bee991fe071c819cbd928e29a8c61ac Mon Sep 17 00:00:00 2001 From: Haichen Shen Date: Sun, 12 Feb 2023 21:16:43 -0800 Subject: [PATCH] feat: upgrade zktrie version to v0.5.0 (#214) * upgrade zktrie version to v0.5.0 * update go.sum --- go.mod | 2 +- go.sum | 4 ++-- trie/zk_trie.go | 4 ++-- trie/zkproof/writer.go | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index abe3bfa698..b66b8906d8 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 6ae09ba9ee..a77bc83155 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/trie/zk_trie.go b/trie/zk_trie.go index 48b3832748..627d3ee582 100644 --- a/trie/zk_trie.go +++ b/trie/zk_trie.go @@ -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 diff --git a/trie/zkproof/writer.go b/trie/zkproof/writer.go index 193690d72a..e9a2868e2e 100644 --- a/trie/zkproof/writer.go +++ b/trie/zkproof/writer.go @@ -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[:],