Skip to content

Commit e1f32d6

Browse files
PetarMaxrv-auditor
andauthored
^Int and /Int definedness preservation (#2425)
* ^Int and /Int definedness preservation * Set Version: 1.0.555 --------- Co-authored-by: devops <[email protected]>
1 parent f32ea89 commit e1f32d6

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
lines changed

kevm-pyk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "kevm-pyk"
7-
version = "1.0.554"
7+
version = "1.0.555"
88
description = ""
99
authors = [
1010
"Runtime Verification, Inc. <[email protected]>",

kevm-pyk/src/kevm_pyk/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
if TYPE_CHECKING:
66
from typing import Final
77

8-
VERSION: Final = '1.0.554'
8+
VERSION: Final = '1.0.555'

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/lemmas/bitwise-simplification.k

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ module BITWISE-SIMPLIFICATION [symbolic]
5050
requires 0 <=Int X
5151
andBool X +Int 1 ==Int 2 ^Int log2Int(X +Int 1)
5252
andBool 0 <=Int Y andBool Y <Int X +Int 1
53-
[concrete(X), simplification, comm]
53+
[concrete(X), simplification, comm, preserves-definedness]
5454

5555
// Generalization of: notMaxUIntXXX &Int Y => 0 requires #rangeUInt(XXX, Y)
5656
rule [bitwise-and-notMaxUInt-zero]:
5757
X &Int Y => 0
5858
requires #rangeUInt(256, X)
5959
andBool pow256 -Int X ==Int 2 ^Int ( log2Int ( pow256 -Int X ) )
6060
andBool 0 <=Int Y andBool Y <Int pow256 -Int X
61-
[simplification, concrete(X)]
61+
[simplification, concrete(X), preserves-definedness]
6262

6363
// Generalization of: maxUIntXXX &Int #asWord ( BA )
6464
rule X &Int #asWord ( BA ) => #asWord ( #range(BA, 32 -Int (log2Int(X +Int 1) /Int 8), log2Int(X +Int 1) /Int 8) )
@@ -113,7 +113,7 @@ module BITWISE-SIMPLIFICATION [symbolic]
113113

114114
rule (X <<Int Y) <Int pow256 => true
115115
requires 0 <=Int X andBool 0 <=Int Y andBool Y <Int 256 andBool X <Int 2 ^Int (256 -Int Y)
116-
[simplification]
116+
[simplification, preserves-definedness]
117117

118118
rule 0 <=Int (X <<Int Y) => true requires 0 <=Int X andBool 0 <=Int Y [simplification]
119119

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/lemmas/bytes-simplification.k

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ module BYTES-SIMPLIFICATION [symbolic]
4141
requires 0 <=Int W
4242
andBool 0 <=Int X andBool X <Int 2 ^Int (8 *Int W)
4343
andBool 0 <=Int Y andBool Y <Int 2 ^Int (8 *Int W)
44-
[simplification]
44+
[simplification, preserves-definedness]
4545

4646
rule [buf-inject-ml]:
4747
{ #buf(W:Int, X:Int) #Equals #buf(W:Int, Y:Int) } => { X #Equals Y }
4848
requires 0 <=Int W
4949
andBool 0 <=Int X andBool X <Int 2 ^Int (8 *Int W)
5050
andBool 0 <=Int Y andBool Y <Int 2 ^Int (8 *Int W)
51-
[simplification]
51+
[simplification, preserves-definedness]
5252

5353
rule [buf-as-int]: B:Bytes ==K #buf(32, X:Int) => X ==Int #asInteger(B)
5454
requires lengthBytes(B) <=Int 32
@@ -68,21 +68,21 @@ module BYTES-SIMPLIFICATION [symbolic]
6868
#buf (W:Int , #asWord(B:Bytes)) => #range(B, lengthBytes(B) -Int W, W)
6969
requires 0 <=Int W andBool W <Int lengthBytes(B) andBool lengthBytes(B) <=Int 32
7070
andBool #asWord(B) <Int 2 ^Int (8 *Int W)
71-
[simplification, concrete(W)]
71+
[simplification, concrete(W), preserves-definedness]
7272

7373
rule [buf-asWord-invert-rl]:
7474
#asWord ( #buf ( WB:Int, X:Int ) ) => X
7575
requires 0 <=Int WB andBool 0 <=Int X andBool
7676
( ( WB <=Int 32 andBool X <Int 2 ^Int (WB *Int 8) ) orBool
7777
( WB >Int 32 andBool X <Int pow256 ) )
78-
[simplification, concrete(WB)]
78+
[simplification, concrete(WB), preserves-definedness]
7979

8080
rule [buf-asWord-invert-rl-range]:
8181
#asWord ( #range ( #buf ( WB:Int, X:Int ), S:Int, WR:Int ) ) => X
8282
requires 0 <=Int WB andBool 0 <=Int X andBool 0 <=Int S andBool 0 <=Int WR
8383
andBool S +Int WR ==Int WB
8484
andBool X <Int 2 ^Int (WR *Int 8)
85-
[simplification, concrete(WB, S, WR)]
85+
[simplification, concrete(WB, S, WR), preserves-definedness]
8686

8787
rule [buf-zero-concat-base]:
8888
#buf(W1:Int, 0) +Bytes #buf(W2:Int, 0) => #buf(W1 +Int W2, 0)
@@ -189,13 +189,13 @@ module BYTES-SIMPLIFICATION [symbolic]
189189
B:Bytes +Bytes #buf(W:Int, X:Int) => #buf(lengthBytes(B) +Int W, X)
190190
requires 0 <=Int W andBool 0 <=Int X andBool X <Int 2 ^Int (W *Int 8)
191191
andBool #asInteger(B) ==Int 0 andBool lengthBytes(B) +Int W <=Int 32
192-
[concrete(B, W), simplification]
192+
[concrete(B, W), simplification, preserves-definedness]
193193

194194
rule [range-buf-zero-concat-extend]:
195195
B1:Bytes +Bytes #buf(W:Int, X:Int) +Bytes B2 => #buf(lengthBytes(B1) +Int W, X) +Bytes B2
196196
requires 0 <=Int W andBool 0 <=Int X andBool X <Int 2 ^Int (W *Int 8)
197197
andBool #asInteger(B1) ==Int 0 andBool lengthBytes(B1) +Int W <=Int 32
198-
[concrete(B1, W), simplification]
198+
[concrete(B1, W), simplification, preserves-definedness]
199199

200200
rule [range-memUpdate-before]:
201201
#range(B1:Bytes [ S1:Int := B2:Bytes ], S2:Int, W2:Int) =>
@@ -220,13 +220,13 @@ module BYTES-SIMPLIFICATION [symbolic]
220220
#range (#buf(W1:Int, X:Int), S2:Int, W2:Int) => #buf(W2, 0)
221221
requires 0 <=Int X andBool X <Int 2 ^Int (8 *Int (W1 -Int (S2 +Int W2)))
222222
andBool 0 <=Int S2 andBool 0 <=Int W2 andBool S2 +Int W2 <=Int W1
223-
[simplification, concrete(W1, S2, W2)]
223+
[simplification, concrete(W1, S2, W2), preserves-definedness]
224224

225225
rule [range-buf-value]:
226226
#range (#buf(W1:Int, X:Int), S2:Int, W2:Int) => #buf(W2, X)
227227
requires 0 <=Int X andBool X <Int 2 ^Int (8 *Int W2)
228228
andBool 0 <=Int S2 andBool 0 <=Int W2 andBool W1 ==Int S2 +Int W2
229-
[simplification, concrete(W1, S2, W2)]
229+
[simplification, concrete(W1, S2, W2), preserves-definedness]
230230

231231
rule [range-padRightToWidth]:
232232
#range(#padRightToWidth(_, BUF), 0, WIDTH) => BUF
@@ -239,7 +239,7 @@ module BYTES-SIMPLIFICATION [symbolic]
239239
andBool #asInteger( BZ ) ==Int 0
240240
andBool lengthBytes( BZ ) ==Int S
241241
andBool #asWord ( B ) <Int 2 ^Int ( 8 *Int W )
242-
[simplification, concrete(BZ, S, W), comm]
242+
[simplification, concrete(BZ, S, W), comm, preserves-definedness]
243243

244244
rule [range-eq-check-ml]:
245245
{ BZ +Bytes #range ( B, S, W ) #Equals B } => #Top
@@ -248,7 +248,7 @@ module BYTES-SIMPLIFICATION [symbolic]
248248
andBool #asInteger( BZ ) ==Int 0
249249
andBool lengthBytes( BZ ) ==Int S
250250
andBool #asWord ( B ) <Int 2 ^Int ( 8 *Int W )
251-
[simplification, concrete(BZ, S, W), comm]
251+
[simplification, concrete(BZ, S, W), comm, preserves-definedness]
252252

253253
// Memory update
254254

@@ -291,7 +291,9 @@ module BYTES-SIMPLIFICATION [symbolic]
291291

292292
// #asWord
293293

294-
rule #asWord(WS) >>Int M => #asWord(#range(WS, 0, lengthBytes(WS) -Int (M /Int 8) )) requires 0 <=Int M andBool M modInt 8 ==Int 0 [simplification]
294+
rule #asWord(WS) >>Int M => #asWord(#range(WS, 0, lengthBytes(WS) -Int (M /Int 8) ))
295+
requires 0 <=Int M andBool M modInt 8 ==Int 0
296+
[simplification, preserves-definedness]
295297

296298
// This simplification needs to be generalised properly
297299
rule notMaxUInt224 &Int #asWord(#padRightToWidth(32, BUF)) => #asWord(#padRightToWidth(32, BUF))

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/lemmas/evm-int-simplification.k

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,20 @@ module EVM-INT-SIMPLIFICATION-COMMON
6868
rule [asWord-lt-concat]:
6969
#asWord ( BA1 +Bytes BA2 ) <Int X => #asWord ( BA1 ) <Int ( X -Int #asWord ( BA2 ) ) /Int ( 2 ^Int ( 8 *Int lengthBytes ( BA2 ) ) )
7070
requires ( X -Int #asWord ( BA2 ) ) modInt ( 2 ^Int ( 8 *Int lengthBytes ( BA2 ) ) ) ==Int 0
71-
[concrete(BA2, X), simplification]
71+
[concrete(BA2, X), simplification, preserves-definedness]
7272

7373
rule [asWord-lt-range]:
7474
#asWord ( #range ( _:Bytes, S, W ) ) <Int X => true
7575
requires 0 <=Int S andBool 0 <=Int W
7676
andBool 2 ^Int ( 8 *Int W ) <=Int X
77-
[simplification, concrete(S, W, X)]
77+
[simplification, concrete(S, W, X), preserves-definedness]
7878

7979
rule [lt-asWord-range]:
8080
X <Int #asWord ( #range ( B:Bytes, S, W ) ) => X <Int #asWord ( B )
8181
requires 0 <=Int S andBool 0 <=Int W
8282
andBool lengthBytes(B) ==Int S +Int W
8383
andBool #asWord ( B ) <Int 2 ^Int ( 8 *Int W )
84-
[simplification, concrete(X, S, W)]
84+
[simplification, concrete(X, S, W), preserves-definedness]
8585

8686
// ###########################################################################
8787
// chop

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/lemmas/lemmas.k

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ module LEMMAS-HASKELL [symbolic]
159159
requires D ==Int 256 ^Int log256Int(D) andBool D >=Int 0
160160
andBool lengthBytes(BUF) >=Int log256Int(D) [simplification, preserves-definedness]
161161

162-
rule #asWord(#buf(N, BUF)) => BUF
163-
requires #range(0 < N <= 32)
164-
andBool #range(0 <= BUF < 2 ^Int (N *Int 8)) [simplification]
165-
166162
rule notBool (X ==Int 0) => X ==Int 1 requires #rangeBool(X) [simplification]
167163
rule notBool (X ==Int 1) => X ==Int 0 requires #rangeBool(X) [simplification]
168164
rule bool2Word(X ==Int 1) => X requires #rangeBool(X) [simplification]

package/version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.0.554
1+
1.0.555

0 commit comments

Comments
 (0)