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

Make EXT*CALL ASE-ready #915

Merged
merged 1 commit into from
Jun 4, 2024
Merged
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
9 changes: 8 additions & 1 deletion lib/evmone/instructions_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Result extcall_impl(StackTop stack, int64_t gas_left, ExecutionState& state) noe
{
static_assert(Op == OP_EXTCALL || Op == OP_EXTDELEGATECALL || Op == OP_EXTSTATICCALL);

const auto dst = intx::be::trunc<evmc::address>(stack.pop());
const auto dst_u256 = stack.pop();
const auto input_offset_u256 = stack.pop();
const auto input_size_u256 = stack.pop();
const auto value = (Op == OP_EXTSTATICCALL || Op == OP_EXTDELEGATECALL) ? 0 : stack.pop();
Expand All @@ -165,6 +165,13 @@ Result extcall_impl(StackTop stack, int64_t gas_left, ExecutionState& state) noe
stack.push(EXTCALL_ABORT); // Assume (hard) failure.
state.return_data.clear();

// Address space expansion ready check.
static constexpr auto ADDRESS_MAX = (uint256{1} << 160) - 1;
if (dst_u256 > ADDRESS_MAX)
return {EVMC_ARGUMENT_OUT_OF_RANGE, gas_left};

const auto dst = intx::be::trunc<evmc::address>(dst_u256);

if (state.host.access_account(dst) == EVMC_ACCESS_COLD)
{
if ((gas_left -= instr::additional_cold_account_access_cost) < 0)
Expand Down
45 changes: 45 additions & 0 deletions test/unittests/state_transition_eof_calls_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,51 @@ TEST_F(state_transition, extstaticcall_memory)
expect.status = EVMC_OUT_OF_GAS;
}

TEST_F(state_transition, extcall_ase_ready_violation)
{
rev = EVMC_PRAGUE;
constexpr auto callee =
0x0000000000000000000000010000000000000000000000000000000000000000_bytes32;

tx.to = To;
pre.insert(*tx.to, {
.code = eof_bytecode(extcall(callee) + OP_STOP, 4),
});
expect.gas_used = tx.gas_limit;
expect.post[*tx.to].exists = true;
expect.status = EVMC_ARGUMENT_OUT_OF_RANGE;
}

TEST_F(state_transition, extdelegatecall_ase_ready_violation)
{
rev = EVMC_PRAGUE;
constexpr auto callee =
0x0000000000000000000000010000000000000000000000000000000000000000_bytes32;

tx.to = To;
pre.insert(*tx.to, {
.code = eof_bytecode(extdelegatecall(callee) + OP_STOP, 3),
});
expect.gas_used = tx.gas_limit;
expect.post[*tx.to].exists = true;
expect.status = EVMC_ARGUMENT_OUT_OF_RANGE;
}

TEST_F(state_transition, extstaticcall_ase_ready_violation)
{
rev = EVMC_PRAGUE;
constexpr auto callee =
0x0000000000000000000000010000000000000000000000000000000000000000_bytes32;

tx.to = To;
pre.insert(*tx.to, {
.code = eof_bytecode(extstaticcall(callee) + OP_STOP, 3),
});
expect.gas_used = tx.gas_limit;
expect.post[*tx.to].exists = true;
expect.status = EVMC_ARGUMENT_OUT_OF_RANGE;
}

TEST_F(state_transition, extcall_cold_oog)
{
rev = EVMC_PRAGUE;
Expand Down