@@ -554,12 +554,42 @@ func convertProofToWitness(statedb *state.StateDB, addr common.Address, addrh []
554
554
branchRlp := proof [len (proof )- 2 ] // the last element has to be a leaf
555
555
isExtension := true
556
556
557
- extNode := proof2 [len (proof2 )- 1 ]
557
+ extNode := proof2 [len (proof2 )- 1 ] // Let's name it E1
558
558
bNode := prepareBranchNode (branchRlp , branchRlp , extNode , extNode , extListRlpBytes , extValues ,
559
559
key [keyIndex ], key [keyIndex ], false , false , isExtension )
560
560
nodes = append (nodes , bNode )
561
561
562
- node := prepareStorageLeafNode (proof [len (proof )- 1 ], proof [len (proof )- 1 ], nil , storage_key , key , nonExistingStorageProof , false , false , false , false )
562
+ /*
563
+ Let's say we have an extension node E1 at the following path [3, 5, 8].
564
+ Let's say E1 has nibbles [1, 2, 3]. Let's say we want to prove there does not exist
565
+ a leaf at [3, 5, 8, 1, 2] (because there is E1 there).
566
+
567
+ We need to construct a leaf L1 that will have the key equal to the queried key.
568
+ This means the nibbles are the same as in the path to E1 (without extension nibbles).
569
+
570
+ In the circuit, the leaf L1 will have the same key as the queried key once
571
+ the KeyData will be queried with offset 1 (to get the accumulated key RLC up until E1).
572
+ The nibbles stored in L1 will be added to the RLC and compared with the queried
573
+ key (has to be the same).
574
+ */
575
+
576
+ l := keyIndex - len (nibbles )
577
+ path := make ([]byte , l ) // Up to the E1 nibbles (without them)
578
+ copy (path , key [:l ])
579
+ // The remaining `key` nibbles are to be stored in the constructed leaf.
580
+
581
+ compact := trie .HexToCompact (key [l :])
582
+ // Add RLP:
583
+ compactLen := byte (len (compact ))
584
+ rlp2 := 128 + compactLen
585
+ rlp1 := 192 + compactLen + 1
586
+ // Constructed leaf L1:
587
+ constructedLeaf := append ([]byte {rlp1 , rlp2 }, compact ... )
588
+
589
+ // Add dummy value:
590
+ constructedLeaf = append (constructedLeaf , 1 )
591
+
592
+ node := prepareStorageLeafNode (proof [len (proof )- 1 ], constructedLeaf , nil , storage_key , key , nonExistingStorageProof , false , false , false , false )
563
593
nodes = append (nodes , node )
564
594
}
565
595
}
0 commit comments