Skip to content

Commit

Permalink
eof: Return constant hash of EXTCODEHASH of EOF
Browse files Browse the repository at this point in the history
Replace runtime evaluated `keccak256("EF00")` with a constant returned
for an account with EOF code.
  • Loading branch information
chfast committed Sep 27, 2024
1 parent 2cd8bf7 commit 0fa90c6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,18 @@ size_t Host::get_code_size(const address& addr) const noexcept

bytes32 Host::get_code_hash(const address& addr) const noexcept
{
// TODO: Cache code hash. It will be needed also to compute the MPT hash.
/// The value returned by EXTCODEHASH of an address with EOF code.
/// See EIP-3540: https://eips.ethereum.org/EIPS/eip-3540#changes-to-execution-semantics.
static constexpr auto EOF_CODE_HASH_SENTINEL =
0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5_bytes32;

const auto* const acc = m_state.find(addr);
return (acc != nullptr && !acc->is_empty()) ? keccak256(extcode(acc->code)) : bytes32{};
if (acc == nullptr || acc->is_empty())
return bytes32{};
if (is_eof_container(acc->code))
return EOF_CODE_HASH_SENTINEL;
// TODO: Cache code hash. It will be needed also to compute the MPT hash.
return keccak256(acc->code);
}

size_t Host::copy_code(const address& addr, size_t code_offset, uint8_t* buffer_data,
Expand Down

0 comments on commit 0fa90c6

Please sign in to comment.