Skip to content

Commit

Permalink
lemmas: fix #145 (#614)
Browse files Browse the repository at this point in the history
* lemmas: fix #145

* specs: improve lemmas

* edsl: fix space alignment
  • Loading branch information
daejunpark authored and rv-jenkins committed Dec 11, 2019
1 parent 3c0be77 commit e8e1979
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
6 changes: 3 additions & 3 deletions edsl.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ This notation makes the specification independent of the underlying compilers, e
For dynamically sized arrays in Solidity, and both statically and dynamically sized arrays in Vyper, the length of the array is stored at:

```
hash(slot(array))
hash(slot(array))
```

and the element at index `i` is stored at:
Expand All @@ -334,9 +334,9 @@ Specifically, `#hashedLocation` is defined as follows, capturing the storage lay
// -----------------------------------------------------------------------
rule #hashedLocation(LANG, BASE, .IntList) => BASE
rule #hashedLocation("Vyper", BASE, OFFSET OFFSETS) => #hashedLocation("Vyper", keccakIntList(BASE OFFSET), OFFSETS)
rule #hashedLocation("Vyper", BASE, OFFSET OFFSETS) => #hashedLocation("Vyper", keccakIntList(BASE OFFSET), OFFSETS)
rule #hashedLocation("Solidity", BASE, OFFSET OFFSETS) => #hashedLocation("Solidity", keccakIntList(OFFSET BASE), OFFSETS)
rule #hashedLocation("Array", BASE, OFFSET OFFSETS) => #hashedLocation("Array", keccakIntList(BASE) +Word OFFSET, OFFSETS)
rule #hashedLocation("Array", BASE, OFFSET OFFSETS) => #hashedLocation("Array", keccakIntList(BASE) +Word OFFSET, OFFSETS)
syntax Int ::= keccakIntList( IntList ) [function]
// --------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/benchmarks/lemmas.k
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ module LEMMAS

// for Solidity
rule #asWord(WS) /Int D => #asWord(#take(#sizeWordStack(WS) -Int log256Int(D), WS))
requires D modInt 256 ==Int 0 andBool D >=Int 0
requires D ==Int 256 ^Int log256Int(D) andBool D >=Int 0
andBool #sizeWordStack(WS) >=Int log256Int(D)
andBool #noOverflow(WS)

Expand Down
8 changes: 3 additions & 5 deletions tests/specs/benchmarks/verification.k
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,8 @@ module VERIFICATION
rule #bufElm(_, _) <Int 256 => true
rule #bufElm(_, _) <Int pow256 => true

// X xorInt (pow256 - 1)
rule 0 <=Int X xorInt 115792089237316195423570985008687907853269984665640564039457584007913129639935 => true requires 0<=Int X andBool X <Int pow256
rule X xorInt 115792089237316195423570985008687907853269984665640564039457584007913129639935 <Int pow256 => true requires 0<=Int X andBool X <Int pow256
rule 0 <=Int X xorInt maxUInt256 => true requires #rangeUInt(256, X)
rule X xorInt maxUInt256 <Int pow256 => true requires #rangeUInt(256, X)


// ########################
Expand Down Expand Up @@ -201,8 +200,7 @@ module VERIFICATION
andBool #sizeWordStack(WS0) ==Int MASKWIDHT1
andBool MASKWIDTH0 ==Int #sizeWordStack(WS1)

// #asWord(WS) &Int (pow256 - 1)
rule #asWord(WS) &Int 115792089237316195423570985008687907853269984665640564039457584007913129639935 => #asWord(WS)
rule #asWord(WS) &Int maxUInt256 => #asWord(WS)

// 2^256 - 2^160 = 0xff..ff00..00 (96 1's followed by 160 0's)
rule 115792089237316195423570985007226406215939081747436879206741300988257197096960 &Int ADDR => 0
Expand Down
2 changes: 1 addition & 1 deletion tests/specs/lemmas.k
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ module LEMMAS

// for Solidity
rule #asWord(WS) /Int D => #asWord(#take(#sizeWordStack(WS) -Int log256Int(D), WS))
requires D modInt 256 ==Int 0 andBool D >=Int 0
requires D ==Int 256 ^Int log256Int(D) andBool D >=Int 0
andBool #sizeWordStack(WS) >=Int log256Int(D)
andBool #noOverflow(WS)

Expand Down

0 comments on commit e8e1979

Please sign in to comment.