Skip to content

Commit 3eb91a8

Browse files
committed
bin/kevm, kevm-pyk/__main__: add foundry-list command for seeing KCFG information
1 parent f2432eb commit 3eb91a8

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

bin/kevm

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,10 @@ run_foundry_show_cfg() {
298298
run_kevm_pyk foundry-show-cfg "$@"
299299
}
300300

301+
run_foundry_list() {
302+
run_kevm_pyk foundry-list "$@"
303+
}
304+
301305
# Main
302306
# ----
303307

@@ -313,8 +317,10 @@ if [[ "$run_command" == 'help' ]] || [[ "$run_command" == '--help' ]] ; then
313317
${KEVM} kompile [--backend (java|llvm|haskell)] [--profile|--debug] <main> <K arg>*
314318
${KEVM} klab-view [--profile|--debug] <spec>
315319
${KEVM} solc-to-k [--profile|--debug] <sol-file> <contract-name> <solc-arg>*
316-
${KEVM} foundry-kompile
317-
${KEVM} foundry-prove
320+
${KEVM} foundry-list # see dedicated help menu
321+
${KEVM} foundry-cfg # see dedicated help menu
322+
${KEVM} foundry-kompile # see dedicated help menu
323+
${KEVM} foundry-prove # see dedicated help menu
318324
319325
${KEVM} [help|--help|version|--version]
320326
@@ -438,7 +444,7 @@ if ${pyk}; then
438444
fi
439445

440446
# get the run file
441-
if [[ "${run_command}" != 'foundry-kompile' ]] && [[ "${run_command}" != 'foundry-prove' ]] && [[ "${run_command}" != 'foundry-show-cfg' ]]; then
447+
if [[ "${run_command}" != 'foundry-kompile' ]] && [[ "${run_command}" != 'foundry-prove' ]] && [[ "${run_command}" != 'foundry-show-cfg' ]] && [[ "${run_command}" != 'foundry-list' ]]; then
442448
run_file="$1" ; shift
443449
if [[ "${run_file}" == '-' ]]; then
444450
tmp_input="$(mktemp)"
@@ -471,5 +477,6 @@ case "$run_command-$backend" in
471477
foundry-kompile-* ) run_foundry_kompile "$@" ;;
472478
foundry-prove-* ) run_foundry_prove "$@" ;;
473479
foundry-show-cfg-* ) run_foundry_show_cfg "$@" ;;
480+
foundry-list-* ) run_foundry_list "$@" ;;
474481
*) ${KEVM} help ; fatal "Unknown command on backend: $run_command $backend" ;;
475482
esac

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,30 @@ def exec_foundry_show_cfg(
492492
print(f'\n\nState Delta {node_id_1} => {node_id_2}:\n\n{foundry.pretty_print(config_delta)}\n')
493493

494494

495+
def exec_foundry_list(
496+
profile: bool,
497+
foundry_out: Path,
498+
details: bool = True,
499+
**kwargs: Any,
500+
) -> None:
501+
kcfgs_dir = foundry_out / 'kcfgs'
502+
pattern = '*.json'
503+
paths = kcfgs_dir.glob(pattern)
504+
for kcfg_file in paths:
505+
with open(kcfg_file, 'r') as kf:
506+
kcfg = KCFG.from_dict(json.loads(kf.read()))
507+
total_nodes = len(kcfg.nodes)
508+
frontier_nodes = len(kcfg.frontier)
509+
stuck_nodes = len(kcfg.stuck)
510+
proven = 'passed' if frontier_nodes + stuck_nodes == 0 else 'failed'
511+
print(f'{kcfg_file}: {proven}')
512+
if details:
513+
print(f' nodes: {total_nodes}')
514+
print(f' frontier: {frontier_nodes}')
515+
print(f' stuck: {stuck_nodes}')
516+
print()
517+
518+
495519
def exec_run(
496520
definition_dir: Path,
497521
profile: bool,
@@ -790,6 +814,17 @@ def parse(s: str) -> List[T]:
790814
'--no-minimize', dest='minimize', action='store_false', help='Do not minimize output.'
791815
)
792816

817+
foundry_list_args = command_parser.add_parser(
818+
'foundry-list',
819+
help='List information about KCFGs on disk',
820+
parents=[shared_args, k_args],
821+
)
822+
foundry_list_args.add_argument('foundry_out', type=dir_path, help='Path to Foundry output directory.')
823+
foundry_list_args.add_argument(
824+
'--details', dest='details', default=True, action='store_true', help='Information about progress on each KCFG.'
825+
)
826+
foundry_list_args.add_argument('--no-details', dest='details', action='store_false', help='Just list the KCFGs.')
827+
793828
return parser
794829

795830

0 commit comments

Comments
 (0)