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

Commit

Permalink
Curr/next change state failures resolved
Browse files Browse the repository at this point in the history
  • Loading branch information
miha-stopar committed Jan 24, 2024
1 parent e161d91 commit 835d71b
Showing 1 changed file with 45 additions and 21 deletions.
66 changes: 45 additions & 21 deletions light-client-poc/src/witness/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,46 @@ impl<F: Field> Witness<F> {
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 = client
.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 @@ -246,33 +286,17 @@ 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 the account has been implicitly created before this code_hash modification
// and if this code_hash modification sets it to the default value (which have been
// already set implicitly), omit it.

// Prevent state change constraint failure (if there was a change in the previous
// row, it has to be in the next too) when the account has been created by nonce or
// balance modification and the codehash has been set to the default value already then.
let default_code_hash = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470";
let is_default = new.code_hash == H256::from_str(default_code_hash).unwrap();

Check failure on line 301 in light-client-poc/src/witness/mod.rs

View workflow job for this annotation

GitHub Actions / Various lints

no function or associated item named `from_str` found for struct `H256` in the current scope

Check failure on line 301 in light-client-poc/src/witness/mod.rs

View workflow job for this annotation

GitHub Actions / Linux Build

no function or associated item named `from_str` found for struct `H256` in the current scope

Check failure on line 301 in light-client-poc/src/witness/mod.rs

View workflow job for this annotation

GitHub Actions / Heavy unit tests

no function or associated item named `from_str` found for struct `H256` in the current scope

Check failure on line 301 in light-client-poc/src/witness/mod.rs

View workflow job for this annotation

GitHub Actions / Light unit tests

no function or associated item named `from_str` found for struct `H256` in the current scope
if old.code_hash != new.code_hash && !is_default {
Expand All @@ -283,7 +307,7 @@ impl<F: Field> Witness<F> {
let new = new.storage_proof.iter().find(|p| p.key == key).unwrap();
changed_values.push(TrieModification::storage(address, key, new.value));
}
}
}

println!("initial_values.len(): {}", initial_values.len());
println!("changed_values.len(): {}", changed_values.len());
Expand Down

0 comments on commit 835d71b

Please sign in to comment.