Skip to content

Commit

Permalink
fix: NodeIterator return error from empty trie root
Browse files Browse the repository at this point in the history
  • Loading branch information
jyc228 committed Oct 25, 2024
1 parent 71b2588 commit 6fbe92a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion trie/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ func zkMerkleTreeNodeBlobFunctions(findBlobByHash func(key []byte) ([]byte, erro
) {
return func(hash common.Hash) ([]byte, error) {
if bytes.Equal(hash.Bytes(), zkt.HashZero[:]) {
return nil, nil
return zk.EmptyNodeValue.CanonicalValue(), nil
}
return findBlobByHash(zkt.ReverseByteOrder(hash.Bytes()))
},
Expand Down
23 changes: 23 additions & 0 deletions trie/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,29 @@ func TestMerkleTreeIterator(t *testing.T) {
return tree, db
}

t.Run("empty root", func(t *testing.T) {
t.Run("zk merkle tree", func(t *testing.T) {
trie := NewEmptyMerkleTrie(NewZkDatabase(rawdb.NewMemoryDatabase()))
it, _ := trie.NodeIterator(nil)
for it.Next(true) {
t.Fail()
}
if it.Error() != nil {
t.Error(it.Error())
}
})
t.Run("zk trie", func(t *testing.T) {
trie, _ := NewZkTrie(common.Hash{}, NewZkDatabase(rawdb.NewDatabase(memorydb.New())))
it, _ := trie.NodeIterator(nil)
for it.Next(true) {
t.Fail()
}
if it.Error() != nil {
t.Error(it.Error())
}
})
})

t.Run("zk merkle tree", func(t *testing.T) {
tree, db := makeMerkleTreeWithData(testdata1)
expected := db.Len()
Expand Down

0 comments on commit 6fbe92a

Please sign in to comment.