Skip to content

Commit

Permalink
Make EXT*CALL ASE-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
pdobacz committed Jun 4, 2024
1 parent 8c3dd4f commit 99e2a46
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
8 changes: 7 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,12 @@ 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.
if (dst_u256 > (uint256{1} << 160) - 1)
return {EVMC_OUT_OF_GAS, 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_OUT_OF_GAS;
}

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_OUT_OF_GAS;
}

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_OUT_OF_GAS;
}

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

0 comments on commit 99e2a46

Please sign in to comment.