Skip to content

Commit

Permalink
Increment transaction sender's nonce before entering execution frame (#…
Browse files Browse the repository at this point in the history
…1021)

This is required for [EIP-7702
implementation](#961), because
there the sender's nonce must be bumped before processing transaction's
Authorization List.
  • Loading branch information
gumb0 authored Sep 20, 2024
1 parent 4a3cb41 commit bae4933
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,27 @@ std::optional<evmc_message> Host::prepare_message(evmc_message msg) noexcept
msg.kind == EVMC_EOFCREATE)
{
auto& sender_acc = m_state.get(msg.sender);
const auto sender_nonce = sender_acc.nonce;

// EIP-2681 (already checked for depth 0 during transaction validation).
if (sender_nonce == Account::NonceMax)
if (sender_acc.nonce == Account::NonceMax)
return {}; // Light early exception.

if (msg.depth != 0)
{
m_state.journal_bump_nonce(msg.sender);
++sender_acc.nonce; // Bump sender nonce.
++sender_acc.nonce; // Bump sender nonce.
}

if (msg.kind == EVMC_CREATE || msg.kind == EVMC_CREATE2 || msg.kind == EVMC_EOFCREATE)
{
// Compute and set the address of the account being created.
assert(msg.recipient == address{});
assert(msg.code_address == address{});
// Nonce was already incremented, but creation calculation needs non-incremented value
assert(sender_acc.nonce != 0);
const auto creation_sender_nonce = sender_acc.nonce - 1;
if (msg.kind == EVMC_CREATE)
msg.recipient = compute_create_address(msg.sender, sender_nonce);
msg.recipient = compute_create_address(msg.sender, creation_sender_nonce);
else if (msg.kind == EVMC_CREATE2)
{
msg.recipient = compute_create2_address(
Expand Down Expand Up @@ -256,7 +260,7 @@ std::optional<evmc_message> Host::prepare_message(evmc_message msg) noexcept
EOFValidationError::success)
return {}; // Light early exception.

msg.recipient = compute_create_address(msg.sender, sender_nonce);
msg.recipient = compute_create_address(msg.sender, creation_sender_nonce);
}
// EOFCREATE
else
Expand Down
3 changes: 3 additions & 0 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,9 @@ std::variant<TransactionReceipt, std::error_code> transition(State& state, const
// The account won't be empty because its nonce will be bumped.
auto& sender_acc = (sender_ptr != nullptr) ? *sender_ptr : state.insert(tx.sender);

assert(sender_acc.nonce < Account::NonceMax); // Checked in transaction validation
++sender_acc.nonce; // Bump sender nonce.

const auto execution_gas_limit = get<int64_t>(validation_result);

const auto base_fee = (rev >= EVMC_LONDON) ? block.base_fee : 0;
Expand Down

0 comments on commit bae4933

Please sign in to comment.