Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify withdrawals logic #168

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- fix(keccak-sponge): properly constrain padding bytes ([#158](https://github.com/0xPolygonZero/zk_evm/pull/158))
- Reduce verbosity in logs ([#160](https://github.com/0xPolygonZero/zk_evm/pull/160))
- Bump with latest starky ([#161](https://github.com/0xPolygonZero/zk_evm/pull/161))
- Simplify withdrawals logic ([#168](https://github.com/0xPolygonZero/zk_evm/pull/168))

## [0.3.0] - 2024-04-03

Expand Down
52 changes: 10 additions & 42 deletions trace_decoder/src/decoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,11 +225,8 @@ impl ProcessedBlockTrace {
if !self.withdrawals.is_empty() {
Self::add_withdrawals_to_txns(
&mut txn_gen_inputs,
&other_data,
&extra_data,
&mut curr_block_tries,
self.withdrawals,
dummies_added,
)?;
}

Expand Down Expand Up @@ -504,56 +501,27 @@ impl ProcessedBlockTrace {
/// - If no dummy proofs are already present, then a dummy proof that just
/// contains the withdrawals is appended to the end of the IR vec.
fn add_withdrawals_to_txns(
txn_ir: &mut Vec<GenerationInputs>,
other_data: &OtherBlockData,
extra_data: &ExtraBlockData,
txn_ir: &mut [GenerationInputs],
final_trie_state: &mut PartialTrieState,
withdrawals: Vec<(Address, U256)>,
dummies_already_added: bool,
) -> TraceParsingResult<()> {
let withdrawals_with_hashed_addrs_iter = || {
withdrawals
.iter()
.map(|(addr, v)| (*addr, hash(addr.as_bytes()), *v))
};

match dummies_already_added {
// If we have no actual dummy proofs, then we create one and append it to the
// end of the block.
false => {
let withdrawal_addrs =
withdrawals_with_hashed_addrs_iter().map(|(_, h_addr, _)| h_addr);
let mut withdrawal_dummy = create_dummy_gen_input_with_state_addrs_accessed(
other_data,
extra_data,
final_trie_state,
withdrawal_addrs,
)?;

Self::update_trie_state_from_withdrawals(
withdrawals_with_hashed_addrs_iter(),
&mut final_trie_state.state,
)?;

withdrawal_dummy.withdrawals = withdrawals;

// Only the state root hash needs to be updated from the withdrawals.
withdrawal_dummy.trie_roots_after.state_root = final_trie_state.state.hash();
Self::update_trie_state_from_withdrawals(
withdrawals_with_hashed_addrs_iter(),
&mut final_trie_state.state,
)?;

txn_ir.push(withdrawal_dummy);
}
true => {
Self::update_trie_state_from_withdrawals(
withdrawals_with_hashed_addrs_iter(),
&mut final_trie_state.state,
)?;
let last_inputs = txn_ir
.last_mut()
.expect("We cannot have an empty list of payloads.");

// If we have dummy proofs (note: `txn_ir[1]` is always a dummy txn in this
// case), then this dummy will get the withdrawals.
txn_ir[1].withdrawals = withdrawals;
txn_ir[1].trie_roots_after.state_root = final_trie_state.state.hash();
}
}
last_inputs.withdrawals = withdrawals;
last_inputs.trie_roots_after.state_root = final_trie_state.state.hash();

Ok(())
}
Expand Down