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

Commit

Permalink
chore: remove debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
KimiWu123 committed Apr 19, 2024
1 parent 3e90dda commit aaf5e6f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 48 deletions.
45 changes: 1 addition & 44 deletions geth-utils/gethutil/mpt/trie/stacktrie.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,28 +656,16 @@ func isBranch(proofEl []byte) bool {
}

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

enable := byte(150)
fmt.Print(" [")
for i, p := range ps {
for i, _ := range ps {
if t[i] == ExtNode {
fmt.Print("EXT - ")
if idx[0] >= enable {
fmt.Print(" (", p, ") - ")
}
} else if t[i] == BranchNode {
fmt.Print("BRANCH - ")
// fmt.Print(" (", p, ") - ")
} else if t[i] == LeafNode {
fmt.Print("LEAF - ")
if idx[0] >= enable {
fmt.Print(" (", p, ") - ")
}
} else if t[i] == HashedNode {
fmt.Print("HASHED - ")
// elems, _, _ := rlp.SplitList(p)
// c, _ := rlp.CountValues(elems)
// fmt.Print(c, " (", p, ") - ")
} else {
fmt.Print("NOT SUPPORT NOW!!")
}
Expand All @@ -687,8 +675,6 @@ func printProof(ps [][]byte, t, idx []byte) {
}

func (st *StackTrie) UpdateAndGetProof(db ethdb.KeyValueReader, indexBuf, value []byte) (StackProof, error) {
// fmt.Println(" ====", indexBuf, "-->", KeybytesToHex(indexBuf))

proofS, nibblesS, typesS, err := st.GetProof(db, indexBuf)
if err != nil {
return StackProof{}, err
Expand Down Expand Up @@ -719,7 +705,6 @@ func (st *StackTrie) UpdateAndGetProofs(db ethdb.KeyValueReader, list types.Deri
// order is correct.
var indexBuf []byte
for i := 1; i < list.Len() && i <= 0x7f; i++ {
fmt.Print(i)
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := types.EncodeForDerive(list, i, valueBuf)
proof, err := st.UpdateAndGetProof(db, indexBuf, value)
Expand All @@ -732,7 +717,6 @@ func (st *StackTrie) UpdateAndGetProofs(db ethdb.KeyValueReader, list types.Deri
// special case when index is 0
// rlp.AppendUint64() encodes index 0 to [128]
if list.Len() > 0 {
fmt.Print("0")
indexBuf = rlp.AppendUint64(indexBuf[:0], 0)
value := types.EncodeForDerive(list, 0, valueBuf)
proof, err := st.UpdateAndGetProof(db, indexBuf, value)
Expand All @@ -743,7 +727,6 @@ func (st *StackTrie) UpdateAndGetProofs(db ethdb.KeyValueReader, list types.Deri
}

for i := 0x80; i < list.Len(); i++ {
fmt.Print(i)
indexBuf = rlp.AppendUint64(indexBuf[:0], uint64(i))
value := types.EncodeForDerive(list, i, valueBuf)
proof, err := st.UpdateAndGetProof(db, indexBuf, value)
Expand All @@ -752,14 +735,12 @@ func (st *StackTrie) UpdateAndGetProofs(db ethdb.KeyValueReader, list types.Deri
}
proofs = append(proofs, proof)
}
// fmt.Println("* ROOT", root)

return proofs, nil
}

func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, [][]byte, []uint8, error) {
k := KeybytesToHex(key)
// fmt.Println(" k", k)
if st.nodeType == EmptyNode {
return [][]byte{}, nil, []uint8{EmptyNode}, nil
}
Expand All @@ -783,10 +764,8 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
c := st

for i := 0; i < len(k); i++ {
// fmt.Print(" ", k[i], "/", c.nodeType, " | ")
proofType = append(proofType, c.nodeType)
if c.nodeType == ExtNode {
// fmt.Print(c.key, " ")
i += len(c.key) - 1
nodes = append(nodes, c)
c = c.children[0]
Expand All @@ -804,17 +783,6 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
if error != nil {
panic(error)
}

// if c_rlp[0] > 192 && c_rlp[0] < 248 {
// numNibbles := c_rlp[0] - 225
// var nibble = make([]byte, numNibbles)
// for i := 0; i < int(numNibbles); i++ {
// nibble[i] = c_rlp[i+1] - 16
// }
// // fmt.Println(" HASHED Ext nibble:", nibble, c_rlp)
// }

// fmt.Println(" c_rlp:", c_rlp)
proof = append(proof, c_rlp)
nibbles = append(nibbles, c.key)
branchChild := st.getNodeFromBranchRLP(c_rlp, int(k[i]))
Expand Down Expand Up @@ -860,17 +828,6 @@ func (st *StackTrie) GetProof(db ethdb.KeyValueReader, key []byte) ([][]byte, []
if rlp_flag < 192 || rlp_flag >= 248 {
panic("should not happen!")
}

// 192 ~ 247 is a short list
// if it's an ext node, it contains 1.)nibbles and 2.) 32bytes hashed value
// 2.) 32 bytes long data plus rlp flag, it becomes 33 bytes long data
// 192 + 33 = 225, and the left bytes are for nibbles.
// numNibbles := raw_rlp[0] - 225
// var nibble = make([]byte, numNibbles)
// for i := 0; i < int(numNibbles); i++ {
// nibble[i] = raw_rlp[i+1] - 16
// }
// fmt.Println(" Ext nibble:", numNibbles, node.key)
nibbles = append(nibbles, node.key)
} else {
nibbles = append(nibbles, []byte{})
Expand Down
5 changes: 1 addition & 4 deletions geth-utils/gethutil/mpt/witness/prepare_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ func GenerateWitness(txIdx uint, key, value []byte, proof *trie.StackProof) []No
// padding k to 32 bytes
kk := make([]byte, 32-len(k))
k = append(k, kk...)
fmt.Println("== txIdx", txIdx)
// fmt.Println(" k", k)

proofS := proof.GetProofS()
proofC := proof.GetProofC()
Expand Down Expand Up @@ -396,7 +394,6 @@ func GenerateWitness(txIdx uint, key, value []byte, proof *trie.StackProof) []No
var numberOfNibbles byte
isExtension := false
mismatchedIdx := -1
fmt.Println("upto", upTo, additionalBranch, proofTypeS)
for i := 0; i < upTo; i++ {
if proofTypeS[i] != trie.BranchNode {
// This is for the case of extension modified node due to the order of the types mismatched.
Expand Down Expand Up @@ -483,7 +480,7 @@ func GenerateWitness(txIdx uint, key, value []byte, proof *trie.StackProof) []No
}

} else {
fmt.Println("MODIFIED EXT CASE!!")
fmt.Println("MODIFIED EXT CASE!! NOT WORKING NOW")
leafNode = prepareTxLeafAndPlaceholderNode(txIdx, proofC[len2-1], k, true)

// When a proof element is a modified extension node (new extension node appears at the position
Expand Down

0 comments on commit aaf5e6f

Please sign in to comment.