Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new(tests): EIP-7702: Updates for Devnet-3 #733

Merged
merged 57 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
fd12981
feat(base_types): Add `keccak256` to `Bytes`
marioevz Aug 23, 2024
b05e545
fix(fw): EIP-7702 types update
marioevz Aug 5, 2024
f3fe06e
fix(types): nonce list logic removal
marioevz Aug 6, 2024
d8748db
feat(types): Calculate signer if v,r,s parameters are in the Auth Tuple
marioevz Aug 13, 2024
e04c055
feat(types/filler): Allow delegation on `pre.fund_eoa`
marioevz Aug 22, 2024
6aceae9
feat(types): Add `Literal["Self"]` as option to delegation in `pre.fu…
marioevz Aug 23, 2024
4e36074
fix(plugins/filler): fix delegation check
marioevz Aug 23, 2024
ea64627
fix(plugins/filler): delegation designation in case of `None`
marioevz Aug 23, 2024
2946057
feat(evm_transition_tool): `SetCodeDelegation` to transaction receipt
marioevz Aug 6, 2024
53d1866
new(tests): EIP-7702 spec update
marioevz Aug 5, 2024
244d002
new(tests): EIP-7702 add all invalid auth tuples test
marioevz Aug 6, 2024
bbc869d
new(tests): EIP-7702 add multiple valid, self-sponsored test
marioevz Aug 6, 2024
ba9a5e6
fix(tests): EIP-7702 enable skipped tests
marioevz Aug 6, 2024
3d4f24c
refactor(tests): EIP-7702 rename folder and files
marioevz Aug 6, 2024
5832e74
new(tests): EIP-7702, some failing tests
marioevz Aug 6, 2024
c5a8a68
fix(tests): EIP-7702 gas test
marioevz Aug 7, 2024
d4fe330
fix(tests): EIP-7702 move gas tests
marioevz Aug 7, 2024
3fcbe47
new(tests): EIP-7702 intrinsic gas tests
marioevz Aug 7, 2024
a2ca8be
fix(fixtures): tests
marioevz Aug 7, 2024
b8b4db8
fix(tests): import
marioevz Aug 8, 2024
4a8bbe2
simplify parametrization
marioevz Aug 9, 2024
11d4663
refactor(tests): EIP-7702 gas tests
marioevz Aug 9, 2024
8199c38
new(tests): EIP-7702 more gas tests
marioevz Aug 9, 2024
f926f3c
new(tests): EIP-7702 parametrize and add new tests
marioevz Aug 9, 2024
9e42548
fix(tests): EIP-7702 add check
marioevz Aug 12, 2024
186f1b8
feat(exceptions): Add two type-4 tx exceptions
marioevz Aug 13, 2024
5712fe6
new(tests): EIP-7702 tests
marioevz Aug 13, 2024
8711d88
fix(tests): Update tests according to spec changes
marioevz Aug 13, 2024
82b87ab
fix(tests): EIP-7702, use `named_parametrize`
marioevz Aug 14, 2024
ee92099
fix(tests): EIP-7702 test not following spec
marioevz Aug 19, 2024
383f977
fix(tests): EIP-7702 test authorization list nonce/gas
marioevz Aug 19, 2024
934d945
fix(tests): EIP-7702 fix test_ext_code_on_chain_delegating_set_code
marioevz Aug 19, 2024
6226f3a
fix(tests): EIP-7702 fix test_set_code_all_invalid_authorization_tuples
marioevz Aug 19, 2024
f6a5d83
fix(tests): EIP-7702 fix test_set_code_invalid_authorization_tuple
marioevz Aug 19, 2024
62d5981
fix(tests): EIP-7702 system-contract tests
marioevz Aug 19, 2024
25b090f
fix(tests): EIP-7702 tox
marioevz Aug 19, 2024
3039d08
refactor(tests): EIP-7702 `parametrize_with_defaults` rename
marioevz Aug 19, 2024
f518215
fix(tests): EIP-7702 test_ext_code_on_set_code
marioevz Aug 19, 2024
4d9fa3d
fix(tests): EIP-7702 test_ext_code_on_set_code
marioevz Aug 19, 2024
19e81ad
fix(tests): EIP-7702 test_set_code_to_sstore
marioevz Aug 20, 2024
bf545a9
fix(tests): EIP-7702, add delegation designation to all expected outputs
marioevz Aug 20, 2024
86ef92d
fix(tests): EIP-7702, add delegation designation
marioevz Aug 20, 2024
6a6512d
new(tests): EIP-7702, add eoa tx after set code tests
marioevz Aug 20, 2024
3f11b1f
refactor(tests): EIP-7702 update for parametrize_with_defaults -> ext…
danceratopz Aug 22, 2024
7798a8e
fix(tests): Marker
marioevz Aug 22, 2024
008ee59
fix(tests): EIP-7702: pre-existing delegation gas tests
marioevz Aug 22, 2024
80daaae
fix(tests): EIP-7702: fix warm costs expectations
marioevz Aug 22, 2024
e8798bf
fix(tests): EIP-7702 re-authorization tests
marioevz Aug 23, 2024
435a82f
fix(tests): EIP-7702 warm account logic revamp
marioevz Aug 23, 2024
9125629
fix(tests): EIP-7702 test fixes
marioevz Aug 23, 2024
bb93f7d
feat(tests): EIP-7702 add self-delegation warm cost test
marioevz Aug 23, 2024
d31824f
fix(test): EIP-7702, test_call_into_self_delegating_set_code
marioevz Aug 23, 2024
0369868
fix(tests): EIP-7702 use kwargs on `with_all` markers
marioevz Aug 23, 2024
f576765
docs: Changelog
marioevz Aug 27, 2024
d8cd1e5
fix(tests): EIP-7702 return code expectations
marioevz Aug 27, 2024
16978ca
fix(tests): EIP-7702 invalid tx on invalid signatures
marioevz Aug 28, 2024
266571f
Apply suggestions from code review
marioevz Sep 3, 2024
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 docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Test fixtures for use by clients are available for each release on the [Github r
- ✨ EIP-4844 test `tests/cancun/eip4844_blobs/test_point_evaluation_precompile.py` includes an EOF test case ([#610](https://github.com/ethereum/execution-spec-tests/pull/610)).
- ✨ Example test `tests/frontier/opcodes/test_dup.py` now includes EOF parametrization ([#610](https://github.com/ethereum/execution-spec-tests/pull/610)).
- ✨ Convert all opcodes validation test `tests/frontier/opcodes/test_all_opcodes.py` ([#748](https://github.com/ethereum/execution-spec-tests/pull/748)).
- ✨ Update [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702) tests for Devnet-3 ([#733](https://github.com/ethereum/execution-spec-tests/pull/733))

### 🛠️ Framework

Expand Down
8 changes: 8 additions & 0 deletions src/ethereum_test_base_types/base_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from typing import Any, ClassVar, SupportsBytes, Type, TypeVar

from Crypto.Hash import keccak
from pydantic import GetCoreSchemaHandler
from pydantic_core.core_schema import (
PlainValidatorFunctionSchema,
Expand Down Expand Up @@ -146,6 +147,13 @@ def or_none(cls, input: "Bytes | BytesConvertible | None") -> "Bytes | None":
return input
return cls(input)

def keccak256(self) -> "Bytes":
"""
Return the keccak256 hash of the opcode byte representation.
"""
k = keccak.new(digest_bits=256)
return Bytes(k.update(bytes(self)).digest())


S = TypeVar("S", bound="FixedSizeHexNumber")

Expand Down
8 changes: 8 additions & 0 deletions src/ethereum_test_exceptions/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,14 @@ class TransactionException(ExceptionBase):
"""
Transaction is type 3, but has no blobs.
"""
TYPE_4_EMPTY_AUTHORIZATION_LIST = auto()
"""
Transaction is type 4, but has an empty authorization list.
"""
TYPE_4_INVALID_AUTHORITY_SIGNATURE = auto()
"""
Transaction is type 4, but has an empty authorization list.
"""


@unique
Expand Down
12 changes: 6 additions & 6 deletions src/ethereum_test_fixtures/tests/test_blockchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@
AuthorizationTuple(
chain_id=1,
address=2,
nonce=[3],
nonce=3,
signer=EOA(key=TestPrivateKey),
)
],
Expand All @@ -212,16 +212,16 @@
{
"chainId": "0x01",
"address": Address(2).hex(),
"nonce": ["0x03"],
"nonce": "0x03",
"v": "0x00",
"r": "0x796b0a59fe796b5aab79259988f4b18bb7966dc9aa0a01d226859057f539d8f6",
"s": "0x7456ad9b8b4e157d8a150ae7d568bb93e668bf1d5970756f7fe7b7f2472235fe",
"r": "0xda29c3bd0304ae475b06d1a11344e0b6d75590f2c23138c9507f4b5bedde3c79",
"s": "0x3e1fb143ae0460373d567cf901645757b321e42c423a53b2d46ed13c9ef0a9ab",
"signer": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
}
],
"v": "0x01",
"r": "0xb9f3ad929ffdb846cbe357fa25e6ab93cc6e10e76da170a12baf03f8a34ba141",
"s": "0x04992060cfa252f5ac18ac1ccb340a821497d50812a225646094d2ad08b8eeaa",
"r": "0xe7da7f244c95cea73ac6316971139ac0eb8fad455d9a25e1c134d7a157c38ff9",
"s": "0x1939185d2e2a2b3375183e42b5755d695efbd72e186cf9a3e6958a3fb84cc709",
"sender": "0xa94f5374fce5edbc8e2a8697c15331677e6ebf0b",
},
id="fixture_transaction_type_4",
Expand Down
42 changes: 27 additions & 15 deletions src/ethereum_test_types/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from dataclasses import dataclass
from functools import cached_property
from typing import Any, ClassVar, Dict, Generic, List, Sequence, Tuple
from typing import Any, ClassVar, Dict, Generic, List, Literal, Sequence, Tuple

from coincurve.keys import PrivateKey, PublicKey
from ethereum import rlp as eth_rlp
Expand Down Expand Up @@ -283,6 +283,7 @@ def fund_eoa(
amount: NumberConvertible = 10**21,
label: str | None = None,
storage: Storage | None = None,
delegation: Address | Literal["Self"] | None = None,
) -> EOA:
"""
Add a previously unused EOA to the pre-alloc with the balance specified by `amount`.
Expand Down Expand Up @@ -469,34 +470,24 @@ class AuthorizationTupleGeneric(CamelModel, Generic[NumberBoundTypeVar]):
Authorization tuple for transactions.
"""

chain_id: NumberBoundTypeVar = Field(1) # type: ignore
chain_id: NumberBoundTypeVar = Field(0) # type: ignore
address: Address
nonce: List[NumberBoundTypeVar] = Field(default_factory=list)
nonce: NumberBoundTypeVar = Field(0) # type: ignore

v: NumberBoundTypeVar = Field(0) # type: ignore
r: NumberBoundTypeVar = Field(0) # type: ignore
s: NumberBoundTypeVar = Field(0) # type: ignore

magic: ClassVar[int] = 0x05

@model_validator(mode="before")
@classmethod
def convert_nonce_information(cls, data: Any) -> Any:
"""
Automatically converts the nonce to a list if it is not already.
"""
if "nonce" in data and not isinstance(data["nonce"], list):
data["nonce"] = [data["nonce"]]
return data

def to_list(self) -> List[Any]:
"""
Returns the authorization tuple as a list of serializable elements.
"""
return [
Uint(self.chain_id),
self.address,
[Uint(n) for n in self.nonce],
Uint(self.nonce),
Uint(self.v),
Uint(self.r),
Uint(self.s),
Expand All @@ -511,7 +502,7 @@ def signing_bytes(self) -> bytes:
[
Uint(self.chain_id),
self.address,
[Uint(n) for n in self.nonce],
Uint(self.nonce),
]
)

Expand Down Expand Up @@ -548,6 +539,27 @@ def model_post_init(self, __context: Any) -> None:
elif self.signer is not None:
assert self.signer.key is not None, "signer must have a key"
self.sign(self.signer.key)
else:
assert self.v is not None, "v must be set"
assert self.r is not None, "r must be set"
assert self.s is not None, "s must be set"

# Calculate the address from the signature
try:
signature_bytes = (
int(self.r).to_bytes(32, byteorder="big")
+ int(self.s).to_bytes(32, byteorder="big")
+ bytes([self.v])
)
public_key = PublicKey.from_signature_and_message(
signature_bytes, keccak256(self.signing_bytes), hasher=None
)
self.signer = EOA(
address=Address(keccak256(public_key.format(compressed=False)[1:])[32 - 20 :])
)
except Exception:
# Signer remains `None` in this case
pass

def sign(self, private_key: Hash) -> None:
"""
Expand Down
11 changes: 11 additions & 0 deletions src/evm_transition_tool/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ class TransactionLog(CamelModel):
removed: bool


class SetCodeDelegation(CamelModel):
"""
Set code delegation
"""

from_address: Address = Field(..., alias="from")
nonce: HexNumber
target: Address


class TransactionReceipt(CamelModel):
"""
Transaction receipt
Expand All @@ -51,6 +61,7 @@ class TransactionReceipt(CamelModel):
transaction_index: HexNumber | None = None
blob_gas_used: HexNumber | None = None
blob_gas_price: HexNumber | None = None
delegations: List[SetCodeDelegation] | None = None


class RejectedTransaction(CamelModel):
Expand Down
17 changes: 13 additions & 4 deletions src/pytest_plugins/filler/pre_alloc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import IntEnum
from functools import cache
from itertools import count
from typing import Iterator
from typing import Iterator, Literal

import pytest
from pydantic import PrivateAttr
Expand Down Expand Up @@ -86,6 +86,9 @@ class AllocMode(IntEnum):
STRICT = 1


DELEGATION_DESIGNATION = b"\xef\x01\x00"


class Alloc(BaseAlloc):
"""
Allocation of accounts in the state, pre and post test execution.
Expand Down Expand Up @@ -193,6 +196,7 @@ def fund_eoa(
amount: NumberConvertible = 10**21,
label: str | None = None,
storage: Storage | None = None,
delegation: Address | Literal["Self"] | None = None,
) -> EOA:
"""
Add a previously unused EOA to the pre-alloc with the balance specified by `amount`.
Expand All @@ -201,18 +205,23 @@ def fund_eoa(
returned.
"""
eoa = next(self._eoa_iterator)
if Number(amount) > 0 or storage is not None:
if storage is None:
if Number(amount) > 0 or storage is not None or delegation is not None:
if storage is None and delegation is None:
account = Account(
nonce=0,
balance=amount,
)
else:
# Type-4 transaction is sent to the EOA to set the storage, so the nonce must be 1
if not isinstance(delegation, Address) and delegation == "Self":
delegation = eoa
account = Account(
nonce=1,
balance=amount,
storage=storage,
storage=storage if storage is not None else {},
code=DELEGATION_DESIGNATION + bytes(delegation) # type: ignore
if delegation is not None
else b"",
)
eoa.nonce = Number(1)

Expand Down
29 changes: 0 additions & 29 deletions tests/prague/eip7702_eoa_code_tx/spec.py

This file was deleted.

Loading