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

Commit

Permalink
reapplying changes from PR #1724
Browse files Browse the repository at this point in the history
  • Loading branch information
miha-stopar committed Feb 9, 2024
1 parent dd04ccc commit 39a8743
Showing 1 changed file with 54 additions and 20 deletions.
74 changes: 54 additions & 20 deletions bin/mpt-test/src/circuit/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,51 @@ impl<F: Field> Witness<F> {
storage_keys: Vec::new(),
});
}
}
}

let mut initial_values = Vec::new();
let mut changed_values = Vec::new();

// Put the read proofs first:
if include_initial_values {
for entry in access_list.clone().0 {
let AccessListItem {
address,
storage_keys,
} = entry;

let old = provider
.get_proof(
address,
storage_keys.clone(),
Some(BlockId::Number(BlockNumber::Number(block_no - 1))),
)
.await?;

// Skip if the account doesn't exist in the old block.
if old.balance.is_zero() && old.code_hash.is_zero()
&& old.nonce.is_zero() && old.storage_hash.is_zero()
{
continue;
}

initial_values.push(TrieModification::balance(address, old.balance));
initial_values.push(TrieModification::nonce(address, old.nonce));
initial_values.push(TrieModification::codehash(address, old.code_hash));

for key in storage_keys.iter() {
let old = old.storage_proof.iter().find(|p| p.key == *key).unwrap();
if old.value == U256::zero() {
initial_values.push(TrieModification::storage_does_not_exist(
address, *key, old.value,
));
} else {
initial_values.push(TrieModification::storage(address, *key, old.value));
}
}
}
}

for entry in access_list.0 {
let AccessListItem {
address,
Expand Down Expand Up @@ -252,39 +292,33 @@ impl<F: Field> Witness<F> {
continue;
}

if include_initial_values {
initial_values.push(TrieModification::balance(address, old.balance));
initial_values.push(TrieModification::nonce(address, old.nonce));
initial_values.push(TrieModification::codehash(address, old.code_hash));

for key in storage_keys.iter() {
let old = old.storage_proof.iter().find(|p| p.key == *key).unwrap();
if old.value == U256::zero() {
initial_values.push(TrieModification::storage_does_not_exist(
address, *key, old.value,
));
} else {
initial_values.push(TrieModification::storage(address, *key, old.value));
}
}
}

// check for this address changes
if old.nonce != new.nonce {
changed_values.push(TrieModification::nonce(address, new.nonce));
}
if old.balance != new.balance {
changed_values.push(TrieModification::balance(address, new.balance));
}
if old.code_hash != new.code_hash
// && new.code_hash != *DEFAULT_CODE_HASH

if old.code_hash != new.code_hash && new.code_hash != *DEFAULT_CODE_HASH
{
changed_values.push(TrieModification::codehash(address, new.code_hash));
}

for key in storage_keys {
let new = new.storage_proof.iter().find(|p| p.key == key).unwrap();
changed_values.push(TrieModification::storage(address, key, new.value));

/*
let old = old.storage_proof.iter().find(|p| p.key == key).unwrap();
if old.value == U256::zero() && new.value == U256::zero() {
changed_values.push(TrieModification::storage_does_not_exist(
address, key, old.value,
));
} else {
changed_values.push(TrieModification::storage(address, key, new.value));
}
*/
}
}

Expand Down

0 comments on commit 39a8743

Please sign in to comment.