Skip to content

Commit f86390f

Browse files
committed
kevm-pyk/__main__: use KProve kore-rpc endpoints
1 parent 4de886e commit f86390f

File tree

1 file changed

+16
-38
lines changed

1 file changed

+16
-38
lines changed

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -331,24 +331,14 @@ def exec_foundry_prove(
331331
contract_name, method_name = test.split('.')
332332
contract = [c for c in contracts if c.name == contract_name][0]
333333
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)
335335
cfg = method_to_cfg(empty_config, contract, method)
336336
if simplify_init:
337337
_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))
344339
cfg = KCFG__replace_node(cfg, cfg.get_unique_init().id, CTerm(init_simplified))
345340
_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))
352342
cfg = KCFG__replace_node(cfg, cfg.get_unique_target().id, CTerm(target_simplified))
353343
kcfgs[test] = (cfg, kcfg_file)
354344
with open(kcfg_file, 'w') as kf:
@@ -378,21 +368,16 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
378368
curr_node = cfg.frontier[0]
379369
cfg.add_expanded(curr_node.id)
380370
_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():
389374
cfg.create_edge(curr_node.id, target_node.id, mlTop(), depth)
390375
_LOGGER.info(
391376
f'Target state reached at depth {depth} for {cfgid}: {shorten_hashes((curr_node.id, target_node.id))}.'
392377
)
393378

394379
else:
395-
next_state = CTerm(sanitize_config(foundry.definition, result))
380+
next_state = CTerm(sanitize_config(foundry.definition, term))
396381
next_node = cfg.get_or_create_node(next_state)
397382
if next_node != curr_node:
398383
_LOGGER.info(
@@ -404,7 +389,7 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
404389
cfg.add_expanded(next_node.id)
405390
_LOGGER.info(f'Terminal node {cfgid}: {shorten_hashes((curr_node.id))}.')
406391

407-
elif branching:
392+
elif len(next_terms) > 1:
408393
cfg.add_expanded(next_node.id)
409394
branches = KEVM.extract_branches(next_state)
410395
if len(list(branches)) > 0:
@@ -420,24 +405,17 @@ def prove_it(id_and_cfg: Tuple[str, Tuple[KCFG, Path]]) -> bool:
420405
# cfg.create_cover(branch_node.id, next_node.id)
421406
# _LOGGER.info(f'Made cover: {shorten_hashes((branch_node.id, next_node.id))}')
422407
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
434412
]
435413
_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]}'
437415
)
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)
441419

442420
_write_cfg(cfg, cfgpath)
443421

0 commit comments

Comments
 (0)