Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit c9eb6f5

Browse files
ehildenbrv-auditor
andauthored
Add RPC based prover to KProve interface (#948)
This PR aims to expose a very basic RPC prover in the `KProve` class. In particular: - The command `pyk prove ...` is renamed to `pyk prove-legacy ...` (and single test adjusted). This functionality is not really used anywhere. - The functionality `legacy_explore` from KEVM is upstreamd to `cterm_symbolic` helper in `cterm.symbolic`. It has the same option to start or not an RPC server, and also implements the context-manager functionality. - The functionality to do proving with RPC server is added to `KProve`. We have: - `KProve.prove_claim_rpc`: starts up a `kore-rpc` server using `cterm_symbolic`, and runs the proof as an `APRProof`. Nothing fancy is done with interpreting claim dependencies, circularities, or parallelism. - `KProve.prove_rpc`: mimics the `KProve.prove` interface where a spec file with a potential list of claims is passed in, collects the claims and discharges them with `KProve.prove_claim_rpc`. - A lot of defunct functionality is removed from `KProve`: - Early prototype of RPC based prover `KProve.prove_cterm` is removed, and associated tests. - Various arguments to `KProve.prove` which were not being used anywhere, or only used in specific ways, are eliminated to simplify the function (for eventual removal of that function, as it's the `prove-legacy` hookup). - The function `KProve.get_claim_modules` no longer uses `KProve.prove(...)` functionality, instead directly invokes `_kprove(...)` helper to further allow `KProve.prove(...)` to be simplified. - A test-suite is added for `KProve.prove_rpc` which re-uses all the tests from `proof/test_imp.py` which are passing using the new interface directly, to make sure the functionality doesn't break. --------- Co-authored-by: devops <[email protected]>
1 parent e8537c0 commit c9eb6f5

File tree

12 files changed

+435
-155
lines changed

12 files changed

+435
-155
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
project = 'pyk'
1010
author = 'Runtime Verification, Inc'
1111
copyright = '2024, Runtime Verification, Inc'
12-
version = '0.1.691'
13-
release = '0.1.691'
12+
version = '0.1.692'
13+
release = '0.1.692'
1414

1515
# -- General configuration ---------------------------------------------------
1616
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.691
1+
0.1.692

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pyk"
7-
version = "0.1.691"
7+
version = "0.1.692"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

src/pyk/__main__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def exec_rpc_kast(args: Namespace) -> None:
210210
args.output_file.write(json.dumps(request))
211211

212212

213-
def exec_prove(args: Namespace) -> None:
213+
def exec_prove_legacy(args: Namespace) -> None:
214214
kompiled_dir: Path = args.definition_dir
215215
kprover = KProve(kompiled_dir, args.main_file)
216216
final_state = kprover.prove(Path(args.spec_file), spec_module_name=args.spec_module, args=args.kArgs)
@@ -310,16 +310,16 @@ def create_argument_parser() -> ArgumentParser:
310310
)
311311
rpc_kast_args.add_argument('--output-file', type=FileType('w'), default='-')
312312

313-
prove_args = pyk_args_command.add_parser(
314-
'prove',
313+
prove_legacy_args = pyk_args_command.add_parser(
314+
'prove-legacy',
315315
help='Prove an input specification (using kprovex).',
316316
parents=[k_cli_args.logging_args, definition_args],
317317
)
318-
prove_args.add_argument('main_file', type=str, help='Main file used for kompilation.')
319-
prove_args.add_argument('spec_file', type=str, help='File with the specification module.')
320-
prove_args.add_argument('spec_module', type=str, help='Module with claims to be proven.')
321-
prove_args.add_argument('--output-file', type=FileType('w'), default='-')
322-
prove_args.add_argument('kArgs', nargs='*', help='Arguments to pass through to K invocation.')
318+
prove_legacy_args.add_argument('main_file', type=str, help='Main file used for kompilation.')
319+
prove_legacy_args.add_argument('spec_file', type=str, help='File with the specification module.')
320+
prove_legacy_args.add_argument('spec_module', type=str, help='Module with claims to be proven.')
321+
prove_legacy_args.add_argument('--output-file', type=FileType('w'), default='-')
322+
prove_legacy_args.add_argument('kArgs', nargs='*', help='Arguments to pass through to K invocation.')
323323

324324
pyk_args_command.add_parser(
325325
'graph-imports',

src/pyk/cterm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .cterm import CSubst, CTerm, build_claim, build_rule, cterm_build_claim, cterm_build_rule
2-
from .symbolic import CTermSymbolic
2+
from .symbolic import CTermSymbolic, cterm_symbolic

src/pyk/cterm/symbolic.py

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
from __future__ import annotations
22

33
import logging
4+
from contextlib import contextmanager
45
from typing import TYPE_CHECKING, NamedTuple
56

67
from ..cterm import CSubst, CTerm
78
from ..kast.inner import KApply, KLabel, KRewrite, KVariable, Subst
89
from ..kast.manip import flatten_label, free_vars
910
from ..konvert import kast_to_kore, kore_to_kast
10-
from ..kore.rpc import AbortedResult, SatResult, StopReason, UnknownResult, UnsatResult
11+
from ..kore.rpc import (
12+
AbortedResult,
13+
KoreClient,
14+
KoreExecLogFormat,
15+
SatResult,
16+
StopReason,
17+
TransportType,
18+
UnknownResult,
19+
UnsatResult,
20+
kore_server,
21+
)
1122
from ..prelude.k import GENERATED_TOP_CELL
1223
from ..prelude.ml import is_top, mlEquals, mlTop
1324

1425
if TYPE_CHECKING:
15-
from collections.abc import Iterable
26+
from collections.abc import Iterable, Iterator
27+
from pathlib import Path
1628
from typing import Final
1729

1830
from ..kast import KInner
1931
from ..kast.outer import KDefinition
2032
from ..kore.kompiled import KompiledKore
21-
from ..kore.rpc import KoreClient, LogEntry
33+
from ..kore.rpc import FallbackReason, LogEntry
2234
from ..kore.syntax import Pattern
35+
from ..utils import BugReport
2336

2437

2538
_LOGGER: Final = logging.getLogger(__name__)
@@ -228,3 +241,66 @@ def assume_defined(self, cterm: CTerm, module_name: str | None = None) -> CTerm:
228241
kast_simplified, logs = self.kast_simplify(kast, module_name=module_name)
229242
_LOGGER.debug(f'Definedness condition computed: {kast_simplified}')
230243
return cterm.add_constraint(kast_simplified)
244+
245+
246+
@contextmanager
247+
def cterm_symbolic(
248+
definition: KDefinition,
249+
kompiled_kore: KompiledKore,
250+
definition_dir: Path,
251+
*,
252+
id: str | None = None,
253+
port: int | None = None,
254+
kore_rpc_command: str | Iterable[str] | None = None,
255+
llvm_definition_dir: Path | None = None,
256+
smt_timeout: int | None = None,
257+
smt_retry_limit: int | None = None,
258+
smt_tactic: str | None = None,
259+
bug_report: BugReport | None = None,
260+
haskell_log_format: KoreExecLogFormat = KoreExecLogFormat.ONELINE,
261+
haskell_log_entries: Iterable[str] = (),
262+
log_axioms_file: Path | None = None,
263+
trace_rewrites: bool = False,
264+
start_server: bool = True,
265+
maude_port: int | None = None,
266+
fallback_on: Iterable[FallbackReason] | None = None,
267+
interim_simplification: int | None = None,
268+
no_post_exec_simplify: bool = False,
269+
) -> Iterator[CTermSymbolic]:
270+
if start_server:
271+
# Old way of handling KoreServer, to be removed
272+
with kore_server(
273+
definition_dir=definition_dir,
274+
llvm_definition_dir=llvm_definition_dir,
275+
module_name=definition.main_module_name,
276+
port=port,
277+
command=kore_rpc_command,
278+
bug_report=bug_report,
279+
smt_timeout=smt_timeout,
280+
smt_retry_limit=smt_retry_limit,
281+
smt_tactic=smt_tactic,
282+
haskell_log_format=haskell_log_format,
283+
haskell_log_entries=haskell_log_entries,
284+
log_axioms_file=log_axioms_file,
285+
fallback_on=fallback_on,
286+
interim_simplification=interim_simplification,
287+
no_post_exec_simplify=no_post_exec_simplify,
288+
) as server:
289+
with KoreClient('localhost', server.port, bug_report=bug_report, bug_report_id=id) as client:
290+
yield CTermSymbolic(client, definition, kompiled_kore, trace_rewrites=trace_rewrites)
291+
else:
292+
if port is None:
293+
raise ValueError('Missing port with start_server=False')
294+
if maude_port is None:
295+
dispatch = None
296+
else:
297+
dispatch = {
298+
'execute': [('localhost', maude_port, TransportType.HTTP)],
299+
'simplify': [('localhost', maude_port, TransportType.HTTP)],
300+
'add-module': [
301+
('localhost', maude_port, TransportType.HTTP),
302+
('localhost', port, TransportType.SINGLE_SOCKET),
303+
],
304+
}
305+
with KoreClient('localhost', port, bug_report=bug_report, bug_report_id=id, dispatch=dispatch) as client:
306+
yield CTermSymbolic(client, definition, kompiled_kore, trace_rewrites=trace_rewrites)

0 commit comments

Comments
 (0)