7
7
import json
8
8
import os
9
9
from functools import partial
10
- from typing import Any , TextIO
10
+ from typing import Any , Final , TextIO
11
11
12
12
from ethereum_rlp import rlp
13
13
from ethereum_types .numeric import U64 , U256 , Uint
25
25
parse_hex_or_int ,
26
26
)
27
27
from .env import Env
28
- from .evm_trace .eip3155 import evm_trace
28
+ from .evm_trace .count import evm_trace as evm_trace_count
29
+ from .evm_trace .count import results as count_results
30
+ from .evm_trace .eip3155 import evm_trace as evm_trace_eip3155
31
+ from .evm_trace .group import GroupTracer
29
32
from .t8n_types import Alloc , Result , Txs
30
33
31
34
@@ -73,12 +76,16 @@ def t8n_arguments(subparsers: argparse._SubParsersAction) -> None:
73
76
t8n_parser .add_argument ("--trace.nostack" , action = "store_true" )
74
77
t8n_parser .add_argument ("--trace.returndata" , action = "store_true" )
75
78
79
+ t8n_parser .add_argument ("--opcode.count" , dest = "opcode_count" , type = str )
80
+
76
81
t8n_parser .add_argument ("--state-test" , action = "store_true" )
77
82
78
83
79
84
class T8N (Load ):
80
85
"""The class that carries out the transition"""
81
86
87
+ tracers : Final [GroupTracer | None ]
88
+
82
89
def __init__ (
83
90
self , options : Any , out_file : TextIO , in_file : TextIO
84
91
) -> None :
@@ -101,19 +108,34 @@ def __init__(
101
108
)
102
109
self .fork = ForkLoad (fork_module )
103
110
111
+ tracers = GroupTracer ()
112
+
104
113
if self .options .trace :
105
114
trace_memory = getattr (self .options , "trace.memory" , False )
106
115
trace_stack = not getattr (self .options , "trace.nostack" , False )
107
116
trace_return_data = getattr (self .options , "trace.returndata" )
108
- trace . set_evm_trace (
117
+ tracers . add (
109
118
partial (
110
- evm_trace ,
119
+ evm_trace_eip3155 ,
111
120
trace_memory = trace_memory ,
112
121
trace_stack = trace_stack ,
113
122
trace_return_data = trace_return_data ,
114
123
output_basedir = self .options .output_basedir ,
115
124
)
116
125
)
126
+
127
+ if self .options .opcode_count is not None :
128
+ tracers .add (evm_trace_count )
129
+
130
+ maybe_tracers : GroupTracer | None
131
+ if tracers .tracers :
132
+ trace .set_evm_trace (tracers )
133
+ maybe_tracers = tracers
134
+ else :
135
+ maybe_tracers = None
136
+
137
+ self .tracers = maybe_tracers
138
+
117
139
self .logger = get_stream_logger ("T8N" )
118
140
119
141
super ().__init__ (
@@ -349,6 +371,18 @@ def run(self) -> int:
349
371
json .dump (json_result , f , indent = 4 )
350
372
self .logger .info (f"Wrote result to { result_output_path } " )
351
373
374
+ opcode_count_results = count_results ()
375
+ if self .options .opcode_count == "stdout" :
376
+ json_output ["opcodes" ] = opcode_count_results
377
+ elif self .options .opcode_count is not None :
378
+ result_output_path = os .path .join (
379
+ self .options .output_basedir ,
380
+ self .options .opcode_count ,
381
+ )
382
+ with open (result_output_path , "w" ) as f :
383
+ json .dump (opcode_count_results , f , indent = 4 )
384
+ self .logger .info (f"Wrote opcode counts to { result_output_path } " )
385
+
352
386
if json_output :
353
387
json .dump (json_output , self .out_file , indent = 4 )
354
388
0 commit comments