@@ -267,22 +267,6 @@ func obtainTwoProofsAndConvertToWitness(trieModifications []TrieModification, st
267
267
// Needs to be after `specialTest == 1` preparation:
268
268
nodes = append (nodes , GetStartNode (proofType , sRoot , cRoot , specialTest ))
269
269
270
- /*
271
- if tMod.Type == StorageDoesNotExist {
272
- fmt.Println("===================");
273
- fmt.Println(addr);
274
- fmt.Println(tMod.Key);
275
- fmt.Println("");
276
-
277
- for i := 0; i < len(storageProof); i++ {
278
- fmt.Println(storageProof[i])
279
- fmt.Println("")
280
- }
281
- fmt.Println("========");
282
- fmt.Println("");
283
- }
284
- */
285
-
286
270
// In convertProofToWitness, we can't use account address in its original form (non-hashed), because
287
271
// of the "special" test for which we manually manipulate the "hashed" address and we don't have a preimage.
288
272
// TODO: addr is used for calling GetProof for modified extension node only, might be done in a different way
@@ -380,8 +364,6 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
380
364
}
381
365
382
366
var isExtension bool
383
- extensionNodeInd := 0
384
-
385
367
var extListRlpBytes []byte
386
368
var extValues [][]byte
387
369
for i := 0 ; i < 4 ; i ++ {
@@ -393,7 +375,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
393
375
for i := 0 ; i < upTo ; i ++ {
394
376
if ! isBranch (proof1 [i ]) {
395
377
isNonExistingProof := (isAccountProof && nonExistingAccountProof ) || (! isAccountProof && nonExistingStorageProof )
396
- areThereNibbles := len (extNibblesS ) != 0 || len (extNibblesC ) != 0
378
+ areThereNibbles := len (extNibblesS [ i ] ) != 0 || len (extNibblesC [ i ] ) != 0
397
379
// If i < upTo-1, it means it's not a leaf, so it's an extension node.
398
380
// There is no any special relation between isNonExistingProof and isExtension,
399
381
// except that in the non-existing proof the extension node can appear in `i == upTo-1`.
@@ -404,10 +386,9 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
404
386
if (i != upTo - 1 ) || (areThereNibbles && isNonExistingProof ) { // extension node
405
387
var numberOfNibbles byte
406
388
isExtension = true
407
- numberOfNibbles , extListRlpBytes , extValues = prepareExtensions (extNibblesS , extensionNodeInd , proof1 [i ], proof2 [i ])
389
+ numberOfNibbles , extListRlpBytes , extValues = prepareExtensions (extNibblesS [ i ] , proof1 [i ], proof2 [i ])
408
390
409
391
keyIndex += int (numberOfNibbles )
410
- extensionNodeInd ++
411
392
continue
412
393
}
413
394
@@ -445,9 +426,10 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
445
426
leafRow0 = proof2 [len2 - 1 ]
446
427
}
447
428
448
- isModifiedExtNode , _ , numberOfNibbles , bNode := addBranchAndPlaceholder (proof1 , proof2 , extNibblesS , extNibblesC ,
429
+ isModifiedExtNode , _ , numberOfNibbles , bNode := addBranchAndPlaceholder (proof1 , proof2 ,
430
+ extNibblesS [len1 - 1 ], extNibblesC [len2 - 1 ],
449
431
leafRow0 , key , neighbourNode ,
450
- keyIndex , extensionNodeInd , additionalBranch ,
432
+ keyIndex , additionalBranch ,
451
433
isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , & toBeHashed )
452
434
453
435
nodes = append (nodes , bNode )
@@ -488,7 +470,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
488
470
// modification).
489
471
if isModifiedExtNode {
490
472
leafNode = equipLeafWithModExtensionNode (statedb , leafNode , addr , proof1 , proof2 , extNibblesS , extNibblesC , key , neighbourNode ,
491
- keyIndex , extensionNodeInd , numberOfNibbles , additionalBranch ,
473
+ keyIndex , numberOfNibbles , additionalBranch ,
492
474
isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , & toBeHashed )
493
475
}
494
476
nodes = append (nodes , leafNode )
@@ -513,7 +495,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
513
495
node := prepareStorageLeafPlaceholderNode (storage_key , key , keyIndex )
514
496
nodes = append (nodes , node )
515
497
}
516
- } else if len ( extNibblesC ) > len ( proof2 ) - 1 {
498
+ } else {
517
499
isLastExtNode := len (extNibblesC [len (proof2 )- 1 ]) != 0
518
500
if isLastExtNode {
519
501
// We need to add a placeholder branch and a placeholder leaf.
@@ -564,7 +546,11 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
564
546
newKey [keyIndex ] = byte (i )
565
547
k := trie .HexToKeybytes (newKey )
566
548
ky := common .BytesToHash (k )
567
- proof , _ , _ , _ , _ , err = statedb .GetStorageProof (addr , ky )
549
+ if isAccountProof {
550
+ proof , _ , _ , _ , _ , err = statedb .GetProof (addr )
551
+ } else {
552
+ proof , _ , _ , _ , _ , err = statedb .GetStorageProof (addr , ky )
553
+ }
568
554
check (err )
569
555
if ! isBranch (proof [len (proof )- 1 ]) {
570
556
break
@@ -586,6 +572,8 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
586
572
copy (path , key [:l ])
587
573
// The remaining `key` nibbles are to be stored in the constructed leaf - in our example [1 2 4 ...]
588
574
575
+ // TODO: construct for account proof
576
+
589
577
compact := trie .HexToCompact (key [l :])
590
578
// Add RLP:
591
579
compactLen := byte (len (compact ))
0 commit comments