17
17
from typing import TYPE_CHECKING
18
18
19
19
import tomlkit
20
- from kevm_pyk .kevm import KEVM , KEVMNodePrinter , KEVMSemantics
20
+ from kevm_pyk .kevm import KEVM , CustomStep , KEVMNodePrinter , KEVMSemantics
21
21
from kevm_pyk .utils import byte_offset_to_lines , legacy_explore , print_failure_info , print_model
22
22
from pyk .cterm import CTerm
23
23
from pyk .kast .inner import KApply , KInner , KSequence , KSort , KToken , KVariable , Subst , build_assoc
@@ -103,21 +103,26 @@ class KontrolSemantics(KEVMSemantics):
103
103
def __init__ (
104
104
self , auto_abstract_gas : bool = False , allow_symbolic_program : bool = False , provider_url : str | None = None
105
105
) -> None :
106
- super ().__init__ (auto_abstract_gas = auto_abstract_gas , allow_symbolic_program = allow_symbolic_program )
106
+
107
+ custom_steps = (
108
+ CustomStep (self ._rename_pattern , self ._exec_rename_custom_step ),
109
+ CustomStep (self ._forget_branch_pattern , self ._exec_forget_custom_step ),
110
+ CustomStep (self ._call_fork_pattern , self ._exec_fork_call_custom_step ),
111
+ CustomStep (self ._sload_fork_pattern , self ._exec_fork_sload_custom_step ),
112
+ )
113
+
114
+ super ().__init__ (
115
+ auto_abstract_gas = auto_abstract_gas ,
116
+ allow_symbolic_program = allow_symbolic_program ,
117
+ custom_step_definitions = custom_steps ,
118
+ )
107
119
108
120
self ._external_accounts = set ()
109
121
if provider_url :
110
122
self ._provider = Web3Providers .get_provider (provider_url )
111
123
else :
112
124
self ._provider = None
113
125
114
- self ._custom_step_definitions = self ._custom_step_definitions + (
115
- (self ._rename_pattern , self ._exec_rename_custom_step ),
116
- (self ._forget_branch_pattern , self ._exec_forget_custom_step ),
117
- (self ._call_fork_pattern , self ._exec_fork_call_custom_step ),
118
- (self ._sload_fork_pattern , self ._exec_fork_sload_custom_step ),
119
- )
120
-
121
126
@staticmethod
122
127
def cut_point_rules (
123
128
break_on_jumpi : bool ,
@@ -133,7 +138,11 @@ def cut_point_rules(
133
138
cut_point_rules .extend (
134
139
[
135
140
'EVM.call.false' ,
136
- 'FOUNDRY.sload.false' ,
141
+ 'FOUNDRY.sload.w3provider' ,
142
+ 'FOUNDRY.balance.w3provider' ,
143
+ 'FOUNDRY.extcodesize.w3provider' ,
144
+ 'FOUNDRY.extcodehash.w3provider' ,
145
+ 'FOUNDRY.extcodecopy.w3provider' ,
137
146
]
138
147
)
139
148
return cut_point_rules + KEVMSemantics .cut_point_rules (
@@ -201,6 +210,16 @@ def _sload_fork_pattern(self) -> KSequence:
201
210
]
202
211
)
203
212
213
+ @property
214
+ def _balance_fork_pattern (self ) -> KSequence :
215
+ return KSequence (
216
+ [
217
+ KApply ('FETCH_ACCOUNT_BALANCE' , KVariable ('###ACCTID' )),
218
+ KApply ('#push_EVM_InternalOp' ),
219
+ KVariable ('###CONTINUATION' ),
220
+ ]
221
+ )
222
+
204
223
def _exec_rename_custom_step (self , subst : Subst , cterm : CTerm , _c : CTermSymbolic ) -> KCFGExtendResult | None :
205
224
# Extract the target var and new name from the substitution
206
225
target_var = subst ['###RENAME_TARGET' ]
@@ -357,6 +376,10 @@ def _exec_fork_call_custom_step(self, subst: Subst, cterm: CTerm, _c: CTermSymbo
357
376
all_accounts .append (account )
358
377
new_accounts_cell = KEVM .accounts (all_accounts )
359
378
379
+ if account_code is KToken ('b""' , sort = 'Bytes' ):
380
+ _LOGGER .warning (f'Account { target_address .token } has no code available. Continuing execution.' )
381
+ return None
382
+
360
383
# Build a new continuation, replacing the account code placeholder with the fetched code.
361
384
continuation = KSequence (
362
385
[
@@ -390,7 +413,7 @@ def _exec_fork_call_custom_step(self, subst: Subst, cterm: CTerm, _c: CTermSymbo
390
413
new_cterm = CTerm .from_kast (set_cell (new_cterm .kast , 'K_CELL' , continuation ))
391
414
392
415
_LOGGER .info (f'Successfully read account { address_value } from provider and added it to the state' )
393
- return Step (CTerm (new_cterm .config , cterm .constraints ), 1 , (), ['call.false ' ], cut = True )
416
+ return Step (CTerm (new_cterm .config , cterm .constraints ), 1 , (), ['call.true ' ], cut = True )
394
417
395
418
def _exec_fork_sload_custom_step (self , subst : Subst , cterm : CTerm , _c : CTermSymbolic ) -> KCFGExtendResult | None :
396
419
if self ._provider is None :
0 commit comments