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

Commit 47ff445

Browse files
committed
cleanup
1 parent e5fc51d commit 47ff445

7 files changed

+20
-58
lines changed

Diff for: geth-utils/gethutil/mpt/trie/stacktrie.go

+3-17
Original file line numberDiff line numberDiff line change
@@ -655,20 +655,6 @@ func isBranch(proofEl []byte) bool {
655655
return c == 17
656656
}
657657

658-
func isTxLeaf(proofEl []byte) bool {
659-
elems, _, _ := rlp.SplitList(proofEl)
660-
c, _ := rlp.CountValues(elems)
661-
662-
// 9: for tx (Nonce, Gas, GasPrice, Value, To, Data, r, s, v)
663-
return (c == 9) && !isTxExt(proofEl)
664-
}
665-
666-
func isTxExt(proofEl []byte) bool {
667-
elems, _, _ := rlp.SplitList(proofEl)
668-
idx := proofEl[0] - 225
669-
return len(proofEl) < 50 && proofEl[0] < 248 && elems[idx] == 160
670-
}
671-
672658
func printProof(ps [][]byte, t, idx []byte) {
673659

674660
enable := byte(150)
@@ -701,21 +687,21 @@ func printProof(ps [][]byte, t, idx []byte) {
701687
}
702688

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

706692
proofS, nibblesS, typesS, err := st.GetProof(db, indexBuf)
707693
if err != nil {
708694
return StackProof{}, err
709695
}
710-
printProof(proofS, typesS, indexBuf)
696+
// printProof(proofS, typesS, indexBuf)
711697

712698
st.Update(indexBuf, value)
713699

714700
proofC, nibblesC, typesC, err := st.GetProof(db, indexBuf)
715701
if err != nil {
716702
return StackProof{}, err
717703
}
718-
printProof(proofC, typesC, indexBuf)
704+
// printProof(proofC, typesC, indexBuf)
719705

720706
return StackProof{proofS, proofC, nibblesS, nibblesC, typesS, typesC}, nil
721707
}

Diff for: geth-utils/gethutil/mpt/witness/branch.go

+8-27
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,6 @@ import (
66
"github.com/ethereum/go-ethereum/rlp"
77
)
88

