Skip to content

Commit 6216a45

Browse files
committed
kevm-pyk/__main__: simplify each frontier node before expanding it
1 parent d4647f7 commit 6216a45

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pyk.ktool.kit import KIT
1616
from pyk.ktool.krun import KRunOutput, _krun
1717
from pyk.prelude.k import GENERATED_TOP_CELL
18-
from pyk.prelude.ml import mlAnd, mlTop
18+
from pyk.prelude.ml import is_bottom, is_top, mlAnd, mlTop
1919
from pyk.utils import shorten_hashes
2020

2121
from .gst_to_kore import gst_to_kore
@@ -376,6 +376,22 @@ def prove_it(id_cfg_port: Tuple[str, Tuple[KCFG, Path], int]) -> bool:
376376
iterations += 1
377377
curr_node = cfg.frontier[0]
378378

379+
_LOGGER.info(f'Simplifying {cfgid}: {shorten_hashes((curr_node.id))}')
380+
_simplified = foundry.simplify(curr_node.cterm)
381+
if is_bottom(_simplified):
382+
cfg.create_cover(curr_node.id, cfg.get_unique_target().id, constraint=mlTop())
383+
_LOGGER.info(
384+
f'Infeasible node marked as proven {cfgid}: {shorten_hashes((curr_node.id, cfg.get_unique_target().id))}'
385+
)
386+
continue
387+
if is_top(_simplified):
388+
raise ValueError(f'Found #Top node {cfgid}: {shorten_hashes((curr_node.id))}')
389+
simplified = CTerm(_simplified)
390+
if simplified != curr_node.cterm:
391+
cfg, new_node_id = KCFG__replace_node(cfg, curr_node.id, simplified)
392+
_LOGGER.info(f'Replaced with simplified node: {shorten_hashes((curr_node.id, new_node_id))}')
393+
continue
394+
379395
_LOGGER.info(
380396
f'Checking subsumption into target state {cfgid}: {shorten_hashes((curr_node.id, target_node.id))}'
381397
)
@@ -386,13 +402,13 @@ def prove_it(id_cfg_port: Tuple[str, Tuple[KCFG, Path], int]) -> bool:
386402

387403
cfg.add_expanded(curr_node.id)
388404

389-
_LOGGER.info(f'Checking terminal node {cfgid}: {shorten_hashes((curr_node.id))}')
405+
_LOGGER.info(f'Checking terminal {cfgid}: {shorten_hashes((curr_node.id))}')
390406
if KEVM.is_terminal(curr_node.cterm):
391407
_LOGGER.info(f'Terminal node {cfgid}: {shorten_hashes((curr_node.id))}.')
392408
continue
393409

394410
_LOGGER.info(f'Advancing proof from node {cfgid}: {shorten_hashes(curr_node.id)}')
395-
depth, cterm, next_cterms = foundry.execute(curr_node.cterm, depth=max_depth, terminal_rules=['EVM.halt'])
411+
depth, cterm, next_cterms = foundry.execute(simplified, depth=max_depth, terminal_rules=['EVM.halt'])
396412
if depth == 0:
397413
_LOGGER.info(f'Found stuck node {cfgid}: {shorten_hashes(curr_node.id)}')
398414
continue

0 commit comments

Comments
 (0)