@@ -32,6 +32,7 @@ func main() {
32
32
zkDbPath = flag .String ("zk-db" , "" , "path to the ZK node DB" )
33
33
mptRoot = flag .String ("mpt-root" , "" , "root hash of the MPT node" )
34
34
zkRoot = flag .String ("zk-root" , "" , "root hash of the ZK node" )
35
+ paranoid = flag .Bool ("paranoid" , false , "verifies all node contents against their expected hash" )
35
36
)
36
37
flag .Parse ()
37
38
@@ -50,7 +51,7 @@ func main() {
50
51
checkTrieEquality (& dbs {
51
52
zkDb : zkDb ,
52
53
mptDb : mptDb ,
53
- }, zkRootHash , mptRootHash , "" , checkAccountEquality , true )
54
+ }, zkRootHash , mptRootHash , "" , checkAccountEquality , true , * paranoid )
54
55
55
56
for i := 0 ; i < runtime .GOMAXPROCS (0 )* 4 ; i ++ {
56
57
<- trieCheckers
@@ -66,14 +67,14 @@ func panicOnError(err error, label, msg string) {
66
67
func dup (s []byte ) []byte {
67
68
return append ([]byte {}, s ... )
68
69
}
69
- func checkTrieEquality (dbs * dbs , zkRoot , mptRoot common.Hash , label string , leafChecker func (string , * dbs , []byte , []byte ), top bool ) {
70
+ func checkTrieEquality (dbs * dbs , zkRoot , mptRoot common.Hash , label string , leafChecker func (string , * dbs , []byte , []byte , bool ), top , paranoid bool ) {
70
71
zkTrie , err := trie .NewZkTrie (zkRoot , trie .NewZktrieDatabaseFromTriedb (trie .NewDatabaseWithConfig (dbs .zkDb , & trie.Config {Preimages : true })))
71
72
panicOnError (err , label , "failed to create zk trie" )
72
73
mptTrie , err := trie .NewSecureNoTracer (mptRoot , trie .NewDatabaseWithConfig (dbs .mptDb , & trie.Config {Preimages : true }))
73
74
panicOnError (err , label , "failed to create mpt trie" )
74
75
75
76
mptLeafCh := loadMPT (mptTrie , top )
76
- zkLeafCh := loadZkTrie (zkTrie , top )
77
+ zkLeafCh := loadZkTrie (zkTrie , top , paranoid )
77
78
78
79
mptLeafMap := <- mptLeafCh
79
80
zkLeafMap := <- zkLeafCh
@@ -107,11 +108,11 @@ func checkTrieEquality(dbs *dbs, zkRoot, mptRoot common.Hash, label string, leaf
107
108
panic (fmt .Sprintf ("%s key %s (preimage %s) not found in mpt" , label , hex .EncodeToString ([]byte (mptKey )), hex .EncodeToString ([]byte (preimageKey ))))
108
109
}
109
110
110
- leafChecker (fmt .Sprintf ("%s key: %s" , label , hex .EncodeToString ([]byte (preimageKey ))), dbs , zkValue , mptVal )
111
+ leafChecker (fmt .Sprintf ("%s key: %s" , label , hex .EncodeToString ([]byte (preimageKey ))), dbs , zkValue , mptVal , paranoid )
111
112
}
112
113
}
113
114
114
- func checkAccountEquality (label string , dbs * dbs , zkAccountBytes , mptAccountBytes []byte ) {
115
+ func checkAccountEquality (label string , dbs * dbs , zkAccountBytes , mptAccountBytes []byte , paranoid bool ) {
115
116
mptAccount := & types.StateAccount {}
116
117
panicOnError (rlp .DecodeBytes (mptAccountBytes , mptAccount ), label , "failed to decode mpt account" )
117
118
zkAccount , err := types .UnmarshalStateAccount (zkAccountBytes )
@@ -143,7 +144,7 @@ func checkAccountEquality(label string, dbs *dbs, zkAccountBytes, mptAccountByte
143
144
}
144
145
}()
145
146
146
- checkTrieEquality (dbs , zkRoot , mptRoot , label , checkStorageEquality , false )
147
+ checkTrieEquality (dbs , zkRoot , mptRoot , label , checkStorageEquality , false , paranoid )
147
148
accountsDone .Add (1 )
148
149
fmt .Println ("Accounts done:" , accountsDone .Load ())
149
150
trieCheckers <- struct {}{}
@@ -154,7 +155,7 @@ func checkAccountEquality(label string, dbs *dbs, zkAccountBytes, mptAccountByte
154
155
}
155
156
}
156
157
157
- func checkStorageEquality (label string , _ * dbs , zkStorageBytes , mptStorageBytes []byte ) {
158
+ func checkStorageEquality (label string , _ * dbs , zkStorageBytes , mptStorageBytes []byte , _ bool ) {
158
159
zkValue := common .BytesToHash (zkStorageBytes )
159
160
_ , content , _ , err := rlp .Split (mptStorageBytes )
160
161
panicOnError (err , label , "failed to decode mpt storage" )
@@ -214,7 +215,7 @@ func loadMPT(mptTrie *trie.SecureTrie, parallel bool) chan map[string][]byte {
214
215
return respChan
215
216
}
216
217
217
- func loadZkTrie (zkTrie * trie.ZkTrie , parallel bool ) chan map [string ][]byte {
218
+ func loadZkTrie (zkTrie * trie.ZkTrie , parallel , paranoid bool ) chan map [string ][]byte {
218
219
zkLeafMap := make (map [string ][]byte , 1000 )
219
220
var zkLeafMutex sync.Mutex
220
221
zkDone := make (chan map [string ][]byte )
@@ -238,7 +239,7 @@ func loadZkTrie(zkTrie *trie.ZkTrie, parallel bool) chan map[string][]byte {
238
239
if parallel && len (zkLeafMap )% 10000 == 0 {
239
240
fmt .Println ("ZK Accounts Loaded:" , len (zkLeafMap ))
240
241
}
241
- }, parallel )
242
+ }, parallel , paranoid )
242
243
zkDone <- zkLeafMap
243
244
}()
244
245
return zkDone
0 commit comments