@@ -369,11 +369,18 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
369
369
370
370
var nodes []Node
371
371
372
- branchC16 := byte (0 )
373
- branchC1 := byte (1 )
374
372
for i := 0 ; i < upTo ; i ++ {
375
373
if ! isBranch (proof1 [i ]) {
376
- if i != len1 - 1 { // extension node
374
+ isNonExistingProof := (isAccountProof && nonExistingAccountProof ) || (! isAccountProof && nonExistingStorageProof )
375
+ areThereNibbles := len (extNibblesS ) != 0 || len (extNibblesC ) != 0
376
+ // If i < upTo-1, it means it's not a leaf, so it's an extension node.
377
+ // There is no any special relation between isNonExistingProof and isExtension,
378
+ // except that in the non-existing proof the extension node can appear in `i == upTo-1`.
379
+ // For non-existing proof, the last node in the proof could be an extension node (we have
380
+ // nil in the underlying branch). For the non-existing proof with the wrong leaf
381
+ // (non-existing proofs can be with a nil leaf or with a wrong leaf),
382
+ // we don't need to worry because it appears in i = upTo-1).
383
+ if (i != upTo - 1 ) || (areThereNibbles && isNonExistingProof ) { // extension node
377
384
var numberOfNibbles byte
378
385
isExtension = true
379
386
numberOfNibbles , extListRlpBytes , extValues = prepareExtensions (extNibblesS , extensionNodeInd , proof1 [i ], proof2 [i ])
@@ -393,27 +400,6 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
393
400
394
401
nodes = append (nodes , node )
395
402
} else {
396
- switchC16 := true // If not extension node, switchC16 = true.
397
- if isExtension {
398
- keyLen := getExtensionNodeKeyLen (proof1 [i - 1 ])
399
- if keyLen == 1 {
400
- switchC16 = false
401
- } else {
402
- if proof1 [i - 1 ][2 ] != 0 { // If even, switch16 = true.
403
- switchC16 = false
404
- }
405
- }
406
- }
407
- if switchC16 {
408
- if branchC16 == 1 {
409
- branchC16 = 0
410
- branchC1 = 1
411
- } else {
412
- branchC16 = 1
413
- branchC1 = 0
414
- }
415
- }
416
-
417
403
var extNode1 []byte = nil
418
404
var extNode2 []byte = nil
419
405
if isExtension {
@@ -422,7 +408,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
422
408
}
423
409
424
410
bNode := prepareBranchNode (proof1 [i ], proof2 [i ], extNode1 , extNode2 , extListRlpBytes , extValues ,
425
- key [keyIndex ], key [keyIndex ], branchC16 , branchC1 , false , false , isExtension )
411
+ key [keyIndex ], key [keyIndex ], false , false , isExtension )
426
412
nodes = append (nodes , bNode )
427
413
428
414
keyIndex += 1
@@ -438,10 +424,10 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
438
424
leafRow0 = proof2 [len2 - 1 ]
439
425
}
440
426
441
- isModifiedExtNode , _ , numberOfNibbles , branchC16 , bNode := addBranchAndPlaceholder (proof1 , proof2 , extNibblesS , extNibblesC ,
427
+ isModifiedExtNode , _ , numberOfNibbles , bNode := addBranchAndPlaceholder (proof1 , proof2 , extNibblesS , extNibblesC ,
442
428
leafRow0 , key , neighbourNode ,
443
429
keyIndex , extensionNodeInd , additionalBranch ,
444
- isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , branchC16 , branchC1 , & toBeHashed )
430
+ isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , & toBeHashed )
445
431
446
432
nodes = append (nodes , bNode )
447
433
@@ -458,7 +444,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
458
444
} else {
459
445
isCModExtension = true
460
446
}
461
- leafNode = prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , nonExistingAccountProof , isAccountProof , isSModExtension , isCModExtension )
447
+ leafNode = prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , isAccountProof , isSModExtension , isCModExtension )
462
448
}
463
449
} else {
464
450
// Add storage leaf after branch placeholder
@@ -472,7 +458,7 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
472
458
} else {
473
459
isCModExtension = true
474
460
}
475
- leafNode = prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , nonExistingAccountProof , isAccountProof , isSModExtension , isCModExtension )
461
+ leafNode = prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , isAccountProof , isSModExtension , isCModExtension )
476
462
}
477
463
}
478
464
@@ -482,14 +468,14 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
482
468
if isModifiedExtNode {
483
469
leafNode = equipLeafWithModExtensionNode (statedb , leafNode , addr , proof1 , proof2 , extNibblesS , extNibblesC , key , neighbourNode ,
484
470
keyIndex , extensionNodeInd , numberOfNibbles , additionalBranch ,
485
- isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , branchC16 , branchC1 , & toBeHashed )
471
+ isAccountProof , nonExistingAccountProof , isShorterProofLastLeaf , & toBeHashed )
486
472
}
487
473
nodes = append (nodes , leafNode )
488
474
} else {
489
- node := prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , nonExistingAccountProof , isAccountProof , false , false )
475
+ node := prepareLeafAndPlaceholderNode (addr , addrh , proof1 , proof2 , storage_key , key , isAccountProof , false , false )
490
476
nodes = append (nodes , node )
491
477
}
492
- } else if isBranch (proof2 [len (proof2 )- 1 ]) {
478
+ } else if ( len1 == 0 && len2 == 0 ) || isBranch (proof2 [len (proof2 )- 1 ]) {
493
479
// Account proof has drifted leaf as the last row, storage proof has non-existing-storage row
494
480
// as the last row.
495
481
// When non existing proof and only the branches are returned, we add a placeholder leaf.
0 commit comments