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

EIP-3855: PUSH0 instruction #432

Merged
merged 1 commit into from
Mar 21, 2022
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
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);
}