Skip to content

Commit

Permalink
state: Fix processing withdrawals of 0 (#670)
Browse files Browse the repository at this point in the history
The withdrawals should be processed before state clearing
so the empty accounts touched with 0 value withdrawals
are also cleared from the state.
  • Loading branch information
chfast authored Jul 8, 2023
1 parent 9399750 commit 606ba82
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,13 @@ evmc_message build_message(const Transaction& tx, int64_t execution_gas_limit) n
void finalize(State& state, evmc_revision rev, const address& coinbase,
std::optional<uint64_t> block_reward, std::span<Withdrawal> withdrawals)
{
// TODO: The block reward can be represented as a withdrawal.
if (block_reward.has_value())
state.touch(coinbase).balance += *block_reward;

for (const auto& withdrawal : withdrawals)
state.touch(withdrawal.recipient).balance += withdrawal.get_amount();

if (rev >= EVMC_SPURIOUS_DRAGON)
{
std::erase_if(
Expand All @@ -131,9 +135,6 @@ void finalize(State& state, evmc_revision rev, const address& coinbase,
return acc.erasable && acc.is_empty();
});
}

for (const auto& withdrawal : withdrawals)
state.touch(withdrawal.recipient).balance += withdrawal.get_amount();
}

std::variant<TransactionReceipt, std::error_code> transition(
Expand Down

0 comments on commit 606ba82

Please sign in to comment.