From e8fcef7f3018126bf1c7adb18fd4b88eae803ea5 Mon Sep 17 00:00:00 2001 From: rodiazet Date: Mon, 4 Sep 2023 16:19:49 +0200 Subject: [PATCH] Clear empty accounts after each tx and in the end of block processing --- test/state/state.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/test/state/state.cpp b/test/state/state.cpp index 8f0ddf8b29..52682ca753 100644 --- a/test/state/state.cpp +++ b/test/state/state.cpp @@ -135,6 +135,17 @@ std::variant validate_transaction(const Account& sende return execution_gas_limit; } +namespace +{ +void clear_empty_accounts(State& state) +{ + std::erase_if(state.get_accounts(), [](const std::pair& p) noexcept { + const auto& acc = p.second; + return acc.erasable && acc.is_empty(); + }); +} +} // namespace + void finalize(State& state, evmc_revision rev, const address& coinbase, std::optional block_reward, std::span ommers, std::span withdrawals) @@ -158,14 +169,9 @@ void finalize(State& state, evmc_revision rev, const address& coinbase, for (const auto& withdrawal : withdrawals) state.touch(withdrawal.recipient).balance += withdrawal.get_amount(); + // Empty accounts need to be clear because is 'block_reward' coinbase should be removed. if (rev >= EVMC_SPURIOUS_DRAGON) - { - std::erase_if( - state.get_accounts(), [](const std::pair& p) noexcept { - const auto& acc = p.second; - return acc.erasable && acc.is_empty(); - }); - } + clear_empty_accounts(state); } std::variant transition(State& state, const BlockInfo& block, @@ -241,6 +247,11 @@ std::variant transition(State& state, const // Cannot put it into constructor call because logs are std::moved from host instance. receipt.logs_bloom_filter = compute_bloom_filter(receipt.logs); + // Empty accounts need to be cleared here to properly calculate post state hash which is a part + // of the receipt pre Byzantium + if (rev >= EVMC_SPURIOUS_DRAGON) + clear_empty_accounts(state); + // Set accounts and their storage access status to cold in the end of transition process for (auto& acc : state.get_accounts()) {