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

Extending CSE support #355

Merged
merged 114 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 37 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
ac29afc
test for CSE function calls
PetarMax Feb 9, 2024
f001577
Set Version: 0.1.152
Feb 9, 2024
a86786e
Merge remote-tracking branch 'origin/master' into petar/cse-exploration
PetarMax Feb 9, 2024
ea8b4df
Set Version: 0.1.153
Feb 9, 2024
781820e
further examples, tests, and lemmas
PetarMax Feb 12, 2024
738aa81
merge with master
PetarMax Feb 12, 2024
2cc66ad
Set Version: 0.1.155
Feb 12, 2024
b0d2270
Update dependency: deps/kevm_release (#364)
rv-jenkins Feb 13, 2024
5e7808d
Set Version: 0.1.156
Feb 13, 2024
611d972
merge with master
PetarMax Feb 13, 2024
2eb00d3
Set Version: 0.1.158
Feb 13, 2024
0cf45fd
Merge branch 'master' into petar/cse-exploration
PetarMax Feb 22, 2024
f65a253
Set Version: 0.1.167
Feb 22, 2024
8420897
refactoring, removing unneeded files
PetarMax Feb 22, 2024
e9dd9c3
Merge branch 'master' into petar/cse-exploration
PetarMax Feb 22, 2024
b8209ee
Set Version: 0.1.169
Feb 22, 2024
fca77f7
Add `kontrol refute-node` and `kontrol unrefute-node` commands (#381)
lucasmt Feb 22, 2024
c8d6329
Update dependency: deps/kevm_release (#392)
rv-jenkins Feb 23, 2024
8bcbf47
Set Version: 0.1.171
Feb 23, 2024
4850100
merge with master
PetarMax Feb 26, 2024
f798d5e
Set Version: 0.1.172
Feb 26, 2024
bbffd7d
path correction
PetarMax Feb 26, 2024
4730d4c
redesigning CSE tests
PetarMax Feb 27, 2024
2cd38e0
slightly more general WETH contract
PetarMax Feb 27, 2024
8b7bdc8
minor spacing consistencies
PetarMax Feb 27, 2024
d028c13
generalising test harness
PetarMax Feb 27, 2024
8f09a05
Merge branch 'master' into petar/cse-exploration
PetarMax Feb 28, 2024
c6139b3
Set Version: 0.1.174
Feb 28, 2024
3947a6a
additional proof options for dependency tests
PetarMax Feb 27, 2024
e52cc6a
AddConst test
PetarMax Feb 28, 2024
bcc25d3
initialisation of accessedStorage
PetarMax Feb 28, 2024
f41c7c0
formatting
PetarMax Feb 28, 2024
376af18
test correction
PetarMax Feb 28, 2024
7869c2a
adding expected files, WETH9 contract
PetarMax Feb 28, 2024
157a3d6
correction
PetarMax Feb 28, 2024
b47afb7
removing accessStorage manipulation, adding full WETH9
PetarMax Feb 28, 2024
d484347
adding nocse kcfgs and updating cse ones
PetarMax Feb 28, 2024
11c998d
correction
PetarMax Feb 28, 2024
63de5e6
Merge branch 'master' into petar/cse-exploration
PetarMax Feb 28, 2024
81afef8
Set Version: 0.1.175
Feb 28, 2024
c8b0a95
addresses not equal to cheatcode address
PetarMax Feb 28, 2024
fcf0a74
Merge branch 'master' into petar/cse-exploration
PetarMax Feb 29, 2024
73e1185
Set Version: 0.1.177
Feb 29, 2024
11711c5
deps/kevm_release: Set Version 1.0.465
Feb 28, 2024
1941bed
Sync Poetry files: kevm-pyk version 1.0.465
Feb 28, 2024
b2c0c8f
flake.{nix,lock}: update Nix derivations
Feb 28, 2024
0ffab2c
deps/kevm_release: Set Version 1.0.466
Feb 28, 2024
418f484
Sync Poetry files: kevm-pyk version 1.0.466
Feb 28, 2024
d743cdc
deps/k_release: sync release file version 6.3.17
Feb 28, 2024
7a9fa5c
flake.{nix,lock}: update Nix derivations
Feb 28, 2024
b13c7d7
kontrol/{solc_to_k,prove,foundry}: updates from upstream
ehildenb Feb 28, 2024
050a926
src/tests/unit: update expected output
ehildenb Feb 28, 2024
44015a0
additional lemmas for discharging infeasible branches
PetarMax Feb 29, 2024
4ed23e3
merge with master
PetarMax Mar 1, 2024
761bd71
Set Version: 0.1.178
Mar 1, 2024
b523bfc
caller in accounts
PetarMax Mar 1, 2024
b549059
:integration/test_kontrol_cse.py: init
anvacaru Mar 1, 2024
4af255c
updating expected outputs
PetarMax Mar 1, 2024
cf92e53
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 4, 2024
8eb77c0
Set Version: 0.1.180
Mar 4, 2024
6efcc71
Generate xml report (#377)
lisandrasilva Mar 5, 2024
c9e33d1
Refactor get_test_id to fetch latest version (#406)
anvacaru Mar 5, 2024
4949d0b
Remove upper bound from pytest version (#408)
tothtamas28 Mar 5, 2024
cd0ea2c
Update dependency: deps/kevm_release (#410)
rv-jenkins Mar 6, 2024
50bb141
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 6, 2024
9d7e7ab
Set Version: 0.1.184
Mar 6, 2024
006a320
simplifying lemams and adding them to CI
PetarMax Mar 6, 2024
8a7fdda
Set Version: 0.1.185
Mar 6, 2024
87db3ee
Merge remote-tracking branch 'origin/master' into petar/cse-exploration
anvacaru Mar 7, 2024
d16d3df
test_kontrol_cse.py: move dependency test from test_foundry_prove
anvacaru Mar 7, 2024
f7f01ac
Set Version: 0.1.188
Mar 7, 2024
3b333e3
test_kontrol_cse.py: refactor test harness
anvacaru Mar 8, 2024
7873fa8
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 8, 2024
2c22a28
Set Version: 0.1.192
Mar 8, 2024
cf8b92e
Update dependency: deps/kevm_release (#419)
rv-jenkins Mar 7, 2024
bc3e3a1
skipping tests
PetarMax Mar 8, 2024
5855667
correction
PetarMax Mar 8, 2024
22914ec
correction: caller in accounts
PetarMax Mar 8, 2024
752d759
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 9, 2024
cdf793f
Set Version: 0.1.193
Mar 9, 2024
82c276d
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 9, 2024
fb699ca
Set Version: 0.1.194
Mar 9, 2024
653ddac
removing cbor and hash disabling
PetarMax Mar 9, 2024
071e079
updating expected output
PetarMax Mar 9, 2024
9aa2649
manual correction of expected output
PetarMax Mar 10, 2024
8fa5f73
adding appropriate expected outputs
PetarMax Mar 10, 2024
23dbbb0
attempting to manually fix expected output
PetarMax Mar 10, 2024
cfb570e
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 11, 2024
74bd5dc
Set Version: 0.1.195
Mar 11, 2024
af253fa
Merge remote-tracking branch 'origin/master' into petar/cse-exploration
PetarMax Mar 12, 2024
3db29ba
adding a CSE CI runner, removing no-cse executions
PetarMax Mar 12, 2024
40cc541
removing no-cse.expected files
PetarMax Mar 12, 2024
a7d3a2c
updating expected outputs
PetarMax Mar 12, 2024
c6012d2
Set Version: 0.1.197
Mar 12, 2024
cdeaab1
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 12, 2024
50e6659
Set Version: 0.1.197
Mar 12, 2024
ef1147f
name correction for CI job
PetarMax Mar 12, 2024
31e823b
Update src/tests/integration/test-data/foundry-dependency-all
PetarMax Mar 12, 2024
dd04e05
Update src/tests/integration/test-data/foundry-dependency-skip
PetarMax Mar 12, 2024
3ab1067
removing unused code
PetarMax Mar 12, 2024
ac7cd09
bringing back execution without CSE for testing purposes
PetarMax Mar 13, 2024
f185905
merge with master
PetarMax Mar 13, 2024
d21d2fe
Set Version: 0.1.200
Mar 13, 2024
765661a
adding expected output for no-cse tests
PetarMax Mar 13, 2024
20690e0
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 13, 2024
79cfee9
Set Version: 0.1.202
Mar 13, 2024
40d413a
merge with master, update expected outputs
PetarMax Mar 14, 2024
ad142c3
Set Version: 0.1.204
Mar 14, 2024
63d4659
updating expected outputs, correcting non-cse executions
PetarMax Mar 14, 2024
f312d02
removing no-cse and updating expected outputs
PetarMax Mar 14, 2024
499ac0b
Updating the running of proofs
PetarMax Mar 14, 2024
1a34f80
Set Version: 0.1.205
Mar 14, 2024
9fc0fb7
Merge branch 'master' into petar/cse-exploration
PetarMax Mar 14, 2024
88bd720
adding a skipped test in init tests due to a run-constructor error
PetarMax Mar 15, 2024
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.173
0.1.174
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.173"
version = "0.1.174"
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.173'
VERSION: Final = '0.1.174'
19 changes: 19 additions & 0 deletions src/kontrol/foundry.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ def loc_FOUNDRY_FAILED() -> KApply: # noqa: N802
)
)

@staticmethod
def symbolic_contract_prefix() -> str:
return 'CONTRACT'

@staticmethod
def symbolic_contract_id() -> str:
return Foundry.symbolic_contract_prefix() + '_ID'

@staticmethod
def address_TEST_CONTRACT() -> KToken: # noqa: N802
return intToken(0x7FA9385BE102AC3EAC297483DD6233D62B3E1496)
Expand All @@ -357,6 +365,17 @@ def account_CHEATCODE_ADDRESS(store_var: KInner) -> KApply: # noqa: N802
intToken(0),
)

@staticmethod
def symbolic_account(prefix: str, program: KInner, storage: KInner | None = None) -> KApply:
return KEVM.account_cell(
KVariable(prefix + '_ID', sort=KSort('Int')),
KVariable(prefix + '_BAL', sort=KSort('Int')),
program,
storage if storage is not None else KVariable(prefix + '_STORAGE', sort=KSort('Map')),
KVariable(prefix + '_ORIGSTORAGE', sort=KSort('Map')),
KVariable(prefix + '_NONCE', sort=KSort('Int')),
)

@staticmethod
def help_info() -> list[str]:
res_lines: list[str] = []
Expand Down
22 changes: 21 additions & 1 deletion src/kontrol/prove.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pyk.prelude.k import GENERATED_TOP_CELL
from pyk.prelude.kbool import FALSE, TRUE, notBool
from pyk.prelude.kint import intToken
from pyk.prelude.ml import mlEqualsTrue
from pyk.prelude.ml import mlEqualsFalse, mlEqualsTrue
from pyk.prelude.string import stringToken
from pyk.proof.proof import Proof
from pyk.proof.reachability import APRProof
Expand Down Expand Up @@ -572,6 +572,7 @@ def _init_cterm(
'STATUSCODE_CELL': KVariable('STATUSCODE'),
'PROGRAM_CELL': program,
'JUMPDESTS_CELL': KEVM.compute_valid_jumpdests(program),
'ID_CELL': KVariable(Foundry.symbolic_contract_id(), sort=KSort('Int')),
'ORIGIN_CELL': KVariable('ORIGIN_ID', sort=KSort('Int')),
'CALLER_CELL': KVariable('CALLER_ID', sort=KSort('Int')),
'LOCALMEM_CELL': bytesToken(b''),
Expand Down Expand Up @@ -609,6 +610,17 @@ def _init_cterm(
'ACCOUNTS_CELL': KEVM.accounts(init_account_list),
}
init_subst.update(init_subst_test)
else:
# Symbolic accounts of all relevant contracts
# Status: Currently, only the executing contract
# TODO: Add all other accounts belonging to relevant contracts
accounts: list[KInner] = [
Foundry.symbolic_account(Foundry.symbolic_contract_prefix(), program),
KVariable('ACCOUNTS_REST', sort=KSort('AccountCellMap')),
]

init_subst_accounts = {'ACCOUNTS_CELL': KEVM.accounts(accounts)}
init_subst.update(init_subst_accounts)

if calldata is not None:
init_subst['CALLDATA_CELL'] = calldata
Expand All @@ -623,6 +635,14 @@ def _init_cterm(

init_term = Subst(init_subst)(empty_config)
init_cterm = CTerm.from_kast(init_term)
# The address of the executing contract is always guaranteed not to be the address of the cheatcode contract
init_cterm = init_cterm.add_constraint(
mlEqualsFalse(
KApply(
'_==Int_', [KVariable(Foundry.symbolic_contract_id(), sort=KSort('Int')), Foundry.address_CHEATCODE()]
)
)
)
init_cterm = KEVM.add_invariant(init_cterm)

return init_cterm
Expand Down
4 changes: 4 additions & 0 deletions src/tests/integration/test-data/foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ out = 'out'
test = 'test'
extra_output = ['storageLayout', 'abi', 'evm.methodIdentifiers', 'evm.deployedBytecode.object', 'devdoc']
rpc_endpoints = { optimism = "https://optimism.alchemyapi.io/v2/...", mainnet = "${RPC_MAINNET}" }

bytecode_hash = "none"
cbor_metadata = false

ast = true
39 changes: 39 additions & 0 deletions src/tests/integration/test-data/foundry/src/cse/Binary.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.13;

import { UIntBinaryOp } from "./OperatorInterfaces.sol";
import { Identity } from "./Unary.sol";

// CSE challenge: storage variable of a contract type
// CSE challenge: cross-contract external function call
contract Add is UIntBinaryOp {
Identity id;

function applyOp(uint256 x, uint256 y) external view returns (uint256 result) {
return id.applyOp(x) + id.applyOp(y);
}

}

// CSE challenge: storage variable of a contract type
// CSE challenge: cross-contract external function call
contract Sub is UIntBinaryOp {
Identity id;

function applyOp(uint256 x, uint256 y) external view returns (uint256 result) {
return id.applyOp(x) - id.applyOp(y);
}
}

// CSE challenge: storage variable of a contract type
// CSE challenge: cross-contract external function call
// CSE challenge: bounded reasoning
contract Multiply is UIntBinaryOp {
Add adder;

function applyOp(uint256 x, uint256 y) external view returns (uint256 result) {
for (result = 0; y > 0; y--) {
result = adder.applyOp(result, x);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.13;

interface UIntUnaryOp {
function applyOp(uint256 x) external view returns (uint256);
}

interface UIntBinaryOp {
function applyOp(uint256 x, uint256 y) external view returns (uint256 result);
}
42 changes: 42 additions & 0 deletions src/tests/integration/test-data/foundry/src/cse/Unary.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.13;

import { UIntUnaryOp } from "./OperatorInterfaces.sol";

// CSE challenge: external function call
contract Identity is UIntUnaryOp {

function identity(uint256 x) external pure returns (uint256) {
return x;
}

function applyOp(uint256 x) external view returns (uint256) {
return this.identity(x);
}
}

// CSE challenge: storage variable of a basic type
contract AddConst is UIntUnaryOp {
uint256 c;

function setConst(uint256 x) external {
c = x;
}

function applyOp(uint256 x) external view returns (uint256) {
return x + c;
}
}

// CSE challenge: storage variable of an interface type
// this is higher-order and not possible in general
// one way of handling this is instantiating the `UIntUnaryOp`
// interface with specific contracts that implement it
// CSE challenge: cross-contract external function call
contract Iterate is UIntUnaryOp {
UIntUnaryOp f;

function applyOp(uint256 x) external view returns (uint256) {
return f.applyOp((f.applyOp(x)));
}
}
66 changes: 66 additions & 0 deletions src/tests/integration/test-data/foundry/src/cse/WETH9.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity =0.8.13;

// CSE challenge: initialised contract variables
// CSE challenge: global variables
// CSE challenge: mappings in storage

contract WETH9 {
string public name = "Wrapped Ether";
string public symbol = "WETH";
uint8 public decimals = 18;

event Approval(address indexed src, address indexed guy, uint256 wad);
event Transfer(address indexed src, address indexed dst, uint256 wad);
event Deposit(address indexed dst, uint256 wad);
event Withdrawal(address indexed src, uint256 wad);

mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;

fallback() external payable {
deposit();
}

function deposit() public payable {
balanceOf[msg.sender] += msg.value;
emit Deposit(msg.sender, msg.value);
}

function withdraw(uint256 wad) public {
require(balanceOf[msg.sender] >= wad);
balanceOf[msg.sender] -= wad;
payable(msg.sender).transfer(wad);
emit Withdrawal(msg.sender, wad);
}

function totalSupply() public view returns (uint256) {
return address(this).balance;
}

function approve(address guy, uint256 wad) public returns (bool) {
allowance[msg.sender][guy] = wad;
emit Approval(msg.sender, guy, wad);
return true;
}

function transfer(address dst, uint256 wad) public returns (bool) {
return transferFrom(msg.sender, dst, wad);
}

function transferFrom(address src, address dst, uint256 wad) public returns (bool) {
require(balanceOf[src] >= wad);

if (src != msg.sender && allowance[src][msg.sender] != type(uint256).max) {
require(allowance[src][msg.sender] >= wad);
allowance[src][msg.sender] -= wad;
}

balanceOf[src] -= wad;
balanceOf[dst] += wad;

emit Transfer(src, dst, wad);

return true;
}
}
33 changes: 33 additions & 0 deletions src/tests/integration/test-data/foundry/src/cse/lemmas.k
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
requires "evm.md"
requires "foundry.md"

module CSE-LEMMAS
imports BOOL
imports FOUNDRY
imports INFINITE-GAS
imports INT-SYMBOLIC
imports MAP-SYMBOLIC
imports SET-SYMBOLIC

// xor in terms of -Int
rule X xorInt maxUInt256 => maxUInt256 -Int X
requires #rangeUInt ( 256 , X )
[simplification]

// for-loop chop
rule chop ( ( X:Int +Int Y:Int ) ) ==Int 0 => X ==Int pow256 -Int (Y modInt pow256)
requires #rangeUInt(256, X) andBool 0 <=Int Y
[simplification, concrete(Y)]

// Set equality needed for discharging `#Not ( #Exists ( ... )` on `<accessedAccounts>` unification
rule { S1:Set #Equals S2:Set |Set SetItem ( X ) } =>
{ X in S1 } #And
( { S2 #Equals S1 } #Or { S2 #Equals S1 -Set SetItem ( X ) } )
[simplification]

endmodule
ehildenb marked this conversation as resolved.
Show resolved Hide resolved

module CSE-LEMMAS-SPEC
imports CSE-LEMMAS

endmodule
34 changes: 34 additions & 0 deletions src/tests/integration/test-data/foundry/test/CSE.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;

import "forge-std/Test.sol";

import "src/cse/Unary.sol";
import "src/cse/Binary.sol";
import "src/cse/WETH9.sol";

contract CSETest is Test {
Identity i;
AddConst c;
Multiply m;

function setUp() external {
i = new Identity();
c = new AddConst();
m = new Multiply();
}

// CSE challenge: External function call
function test_identity(uint256 x, uint256 y) external view {
vm.assume(x < 2 ** 64 && y < 2 ** 64);
uint256 z = i.applyOp(x) + i.applyOp(y) + i.applyOp(y);
assert(z == x + 2 * y);
}

function test_add_const(uint256 x, uint256 y) external {
vm.assume(x < 2 ** 64 && y < 2 ** 64);
c.setConst(x);
uint256 z = c.applyOp(y);
assert(z == x + y);
}
}
Loading
Loading