-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for nonce bump in case of invalid EOF initcode
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |