Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent verkle trie iterator from missing the first value in a LeafNode #88

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions trie/verkle_iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package trie

import (
"fmt"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/ethdb"

Expand Down Expand Up @@ -88,12 +86,13 @@ func (it *verkleNodeIterator) Next(descend bool) bool {
return it.Next(descend)
case *verkle.LeafNode:
// Look for the next non-empty value
for i := it.stack[len(it.stack)-1].Index + 1; i < 256; i++ {
for i := it.stack[len(it.stack)-1].Index; i < 256; i++ {
if node.Value(i) != nil {
it.stack[len(it.stack)-1].Index = i
it.stack[len(it.stack)-1].Index = i + 1
return true
}
}

// go back to parent to get the next leaf
it.stack = it.stack[:len(it.stack)-1]
it.current = it.stack[len(it.stack)-1].Node
Expand All @@ -116,7 +115,6 @@ func (it *verkleNodeIterator) Next(descend bool) bool {
parent.Node.(*verkle.InternalNode).SetChild(parent.Index, it.current)
return true
default:
fmt.Println(node)
panic("invalid node type")
}
}
Expand Down Expand Up @@ -163,7 +161,7 @@ func (it *verkleNodeIterator) LeafKey() []byte {
panic("Leaf() called on an verkle node iterator not at a leaf location")
}

return leaf.Key(it.stack[len(it.stack)-1].Index)
return leaf.Key(it.stack[len(it.stack)-1].Index - 1)
}

// LeafBlob returns the content of the leaf. The method panics if the iterator
Expand All @@ -175,7 +173,7 @@ func (it *verkleNodeIterator) LeafBlob() []byte {
panic("LeafBlob() called on an verkle node iterator not at a leaf location")
}

return leaf.Value(it.stack[len(it.stack)-1].Index)
return leaf.Value(it.stack[len(it.stack)-1].Index - 1)
}

// LeafProof returns the Merkle proof of the leaf. The method panics if the
Expand Down