Skip to content

Commit 606ba82

Browse files
authored
state: Fix processing withdrawals of 0 (#670)
The withdrawals should be processed before state clearing so the empty accounts touched with 0 value withdrawals are also cleared from the state.
1 parent 9399750 commit 606ba82

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

test/state/state.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,13 @@ evmc_message build_message(const Transaction& tx, int64_t execution_gas_limit) n
120120
void finalize(State& state, evmc_revision rev, const address& coinbase,
121121
std::optional<uint64_t> block_reward, std::span<Withdrawal> withdrawals)
122122
{
123+
// TODO: The block reward can be represented as a withdrawal.
123124
if (block_reward.has_value())
124125
state.touch(coinbase).balance += *block_reward;
125126

127+
for (const auto& withdrawal : withdrawals)
128+
state.touch(withdrawal.recipient).balance += withdrawal.get_amount();
129+
126130
if (rev >= EVMC_SPURIOUS_DRAGON)
127131
{
128132
std::erase_if(
@@ -131,9 +135,6 @@ void finalize(State& state, evmc_revision rev, const address& coinbase,
131135
return acc.erasable && acc.is_empty();
132136
});
133137
}
134-
135-
for (const auto& withdrawal : withdrawals)
136-
state.touch(withdrawal.recipient).balance += withdrawal.get_amount();
137138
}
138139

139140
std::variant<TransactionReceipt, std::error_code> transition(

0 commit comments

Comments
 (0)