Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment transaction sender's nonce before entering execution frame #1021

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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