Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

$do_balance verification #14

Open
wants to merge 83 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
94e49d3
update to wasm master
sskeirik Mar 11, 2020
7a557b7
add contract invocation example
sskeirik Mar 11, 2020
cbb0074
add more complex invocation example
sskeirik Mar 11, 2020
57002f0
Rename files
hjorthjort Mar 11, 2020
dd9722f
Make function total
hjorthjort Mar 11, 2020
46b42ca
Generalize configuration
hjorthjort Mar 11, 2020
e27e142
Specialize configuration
hjorthjort Mar 11, 2020
f71f0e7
Remove helper files not actually used for verification
hjorthjort Mar 12, 2020
a4e268e
Add kewasm-lemmas.md and set up automatic proving
hjorthjort Mar 12, 2020
cbd14fe
Remove test file
hjorthjort Mar 12, 2020
72e1586
WIP: Config for do_balance
hjorthjort Mar 12, 2020
65f16d1
Improved #storeEeiResults---feweer store operations, non-symbolic len…
hjorthjort Mar 16, 2020
988f310
Fix typo
hjorthjort Mar 16, 2020
a3ad789
Fix typing
hjorthjort Mar 16, 2020
0fe137e
Correct call to #storeEeiResult
hjorthjort Mar 16, 2020
6094cd5
Lemmas for bytes
hjorthjort Mar 16, 2020
a3b6165
A preliminary spec for $do_balance
hjorthjort Mar 16, 2020
9f98101
Update submodule
hjorthjort Mar 16, 2020
1085cee
Remove unneeded cells
hjorthjort Mar 16, 2020
a5a2325
Update deps
hjorthjort Mar 16, 2020
73c3f36
Simplify #storeEeiResult
hjorthjort Mar 16, 2020
1896e8c
Add wrapping lemmas
hjorthjort Mar 17, 2020
67c4db9
Fix spec: assure that output matches internal state of contract
hjorthjort Mar 17, 2020
294a232
Remove unused cells
hjorthjort Mar 17, 2020
d3751fd
Makefile tip
hjorthjort Mar 17, 2020
4cf323c
Use Haskell backend for proving
hjorthjort Mar 17, 2020
51521d8
Fix naming in lemma
hjorthjort Mar 17, 2020
647140e
TODO comment
hjorthjort Mar 17, 2020
9b3b072
Restore invoke-contract-spec.k
hjorthjort Mar 17, 2020
c6d1637
Use correct module for verification
hjorthjort Mar 17, 2020
3c5be41
Update KWasm submodule
hjorthjort Mar 17, 2020
0bd440c
WIP: Try erlier version of KWasm
hjorthjort Mar 18, 2020
2d28dd6
WIP: Try with old K
hjorthjort Mar 19, 2020
81c98b8
Update deps
hjorthjort Mar 31, 2020
9a72fca
Update submoudule
hjorthjort Apr 1, 2020
e8c1922
Formatting fix
hjorthjort Apr 1, 2020
05648a4
Update submodule
hjorthjort Apr 1, 2020
21cb701
Formatting
hjorthjort Apr 2, 2020
edb0fae
Avoid branching when returning
hjorthjort Apr 2, 2020
8519d6a
Spec formatting
hjorthjort Apr 2, 2020
3628675
Update submodule
hjorthjort Apr 2, 2020
7d6c8ad
Merge remote-tracking branch 'origin/master' into balance-verification
hjorthjort Apr 2, 2020
8921384
Merge remote-tracking branch 'origin/master' into balance-verification
hjorthjort Apr 8, 2020
0b307b1
Add lemma for in_keys, proof passes
hjorthjort Apr 8, 2020
afe8d50
Lemma generalization
hjorthjort Apr 8, 2020
3ba0043
Remove invocation spec for now, since it's part of a different branch
hjorthjort Apr 8, 2020
57459ac
Change to using simpler #storeEeiResult when storing Bytes
hjorthjort Apr 9, 2020
10450fa
Revert "Change to using simpler #storeEeiResult when storing Bytes"
hjorthjort Apr 9, 2020
9f5c87c
Allow further accounts
hjorthjort Apr 9, 2020
aac54d4
Generalize identifier map
hjorthjort Apr 9, 2020
97ff124
Generalize function addresses
hjorthjort Apr 9, 2020
962d001
Generalize functions addresses
hjorthjort Apr 9, 2020
876ad47
Further generalize spec config
hjorthjort Apr 9, 2020
468cfbf
Add more upstream lemmas and rearrange
hjorthjort Apr 9, 2020
625ce6f
Formatting of proof
hjorthjort Apr 9, 2020
2904ab7
Remove whitespace
hjorthjort Apr 9, 2020
59cd5e5
Remove functions for keeping function addresses distinct
hjorthjort Apr 9, 2020
3656a95
Merge branch 'master' into balance-verification
hjorthjort Apr 9, 2020
4d0999a
Use symbolic selector
hjorthjort Apr 9, 2020
44534e6
Update submodule
hjorthjort Apr 16, 2020
3753ee4
Merge branch 'balance-verification' of github.com:kframework/ewasm-se…
hjorthjort Apr 16, 2020
63dfbd0
Update submodule
hjorthjort Apr 16, 2020
b8931e1
Update submodule
hjorthjort Apr 16, 2020
8001714
Make storeEeiResult total
hjorthjort Apr 16, 2020
f92cfc5
Make simplification match more cases
hjorthjort Apr 16, 2020
d9082b4
Update submodule
hjorthjort Apr 16, 2020
a535624
Reduce size of invoke-contract-spec by spcifying a smaller configuration
hjorthjort Apr 17, 2020
0bee680
Merge branch 'master' into balance-verification
hjorthjort Apr 17, 2020
b681942
Restructure lemmas file
hjorthjort Apr 19, 2020
15dc3be
Add definedness lemma for substrBytes
hjorthjort Apr 19, 2020
3f2fab5
Update deps
hjorthjort Apr 21, 2020
f43b322
Add imports for wrc20.k file
hjorthjort Apr 21, 2020
ed3f06e
Add TODO
hjorthjort Apr 22, 2020
04c38ee
Merge remote-tracking branch 'origin/master' into balance-verification
hjorthjort Apr 30, 2020
efec44c
Remove TODO
hjorthjort Apr 30, 2020
2ae7606
Move sort assertion to LHS
hjorthjort May 6, 2020
f5a9ff9
Formatting
hjorthjort May 6, 2020
488e467
Merge branch 'master' into balance-verification
hjorthjort May 6, 2020
28326f7
Remove simplifications
hjorthjort May 14, 2020
a433abf
Merge branch 'master' into balance-verification
hjorthjort May 27, 2020
a6258c0
Merge branch 'master' into balance-verification
hjorthjort May 28, 2020
23e5cf4
ewasm: formatting
hjorthjort May 28, 2020
e2a1465
Merge branch 'master' into balance-verification
hjorthjort Jun 13, 2020
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
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ clean:
# Build Dependencies (K Submodule)
# --------------------------------

