Skip to content
This repository was archived by the owner on Jul 5, 2024. It is now read-only.

Commit 39a8743

Browse files
committed
reapplying changes from PR #1724
1 parent dd04ccc commit 39a8743

File tree

1 file changed

+54
-20
lines changed

1 file changed

+54
-20
lines changed

bin/mpt-test/src/circuit/witness.rs

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,51 @@ impl<F: Field> Witness<F> {
215215
storage_keys: Vec::new(),
216216
});
217217
}
218-
}
218+
}
219219

220220
let mut initial_values = Vec::new();
221221
let mut changed_values = Vec::new();
222222

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+
223263
for entry in access_list.0 {
224264
let AccessListItem {
225265
address,
@@ -252,39 +292,33 @@ impl<F: Field> Witness<F> {
252292
continue;
253293
}
254294

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-
272295
// check for this address changes
273296
if old.nonce != new.nonce {
274297
changed_values.push(TrieModification::nonce(address, new.nonce));
275298
}
276299
if old.balance != new.balance {
277300
changed_values.push(TrieModification::balance(address, new.balance));
278301
}
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
281304
{
282305
changed_values.push(TrieModification::codehash(address, new.code_hash));
283306
}
284307

285308
for key in storage_keys {
286309
let new = new.storage_proof.iter().find(|p| p.key == key).unwrap();
287310
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+
*/
288322
}
289323
}
290324

0 commit comments

Comments
 (0)