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
  • Loading branch information
gumb0 committed Sep 19, 2024
1 parent 4a3cb41 commit e54f990
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 8 additions & 3 deletions test/state/host.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,16 +208,21 @@ std::optional<evmc_message> Host::prepare_message(evmc_message msg) noexcept
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 +261,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 e54f990

Please sign in to comment.