Skip to content

Initial manual implementation of CSE #284

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.140
0.1.141
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"

[tool.poetry]
name = "kontrol"
version = "0.1.140"
version = "0.1.141"
description = "Foundry integration for KEVM"
authors = [
"Runtime Verification, Inc. <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/kontrol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
if TYPE_CHECKING:
from typing import Final

VERSION: Final = '0.1.140'
VERSION: Final = '0.1.141'
10 changes: 10 additions & 0 deletions src/kontrol/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def exec_prove(
max_iterations: int | None = None,
reinit: bool = False,
tests: Iterable[tuple[str, int | None]] = (),
include_summaries: Iterable[tuple[str, int | None]] = (),
workers: int = 1,
break_every_step: bool = False,
break_on_jumpi: bool = False,
Expand Down Expand Up @@ -294,6 +295,7 @@ def exec_prove(
prove_options=prove_options,
rpc_options=rpc_options,
tests=tests,
include_summaries=include_summaries,
)
failed = 0
for proof in results:
Expand Down Expand Up @@ -777,6 +779,14 @@ def _parse_test_version_tuple(value: str) -> tuple[str, int | None]:
type=file_path,
help='Path to JSON file containing the summary of the deployment process used for the project.',
)
prove_args.add_argument(
'--include-summary',
type=_parse_test_version_tuple,
dest='include_summaries',
default=[],
action='append',
help='Specify a summary to include as a lemma.',
)

show_args = command_parser.add_parser(
'show',
Expand Down
27 changes: 22 additions & 5 deletions src/kontrol/prove.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def foundry_prove(
prove_options: ProveOptions,
rpc_options: RPCOptions,
tests: Iterable[tuple[str, int | None]] = (),
include_summaries: Iterable[tuple[str, int | None]] = (),
) -> list[APRProof]:
if prove_options.workers <= 0:
raise ValueError(f'Must have at least one worker, found: --workers {prove_options.workers}')
Expand All @@ -62,6 +63,15 @@ def foundry_prove(

foundry.mk_proofs_dir()

summary_ids = (
[
foundry.get_apr_proof(include_summary.id).id
for include_summary in collect_tests(foundry, include_summaries, reinit=False)
]
if include_summaries
else []
)

test_suite = collect_tests(foundry, tests, reinit=prove_options.reinit)
test_names = [test.name for test in test_suite]
print(f'Running functions: {test_names}')
Expand All @@ -87,30 +97,31 @@ def foundry_prove(
for test in constructor_tests:
test.method.update_digest(foundry.digest_file)

def _run_prover(_test_suite: list[FoundryTest]) -> list[APRProof]:
def _run_prover(_test_suite: list[FoundryTest], include_summaries: bool = False) -> list[APRProof]:
return _run_cfg_group(
tests=_test_suite,
foundry=foundry,
prove_options=prove_options,
rpc_options=rpc_options,
summary_ids=(summary_ids if include_summaries else []),
)

if prove_options.run_constructor:
_LOGGER.info(f'Running initialization code for contracts in parallel: {constructor_names}')
results = _run_prover(constructor_tests)
results = _run_prover(constructor_tests, include_summaries=False)
failed = [proof for proof in results if not proof.passed]
if failed:
raise ValueError(f'Running initialization code failed for {len(failed)} contracts: {failed}')

_LOGGER.info(f'Running setup functions in parallel: {setup_method_names}')
results = _run_prover(setup_method_tests)
results = _run_prover(setup_method_tests, include_summaries=False)

failed = [proof for proof in results if not proof.passed]
if failed:
raise ValueError(f'Running setUp method failed for {len(failed)} contracts: {failed}')

_LOGGER.info(f'Running test functions in parallel: {test_names}')
results = _run_prover(test_suite)
results = _run_prover(test_suite, include_summaries=True)
return results


Expand Down Expand Up @@ -185,6 +196,7 @@ def _run_cfg_group(
foundry: Foundry,
prove_options: ProveOptions,
rpc_options: RPCOptions,
summary_ids: Iterable[str],
) -> list[APRProof]:
def init_and_run_proof(test: FoundryTest) -> APRFailureInfo | None:
if Proof.proof_data_exists(test.id, foundry.proofs_dir):
Expand Down Expand Up @@ -214,6 +226,7 @@ def init_and_run_proof(test: FoundryTest) -> APRFailureInfo | None:
run_constructor=prove_options.run_constructor,
use_gas=prove_options.use_gas,
summary_entries=prove_options.summary_entries,
summary_ids=summary_ids,
)

cut_point_rules = KEVMSemantics.cut_point_rules(
Expand Down Expand Up @@ -268,6 +281,7 @@ def method_to_apr_proof(
run_constructor: bool = False,
use_gas: bool = False,
summary_entries: Iterable[SummaryEntry] | None = None,
summary_ids: Iterable[str] = (),
) -> APRProof:
if Proof.proof_data_exists(test.id, foundry.proofs_dir):
apr_proof = foundry.get_apr_proof(test.id)
Expand Down Expand Up @@ -303,9 +317,12 @@ def method_to_apr_proof(
{},
bmc_depth,
proof_dir=foundry.proofs_dir,
subproof_ids=summary_ids,
)
else:
apr_proof = APRProof(test.id, kcfg, [], init_node_id, target_node_id, {}, proof_dir=foundry.proofs_dir)
apr_proof = APRProof(
test.id, kcfg, [], init_node_id, target_node_id, {}, proof_dir=foundry.proofs_dir, subproof_ids=summary_ids
)

apr_proof.write_proof_data()
return apr_proof
Expand Down
Loading