Skip to content

Add foundry-merge-nodes option #1934

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 85 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
6decda9
Add foundry-merge-nodes option
nwatson22 Jun 30, 2023
ab52b3a
Set Version: 1.0.225
rv-auditor Jun 30, 2023
3263a14
Anti-unify without disjunct
nwatson22 Jun 30, 2023
30bbe7c
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Jun 30, 2023
46ed058
Update kevm-pyk/src/kevm_pyk/foundry.py
nwatson22 Jun 30, 2023
554a5b9
Update kevm-pyk/src/kevm_pyk/foundry.py
nwatson22 Jun 30, 2023
7b4fd9d
Fix formatting
nwatson22 Jun 30, 2023
62c2f5d
Rename apr_proof to proof, reduce whitespace
nwatson22 Jun 30, 2023
7ea8281
Disallow merging nodes if they do not match on <k>, <program>, <pc>, …
nwatson22 Jun 30, 2023
dfcc2c2
Improve variable naming
nwatson22 Jun 30, 2023
1c7105d
Add test for branch merging
nwatson22 Jun 30, 2023
2b39df6
Update expected contracts.k
nwatson22 Jul 3, 2023
5528a10
Set Version: 1.0.226
rv-auditor Jul 3, 2023
2ce28d4
Merge branch 'master' into noah/merge-branches
nwatson22 Jul 3, 2023
ce4755d
Set Version: 1.0.226
rv-auditor Jul 3, 2023
97af09f
Update expected output
nwatson22 Jul 3, 2023
94fcacf
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Jul 3, 2023
2f3db2d
Merge branch 'master' into noah/merge-branches
nwatson22 Jul 3, 2023
9e09ba9
Set Version: 1.0.227
rv-auditor Jul 3, 2023
bc19fbc
Update test_foundry_fail expected files
nwatson22 Jul 3, 2023
a7e1c9f
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Jul 3, 2023
9094565
Keep disjunction of concrete values
nwatson22 Jul 4, 2023
459c246
Switch to using associated pyk branch
nwatson22 Jul 4, 2023
a842c40
Merge master into branch
nwatson22 Jul 4, 2023
0522081
Set Version: 1.0.228
rv-auditor Jul 4, 2023
5e15427
Fix foundry_get_apr_proof and foundry_step_node to be compatible with…
nwatson22 Jul 4, 2023
ba9d0cd
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Jul 4, 2023
cb7933c
Fix various commands to work with APRBMCProof
nwatson22 Jul 4, 2023
cb55234
Update kevm-pyk/src/kevm_pyk/__main__.py
nwatson22 Jul 4, 2023
63340fb
Update kevm-pyk/src/kevm_pyk/foundry.py
nwatson22 Jul 4, 2023
3e11a53
Update foundry_merge_nodes test
nwatson22 Jul 4, 2023
686a4f9
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Jul 4, 2023
dccdc1b
Fix formatting
nwatson22 Jul 5, 2023
8160217
Update expected files
nwatson22 Jul 5, 2023
96453a9
Merge branch 'master' into noah/merge-branches
nwatson22 Jul 5, 2023
1b95136
Set Version: 1.0.229
rv-auditor Jul 5, 2023
ea9d9ec
Merge master into branch, update pyk
nwatson22 Jul 7, 2023
02819a7
Set Version: 1.0.231
rv-auditor Jul 7, 2023
014824c
Merge branch 'master' into noah/merge-branches
nwatson22 Jul 10, 2023
02c6884
Set Version: 1.0.232
rv-auditor Jul 10, 2023
32edf02
Merge branch 'master' into noah/merge-branches
nwatson22 Jul 18, 2023
994fbbe
Set Version: 1.0.235
rv-auditor Jul 18, 2023
5fbe678
Merge master into branch
nwatson22 Jul 19, 2023
be24a15
Merge master into branch
nwatson22 Jul 19, 2023
fc65509
Merge master into branch
nwatson22 Jul 19, 2023
53ea9e9
Set Version: 1.0.236
rv-auditor Jul 19, 2023
eb54d76
Revert poetry.lock
nwatson22 Jul 19, 2023
58ab024
Fix setUp method execution being limited by max_iterations
nwatson22 Jul 20, 2023
f48de7c
Merge master into branch, change test_foundry_merge_nodes to use infi…
nwatson22 Jul 26, 2023
0f5d6dd
Set Version: 1.0.239
rv-auditor Jul 26, 2023
a192f0c
Merge master into branch
nwatson22 Aug 3, 2023
153886a
Set Version: 1.0.244
rv-auditor Aug 3, 2023
ef3cd86
Merge master into branch
nwatson22 Aug 8, 2023
5f99e71
Set Version: 1.0.249
rv-auditor Aug 8, 2023
12828c2
Merge master into branch
nwatson22 Aug 9, 2023
ee6cfc9
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Aug 9, 2023
f8f49cf
Set Version: 1.0.250
rv-auditor Aug 9, 2023
6222e33
Revert foundry_get_proof and foundry_get_apr_proof changes as they ha…
nwatson22 Aug 9, 2023
94b63ce
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Aug 9, 2023
42e823d
Fix foundry_list proof_data_exists call
nwatson22 Aug 9, 2023
e4c044f
Use digest, not just method name for looking up setUp method
nwatson22 Aug 9, 2023
115a6e5
Revert change to proof loading path
nwatson22 Aug 9, 2023
29673b7
Merge branch 'master' into noah/merge-branches
nwatson22 Aug 10, 2023
2d15aa7
Use foundry.get_apr_proof in foundry_merge_nodes
nwatson22 Aug 10, 2023
bb6e17b
Set Version: 1.0.251
rv-auditor Aug 10, 2023
4327c53
Use foundry.get_apr_proof in test
nwatson22 Aug 10, 2023
b59c0cc
Merge branch 'noah/merge-branches' of https://github.com/runtimeverif…
nwatson22 Aug 10, 2023
5958001
Merge branch 'master' into noah/merge-branches
nwatson22 Aug 10, 2023
9512ef2
Set Version: 1.0.252
rv-auditor Aug 10, 2023
2bda719
Merge master into branch
nwatson22 Aug 16, 2023
55276fb
Set Version: 1.0.262
rv-auditor Aug 16, 2023
beed907
Merge remote-tracking branch 'origin/master' into noah/merge-branches
nwatson22 Aug 17, 2023
a15f2e9
Use new anti_unification function
nwatson22 Aug 17, 2023
f13245d
Set Version: 1.0.263
rv-auditor Aug 17, 2023
c33157a
Merge branch 'master' into noah/merge-branches
nwatson22 Aug 17, 2023
f59ebb0
Set Version: 1.0.264
rv-auditor Aug 17, 2023
445b9d6
Include kdefinition in anti_unify call and fix test
nwatson22 Aug 17, 2023
14b4ef8
Re-add foundry-merge-nodes command
nwatson22 Aug 18, 2023
89e6598
Set Version: 1.0.265
rv-auditor Aug 18, 2023
f1cb87d
Merge branch 'master' into noah/merge-branches
nwatson22 Aug 18, 2023
bdf7cf0
Set Version: 1.0.265
rv-auditor Aug 18, 2023
2efb5f3
Merge branch 'master' into noah/merge-branches
ehildenb Aug 18, 2023
c82092a
Set Version: 1.0.266
rv-auditor Aug 18, 2023
2e7849b
Merge branch 'master' into noah/merge-branches
nwatson22 Aug 18, 2023
53b4232
Set Version: 1.0.267
rv-auditor Aug 18, 2023
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
63 changes: 62 additions & 1 deletion kevm-pyk/poetry.lock

