Skip to content

Commit fa6226c

Browse files
committed
eof: Remove support for EOF Creation Transaction
1 parent da95f45 commit fa6226c

File tree

7 files changed

+35
-438
lines changed

7 files changed

+35
-438
lines changed

lib/evmone/eof.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ enum class EOFValidationError
192192

193193
enum class ContainerKind : uint8_t
194194
{
195-
/// Container that uses RETURNCODE. Can be used by EOFCREATE/TXCREATE/Creation transaction.
195+
/// Container that uses RETURNCODE. Can be used by EOFCREATE/TXCREATE.
196196
initcode,
197197
/// Container that uses STOP/RETURN. Can be returned by RETURNCODE.
198198
runtime,

test/state/errors.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ enum ErrorCode : int
2828
EMPTY_BLOB_HASHES_LIST,
2929
INVALID_BLOB_HASH_VERSION,
3030
BLOB_GAS_LIMIT_EXCEEDED,
31+
EOF_CREATION_TRANSACTION,
3132
CREATE_SET_CODE_TX,
3233
EMPTY_AUTHORIZATION_LIST,
3334
INIT_CODE_EMPTY,
@@ -81,6 +82,8 @@ inline const std::error_category& evmone_category() noexcept
8182
return "invalid blob hash version";
8283
case BLOB_GAS_LIMIT_EXCEEDED:
8384
return "blob gas limit exceeded";
85+
case EOF_CREATION_TRANSACTION:
86+
return "EOF initcode in creation transaction";
8487
case CREATE_SET_CODE_TX:
8588
return "set code transaction must not be a create transaction";
8689
case EMPTY_AUTHORIZATION_LIST:

test/state/host.cpp

+3-36
Original file line numberDiff line numberDiff line change
@@ -277,42 +277,9 @@ std::optional<evmc_message> Host::prepare_message(evmc_message msg) noexcept
277277
}
278278
else
279279
{
280-
assert(msg.kind == EVMC_EOFCREATE);
281-
const bytes_view input = {msg.input_data, msg.input_size};
282-
283-
// Indicator of an EOF creation tx - EVMC_EOFCREATE at depth 0.
284-
if (msg.depth == 0)
285-
{
286-
// Assert this is a legacy EOF creation tx.
287-
assert(is_eof_container(input));
288-
const auto header_or_error = validate_header(m_rev, input);
289-
290-
const auto* header = std::get_if<EOF1Header>(&header_or_error);
291-
if (header == nullptr)
292-
return {}; // Light early exception.
293-
294-
if (!header->has_full_data(msg.input_size))
295-
return {}; // Light early exception.
296-
297-
const auto container_size =
298-
static_cast<size_t>(header->data_offset + header->data_size);
299-
// Follows from the header->can_init condition above.
300-
assert(container_size <= msg.input_size);
301-
302-
msg.code = msg.input_data;
303-
msg.code_size = container_size;
304-
msg.input_data = msg.input_data + container_size;
305-
msg.input_size = msg.input_size - container_size;
306-
307-
if (validate_eof(m_rev, ContainerKind::initcode, {msg.code, msg.code_size}) !=
308-
EOFValidationError::success)
309-
return {}; // Light early exception.
310-
311-
msg.recipient = compute_create_address(msg.sender, creation_sender_nonce);
312-
}
313280
// EOFCREATE or TXCREATE
314-
else
315-
msg.recipient = compute_eofcreate_address(msg.sender, msg.create2_salt);
281+
assert(msg.kind == EVMC_EOFCREATE);
282+
msg.recipient = compute_eofcreate_address(msg.sender, msg.create2_salt);
316283
}
317284

