Skip to content

Commit 3341717

Browse files
committed
Make room for a new trace function (#1351)
1 parent d619d10 commit 3341717

File tree

8 files changed

+73
-76
lines changed

8 files changed

+73
-76
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ packages = [
3636
"ethereum_spec_tools",
3737
"ethereum_spec_tools.evm_tools",
3838
"ethereum_spec_tools.evm_tools.t8n",
39+
"ethereum_spec_tools.evm_tools.t8n.evm_trace",
3940
"ethereum_spec_tools.evm_tools.b11r",
4041
"ethereum_spec_tools.evm_tools.statetest",
4142
"ethereum_spec_tools.evm_tools.loaders",

src/ethereum_spec_tools/evm_tools/t8n/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
parse_hex_or_int,
2626
)
2727
from .env import Env
28-
from .evm_trace import evm_trace
28+
from .evm_trace.eip3155 import evm_trace
2929
from .t8n_types import Alloc, Result, Txs
3030

3131

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""
2+
EVM Trace Implementations.
3+
4+
See [`ethereum.trace`](ref:ethereum.trace).
5+
"""

src/ethereum_spec_tools/evm_tools/t8n/evm_trace.py renamed to src/ethereum_spec_tools/evm_tools/t8n/evm_trace/eip3155.py

Lines changed: 4 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,7 @@
66
import os
77
from contextlib import ExitStack
88
from dataclasses import asdict, dataclass, is_dataclass
9-
from typing import (
10-
Any,
11-
List,
12-
Optional,
13-
Protocol,
14-
TextIO,
15-
TypeAlias,
16-
Union,
17-
runtime_checkable,
18-
)
19-
20-
from ethereum_types.bytes import Bytes
21-
from ethereum_types.numeric import U256, Uint
9+
from typing import Any, List, Optional, TextIO, TypeAlias, Union
2210

2311
from ethereum.exceptions import EthereumException
2412
from ethereum.trace import (
@@ -34,6 +22,8 @@
3422
TransactionStart,
3523
)
3624

25+
from .protocols import Evm, EvmWithReturnData, TransactionEnvironment
26+
3727
EXCLUDE_FROM_OUTPUT = ["gasCostTraced", "errorTraced", "precompile"]
3828

3929

@@ -79,63 +69,6 @@ def __init__(
7969
self.error = type(error).__name__
8070

8171

82-
@runtime_checkable
83-
class TransactionEnvironment(Protocol):
84-
"""
85-
The class implements the tx_env interface for trace.
86-
"""
87-
88-
index_in_block: Optional[Uint]
89-
tx_hash: Optional[Bytes]
90-
91-
92-
@runtime_checkable
93-
class Message(Protocol):
94-
"""
95-
The class implements the message interface for trace.
96-
"""
97-
98-
depth: int
99-
tx_env: TransactionEnvironment
100-
parent_evm: Optional["Evm"]
101-
102-
103-
@runtime_checkable
104-
class EvmWithoutReturnData(Protocol):
105-
"""
106-
The class implements the EVM interface for pre-byzantium forks trace.
107-
"""
108-
109-
pc: Uint
110-
stack: List[U256]
111-
memory: bytearray
112-
code: Bytes
113-
gas_left: Uint
114-
refund_counter: int
115-
running: bool
116-
message: Message
117-
118-
119-
@runtime_checkable
120-
class EvmWithReturnData(Protocol):
121-
"""
122-
The class implements the EVM interface for post-byzantium forks trace.
123-
"""
124-
125-
pc: Uint
126-
stack: List[U256]
127-
memory: bytearray
128-
code: Bytes
129-
gas_left: Uint
130-
refund_counter: int
131-
running: bool
132-
message: Message
133-
return_data: Bytes
134-
135-
136-
Evm = Union[EvmWithoutReturnData, EvmWithReturnData]
137-
138-
13972
_ActiveTraces: TypeAlias = tuple[
14073
TransactionEnvironment, list[Trace | FinalTrace]
14174
]
@@ -162,7 +95,7 @@ def evm_trace(
16295
):
16396
return
16497

165-
assert isinstance(evm, (EvmWithoutReturnData, EvmWithReturnData))
98+
assert isinstance(evm, Evm)
16699

167100
if _active_traces and _active_traces[0] is evm.message.tx_env:
168101
traces = _active_traces[1]
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
"""
2+
Protocol definitions for working with EVM trace events.
3+
"""
4+
5+
from typing import Optional, Protocol, runtime_checkable
6+
7+
from ethereum_types.bytes import Bytes
8+
from ethereum_types.numeric import U256, Uint
9+
10+
11+
@runtime_checkable
12+
class TransactionEnvironment(Protocol):
13+
"""
14+
The class implements the tx_env interface for trace.
15+
"""
16+
17+
index_in_block: Uint | None
18+
tx_hash: Bytes | None
19+
20+
21+
@runtime_checkable
22+
class Message(Protocol):
23+
"""
24+
The class implements the message interface for trace.
25+
"""
26+
27+
depth: int
28+
tx_env: TransactionEnvironment
29+
parent_evm: Optional["Evm"]
30+
31+
32+
@runtime_checkable
33+
class Evm(Protocol):
34+
"""
35+
The class describes the EVM interface for pre-byzantium forks trace.
36+
"""
37+
38+
pc: Uint
39+
stack: list[U256]
40+
memory: bytearray
41+
code: Bytes
42+
gas_left: Uint
43+
refund_counter: int
44+
running: bool
45+
message: Message
46+
47+
48+
@runtime_checkable
49+
class EvmWithReturnData(Evm, Protocol):
50+
"""
51+
The class describes the EVM interface for post-byzantium forks trace.
52+
"""
53+
54+
return_data: Bytes

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def pytest_configure(config: Config) -> None:
6060

6161
if config.getoption("evm_trace"):
6262
import ethereum.trace
63-
from ethereum_spec_tools.evm_tools.t8n.evm_trace import (
63+
from ethereum_spec_tools.evm_tools.t8n.evm_trace.eip3155 import (
6464
evm_trace as new_trace_function,
6565
)
6666

vulture_whitelist.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@
99
TransactionLoad,
1010
)
1111
from ethereum_spec_tools.evm_tools.t8n.env import Ommer
12-
from ethereum_spec_tools.evm_tools.t8n.evm_trace import Trace, FinalTrace
12+
from ethereum_spec_tools.evm_tools.t8n.evm_trace.eip3155 import (
13+
Trace,
14+
FinalTrace,
15+
)
1316
from ethereum_spec_tools.evm_tools.t8n.transition_tool import EELST8N
1417
from ethereum_spec_tools.lint.lints.glacier_forks_hygiene import (
1518
GlacierForksHygiene,
@@ -87,7 +90,7 @@
8790
# src/ethereum_spec_tools/evm_tools/t8n/env.py
8891
Ommer.delta
8992

90-
# src/ethereum_spec_tools/evm_tools/t8n/evm_trace.py
93+
# src/ethereum_spec_tools/evm_tools/t8n/evm_trace/eip3155.py
9194
Trace.gasCost
9295
Trace.memSize
9396
Trace.returnData

whitelist.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coincurve
2020
crypto
2121
E501
2222
EIP
23+
eip3155
2324
encodings
2425
endian
2526
eth
@@ -499,4 +500,4 @@ sig
499500
CLZ
500501
EELST8N
501502
clis
502-
T8
503+
T8

0 commit comments

Comments
 (0)