wasm_files=test.k wasm.k data.k kwasm-lemmas.k
wasm_files=test.k wasm.k data.k kwasm-lemmas.k wrc20.k
wasm_source_files:=$(patsubst %, $(wasm_submodule)/%, $(patsubst %.k, %.md, $(wasm_files)))
eei_files:=eei.k
eei_source_files:=$(patsubst %, $(eei_submodule)/%, $(patsubst %.k, %.md, $(eei_files)))
Expand Down Expand Up @@ -143,6 +143,8 @@ KPROVE_MODULE:=KEWASM-LEMMAS
KPROVE_OPTS:=
CHECK:=git --no-pager diff --no-index --ignore-all-space

tests/proofs/wrc20-do-balance-spec.k.prove: KPROVE_MODULE=VERIFICATION

tests/%/make.timestamp:
@echo "== submodule: $@"
git submodule update --init -- tests/$*
Expand Down Expand Up @@ -179,7 +181,6 @@ test-simple: $(simple_tests:=.run)
### Proof Tests

proof_tests:=$(wildcard tests/proofs/*-spec.k)
slow_proof_tests:=tests/proofs/loops-spec.k
quick_proof_tests:=$(filter-out $(slow_proof_tests), $(proof_tests))

test-prove: $(proof_tests:=.prove)
Expand Down
21 changes: 12 additions & 9 deletions ewasm.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,13 @@ All byte values in Ewasm are a number of bytes divisible by 4, the same number o
Numbers are stored little-endian in Wasm, so that's the convention that's used when converting bytes to an integer, to ensure the bytes end up as given in memory.

```k
syntax Instr ::= #storeEeiResult(Int, Int, Int) [function]
| #storeEeiResult(Int, Bytes) [function, klabel(storeEeiResultsBytes)]
// ----------------------------------------------------------------------------------------
syntax Instr ::= #storeEeiResult(Int, Int, Int) [function, functional]
| #storeEeiResult(Int, Int, Bytes) [function, functional]
// ------------------------------------------------------------------------
rule #storeEeiResult(STARTIDX, LENGTHBYTES, VALUE) => store { LENGTHBYTES STARTIDX VALUE }

rule #storeEeiResult(STARTIDX, BS:Bytes)
=> #storeEeiResult(STARTIDX, lengthBytes(BS), Bytes2Int(BS, LE, Unsigned))
rule #storeEeiResult(STARTIDX, LENGTH, BS:Bytes)
=> #storeEeiResult(STARTIDX, LENGTH, Bytes2Int(BS, LE, Unsigned))
```

The Wasm engine needs to not make any further progress while waiting for the EEI, since they are not meant to execute concurrently.
Expand Down Expand Up @@ -203,15 +203,15 @@ An exception in the EEI translates into a `trap` in Wasm.
#### `getCaller`

Load the caller address (20 bytes) into memory at the spcified location.
Adresses are integer value numbers, and are stored little-endian in memory.
Addresses are integer value numbers, and are stored little-endian in memory.

```k
syntax HostCall ::= "eei.getCaller"
// -----------------------------------
rule <k> eei.getCaller => #waiting(eei.getCaller) ... </k>
<eeiK> . => EEI.getCaller </eeiK>

rule <k> #waiting(eei.getCaller) => #storeEeiResult(RESULTPTR, 20, ADDR) ... </k>
rule <k> #waiting(eei.getCaller) => #storeEeiResult(RESULTPTR, 20, ADDR:Int) ... </k>
<locals> 0 |-> <i32> RESULTPTR </locals>
<eeiK> #result(ADDR) => . </eeiK>
```
Expand Down Expand Up @@ -241,7 +241,10 @@ Traps if `DATAOFFSET` + `LENGTH` exceeds the length of the call data.
rule <k> eei.callDataCopy => #waiting(eei.callDataCopy) ... </k>
<eeiK> . => EEI.getCallData </eeiK>

rule <k> #waiting(eei.callDataCopy) => #storeEeiResult(RESULTPTR, substrBytes(CALLDATA, DATAPTR, DATAPTR +Int LENGTH)) ... </k>
rule <k> #waiting(eei.callDataCopy)
=> #storeEeiResult(RESULTPTR, LENGTH, substrBytes(CALLDATA, DATAPTR, DATAPTR +Int LENGTH))
...
</k>
<locals>
0 |-> <i32> RESULTPTR
1 |-> <i32> DATAPTR
Expand Down Expand Up @@ -278,7 +281,7 @@ From the executing account's storage, load the 32 bytes stored at the index spec

rule <k> #waiting(eei.storageLoad) => #storeEeiResult(RESULTPTR, 32, VALUE) ... </k>
<locals> ... 1 |-> <i32> RESULTPTR ... </locals>
<eeiK> #result(VALUE) => . </eeiK>
<eeiK> #result(VALUE:Int) => . </eeiK>
```

#### `storageStore`
Expand Down
93 changes: 92 additions & 1 deletion kewasm-lemmas.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,101 @@ They are part of the *trusted* base, and so should be scrutinized carefully.

```k
requires "kwasm-lemmas.k"
requires "kewasm-lemmas.k"

module KEWASM-LEMMAS
imports EWASM-TEST
imports KWASM-LEMMAS
```

Maps
----

These lemmas are needed for our symbolic map accesses to work for now.
They will likely be upstreamed or replaced by something similar upstream in the future.

```k
rule K in_keys (.Map) => false [simplification]
rule K in_keys ((K |-> _) M) => true [simplification]
rule K in_keys ((K' |-> _) M) => K in_keys (M) requires K =/=K K' [simplification]

rule ((K |-> V) M) [ K ] => V [simplification]
rule ((K1 |-> V) M) [ K2 ] => M [ K2 ] requires K1 =/=K K2 [simplification]
```

Bytes
-----

Call data and return data comes in the form of `Bytes`.
Several arguments are passed in a single byte sequence, and are accessed with offsets.
To reason about the byte data, the following rules are helpful.

```k
rule lengthBytes(B1 +Bytes B2) => lengthBytes(B1) +Int lengthBytes(B2) [simplification]
```

The following lemmas tell us that a sequence of bytes, interpreted as an integer, is withing certain limits.

```k
rule Bytes2Int(BS, _, _) <Int N => true
requires N >=Int (1 <<Int (lengthBytes(BS) *Int 8))
[simplification]

rule 0 <=Int Bytes2Int(_, _, Unsigned) => true [simplification]
```

When a value is within the range it is being wrapped to, we can remove the wrapping.

```k
rule #wrap(BITLENGTH, Bytes2Int(BS, ENDIAN, Unsigned)) => Bytes2Int(BS, ENDIAN, Unsigned)
requires lengthBytes(BS) *Int 8 <=Int BITLENGTH
[simplification]
```

### Subsequences of Bytes

`substrBytes(BS, X, Y)` returns the subsequence of `BS` from `X` to `Y`, including index `X` but not index `Y`.
It is a partial function, and only defined when `Y` is larger or equal to `X` and the length of `BS` is less than or equal to `Y`.
The following lemma tells the prover when it can conclude that the function is defined.

```k
rule #Ceil(substrBytes(@B, @START, @END))
=> { @START <=Int @END #Equals true }
#And
{ lengthBytes(@B) <=Int @END #Equals true }
#And #Ceil(@B) #And #Ceil(@START) #And #Ceil(@END)
[anywhere]
```

The identity of the substring operation is when `START` is 0 and `END` is the length of the byte sequence.

```k
rule substrBytes(B, START, END) => B
requires START ==Int 0
andBool lengthBytes(B) ==Int END
[simplification]
```

The following lemmas tell us how `substrBytes` works over concatenation of bytes sequnces.
TODO: The last two don't make the expression smaller, which may be an issue?

ehildenb marked this conversation as resolved.
Show resolved Hide resolved
```k
rule substrBytes(B1 +Bytes B2, START, END)
=> substrBytes(B1, START, END)
requires END <=Int lengthBytes(B1)
[simplification]

rule substrBytes(B1 +Bytes B2, START, END)
=> substrBytes(B2, START -Int lengthBytes(B1), END -Int lengthBytes(B1))
requires lengthBytes(B1) <=Int START

rule substrBytes(B1 +Bytes B2, START, END)
=> substrBytes(B1, START, lengthBytes(B1))
+Bytes
substrBytes(B2, START -Int lengthBytes(B1), END -Int lengthBytes(B1))
requires notBool (lengthBytes(B1) >=Int END)
andBool notBool (lengthBytes(B1) <=Int START)
```

```k
endmodule
```
Loading