318285
// By EIP-2929, the access to new created address is never reverted.
@@ -395,7 +362,7 @@ evmc::Result Host::create(const evmc_message& msg) noexcept
395362
{
396363
if (m_rev >= EVMC_OSAKA)
397364
{
398-
// Only EOFCREATE/TXCREATE/EOF-creation-tx is allowed to deploy code starting with
365+
// Only EOFCREATE/TXCREATE is allowed to deploy code starting with
399366
// EF. It must be valid EOF, which was validated before execution.
400367
if (msg.kind != EVMC_EOFCREATE)
401368
return evmc::Result{EVMC_CONTRACT_VALIDATION_FAILURE};

test/state/state.cpp

+10-11
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ TransactionCost compute_tx_intrinsic_cost(evmc_revision rev, const Transaction&
7575
static constexpr auto INITCODE_WORD_COST = 2;
7676
static constexpr auto TOTAL_COST_FLOOR_PER_TOKEN = 10;
7777

78-
const auto is_create = !tx.to.has_value(); // Covers also EOF creation transactions.
78+
const auto is_create = !tx.to.has_value();
7979

8080
const auto create_cost = (is_create && rev >= EVMC_HOMESTEAD) ? TX_CREATE_COST : 0;
8181

@@ -186,17 +186,12 @@ int64_t process_authorization_list(
186186
return delegation_refund;
187187
}
188188

189-
evmc_message build_message(
190-
const Transaction& tx, int64_t execution_gas_limit, evmc_revision rev) noexcept
189+
evmc_message build_message(const Transaction& tx, int64_t execution_gas_limit) noexcept
191190
{
192191
const auto recipient = tx.to.has_value() ? *tx.to : evmc::address{};
193192

194-
const auto is_legacy_eof_create =
195-
rev >= EVMC_OSAKA && !tx.to.has_value() && is_eof_container(tx.data);
196-
197-
return {.kind = is_legacy_eof_create ? EVMC_EOFCREATE :
198-
tx.to.has_value() ? EVMC_CALL : // NOLINT(readability-avoid-nested-conditional-operator)
199-
EVMC_CREATE,
193+
return {
194+
.kind = tx.to.has_value() ? EVMC_CALL : EVMC_CREATE,
200195
.flags = 0,
201196
.depth = 0,
202197
.gas = execution_gas_limit,
@@ -208,7 +203,8 @@ evmc_message build_message(
208203
.create2_salt = {},
209204
.code_address = recipient,
210205
.code = nullptr,
211-
.code_size = 0};
206+
.code_size = 0,
207+
};
212208
}
213209
} // namespace
214210

@@ -531,6 +527,9 @@ std::variant<TransactionProperties, std::error_code> validate_transaction(
531527
if (rev >= EVMC_SHANGHAI && !tx.to.has_value() && tx.data.size() > MAX_INITCODE_SIZE)
532528
return make_error_code(INIT_CODE_SIZE_LIMIT_EXCEEDED);
533529

530+
if (rev >= EVMC_OSAKA && !tx.to.has_value() && is_eof_container(tx.data))
531+
return make_error_code(EOF_CREATION_TRANSACTION);
532+
534533
// Compute and check if sender has enough balance for the theoretical maximum transaction cost.
535534
// Note this is different from tx_max_cost computed with effective gas price later.
536535
// The computation cannot overflow if done with 512-bit precision.
@@ -634,7 +633,7 @@ TransactionReceipt transition(const StateView& state_view, const BlockInfo& bloc
634633
if (rev >= EVMC_SHANGHAI)
635634
host.access_account(block.coinbase);
636635

637-
auto message = build_message(tx, tx_props.execution_gas_limit, rev);
636+
auto message = build_message(tx, tx_props.execution_gas_limit);
638637
if (tx.to.has_value())
639638
{
640639
if (const auto delegate = get_delegate_address(host, *tx.to))

test/unittests/eof_example_test.cpp

-40
Original file line numberDiff line numberDiff line change
@@ -119,46 +119,6 @@ TEST_F(state_transition, eof_examples_callf)
119119
expect.post[*tx.to].exists = true;
120120
}
121121

122-
TEST_F(state_transition, eof_examples_creation_tx)
123-
{
124-
// # Example 4
125-
//
126-
// A creation transaction used to create a new EOF contract.
127-
128-
rev = EVMC_OSAKA;
129-
130-
const auto initcontainer = bytecode(
131-
//////////////////
132-
// Initcontainer
133-
// Code section: PUSH0 [aux data size], PUSH0 [aux data offset] and
134-
// RETURNCODE first subcontainer
135-
// |
136-
// Header: 1 code section 4 bytes long |
137-
// | |
138-
// version | Header terminator
139-
// | |___________ | |________
140-
"EF00 01 01 0004 02 0001 0004 03 0001 0014 04 0000 00 00 80 0002 5F5F EE00"
141-
// |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾‾‾ |‾‾‾‾‾‾ |‾‾‾‾‾‾‾‾‾
142-
// | | Header: data section 0 bytes long
143-
// | | |
144-
// Header: types section 4 bytes long Types section: first code section
145-
// | 0 inputs, non-returning,
146-
// | max stack height 2
147-
// Header: 1 subcontainer 20 bytes long
148-
//
149-
//////////////////
150-
// Deployed container (contract doing nothing, see Example 1)
151-
"EF00 01 01 0004 02 0001 0001 04 0000 00 00 80 0000 00");
152-
153-
// Put the initcontainer in the `data` field of the transaction, appending some calldata.
154-
tx.data = initcontainer + "ABCDEF";
155-
// Empty `to` field.
156-
tx.to = std::nullopt;
157-
158-
// Address of the newly created contract is calculated using the deployer's address and nonce.
159-
expect.post[0x3442a1dec1e72f337007125aa67221498cdd759d_address].exists = true;
160-
}
161-
162122
TEST_F(state_transition, eof_examples_eofcreate)
163123
{
164124
// # Example 5

0 commit comments

Comments
 (0)