Skip to content

Commit

Permalink
Merge pull request #432 from ethereum/push0
Browse files Browse the repository at this point in the history
EIP-3855: PUSH0 instruction
  • Loading branch information
chfast authored Mar 21, 2022
2 parents de8c83c + cb3a38e commit 0e11c21
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/evmone/instructions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,6 +781,11 @@ inline void gas(StackTop stack, ExecutionState& state) noexcept
stack.push(state.gas_left);
}

inline void push0(StackTop stack) noexcept
{
stack.push({});
}


template <size_t Len>
inline uint64_t load_partial_push_data(code_iterator pos) noexcept
Expand Down
1 change: 1 addition & 0 deletions lib/evmone/instructions_xmacro.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
X(OP_MSIZE, msize) \
X(OP_GAS, gas) \
X(OP_JUMPDEST, jumpdest) \
X(OP_PUSH0, push0) \
X(OP_PUSH1, push<1>) \
X(OP_PUSH2, push<2>) \
X(OP_PUSH3, push<3>) \
Expand Down
1 change: 1 addition & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ add_executable(evmone-unittests
evm_calls_test.cpp
evm_eip2929_test.cpp
evm_eip3198_basefee_test.cpp
evm_eip3855_push0_test.cpp
evm_memory_test.cpp
evm_state_test.cpp
evm_other_test.cpp
Expand Down
50 changes: 50 additions & 0 deletions test/unittests/evm_eip3855_push0_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2022 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

/// This file contains EVM unit tests for EIP-3855 "PUSH0 instruction"
/// https://eips.ethereum.org/EIPS/eip-3855

#include "evm_fixture.hpp"

using namespace evmc::literals;
using evmone::test::evm;

TEST_P(evm, push0_pre_shanghai)
{
rev = EVMC_PARIS;
const auto code = bytecode{OP_PUSH0};

execute(code);
EXPECT_STATUS(EVMC_UNDEFINED_INSTRUCTION);
}

TEST_P(evm, push0)
{
rev = EVMC_SHANGHAI;
execute(OP_PUSH0 + ret_top());
EXPECT_GAS_USED(EVMC_SUCCESS, 17);
EXPECT_OUTPUT_INT(0);
}

TEST_P(evm, push0_return_empty)
{
rev = EVMC_SHANGHAI;
execute(bytecode{} + OP_PUSH0 + OP_PUSH0 + OP_RETURN);
EXPECT_GAS_USED(EVMC_SUCCESS, 4);
EXPECT_EQ(result.output_size, 0);
}

TEST_P(evm, push0_full_stack)
{
rev = EVMC_SHANGHAI;
execute(1024 * bytecode{OP_PUSH0});
EXPECT_GAS_USED(EVMC_SUCCESS, 1024 * 2);
}

TEST_P(evm, push0_stack_overflow)
{
rev = EVMC_SHANGHAI;
execute(1025 * bytecode{OP_PUSH0});
EXPECT_STATUS(EVMC_STACK_OVERFLOW);
}

0 comments on commit 0e11c21

Please sign in to comment.