From ba4cfb98c21ebd6165fffbd6b946192dcd66dff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Fri, 24 Jan 2025 15:38:34 +0100 Subject: [PATCH] state: Simplify code modification indicator in StateDiff --- test/state/state.cpp | 3 +-- test/state/state_diff.hpp | 7 ++----- test/state/test_state.cpp | 6 ++---- 3 files changed, 5 insertions(+), 11 deletions(-) diff --git a/test/state/state.cpp b/test/state/state.cpp index 619c8ae20e..4038a84015 100644 --- a/test/state/state.cpp +++ b/test/state/state.cpp @@ -142,10 +142,9 @@ StateDiff State::build_diff(evmc_revision rev) const // Output only the new code. // TODO: Output also the code hash. It will be needed for DB update and MPT hash. + // TODO: Only use "code_changed" flag to indicate the code change. if ((m.just_created && !m.code.empty()) || m.code_changed) a.code = m.code; - if (m.code_changed && m.code.empty()) - a.code_cleared = true; for (const auto& [k, v] : m.storage) { diff --git a/test/state/state_diff.hpp b/test/state/state_diff.hpp index 29af3f4209..4268804753 100644 --- a/test/state/state_diff.hpp +++ b/test/state/state_diff.hpp @@ -30,11 +30,8 @@ struct StateDiff /// TODO: Currently it is not guaranteed the value is different from the initial one. uint256 balance; - /// New account code. If empty, it means the code has not changed. - bytes code; - - /// If true, account code was emptied due to resetting EIP-7702 delegation. - bool code_cleared = false; + /// New or modified account code. If bytes are empty, it means the code has been cleared. + std::optional code; /// The list of the account's storage modifications: key => new value. /// The value 0 means the storage entry is deleted. diff --git a/test/state/test_state.cpp b/test/state/test_state.cpp index 060e106be8..fc83008422 100644 --- a/test/state/test_state.cpp +++ b/test/state/test_state.cpp @@ -34,10 +34,8 @@ void TestState::apply(const state::StateDiff& diff) auto& a = (*this)[m.addr]; a.nonce = m.nonce; a.balance = m.balance; - if (!m.code.empty()) - a.code = m.code; // TODO: Consider taking rvalue ref to avoid code copy. - if (m.code_cleared) - a.code.clear(); + if (m.code.has_value()) + a.code = *m.code; // TODO: Consider taking rvalue ref to avoid code copy. for (const auto& [k, v] : m.modified_storage) { if (v)