Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 609dbf8

Browse files
committed
fix: nibbles should come from node.key and should shift key index according to nibbles len in GetProof
1 parent ff97339 commit 609dbf8

File tree

2 files changed

+10
-11
lines changed

2 files changed

+10
-11
lines changed

geth-utils/gethutil/mpt/trie/stacktrie.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
806806
// fmt.Print(" ", k[i], "/", c.nodeType, " | ")
807807
proofType = append(proofType, c.nodeType)
808808
if c.nodeType == extNode {
809+
fmt.Print(c.key, " ")
810+
i += len(c.key) - 1
809811
nodes = append(nodes, c)
810812
c = c.children[0]
811813
} else if c.nodeType == branchNode {
@@ -833,6 +835,7 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
833835
nibbles = append(nibbles, nibble)
834836
}
835837

838+
fmt.Print(" hashed node key:", c.key, " ")
836839
// fmt.Println(" c_rlp:", c_rlp)
837840
proof = append(proof, c_rlp)
838841
branchChild := st.getNodeFromBranchRLP(c_rlp, int(k[i]))
@@ -844,7 +847,7 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
844847
}
845848
c.val = branchChild
846849
// if there are children, the node type should be branch
847-
proofType[i] = branchNode
850+
proofType[len(proofType)-1] = branchNode
848851
}
849852
}
850853

@@ -888,8 +891,8 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
888891
for i := 0; i < int(numNibbles); i++ {
889892
nibble[i] = raw_rlp[i+1] - 16
890893
}
891-
// fmt.Println(" Ext nibble:", numNibbles, nibble)
892-
nibbles = append(nibbles, nibble)
894+
// fmt.Println(" Ext nibble:", numNibbles, node.key)
895+
nibbles = append(nibbles, node.key)
893896
} else {
894897
nibbles = append(nibbles, []byte{})
895898
}

geth-utils/gethutil/mpt/witness/prepare_witness.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -383,20 +383,16 @@ func prepareWitnessSpecial(testName string, trieModifications []TrieModification
383383
// -[o] [(empty)] -> [LEAF] --> 1
384384
// -[o] [LEAF] -> [EXT - BRANCH - LEAF] --> 2
385385
// -[o] [EXT - BRANCH] -> [EXT - BRANCH - LEAF] --> "< 16"
386-
// -[M] [EXT - BRANCH] -> [BRANCH - LEAF] --> 16 (modified ext.)
386+
// -[M] [EXT - BRANCH] -> [BRANCH - LEAF] --> 0 under 16 txs or 16 (modified ext.)
387387
// -[o] [BRANCH - BRANCH] -> [BRANCH - BRANCH - LEAF] --> "< 127"
388388
// -[o] [BRANCH - LEAF] -> [BRANCH - BRANCH - LEAF] --> 129
389389
// -[o] [BRANCH] -> [BRANCH - LEAF] --> 0
390-
// -[M] [EXT - BRANCH] -> [BRANCH - LEAF] (modified extension) --> 0 under 16 txs
391390
// -[o] [BRANCH - BRANCH - LEAF] -> [BRANCH - BRANCH - EXT - BRANCH - LEAF] --> 129
392391
// -[o] [BRANCH - BRANCH - EXT - BRANCH] -> [BRANCH - BRANCH - EXT - BRANCH - LEAF] --> 130
393-
// -[H] [BRANCH - BRANCH - EXT - BRANCH - HASHED] -> [BRANCH - BRANCH - BRANCH - LEAF] --> 144 (hashed node)
392+
// -[H] [BRANCH - BRANCH - EXT - BRANCH - HASHED] -> [BRANCH - BRANCH - BRANCH - LEAF] --> 144, 512 (hashed node)
394393
// -[o] [BRANCH - BRANCH - (...BRANCH)] -> [BRANCH - BRANCH - (...BRANCH) - LEAF] --> 146 ~ 176
395-
//
396-
// -[] [BRANCH - BRANCH - EXT - BRANCH - LEAF] -> [BRANCH - BRANCH - EXT - BRANCH - BRANCH - HASHED] --> 258
397-
// -[] [BRANCH - BRANCH - EXT - BRANCH - BRANCH - HASHED] -> [BRANCH - BRANCH - EXT - BRANCH - BRANCH - HASHED] --> 259~
398-
// -[] [BRANCH - BRANCH - EXT - BRANCH - BRANCH - BRANCH - HASHED] -> [BRANCH - BRANCH - EXT - BRANCH - LEAF] --> 512
399-
// -[] [[BRANCH - BRANCH - EXT - BRANCH - EXT - BRANCH] -> [BRANCH - BRANCH - EXT - BRANCH - EXT - BRANCH - LEAF] --> 514~
394+
// -[o] [BRANCH - BRANCH - EXT - (BRANCH..)] -> [BRANCH - BRANCH - EXT - (BRANCH..) - LEAF] --> 258~
395+
// -[o] [BRANCH - BRANCH - EXT - BRANCH - EXT - BRANCH] -> [BRANCH - BRANCH - EXT - BRANCH - EXT - BRANCH - LEAF] --> 514~
400396
func GenerateWitness(txIdx uint, key, value []byte, proof *trie.StackProof) []Node {
401397
k := trie.KeybytesToHex(key)
402398
k = k[:len(k)-1]

0 commit comments

Comments
 (0)