Skip to content

Commit

Permalink
Allow account with delegated code to be originator of transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Aug 2, 2024
1 parent 42e7fe2 commit 54a8831
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
13 changes: 6 additions & 7 deletions test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ evmc_message build_message(
.code = nullptr,
.code_size = 0};
}

constexpr bool is_code_delegated(bytes_view code) noexcept
{
return code.starts_with(DELEGATION_MAGIC);
}
} // namespace

Account& State::insert(const address& addr, Account account)
Expand Down Expand Up @@ -342,8 +347,7 @@ std::variant<int64_t, std::error_code> validate_transaction(const Account& sende
if (tx.max_gas_price < block.base_fee)
return make_error_code(FEE_CAP_LESS_THEN_BLOCKS);

// TODO this is relaxed for 7702
if (!sender_acc.code.empty())
if (!sender_acc.code.empty() && is_code_delegated(sender_acc.code))
return make_error_code(SENDER_NOT_EOA); // Origin must not be a contract (EIP-3607).

if (sender_acc.nonce == Account::NonceMax) // Nonce value limit (EIP-2681).
Expand Down Expand Up @@ -456,11 +460,6 @@ void finalize(State& state, evmc_revision rev, const address& coinbase,
delete_empty_accounts(state);
}

constexpr bool is_code_delegated(bytes_view code) noexcept
{
return code.starts_with(DELEGATION_MAGIC);
}

std::variant<TransactionReceipt, std::error_code> transition(State& state, const BlockInfo& block,
const Transaction& tx, evmc_revision rev, evmc::VM& vm, int64_t block_gas_left,
int64_t blob_gas_left)
Expand Down
18 changes: 10 additions & 8 deletions test/unittests/evm_eof_calls_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,12 @@ TEST_P(evm, extcall_new_account_creation_cost)
EXPECT_EQ(call_msg.value.bytes[31], 0);
EXPECT_EQ(call_msg.input_size, 0);
EXPECT_GAS_USED(EVMC_SUCCESS, gas_before_call + call_msg.gas + 3 + 3 + 3 + 3 + 3);
ASSERT_EQ(host.recorded_account_accesses.size(), 4);
ASSERT_EQ(host.recorded_account_accesses.size(), 5);
EXPECT_EQ(host.recorded_account_accesses[0], 0x00_address); // EIP-2929 tweak
EXPECT_EQ(host.recorded_account_accesses[1], msg.recipient); // EIP-2929 tweak
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // ?
EXPECT_EQ(host.recorded_account_accesses[3], call_dst); // Call.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // EIP-2929 warm up call_dst
EXPECT_EQ(host.recorded_account_accesses[3], call_dst); // EIP-7702 delegation check
EXPECT_EQ(host.recorded_account_accesses[4], call_dst); // Call.
host.recorded_account_accesses.clear();
host.recorded_calls.clear();
}
Expand All @@ -227,13 +228,14 @@ TEST_P(evm, extcall_new_account_creation_cost)
EXPECT_EQ(call_msg.value.bytes[31], 1);
EXPECT_EQ(call_msg.input_size, 0);
EXPECT_GAS_USED(EVMC_SUCCESS, gas_before_call + call_msg.gas + 3 + 3 + 3 + 3 + 3);
ASSERT_EQ(host.recorded_account_accesses.size(), 6);
ASSERT_EQ(host.recorded_account_accesses.size(), 7);
EXPECT_EQ(host.recorded_account_accesses[0], 0x00_address); // EIP-2929 tweak
EXPECT_EQ(host.recorded_account_accesses[1], msg.recipient); // EIP-2929 tweak
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // ?
EXPECT_EQ(host.recorded_account_accesses[3], call_dst); // Account exist?.
EXPECT_EQ(host.recorded_account_accesses[4], msg.recipient); // Balance.
EXPECT_EQ(host.recorded_account_accesses[5], call_dst); // Call.
EXPECT_EQ(host.recorded_account_accesses[2], call_dst); // EIP-2929 warm up call_dst
EXPECT_EQ(host.recorded_account_accesses[3], call_dst); // EIP-7702 delegation check
EXPECT_EQ(host.recorded_account_accesses[4], call_dst); // Account exist?.
EXPECT_EQ(host.recorded_account_accesses[5], msg.recipient); // Balance.
EXPECT_EQ(host.recorded_account_accesses[6], call_dst); // Call.
host.recorded_account_accesses.clear();
host.recorded_calls.clear();
}
Expand Down

0 comments on commit 54a8831

Please sign in to comment.