9-
func PrepareBranchNode(branch1, branch2, extNode1, extNode2, extListRlpBytes []byte, extValues [][]byte, key, driftedInd byte,
10-
isBranchSPlaceholder, isBranchCPlaceholder, isExtension bool) Node {
11-
return prepareBranchNode(branch1, branch2, extNode1, extNode2, extListRlpBytes, extValues, key, driftedInd,
12-
isBranchSPlaceholder, isBranchCPlaceholder, isExtension)
13-
}
14-
159
// isBranch takes GetProof element and returns whether the element is a branch.
1610
func isBranch(proofEl []byte) bool {
1711
elems, _, err := rlp.SplitList(proofEl)
@@ -25,23 +19,6 @@ func isBranch(proofEl []byte) bool {
2519
return c == 17
2620
}
2721

28-
func isTxLeaf(proofEl []byte) bool {
29-
elems, _, err := rlp.SplitList(proofEl)
30-
check(err)
31-
c, err1 := rlp.CountValues(elems)
32-
check(err1)
33-
// 2: hashed node
34-
// 9: for tx (Nonce, Gas, GasPrice, Value, To, Data, r, s, v)
35-
// ext node is also 2
36-
return (c == 9 || c == 2) && !isTxExt(proofEl)
37-
}
38-
39-
func isTxExt(proofEl []byte) bool {
40-
elems, _, _ := rlp.SplitList(proofEl)
41-
idx := proofEl[0] - 225
42-
return len(proofEl) < 50 && proofEl[0] < 248 && elems[idx] == 160
43-
}
44-
4522
// prepareBranchWitness takes the rows that are to be filled with branch data and it takes
4623
// a branch as returned by GetProof. There are 19 rows for a branch and prepareBranchWitness
4724
// fills the rows from index 1 to index 16 (index 0 is init, index 17 and 18 are for extension
@@ -53,7 +30,7 @@ func prepareBranchWitness(rows [][]byte, branch []byte, branchStart int, branchR
5330
rowInd := 1
5431
colInd := branchNodeRLPLen - 1
5532

56-
// TODO: if input branch is a leaf node, it'll work abnormally
33+
// TODO: if the input is a leaf, it would throw exception
5734
i := 0
5835
insideInd := -1
5936
for {
@@ -238,8 +215,11 @@ func getDriftedPosition(leafKeyRow []byte, numberOfNibbles int) byte {
238215

239216
// addBranchAndPlaceholder adds to the rows a branch and its placeholder counterpart
240217
// (used when one of the proofs have one branch more than the other).
241-
func addBranchAndPlaceholder(proof1, proof2 [][]byte, extNibblesS, extNibblesC []byte,
242-
extProofTx, leafRow0, key []byte, keyIndex int, isShorterProofLastLeaf bool,
218+
func addBranchAndPlaceholder(
219+
proof1, proof2 [][]byte,
220+
extNibblesS, extNibblesC []byte,
221+
extProofTx, leafRow0, key []byte,
222+
keyIndex int, isShorterProofLastLeaf bool,
243223
) (bool, bool, int, Node) {
244224

245225
len1 := len(proof1)
@@ -261,6 +241,7 @@ func addBranchAndPlaceholder(proof1, proof2 [][]byte, extNibblesS, extNibblesC [
261241
var proof []byte
262242
var extNibbles []byte
263243
if isTxProof {
244+
// At 16th tx, the length of proofS/C is 2 only
264245
extNibbles = extNibblesS
265246
proof = extProofTx
266247
} else {
@@ -325,7 +306,7 @@ func addBranchAndPlaceholder(proof1, proof2 [][]byte, extNibblesS, extNibblesC [
325306
}
326307

327308
// Note that isModifiedExtNode happens also when we have a branch instead of shortExtNode
328-
isModifiedExtNode := (!isBranch(longExtNode) && !isShorterProofLastLeaf)
309+
isModifiedExtNode := !isBranch(longExtNode) && !isShorterProofLastLeaf
329310

330311
// We now get the first nibble of the leaf that was turned into branch.
331312
// This first nibble presents the position of the leaf once it moved

Diff for: geth-utils/gethutil/mpt/witness/gen_witness_from_local_blockchain_test.go

+1
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,7 @@ func TestExtNodeDeletedExtShortIsBranchFirstLevel(t *testing.T) {
924924
}
925925

926926
func TestSimulateStackTrieUnder128Txs(t *testing.T) {
927+
t.Skip("For stack trie witness check only")
927928
SkipIfNoGeth(t)
928929
// The trie is empty before we add key1, key2, key3.
929930
key1 := common.HexToHash("0x2345610000000000000000000000000000000000000000000000000000000000")

Diff for: geth-utils/gethutil/mpt/witness/gen_witness_transactions_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func TestStackTrieInsertion_33Txs(t *testing.T) {
159159
}
160160

161161
func TestStackTrieInsertion_129Txs(t *testing.T) {
162-
// The first tx (index 0) is inserted into position 8 of the top branch
162+
// The first tx (index 0) is inserted into position 8 of the branch of the first layer
163163
// Th 129th tx is the neighbor of the first tx
164164
transactionsStackTrieInsertionTemplate(t, 129)
165165
}

Diff for: geth-utils/gethutil/mpt/witness/leaf.go

-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package witness
22

33
import (
4-
"fmt"
54
"math"
65

76
"main/gethutil/mpt/trie"
@@ -607,10 +606,6 @@ func prepareStorageLeafNode(leafS, leafC, neighbourNode []byte, storage_key comm
607606

608607
keyC, valueC, listRlpBytes2, valueRlpBytes2 := prepareStorageLeafInfo(leafC, false, isCPlaceholder)
609608

610-
fmt.Println("-", key)
611-
fmt.Println("-", keyS, leafS)
612-
fmt.Println("-", storage_key)
613-
614609
rows = append(rows, keyC)
615610
rows = append(rows, valueC)
616611

Diff for: geth-utils/gethutil/mpt/witness/modified_extension_node.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
// These rows are added only when an existing extension node gets shortened or elongated (in terms
1212
// of the extension node nibbles) because of another extension node being added or deleted.
1313
// The rows added are somewhat exceptional as otherwise they do not appear.
14-
func equipLeafWithModExtensionNode(statedb *state.StateDB, leafNode Node, addr common.Address,
14+
func equipLeafWithModExtensionNode(
15+
statedb *state.StateDB, leafNode Node, addr common.Address,
1516
proof1, proof2, extNibblesS, extNibblesC [][]byte,
1617
proofTx, key []byte,
1718
keyIndex, numberOfNibbles int, isAccountProof bool) Node {
@@ -21,7 +22,6 @@ func equipLeafWithModExtensionNode(statedb *state.StateDB, leafNode Node, addr c
2122
isTxProof := len(proofTx) != 0
2223

2324
var longExtNode []byte
24-
// FIXME this is a workaround to get ext node
2525
if isTxProof {
2626
longExtNode = proofTx
2727
} else {

Diff for: geth-utils/gethutil/mpt/witness/prepare_witness.go

+5-6
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
200200

201201
storageProof, neighbourNode1, extNibbles1, isLastLeaf1, isNeighbourNodeHashed1, err := statedb.GetStorageProof(addr, tMod.Key)
202202
check(err)
203-
fmt.Println("Storage ProofS:", len(storageProof), storageProof)
204203

205204
sRoot := statedb.GetTrie().Hash()
206205

@@ -221,7 +220,6 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
221220

222221
storageProof1, neighbourNode2, extNibbles2, isLastLeaf2, isNeighbourNodeHashed2, err := statedb.GetStorageProof(addr, tMod.Key)
223222
check(err)
224-
fmt.Println("Storage ProofC:", len(storageProof1), storageProof1)
225223

226224
aNode := aNeighbourNode2
227225
aIsLastLeaf := aIsLastLeaf1
@@ -318,9 +316,9 @@ func prepareWitnessSpecial(testName string, trieModifications []TrieModification
318316
// E. [(EXT, BRANCH) - LEAF] -> [(EXT, BRANCH) - EXT - BRANCH - LEAF] --> 130, 514
319317
//
320318
// --- TODO: modified extension nodes, not working now
321-
// M. [EXT - BRANCH] -> [BRANCH - LEAF] --> 0 under 16 txs or 16 (modified ext.)
322-
// M. [(BRANCH) - EXT - BRANCH - HASHED] -> [(BRANCH) - BRANCH - LEAF] --> 144
323-
// M. [(BRANCH, EXT) - BRANCH - HASHED] -> [(BRANCH, EXT) - LEAF] --> 512
319+
// M1. [EXT - BRANCH] -> [BRANCH - LEAF] --> 0 under 16 txs or 16 (modified ext.)
320+
// M2. [(BRANCH) - EXT - BRANCH - HASHED] -> [(BRANCH) - BRANCH - LEAF] --> 144
321+
// M3. [(BRANCH, EXT) - BRANCH - HASHED] -> [(BRANCH, EXT) - LEAF] --> 512
324322
// Issue:
325323
// Take tx144 as example, the proof is
326324
// [BRANCH_S1 - BRANCH_S2 - EXT_S - BRANCH_S3 - HASHED] -> [BRANCH_C1 - BRANCH_C2 - BRANCH_C3 - LEAF]
@@ -518,7 +516,8 @@ func updateStateAndPrepareWitness(testName string, keys, values []common.Hash, a
518516
// convertProofToWitness takes two GetProof proofs (before and after a single modification) and prepares
519517
// a witness for the MPT circuit. Alongside, it prepares the byte streams that need to be hashed
520518
// and inserted into the Keccak lookup table.
521-
func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []byte,
519+
func convertProofToWitness(
520+
statedb *state.StateDB, addr common.Address, addrh []byte,
522521
proof1, proof2, extNibblesS, extNibblesC [][]byte,
523522
storage_key common.Hash, key []byte, neighbourNode []byte,
524523
isAccountProof, nonExistingAccountProof, nonExistingStorageProof, isShorterProofLastLeaf bool) []Node {

0 commit comments

Comments
 (0)