Skip to content
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
1 change: 1 addition & 0 deletions test/state/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_include_directories(evmone-state PUBLIC ${PROJECT_SOURCE_DIR})
target_sources(
evmone-state PRIVATE
account.hpp
authorization.hpp
blob_params.hpp
block.hpp
block.cpp
Expand Down
35 changes: 35 additions & 0 deletions test/state/authorization.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// evmone: Fast Ethereum Virtual Machine implementation
// Copyright 2025 The evmone Authors.
// SPDX-License-Identifier: Apache-2.0
#pragma once

#include <evmc/evmc.hpp>
#include <intx/intx.hpp>
#include <optional>
#include <vector>
Comment thread
chfast marked this conversation as resolved.

namespace evmone::state
{
using evmc::address;
using intx::uint256;

/// The set-code transaction authorization tuple (EIP-7702).
struct Authorization
{
uint256 chain_id;
address addr;
uint64_t nonce = 0;

/// The signature's y_parity. Valid values are 0 and 1, but an out-of-range value only
/// invalidates the authorization, not the transaction.
uint8_t y_parity = 0;

uint256 r;
uint256 s;

/// The signer address. Empty if it cannot be recovered from the signature (y_parity, r, s).
std::optional<address> signer;
};
Comment thread
Copilot marked this conversation as resolved.

using AuthorizationList = std::vector<Authorization>;
} // namespace evmone::state
2 changes: 1 addition & 1 deletion test/state/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ int64_t process_authorization_list(
// 3. Verify if the signer has been successfully recovered from the signature.
// authority = ecrecover(...)
// y_parity must be 0 or 1 for EIP-7702/2930 signatures.
if (auth.v > 1)
if (auth.y_parity > 1)
continue;
// TODO: We actually only do "partial" verification by assuming the signature is valid
// when the test has the signer specified.
Expand Down
15 changes: 1 addition & 14 deletions test/state/transaction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "authorization.hpp"
#include "blob_params.hpp"
#include "bloom_filter.hpp"
#include "state_diff.hpp"
Expand All @@ -18,20 +19,6 @@ constexpr auto MAX_TX_GAS_LIMIT = 0x1000000; // 2**24

using AccessList = std::vector<std::pair<address, std::vector<bytes32>>>;

struct Authorization
{
intx::uint256 chain_id;
address addr;
uint64_t nonce = 0;
/// Signer is empty if it cannot be ecrecovered from r, s, v.
std::optional<address> signer;
intx::uint256 r;
intx::uint256 s;
intx::uint256 v;
};

using AuthorizationList = std::vector<Authorization>;

struct Transaction
{
/// The type of the transaction.
Expand Down
2 changes: 1 addition & 1 deletion test/unittests/state_transition_eip7702_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ TEST_F(state_transition, eip7702_set_code_transaction_invalid_y_parity)
pre[authority] = {.nonce = 1};
tx.to = To;
tx.type = Transaction::Type::set_code;
tx.authorization_list = {{.addr = delegate, .nonce = 1, .signer = authority, .v = 2}};
tx.authorization_list = {{.addr = delegate, .nonce = 1, .y_parity = 2, .signer = authority}};
pre[To] = {.code = ret(0)};

expect.post[authority].nonce = 1;
Expand Down
2 changes: 1 addition & 1 deletion test/utils/rlp_encode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ namespace evmone::state
[[nodiscard]] bytes rlp_encode(const Authorization& authorization)
{
return rlp::encode_tuple(authorization.chain_id, authorization.addr, authorization.nonce,
authorization.v, authorization.r, authorization.s);
authorization.y_parity, authorization.r, authorization.s);
}

[[nodiscard]] bytes rlp_encode(const Withdrawal& withdrawal)
Expand Down
2 changes: 1 addition & 1 deletion test/utils/statetest_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ json::json to_state_test(std::string_view test_name, const state::BlockInfo& blo
if (!tx.authorization_list.empty())
{
auto& ja = jtx["authorizationList"];
for (const auto& [chain_id, addr, nonce, signer, r, s, y_parity] : tx.authorization_list)
for (const auto& [chain_id, addr, nonce, y_parity, r, s, signer] : tx.authorization_list)
{
json::json je;
je["chainId"] = hex0x(chain_id);
Expand Down
2 changes: 1 addition & 1 deletion test/utils/statetest_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ state::AuthorizationList from_json<state::AuthorizationList>(const json::json& j
authorization.signer = from_json<address>(a["signer"]);
authorization.r = from_json<uint256>(a.at("r"));
authorization.s = from_json<uint256>(a.at("s"));
authorization.v = from_json<uint256>(a.at("v"));
authorization.y_parity = from_json<uint8_t>(a.at("v"));
o.emplace_back(authorization);
}
return o;
Expand Down