Large diffs are not rendered by default.

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.263"
version = "1.0.264"
description = ""
authors = [
"Runtime Verification, Inc. <[email protected]>",
Expand Down
68 changes: 60 additions & 8 deletions kevm-pyk/src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,11 +629,11 @@ def _init_and_run_proof(_init_problem: tuple[str, str]) -> tuple[bool, list[str]
contract = foundry.contracts[contract_name]
method = contract.method_by_sig[method_sig]
proof = _method_to_apr_proof(
foundry,
contract,
method,
save_directory,
kcfg_explore,
foundry=foundry,
contract=contract,
method=method,
save_directory=save_directory,
kcfg_explore=kcfg_explore,
reinit=(method.qualified_name in out_of_date_methods),
simplify_init=simplify_init,
bmc_depth=bmc_depth,
Expand Down Expand Up @@ -813,6 +813,53 @@ def foundry_simplify_node(
return foundry.kevm.pretty_print(res_term, unalias=False, sort_collections=sort_collections)


def foundry_merge_nodes(
foundry_root: Path,
test: str,
node_ids: Iterable[NodeIdLike],
bug_report: bool = False,
include_disjunct: bool = False,
) -> None:
def check_cells_equal(cell: str, nodes: Iterable[KCFG.Node]) -> bool:
nodes = list(nodes)
if len(nodes) < 2:
return True
cell_value = nodes[0].cterm.cell(cell)
for node in nodes[1:]:
if cell_value != node.cterm.cell(cell):
return False
return True

node_ids = [int(node) for node in node_ids]
br = BugReport(Path(f'{test}.bug_report')) if bug_report else None
foundry = Foundry(foundry_root, bug_report=br)
proof = foundry.get_apr_proof(test)

if not isinstance(proof, APRProof):
raise ValueError('Specified proof is not an APRProof.')

if len(list(node_ids)) < 2:
raise ValueError(f'Must supply at least 2 nodes to merge, got: {node_ids}')

nodes = [proof.kcfg.node(int(node_id)) for node_id in node_ids]
check_cells = ['K_CELL', 'PROGRAM_CELL', 'PC_CELL', 'CALLDEPTH_CELL']
check_cells_ne = [check_cell for check_cell in check_cells if not check_cells_equal(check_cell, nodes)]
if check_cells_ne:
raise ValueError(f'Nodes {node_ids} cannot be merged because they differ in: {check_cells_ne}')

anti_unification = nodes[0].cterm
for node in nodes[1:]:
anti_unification, _, _ = anti_unification.anti_unify(node.cterm, keep_values=True, kdef=foundry.kevm.definition)
new_node = proof.kcfg.create_node(anti_unification)
for node in nodes:
proof.kcfg.create_cover(node.id, new_node.id)

proof.write_proof_data()

print(f'Merged nodes {node_ids} into new node {new_node.id}.')
print(foundry.kevm.pretty_print(new_node.cterm.kast))


def foundry_step_node(
foundry_root: Path,
test: str,
Expand Down Expand Up @@ -871,8 +918,8 @@ def foundry_section_edge(
smt_retry_limit=smt_retry_limit,
trace_rewrites=trace_rewrites,
) as kcfg_explore:
kcfg, _ = kcfg_explore.section_edge(
apr_proof.kcfg, source_id=source_id, target_id=target_id, logs=apr_proof.logs, sections=sections
kcfg_explore.section_edge(
apr_proof.kcfg, source_id=int(source_id), target_id=int(target_id), logs=apr_proof.logs, sections=sections
)
apr_proof.write_proof_data()

Expand Down Expand Up @@ -1023,7 +1070,12 @@ def _method_to_cfg(
calldata = method.calldata_cell(contract)
callvalue = method.callvalue_cell
init_cterm = _init_cterm(
empty_config, contract.name, kcfgs_dir, calldata=calldata, callvalue=callvalue, init_state=init_state
empty_config,
contract.name,
kcfgs_dir,
calldata=calldata,
callvalue=callvalue,
init_state=init_state,
)
is_test = method.name.startswith('test')
failing = method.name.startswith('testFail')
Expand Down
17 changes: 17 additions & 0 deletions kevm-pyk/src/tests/integration/test-data/contracts.k.expected
Original file line number Diff line number Diff line change
Expand Up @@ -4790,6 +4790,8 @@ module ASSERTTEST-CONTRACT

syntax AssertTestMethod ::= "failed" "(" ")" [symbol(), klabel(method_AssertTest_failed_)]

syntax AssertTestMethod ::= "kevm" "(" ")" [symbol(), klabel(method_AssertTest_kevm_)]

syntax AssertTestMethod ::= "setUp" "(" ")" [symbol(), klabel(method_AssertTest_setUp_)]

syntax AssertTestMethod ::= "testFail_assert_false" "(" ")" [symbol(), klabel(method_AssertTest_testFail_assert_false_)]
Expand All @@ -4804,6 +4806,8 @@ module ASSERTTEST-CONTRACT

syntax AssertTestMethod ::= "test_assert_true_branch" "(" Int ":" "uint256" ")" [symbol(), klabel(method_AssertTest_test_assert_true_branch_uint256)]

syntax AssertTestMethod ::= "test_branch_merge" "(" Int ":" "uint256" ")" [symbol(), klabel(method_AssertTest_test_branch_merge_uint256)]

syntax AssertTestMethod ::= "test_failing_branch" "(" Int ":" "uint256" ")" [symbol(), klabel(method_AssertTest_test_failing_branch_uint256)]

syntax AssertTestMethod ::= "test_revert_branch" "(" Int ":" "uint256" "," Int ":" "uint256" ")" [symbol(), klabel(method_AssertTest_test_revert_branch_uint256_uint256)]
Expand All @@ -4819,6 +4823,9 @@ module ASSERTTEST-CONTRACT
rule ( AssertTest . failed ( ) => #abiCallData ( "failed" , .TypedArgs ) )


rule ( AssertTest . kevm ( ) => #abiCallData ( "kevm" , .TypedArgs ) )


rule ( AssertTest . setUp ( ) => #abiCallData ( "setUp" , .TypedArgs ) )


Expand All @@ -4841,6 +4848,10 @@ module ASSERTTEST-CONTRACT
ensures #rangeUInt ( 256 , V0_x )


rule ( AssertTest . test_branch_merge ( V0_x : uint256 ) => #abiCallData ( "test_branch_merge" , #uint256 ( V0_x ) , .TypedArgs ) )
ensures #rangeUInt ( 256 , V0_x )


rule ( AssertTest . test_failing_branch ( V0_x : uint256 ) => #abiCallData ( "test_failing_branch" , #uint256 ( V0_x ) , .TypedArgs ) )
ensures #rangeUInt ( 256 , V0_x )

Expand All @@ -4863,6 +4874,9 @@ module ASSERTTEST-CONTRACT
rule ( selector ( "failed()" ) => 3124842406 )


rule ( selector ( "kevm()" ) => 3601001590 )


rule ( selector ( "setUp()" ) => 177362148 )


Expand All @@ -4884,6 +4898,9 @@ module ASSERTTEST-CONTRACT
rule ( selector ( "test_assert_true_branch(uint256)" ) => 3267411143 )


rule ( selector ( "test_branch_merge(uint256)" ) => 1000659212 )


rule ( selector ( "test_failing_branch(uint256)" ) => 1176678741 )


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
pragma solidity =0.8.13;

import "forge-std/Test.sol";
import "../src/KEVMCheats.sol";

contract AssertTest is Test {
contract AssertTest is Test, KEVMCheats {
uint y;

function setUp() public {}
Expand All @@ -27,6 +28,16 @@ contract AssertTest is Test {
assert(y <= x);
}

function test_branch_merge(uint x) public {
kevm.infiniteGas();
if (x < 10) {
y = 0;
} else {
y = 1;
}
assert(y < 2);
}

function test_assert_false() public pure {
assert(false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@
│ (407 steps)
├─ 3
│ k: #end EVMC_REVERT ~> #pc [ REVERT ] ~> #execute ~> CONTINUATION:K
│ pc: 992
│ pc: 1249
│ callDepth: 0
│ statusCode: STATUSCODE:StatusCode
│ (1 step)
├─ 4
│ k: #halt ~> #pc [ REVERT ] ~> #execute ~> CONTINUATION:K
│ pc: 992
│ pc: 1249
│ callDepth: 0
│ statusCode: EVMC_REVERT
│ (2 steps)
├─ 5 (terminal)
│ k: #halt ~> CONTINUATION:K
│ pc: 992
│ pc: 1249
│ callDepth: 0
│ statusCode: EVMC_REVERT
Expand Down Expand Up @@ -81,7 +81,7 @@
0
</callValue>
<wordStack>
( .WordStack => ( 399 : ( 212 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) ) )
( .WordStack => ( 495 : ( 250 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) ) )
</wordStack>
<localMem>
( .Bytes => b"NH{q\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80" )
Expand Down Expand Up @@ -301,7 +301,7 @@
0
</callValue>
<wordStack>
( 399 : ( 212 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) )
( 495 : ( 250 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) )
</wordStack>
<localMem>
b"NH{q\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80"
Expand Down Expand Up @@ -509,7 +509,7 @@
0
</callValue>
<wordStack>
( 399 : ( 212 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) )
( 495 : ( 250 : ( selector ( "testFail_assert_false()" ) : .WordStack ) ) )
</wordStack>
<localMem>
b"NH{q\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x80"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
│ callDepth: 0
│ statusCode: STATUSCODE
│ (269 steps)
│ (303 steps)
├─ 3
│ k: #end EVMC_SUCCESS ~> #pc [ STOP ] ~> #execute ~> CONTINUATION:K
│ pc: 213
│ pc: 251
│ callDepth: 0
│ statusCode: STATUSCODE:StatusCode
│ (1 step)
├─ 4
│ k: #halt ~> #pc [ STOP ] ~> #execute ~> CONTINUATION:K
│ pc: 213
│ pc: 251
│ callDepth: 0
│ statusCode: EVMC_SUCCESS
│ (2 steps)
└─ 5 (leaf, terminal)
k: #halt ~> CONTINUATION:K
pc: 213
pc: 251
callDepth: 0
statusCode: EVMC_SUCCESS

Expand Down
Loading