@@ -215,11 +215,51 @@ impl<F: Field> Witness<F> {
215
215
storage_keys : Vec :: new ( ) ,
216
216
} ) ;
217
217
}
218
- }
218
+ }
219
219
220
220
let mut initial_values = Vec :: new ( ) ;
221
221
let mut changed_values = Vec :: new ( ) ;
222
222
223
+ // Put the read proofs first:
224
+ if include_initial_values {
225
+ for entry in access_list. clone ( ) . 0 {
226
+ let AccessListItem {
227
+ address,
228
+ storage_keys,
229
+ } = entry;
230
+
231
+ let old = provider
232
+ . get_proof (
233
+ address,
234
+ storage_keys. clone ( ) ,
235
+ Some ( BlockId :: Number ( BlockNumber :: Number ( block_no - 1 ) ) ) ,
236
+ )
237
+ . await ?;
238
+
239
+ // Skip if the account doesn't exist in the old block.
240
+ if old. balance . is_zero ( ) && old. code_hash . is_zero ( )
241
+ && old. nonce . is_zero ( ) && old. storage_hash . is_zero ( )
242
+ {
243
+ continue ;
244
+ }
245
+
246
+ initial_values. push ( TrieModification :: balance ( address, old. balance ) ) ;
247
+ initial_values. push ( TrieModification :: nonce ( address, old. nonce ) ) ;
248
+ initial_values. push ( TrieModification :: codehash ( address, old. code_hash ) ) ;
249
+
250
+ for key in storage_keys. iter ( ) {
251
+ let old = old. storage_proof . iter ( ) . find ( |p| p. key == * key) . unwrap ( ) ;
252
+ if old. value == U256 :: zero ( ) {
253
+ initial_values. push ( TrieModification :: storage_does_not_exist (
254
+ address, * key, old. value ,
255
+ ) ) ;
256
+ } else {
257
+ initial_values. push ( TrieModification :: storage ( address, * key, old. value ) ) ;
258
+ }
259
+ }
260
+ }
261
+ }
262
+
223
263
for entry in access_list. 0 {
224
264
let AccessListItem {
225
265
address,
@@ -252,39 +292,33 @@ impl<F: Field> Witness<F> {
252
292
continue ;
253
293
}
254
294
255
- if include_initial_values {
256
- initial_values. push ( TrieModification :: balance ( address, old. balance ) ) ;
257
- initial_values. push ( TrieModification :: nonce ( address, old. nonce ) ) ;
258
- initial_values. push ( TrieModification :: codehash ( address, old. code_hash ) ) ;
259
-
260
- for key in storage_keys. iter ( ) {
261
- let old = old. storage_proof . iter ( ) . find ( |p| p. key == * key) . unwrap ( ) ;
262
- if old. value == U256 :: zero ( ) {
263
- initial_values. push ( TrieModification :: storage_does_not_exist (
264
- address, * key, old. value ,
265
- ) ) ;
266
- } else {
267
- initial_values. push ( TrieModification :: storage ( address, * key, old. value ) ) ;
268
- }
269
- }
270
- }
271
-
272
295
// check for this address changes
273
296
if old. nonce != new. nonce {
274
297
changed_values. push ( TrieModification :: nonce ( address, new. nonce ) ) ;
275
298
}
276
299
if old. balance != new. balance {
277
300
changed_values. push ( TrieModification :: balance ( address, new. balance ) ) ;
278
301
}
279
- if old . code_hash != new . code_hash
280
- // && new.code_hash != *DEFAULT_CODE_HASH
302
+
303
+ if old . code_hash != new . code_hash && new. code_hash != * DEFAULT_CODE_HASH
281
304
{
282
305
changed_values. push ( TrieModification :: codehash ( address, new. code_hash ) ) ;
283
306
}
284
307
285
308
for key in storage_keys {
286
309
let new = new. storage_proof . iter ( ) . find ( |p| p. key == key) . unwrap ( ) ;
287
310
changed_values. push ( TrieModification :: storage ( address, key, new. value ) ) ;
311
+
312
+ /*
313
+ let old = old.storage_proof.iter().find(|p| p.key == key).unwrap();
314
+ if old.value == U256::zero() && new.value == U256::zero() {
315
+ changed_values.push(TrieModification::storage_does_not_exist(
316
+ address, key, old.value,
317
+ ));
318
+ } else {
319
+ changed_values.push(TrieModification::storage(address, key, new.value));
320
+ }
321
+ */
288
322
}
289
323
}
290
324
0 commit comments