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

Commit

Permalink
fix isExt()
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Apr 8, 2024
1 parent 5f28ca1 commit 59ac6a4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
13 changes: 10 additions & 3 deletions geth-utils/gethutil/mpt/trie/stacktrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,21 @@ func isTxLeaf(proofEl []byte) bool {
c, _ := rlp.CountValues(elems)

// 9: for tx (Nonce, Gas, GasPrice, Value, To, Data, r, s, v)
return c == 9 || c == 2
return (c == 9 || c == 2) && !isTxExt(proofEl)
}

func isTxExt(proofEl []byte) bool {
elems, _, _ := rlp.SplitList(proofEl)
idx := proofEl[0] - 225
return len(proofEl) < 50 && proofEl[0] < 248 && elems[idx] == 160
}

func printProof(ps [][]byte, idx []byte) {

enable := byte(150)
enable := byte(200)
fmt.Print(" [")
for _, p := range ps {
if p[0] == 226 && p[1]%16 == 0 && p[2] == 160 {
if isTxExt(p) {
fmt.Print("EXT - ")
if idx[0] > enable {
fmt.Print(" (", p, ") - ")
Expand Down Expand Up @@ -784,6 +790,7 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
isHashed := false

for i := 0; i < len(k); i++ {
// fmt.Print(k[i], "- ")
if c.nodeType == extNode {
nodes = append(nodes, c)
c = c.children[0]
Expand Down
4 changes: 3 additions & 1 deletion geth-utils/gethutil/mpt/witness/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ func isTxLeaf(proofEl []byte) bool {
}

func isTxExt(proofEl []byte) bool {
return proofEl[0] == 226 && proofEl[1]%16 == 0 && proofEl[2] == 160
elems, _, _ := rlp.SplitList(proofEl)
idx := proofEl[0] - 225
return len(proofEl) < 50 && proofEl[0] < 248 && elems[idx] == 160
}

// prepareBranchWitness takes the rows that are to be filled with branch data and it takes
Expand Down
2 changes: 1 addition & 1 deletion geth-utils/gethutil/mpt/witness/prepare_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,13 +346,13 @@ func prepareWitnessSpecial(testName string, trieModifications []TrieModification
// -[] [EXT] -> [BRANCH - BRANCH - BRANCH - LEAF] --> 144
// -[] [BRANCH - LEAF] -> [BRANCH - BRANCH - LEAF] (modified extension)
// -[] [BRANCH - BRANCH - (...BRANCH)] -> [BRANCH - BRANCH - (...BRANCH) - LEAF]
// -[] [BRANCH - BRANCH - BRANCH - EXT] -> [BRANCH - BRANCH - BRANCH - BRANCH - LEAF]
// -[] [BRANCH - BRANCH - LEAF ] -> [BRANCH - BRANCH - LEAF - BRANCH - LEAF]
// -[] [LEAF] -> [LEAF]
// -[] [EXT] -> [EXT]
// -[] [EXT - EXT] -> [EXT - EXT]
// -[] [EXT - LEAF] -> [LEAF]
// -[] [BRANCH - LEAF] -> [BRANCH - BRANCH - EXT - BRANCH - LEAF]
// -[] [BRANCH - BRANCH - EXT] -> [BRANCH - BRANCH - EXT - BRANCH - LEAF]
// -[] [BRANCH - BRANCH - EXT - BRANCH - (LEAF)] -> [BRANCH - BRANCH - EXT - BRANCH - EXT - BRANCH - LEAF]
// -[] [BRANCH - BRANCH - EXT - BRANCH - (...BRANCH)] -> [BRANCH - BRANCH - EXT - BRANCH - (...BRANCH) - LEAF]
// -[] [LEAF] -> [BRANCH - BRANCH - EXT - BRANCH - BRANCH - LEAF]
Expand Down

0 comments on commit 59ac6a4

Please sign in to comment.