Skip to content

Commit

Permalink
test: Add test for nonce bump in case of invalid EOF initcode
Browse files Browse the repository at this point in the history
  • Loading branch information
chfast committed Apr 12, 2023
1 parent 78960ff commit 7d61b6d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/unittests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ target_sources(
state_rlp_test.cpp
state_transition.hpp
state_transition.cpp
state_transition_create_test.cpp
statetest_loader_block_info_test.cpp
statetest_loader_test.cpp
statetest_loader_tx_test.cpp
Expand Down
43 changes: 43 additions & 0 deletions test/unittests/state_transition_create_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2023 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0

#include "../utils/bytecode.hpp"
#include "state_transition.hpp"

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

TEST_F(state_transition, create2_factory)
{
static constexpr auto create_address = 0xfd8e7707356349027a32d71eabc7cb0cf9d7cbb4_address;

const auto factory_code = calldatacopy() + create2().input(0, calldatasize());
const auto initcode = mstore8(0, push(0xFE)) + ret(0, 1);

pre.get(*tx.to).code = factory_code;
tx.data = initcode;
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // CREATE caller's nonce must be bumped
expect.post[create_address].code = bytes{0xFE};
}

TEST_F(state_transition, eof_invalid_initcode)
{
// TODO: Correction of this address is not verified.
static constexpr auto create_address = 0x864bbda5c698ac34b47a9ea3bd4228802cc5ce3b_address;

pre.get(*tx.to).code = eof1_bytecode(create() + push(1) + OP_SSTORE + OP_STOP, 3);
pre.get(*tx.to).storage[0x01_bytes32] = {.current = 0x01_bytes32, .original = 0x01_bytes32};

EXPECT_EQ(pre.get(tx.sender).balance, 1000000'001);

expect.gas_used = 985407;

expect.post[tx.sender].nonce = pre.get(tx.sender).nonce + 1;
expect.post[tx.sender].balance =
pre.get(tx.sender).balance -
(block.base_fee + tx.max_priority_gas_price) * static_cast<uint64_t>(*expect.gas_used);
expect.post[*tx.to].nonce = pre.get(*tx.to).nonce + 1; // CREATE caller's nonce must be bumped
expect.post[*tx.to].storage[0x01_bytes32] = 0x00_bytes32; // CREATE must fail
expect.post[create_address].exists = false;
}

0 comments on commit 7d61b6d

Please sign in to comment.