diff --git a/trie/iterator.go b/trie/iterator.go index 26e8e48d4..b80b27b4e 100644 --- a/trie/iterator.go +++ b/trie/iterator.go @@ -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())) }, diff --git a/trie/iterator_test.go b/trie/iterator_test.go index 8322904fc..d60d49ae0 100644 --- a/trie/iterator_test.go +++ b/trie/iterator_test.go @@ -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()