@@ -12,6 +12,7 @@ use halo2_proofs::{arithmetic::FieldExt, halo2curves::bn256::Fr};
1212pub enum StorageProof {
1313 Root ( Fr ) , // Not proving a storage update, so we only need the storage root.
1414 Update {
15+ storage_key : U256 ,
1516 key : Fr ,
1617 trie_rows : TrieRows ,
1718 old_leaf : StorageLeaf ,
@@ -65,12 +66,21 @@ impl StorageProof {
6566 match self {
6667 Self :: Root ( _) => vec ! [ ] ,
6768 Self :: Update {
69+ storage_key,
70+ key,
6871 trie_rows,
6972 old_leaf,
7073 new_leaf,
7174 ..
7275 } => {
73- let mut lookups = trie_rows. poseidon_lookups ( ) ;
76+ let ( key_high, key_low) = u256_hi_lo ( storage_key) ;
77+ let mut lookups = vec ! [ (
78+ Fr :: from_u128( key_high) ,
79+ Fr :: from_u128( key_low) ,
80+ HashDomain :: Pair ,
81+ * key,
82+ ) ] ;
83+ lookups. extend ( trie_rows. poseidon_lookups ( ) ) ;
7484 lookups. extend ( old_leaf. poseidon_lookups ( ) ) ;
7585 lookups. extend ( new_leaf. poseidon_lookups ( ) ) ;
7686 lookups
@@ -126,10 +136,10 @@ impl StorageProof {
126136 #[ cfg( test) ]
127137 pub fn check ( & self ) {
128138 if let Self :: Update {
129- key : _,
130139 trie_rows,
131140 old_leaf,
132141 new_leaf,
142+ ..
133143 } = self
134144 {
135145 // Check that trie rows are consistent and produce claimed roots.
@@ -242,32 +252,23 @@ impl StorageLeaf {
242252 }
243253
244254 fn poseidon_lookups ( & self ) -> Vec < ( Fr , Fr , HashDomain , Fr ) > {
245- let mut lookups = vec ! [ ] ;
246255 match self {
247- Self :: Empty { .. } => ( ) ,
256+ Self :: Empty { .. } => vec ! [ ] ,
248257 Self :: Leaf { value_hash, .. } => {
249- lookups . push ( ( self . key ( ) , * value_hash, HashDomain :: Leaf , self . hash ( ) ) )
258+ vec ! [ ( self . key( ) , * value_hash, HashDomain :: Leaf , self . hash( ) ) ]
250259 }
251- Self :: Entry { storage_key, .. } => {
252- let ( key_high, key_low) = u256_hi_lo ( storage_key) ;
253- lookups. extend ( vec ! [
254- (
255- Fr :: from_u128( key_high) ,
256- Fr :: from_u128( key_low) ,
257- HashDomain :: Pair ,
258- self . key( ) ,
259- ) ,
260+ Self :: Entry { .. } => {
261+ vec ! [
260262 (
261263 self . value_high( ) ,
262264 self . value_low( ) ,
263265 HashDomain :: Pair ,
264266 self . value_hash( ) ,
265267 ) ,
266268 ( self . key( ) , self . value_hash( ) , HashDomain :: Leaf , self . hash( ) ) ,
267- ] ) ;
269+ ]
268270 }
269271 }
270- lookups
271272 }
272273}
273274
@@ -289,10 +290,13 @@ impl From<&SMTTrace> for StorageProof {
289290 ) ;
290291
291292 let [ old_entry, new_entry] = trace. state_update . unwrap ( ) . map ( Option :: unwrap) ;
293+ assert_eq ! ( old_entry. key, new_entry. key) ;
294+ let storage_key = u256_from_hex ( old_entry. key ) ;
292295 let old_leaf = StorageLeaf :: new ( key, & old_leaf, & old_entry) ;
293296 let new_leaf = StorageLeaf :: new ( key, & new_leaf, & new_entry) ;
294297
295298 let storage_proof = Self :: Update {
299+ storage_key,
296300 key,
297301 trie_rows,
298302 old_leaf,
0 commit comments