Skip to content

Commit 19f3700

Browse files
authored
trie/bintrie: fix debug_executionWitness for binary tree (#33739)
The `Witness` method was not implemented for the binary tree, which caused `debug_excutionWitness` to panic. This PR fixes that. Note that the `TransitionTrie` version isn't implemented, and that's on purpose: more thought must be given to what should go in the global witness.
1 parent 16a6531 commit 19f3700

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

trie/bintrie/trie.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,5 +424,5 @@ func (t *BinaryTrie) PrefetchStorage(addr common.Address, keys [][]byte) error {
424424

425425
// Witness returns a set containing all trie nodes that have been accessed.
426426
func (t *BinaryTrie) Witness() map[string][]byte {
427-
panic("not implemented")
427+
return t.tracer.Values()
428428
}

trie/bintrie/trie_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"testing"
2323

2424
"github.com/ethereum/go-ethereum/common"
25+
"github.com/ethereum/go-ethereum/trie"
2526
)
2627

2728
var (
@@ -195,3 +196,29 @@ func TestMerkleizeMultipleEntries(t *testing.T) {
195196
t.Fatalf("invalid root, expected=%x, got = %x", expected, got)
196197
}
197198
}
199+
200+
func TestBinaryTrieWitness(t *testing.T) {
201+
tracer := trie.NewPrevalueTracer()
202+
203+
tr := &BinaryTrie{
204+
root: NewBinaryNode(),
205+
tracer: tracer,
206+
}
207+
if w := tr.Witness(); len(w) != 0 {
208+
t.Fatal("expected empty witness for fresh trie")
209+
}
210+
211+
tracer.Put([]byte("path1"), []byte("blob1"))
212+
tracer.Put([]byte("path2"), []byte("blob2"))
213+
214+
witness := tr.Witness()
215+
if len(witness) != 2 {
216+
t.Fatalf("expected 2 witness entries, got %d", len(witness))
217+
}
218+
if !bytes.Equal(witness[string([]byte("path1"))], []byte("blob1")) {
219+
t.Fatal("unexpected witness value for path1")
220+
}
221+
if !bytes.Equal(witness[string([]byte("path2"))], []byte("blob2")) {
222+
t.Fatal("unexpected witness value for path2")
223+
}
224+
}

0 commit comments

Comments
 (0)