Skip to content

Commit 710742c

Browse files
authored
Refactor summarize command and options in cli.py and __main__.py. (#2725)
- Updated the `exec_summarize` function to support new `SummarizeOptions`, allowing for opcode-specific summarization and an option to clear existing proofs. - Modified the CLI to replace `ProveOptions` with `SummarizeOptions` for the `summarize` command, enhancing argument handling. - Introduced a new `clear_proofs` function to remove existing proof files before summarization. - Improved documentation and help messages for the `summarize` command to clarify usage.
1 parent a225bcb commit 710742c

File tree

3 files changed

+54
-23
lines changed

3 files changed

+54
-23
lines changed

kevm-pyk/src/kevm_pyk/__main__.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@
3232
from pyk.proof.tui import APRProofViewer
3333
from pyk.utils import FrozenDict, hash_str, single
3434

35-
from kevm_pyk.summarizer import batch_summarize
35+
from kevm_pyk.summarizer import batch_summarize, clear_proofs, summarize
3636

3737
from . import VERSION, config
38-
from .cli import _create_argument_parser, generate_options, get_argument_type_setter, get_option_string_destination
38+
from .cli import (
39+
_create_argument_parser,
40+
generate_options,
41+
get_argument_type_setter,
42+
get_option_string_destination,
43+
)
3944
from .gst_to_kore import SORT_ETHEREUM_SIMULATION, filter_gst_keys, gst_to_kore, kore_pgm_to_kore
4045
from .kevm import KEVM, KEVMSemantics, kevm_node_printer
4146
from .kompile import KompileTarget, kevm_kompile
@@ -65,6 +70,7 @@
6570
RunOptions,
6671
SectionEdgeOptions,
6772
ShowKCFGOptions,
73+
SummarizeOptions,
6874
VersionOptions,
6975
ViewKCFGOptions,
7076
)
@@ -636,10 +642,13 @@ def exec_kast(options: KastOptions) -> None:
636642
print(output_text)
637643

638644

639-
def exec_summarize(options: ProveOptions) -> None:
640-
# TODO: provide options to summarize specific opcodes using `summarize(opcode)`
641-
# TODO: provide options to analyze a specific proof using `analyze_proof(opcode, node_id)`
642-
batch_summarize()
645+
def exec_summarize(options: SummarizeOptions) -> None:
646+
if options.clear:
647+
clear_proofs()
648+
if options.opcode is None:
649+
batch_summarize()
650+
else:
651+
summarize(options.opcode)
643652

644653

645654
# Helpers

kevm-pyk/src/kevm_pyk/cli.py

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def generate_options(args: dict[str, Any]) -> LoggingOptions:
7777
case 'run':
7878
return RunOptions(args)
7979
case 'summarize':
80-
return ProveOptions(args)
80+
return SummarizeOptions(args)
8181
case _:
8282
raise ValueError(f'Unrecognized command: {command}')
8383

@@ -104,7 +104,7 @@ def get_option_string_destination(command: str, option_string: str) -> str:
104104
case 'run':
105105
option_string_destinations = RunOptions.from_option_string()
106106
case 'summarize':
107-
option_string_destinations = ProveOptions.from_option_string()
107+
option_string_destinations = SummarizeOptions.from_option_string()
108108

109109
return option_string_destinations.get(option_string, option_string.replace('-', '_'))
110110

@@ -134,7 +134,7 @@ def func(par: str) -> str:
134134
case 'run':
135135
option_types = RunOptions.get_argument_type()
136136
case 'summarize':
137-
option_types = ProveOptions.get_argument_type()
137+
option_types = SummarizeOptions.get_argument_type()
138138

139139
return option_types.get(option_string, func)
140140

@@ -191,22 +191,27 @@ def _create_argument_parser() -> ArgumentParser:
191191
help='Maximum worker threads to use on a single proof to explore separate branches in parallel.',
192192
)
193193

194-
command_parser.add_parser(
194+
summarize_args = command_parser.add_parser(
195195
'summarize',
196-
help='Summarize an Opcode to execute in a single rewrite step.',
196+
help='Summarize a given opcode(s) to execute in a single rewrite step.',
197197
parents=[
198198
kevm_cli_args.logging_args,
199-
kevm_cli_args.parallel_args,
200199
kevm_cli_args.k_args,
201-
kevm_cli_args.kprove_args,
202-
kevm_cli_args.rpc_args,
203-
kevm_cli_args.bug_report_args,
204-
kevm_cli_args.smt_args,
205-
kevm_cli_args.explore_args,
206-
# kevm_cli_args.spec_args,
207-
config_args.config_args,
208200
],
209201
)
202+
summarize_args.add_argument(
203+
'opcode',
204+
type=str,
205+
nargs='?',
206+
help='Opcode to summarize. If not provided, all supported opcodes will be summarized.',
207+
)
208+
summarize_args.add_argument(
209+
'--clear',
210+
dest='clear',
211+
default=False,
212+
action='store_true',
213+
help='Clear all existing proofs and re-run the summarization process.',
214+
)
210215

211216
prune_args = command_parser.add_parser(
212217
'prune',
@@ -620,6 +625,23 @@ def get_argument_type() -> dict[str, Callable]:
620625
)
621626

622627

628+
class SummarizeOptions(LoggingOptions, KOptions):
629+
clear: bool
630+
opcode: str | None
631+
632+
@staticmethod
633+
def default() -> dict[str, Any]:
634+
return {'clear': False, 'opcode': None}
635+
636+
@staticmethod
637+
def from_option_string() -> dict[str, str]:
638+
return LoggingOptions.from_option_string() | KOptions.from_option_string()
639+
640+
@staticmethod
641+
def get_argument_type() -> dict[str, Callable]:
642+
return LoggingOptions.get_argument_type() | KOptions.get_argument_type()
643+
644+
623645
class PruneOptions(LoggingOptions, KOptions, SpecOptions):
624646
node: NodeIdLike
625647

kevm-pyk/src/kevm_pyk/summarizer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import logging
4+
import shutil
45
import time
56
import traceback
67
from multiprocessing import Pool
@@ -673,8 +674,7 @@ def summarize(opcode_symbol: str) -> tuple[KEVMSummarizer, list[APRProof]]:
673674
return summarizer, proofs
674675

675676

676-
def analyze_proof(opcode: str, node_id: int) -> None:
677+
def clear_proofs() -> None:
677678
proof_dir = Path(__file__).parent / 'proofs'
678-
save_directory = Path(__file__).parent / 'summaries'
679-
summarizer = KEVMSummarizer(proof_dir, save_directory)
680-
summarizer.analyze_proof(str(proof_dir / f'{opcode}_SPEC'), node_id)
679+
if proof_dir.exists():
680+
shutil.rmtree(proof_dir)

0 commit comments

Comments
 (0)