Skip to content

Commit

Permalink
EIP-3860: Limit and meter initcode
Browse files Browse the repository at this point in the history
  • Loading branch information
yperbasis committed Dec 7, 2022
1 parent 6d03f5d commit ed8a85d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lib/evmone/instructions_calls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,30 @@ evmc_status_code create_impl(StackTop stack, ExecutionState& state) noexcept
if (!check_memory(state, init_code_offset, init_code_size))
return EVMC_OUT_OF_GAS;

const auto init_code_words = num_words(static_cast<size_t>(init_code_size));

auto salt = uint256{};
if constexpr (Op == OP_CREATE2)
{
salt = stack.pop();
auto salt_cost = num_words(static_cast<size_t>(init_code_size)) * 6;
const auto salt_cost = init_code_words * 6;
if ((state.gas_left -= salt_cost) < 0)
return EVMC_OUT_OF_GAS;
}

stack.push(0);
state.return_data.clear();

if (state.rev >= EVMC_SHANGHAI)
{
if (init_code_size > 0xC000)
return EVMC_SUCCESS;

const auto init_code_cost = init_code_words * 2;
if ((state.gas_left -= init_code_cost) < 0)
return EVMC_OUT_OF_GAS;
}

if (state.msg->depth >= 1024)
return EVMC_SUCCESS;

Expand Down

0 comments on commit ed8a85d

Please sign in to comment.