Skip to content
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

Add functionality for merging covers, target pullbacks #1976

Closed
wants to merge 3 commits into from
Closed
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 kevm-pyk/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 = "kevm-pyk"
version = "1.0.241"
version = "1.0.242"
description = ""
authors = [
"Runtime Verification, Inc. <[email protected]>",
Expand Down
12 changes: 12 additions & 0 deletions kevm-pyk/src/kevm_pyk/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
foundry_get_model,
foundry_kompile,
foundry_list,
foundry_merge_target,
foundry_node_printer,
foundry_prove,
foundry_remove_node,
Expand Down Expand Up @@ -680,6 +681,10 @@ def exec_foundry_remove_node(foundry_root: Path, test: str, node: NodeIdLike, **
foundry_remove_node(foundry_root=foundry_root, test=test, node=node)


def exec_foundry_merge_target(foundry_root: Path, test: str, **kwargs: Any) -> None:
foundry_merge_target(foundry_root=foundry_root, test=test)


def exec_foundry_simplify_node(
foundry_root: Path,
test: str,
Expand Down Expand Up @@ -1032,6 +1037,13 @@ def parse(s: str) -> list[T]:
foundry_remove_node.add_argument('test', type=str, help='View the CFG for this test.')
foundry_remove_node.add_argument('node', type=node_id_like, help='Node to remove CFG subgraph from.')

foundry_merge_target = command_parser.add_parser(
'foundry-merge-target',
help='Merge the target subsumed node of a proof.',
parents=[kevm_cli_args.logging_args, kevm_cli_args.foundry_args],
)
foundry_merge_target.add_argument('test', type=str, help='Test to apply to.')

foundry_simplify_node = command_parser.add_parser(
'foundry-simplify-node',
help='Simplify a given node, and potentially replace it.',
Expand Down
21 changes: 21 additions & 0 deletions kevm-pyk/src/kevm_pyk/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,27 @@ def foundry_remove_node(foundry_root: Path, test: str, node: NodeIdLike) -> None
apr_proof.write_proof()


def foundry_merge_target(foundry_root: Path, test: str) -> None:
foundry = Foundry(foundry_root)
proofs_dir = foundry.out / 'apr_proofs'
contract_name, test_name = test.split('.')
proof_digest = foundry.proof_digest(contract_name, test_name)
proof = Proof.read_proof(proof_digest, proofs_dir)
assert isinstance(proof, APRProof)
target_subsumptions = proof.kcfg.covers(target_id=proof.target)
ts_by_statuscode: dict[KInner, list[KCFG.Cover]] = {}
for ts in target_subsumptions:
status_code = ts.source.cterm.cell('STATUSCODE_CELL')
if type(status_code) is KToken:
if status_code not in ts_by_statuscode:
ts_by_statuscode[status_code] = []
ts_by_statuscode[status_code].append(ts)
for ts_covers in ts_by_statuscode.values():
if len(ts_covers) > 1:
proof.kcfg.minimize_covers([cover.source.id for cover in ts_covers], proof.target)
# proof.write_proof()


def foundry_simplify_node(
foundry_root: Path,
test: str,
Expand Down
2 changes: 1 addition & 1 deletion package/debian/changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kevm (1.0.241) unstable; urgency=medium
kevm (1.0.242) unstable; urgency=medium

* Initial Release.

Expand Down
2 changes: 1 addition & 1 deletion package/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.241
1.0.242
12 changes: 12 additions & 0 deletions tests/foundry/test/Arithmetic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,16 @@ contract ArithmeticTest is Test {
assertTrue(c2 <= c1);
}

function add_uint_int(uint x, int y) public pure returns (uint z) {
if (x < 10) {
z = uint(y) + x;
} else {
z = x + uint(y);
}
}

function test_double_add(uint x, int y) external {
uint z = add_uint_int(x, y);
z = add_uint_int(z, y);
}
}