21
21
from .gst_to_kore import gst_to_kore
22
22
from .kevm import KEVM , Foundry
23
23
from .solc_to_k import Contract , contract_to_main_module , method_to_cfg , solc_compile
24
- from .utils import KCFG__replace_node , KPrint_make_unparsing , add_include_arg , sanitize_config
24
+ from .utils import KCFG__replace_node , KDefinition__expand_macros , KPrint_make_unparsing , add_include_arg
25
25
26
26
T = TypeVar ('T' )
27
27
@@ -342,15 +342,19 @@ def _write_cfg(_cfg: KCFG, _cfgpath: Path) -> None:
342
342
method = [m for m in contract .methods if m .name == method_name ][0 ]
343
343
empty_config = foundry .definition .empty_config (GENERATED_TOP_CELL )
344
344
cfg = method_to_cfg (empty_config , contract , method )
345
+ init_term = cfg .get_unique_init ().cterm .kast
346
+ target_term = cfg .get_unique_target ().cterm .kast
347
+ _LOGGER .info (f'Expanding macros in initial state for test: { test } ' )
348
+ init_term = KDefinition__expand_macros (foundry .definition , init_term )
349
+ _LOGGER .info (f'Expanding macros in target state for test: { test } ' )
350
+ target_term = KDefinition__expand_macros (foundry .definition , target_term )
345
351
if simplify_init :
346
352
_LOGGER .info (f'Simplifying initial state for test: { test } ' )
347
- init_simplified = cfg .get_unique_init ().cterm .kast
348
- init_simplified = foundry .simplify (CTerm (init_simplified ))
349
- cfg = KCFG__replace_node (cfg , cfg .get_unique_init ().id , CTerm (init_simplified ))
353
+ init_term = foundry .simplify (CTerm (init_term ))
350
354
_LOGGER .info (f'Simplifying target state for test: { test } ' )
351
- target_simplified = cfg . get_unique_target (). cterm . kast
352
- target_simplified = foundry . simplify ( CTerm (target_simplified ))
353
- cfg = KCFG__replace_node (cfg , cfg .get_unique_target ().id , CTerm (target_simplified ))
355
+ target_term = foundry . simplify ( CTerm ( target_term ))
356
+ cfg = KCFG__replace_node ( cfg , cfg . get_unique_init (). id , CTerm (init_term ))
357
+ cfg = KCFG__replace_node (cfg , cfg .get_unique_target ().id , CTerm (target_term ))
354
358
kcfgs [test ] = (cfg , kcfg_file )
355
359
_write_cfg (cfg , kcfg_file )
356
360
else :
@@ -368,7 +372,7 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
368
372
iterations += 1
369
373
curr_node = cfg .frontier [0 ]
370
374
371
- if final_subst := foundry .check_implication (curr_node .cterm , target_node .cterm ):
375
+ if foundry .check_implication (curr_node .cterm , target_node .cterm ) is not None :
372
376
cfg .create_cover (curr_node .id , target_node .id )
373
377
_LOGGER .info (f'Subsumed into target node: { shorten_hashes ((curr_node .id , target_node .id ))} ' )
374
378
continue
@@ -380,12 +384,13 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
380
384
continue
381
385
382
386
_LOGGER .info (f'Advancing proof from node { cfgid } : { shorten_hashes (curr_node .id )} ' )
383
- depth , cterm , next_cterms = foundry .execute (curr_node .cterm , depth = max_depth )
387
+ depth , cterm , next_cterms = foundry .execute (curr_node .cterm , depth = max_depth , terminal_rules = [ 'EVM.halt' ] )
384
388
if depth == 0 :
385
389
_LOGGER .info (f'Found stuck node { cfgid } : { shorten_hashes (curr_node .id )} ' )
386
390
continue
387
391
388
- next_state = CTerm (sanitize_config (foundry .definition , cterm .kast ))
392
+ # next_state = CTerm(sanitize_config(foundry.definition, cterm.kast))
393
+ next_state = cterm
389
394
next_node = cfg .get_or_create_node (next_state )
390
395
_LOGGER .info (
391
396
f'Found basic block at depth { depth } for { cfgid } : { shorten_hashes ((curr_node .id , next_node .id ))} .'
0 commit comments