@@ -331,24 +331,14 @@ def exec_foundry_prove(
331
331
contract_name , method_name = test .split ('.' )
332
332
contract = [c for c in contracts if c .name == contract_name ][0 ]
333
333
method = [m for m in contract .methods if m .name == method_name ][0 ]
334
- empty_config = foundry .definition .empty_config (Foundry . Sorts . FOUNDRY_CELL )
334
+ empty_config = foundry .definition .empty_config (GENERATED_TOP_CELL )
335
335
cfg = method_to_cfg (empty_config , contract , method )
336
336
if simplify_init :
337
337
_LOGGER .info (f'Simplifying initial state for test: { test } ' )
338
- edge = KCFG .Edge (cfg .get_unique_init (), cfg .get_unique_target (), mlTop (), - 1 )
339
- claim = edge .to_claim ()
340
- init_simplified = foundry .prove_claim (
341
- claim , f'simplify-init-{ cfg .get_unique_init ().id } ' , args = ['--depth' , '0' ]
342
- )
343
- init_simplified = sanitize_config (foundry .definition , init_simplified )
338
+ init_simplified = foundry .simplify (CTerm (init_simplified ))
344
339
cfg = KCFG__replace_node (cfg , cfg .get_unique_init ().id , CTerm (init_simplified ))
345
340
_LOGGER .info (f'Simplifying target state for test: { test } ' )
346
- edge = KCFG .Edge (cfg .get_unique_target (), cfg .get_unique_init (), mlTop (), - 1 )
347
- claim = edge .to_claim ()
348
- target_simplified = foundry .prove_claim (
349
- claim , f'simplify-target-{ cfg .get_unique_target ().id } ' , args = ['--depth' , '0' ]
350
- )
351
- target_simplified = sanitize_config (foundry .definition , target_simplified )
341
+ target_simplified = foundry .simplify (CTerm (target_simplified ))
352
342
cfg = KCFG__replace_node (cfg , cfg .get_unique_target ().id , CTerm (target_simplified ))
353
343
kcfgs [test ] = (cfg , kcfg_file )
354
344
with open (kcfg_file , 'w' ) as kf :
@@ -378,21 +368,16 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
378
368
curr_node = cfg .frontier [0 ]
379
369
cfg .add_expanded (curr_node .id )
380
370
_LOGGER .info (f'Advancing proof from node { cfgid } : { shorten_hashes (curr_node .id )} ' )
381
- edge = KCFG .Edge (curr_node , target_node , mlTop (), - 1 )
382
- claim = edge .to_claim ()
383
- claim_id = f'gen-block-{ curr_node .id } -to-{ target_node .id } '
384
- depth , branching , result = foundry .get_claim_basic_block (
385
- claim_id , claim , lemmas = lemma_rules , max_depth = max_depth
386
- )
387
-
388
- if result == mlTop ():
371
+ depth , term , next_terms = foundry .execute (curr_node .cterm , depth = max_depth )
372
+
373
+ if term == mlTop ():
389
374
cfg .create_edge (curr_node .id , target_node .id , mlTop (), depth )
390
375
_LOGGER .info (
391
376
f'Target state reached at depth { depth } for { cfgid } : { shorten_hashes ((curr_node .id , target_node .id ))} .'
392
377
)
393
378
394
379
else :
395
- next_state = CTerm (sanitize_config (foundry .definition , result ))
380
+ next_state = CTerm (sanitize_config (foundry .definition , term ))
396
381
next_node = cfg .get_or_create_node (next_state )
397
382
if next_node != curr_node :
398
383
_LOGGER .info (
@@ -404,7 +389,7 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
404
389
cfg .add_expanded (next_node .id )
405
390
_LOGGER .info (f'Terminal node { cfgid } : { shorten_hashes ((curr_node .id ))} .' )
406
391
407
- elif branching :
392
+ elif len ( next_terms ) > 1 :
408
393
cfg .add_expanded (next_node .id )
409
394
branches = KEVM .extract_branches (next_state )
410
395
if len (list (branches )) > 0 :
@@ -420,24 +405,17 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
420
405
# cfg.create_cover(branch_node.id, next_node.id)
421
406
# _LOGGER.info(f'Made cover: {shorten_hashes((branch_node.id, next_node.id))}')
422
407
else :
423
- _LOGGER .warning (
424
- f'Falling back to running backend for branch extraction { cfgid } :\n { foundry .pretty_print (minimize_term (result ))} '
425
- )
426
- edge = KCFG .Edge (next_node , target_node , mlTop (), - 1 )
427
- claim = edge .to_claim ()
428
- claim_id = f'gen-branch-{ curr_node .id } -to-{ target_node .id } '
429
- result = foundry .prove_claim (claim , claim_id , lemmas = lemma_rules , args = ['--depth' , '1' ])
430
- branch_cterms = [CTerm (r ) for r in flatten_label ('#Or' , result )]
431
- old_constraints = next_state .constraints
432
- new_constraints = [
433
- [c for c in s .constraints if c not in old_constraints ] for s in branch_cterms
408
+ _LOGGER .warning (f'Falling back to extracted next states for { cfgid } :\n { next_node .id } ' )
409
+ branch_cterms = [CTerm (nt ) for nt in next_terms ]
410
+ branch_constraints = [
411
+ [c for c in s .constraints if c not in next_state .constraints ] for s in branch_cterms
434
412
]
435
413
_LOGGER .info (
436
- f'Found { len (list (branch_cterms ))} branches manually ad depth 1 for { cfgid } : { [foundry .pretty_print (mlAnd (nc )) for nc in new_constraints ]} '
414
+ f'Found { len (list (branch_cterms ))} branches manually at depth 1 for { cfgid } : { [foundry .pretty_print (mlAnd (bc )) for bc in branch_constraints ]} '
437
415
)
438
- for ns , nc in zip (branch_cterms , new_constraints ):
439
- branch_node = cfg .get_or_create_node (ns )
440
- cfg .create_edge (next_node .id , branch_node .id , mlAnd (nc ), 1 )
416
+ for bs , bc in zip (branch_cterms , branch_constraints ):
417
+ branch_node = cfg .get_or_create_node (bs )
418
+ cfg .create_edge (next_node .id , branch_node .id , mlAnd (bc ), 1 )
441
419
442
420
_write_cfg (cfg , cfgpath )
443
421
0 commit comments