Skip to content

Commit cb3a38e

Browse files
committed
Add PUSH0 instruction implementation
1 parent de8c83c commit cb3a38e

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

lib/evmone/instructions.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,11 @@ inline void gas(StackTop stack, ExecutionState& state) noexcept
781781
stack.push(state.gas_left);
782782
}
783783

784+
inline void push0(StackTop stack) noexcept
785+
{
786+
stack.push({});
787+
}
788+
784789

785790
template <size_t Len>
786791
inline uint64_t load_partial_push_data(code_iterator pos) noexcept

lib/evmone/instructions_xmacro.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
X(OP_MSIZE, msize) \
6969
X(OP_GAS, gas) \
7070
X(OP_JUMPDEST, jumpdest) \
71+
X(OP_PUSH0, push0) \
7172
X(OP_PUSH1, push<1>) \
7273
X(OP_PUSH2, push<2>) \
7374
X(OP_PUSH3, push<3>) \

test/unittests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ add_executable(evmone-unittests
1515
evm_calls_test.cpp
1616
evm_eip2929_test.cpp
1717
evm_eip3198_basefee_test.cpp
18+
evm_eip3855_push0_test.cpp
1819
evm_memory_test.cpp
1920
evm_state_test.cpp
2021
evm_other_test.cpp
+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// evmone: Fast Ethereum Virtual Machine implementation
2+
// Copyright 2022 The evmone Authors.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
/// This file contains EVM unit tests for EIP-3855 "PUSH0 instruction"
6+
/// https://eips.ethereum.org/EIPS/eip-3855
7+
8+
#include "evm_fixture.hpp"
9+
10+
using namespace evmc::literals;
11+
using evmone::test::evm;
12+
13+
TEST_P(evm, push0_pre_shanghai)
14+
{
15+
rev = EVMC_PARIS;
16+
const auto code = bytecode{OP_PUSH0};
17+
18+
execute(code);
19+
EXPECT_STATUS(EVMC_UNDEFINED_INSTRUCTION);
20+
}
21+
22+
TEST_P(evm, push0)
23+
{
24+
rev = EVMC_SHANGHAI;
25+
execute(OP_PUSH0 + ret_top());
26+
EXPECT_GAS_USED(EVMC_SUCCESS, 17);
27+
EXPECT_OUTPUT_INT(0);
28+
}
29+
30+
TEST_P(evm, push0_return_empty)
31+
{
32+
rev = EVMC_SHANGHAI;
33+
execute(bytecode{} + OP_PUSH0 + OP_PUSH0 + OP_RETURN);
34+
EXPECT_GAS_USED(EVMC_SUCCESS, 4);
35+
EXPECT_EQ(result.output_size, 0);
36+
}
37+
38+
TEST_P(evm, push0_full_stack)
39+
{
40+
rev = EVMC_SHANGHAI;
41+
execute(1024 * bytecode{OP_PUSH0});
42+
EXPECT_GAS_USED(EVMC_SUCCESS, 1024 * 2);
43+
}
44+
45+
TEST_P(evm, push0_stack_overflow)
46+
{
47+
rev = EVMC_SHANGHAI;
48+
execute(1025 * bytecode{OP_PUSH0});
49+
EXPECT_STATUS(EVMC_STACK_OVERFLOW);
50+
}

0 commit comments

Comments
 (0)