Skip to content

Commit

Permalink
Merge pull request #119 from kroma-network/fix/zk-iterator
Browse files Browse the repository at this point in the history
fix: NodeIterator return error from empty trie root
  • Loading branch information
Pangssu authored Nov 6, 2024
2 parents 71b2588 + 6fbe92a commit d2fcde4
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 d2fcde4

Please sign in to comment.