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 initial foundry.md #1305

Merged
merged 10 commits into from
Aug 4, 2022
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ kevm_files := abi.md \
evm.md \
evm-types.md \
evm-node.md \
foundry.md \
hashed-locations.md \
infinite-gas.md \
json-rpc.md \
Expand Down Expand Up @@ -606,7 +607,7 @@ test-failure: $(failure_tests:=.run-expected)
# kevm_pyk Tests

kevm_pyk_tests := \
tests/foundry/foundry.k.prove \
tests/foundry/kompiled/timestamp \
tests/foundry/foundry.k.check \
tests/specs/bihu/functional-spec.k.prove \
tests/specs/examples/empty-bin-runtime.k \
Expand Down
2 changes: 2 additions & 0 deletions edsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ requires "hashed-locations.md"
requires "abi.md"
requires "infinite-gas.md"
requires "optimizations.md"
requires "foundry.md"

module EDSL
imports BUF
Expand All @@ -20,6 +21,7 @@ module EDSL
imports EVM-OPTIMIZATIONS
imports INFINITE-GAS
imports BIN-RUNTIME
imports FOUNDRY
endmodule

module BIN-RUNTIME
Expand Down
38 changes: 38 additions & 0 deletions foundry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
Foundry Specifications
======================

### Overview

Foundry's testing framework provides a series of cheatcodes so that developers can specify what situation they want to test.
This file describes the KEVM specification of the Foundry testing framework, which includes the definition of said cheatcodes and what does it mean for a test to pass.

```k
requires "evm.md"
module FOUNDRY
imports FOUNDRY-SUCCESS
imports FOUNDRY-CHEAT-CODES
endmodule
```

Foundry Success Predicate
-------------------------

```k
module FOUNDRY-SUCCESS
imports EVM

syntax Bool ::= "foundry_success" "(" ")" [function, klabel(foundry_success), symbol]
// -------------------------------------------------------------------------------------
rule foundry_success() => false
endmodule
```

Foundry Cheat Codes
-------------------

```k
module FOUNDRY-CHEAT-CODES
imports EVM
endmodule
```

4 changes: 4 additions & 0 deletions kevm_pyk/src/kevm_pyk/kevm.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def wordstack_len(constrainedTerm: KInner) -> int:
def parse_bytestack(s: KInner) -> KApply:
return KApply('#parseByteStack(_)_SERIALIZATION_ByteArray_String', [s])

@staticmethod
def foundry_success() -> KApply:
return KApply('foundry_success')

@staticmethod
def intlist(ints: List[KInner]) -> KApply:
res = KApply('.List{"___HASHED-LOCATIONS_IntList_Int_IntList"}_IntList')
Expand Down
7 changes: 4 additions & 3 deletions kevm_pyk/src/kevm_pyk/solc_to_k.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
KVariable,
)
from pyk.kastManip import abstract_term_safely, substitute
from pyk.prelude import Sorts, intToken, stringToken
from pyk.prelude import Sorts, intToken, mlEqualsTrue, stringToken
from pyk.utils import FrozenDict, intersperse

from .kevm import KEVM
Expand Down Expand Up @@ -294,10 +294,11 @@ def gen_claims_for_contract(empty_config: KInner, contract_name: str, calldata_c
init_terms = [(f'{contract_name.lower()}-{i}', substitute(init_term, {'CALLDATA_CELL': cd})) for i, cd in enumerate(calldata_cells)]
else:
init_terms = [(contract_name.lower(), init_term)]
final_term = abstract_cell_vars(substitute(empty_config, final_subst))
final_cterm = CTerm(abstract_cell_vars(substitute(empty_config, final_subst)))
final_cterm = final_cterm.add_constraint(mlEqualsTrue(KEVM.foundry_success()))
claims: List[KClaim] = []
for claim_id, i_term in init_terms:
claim, _ = build_claim(claim_id, CTerm(i_term), CTerm(final_term))
claim, _ = build_claim(claim_id, CTerm(i_term), final_cterm)
claims.append(claim)
return claims

Expand Down
2 changes: 2 additions & 0 deletions tests/foundry/foundry.k.check.expected
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ module TOKENTEST-BIN-RUNTIME-SPEC
</network>
</ethereum>
</kevm>
ensures foundry_success ( )
[label(tokentest-0)]

claim [tokentest-1]: <kevm>
Expand Down Expand Up @@ -498,6 +499,7 @@ module TOKENTEST-BIN-RUNTIME-SPEC
</network>
</ethereum>
</kevm>
ensures foundry_success ( )
[label(tokentest-1)]

endmodule
Expand Down