Skip to content

Commit 2fdfcac

Browse files
authored
Merge branch 'master' into upstream-lido-lemmas
2 parents 1083591 + 0f07bcd commit 2fdfcac

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,4 +291,20 @@ module BYTES-SIMPLIFICATION [symbolic]
291291
rule #asWord ( #ecrec ( _ , _ , _ , _ ) ) <Int pow160 => true
292292
[simplification, smt-lemma]
293293

294+
// Symbolic bytes lookup
295+
296+
rule [bytes-concat-lookup-left]:
297+
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B1 [ I ]
298+
requires 0 <=Int I andBool I <Int lengthBytes(B1)
299+
[simplification(40), preserves-definedness]
300+
301+
rule [bytes-concat-lookup-right]:
302+
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B2 [ I -Int lengthBytes(B1) ]
303+
requires lengthBytes(B1) <=Int I
304+
[simplification(40), preserves-definedness]
305+
306+
rule [lookup-as-asWord]:
307+
B:Bytes [ I:Int ] => #asWord ( #range ( B, I, 1 ) )
308+
requires 0 <=Int I andBool I <Int lengthBytes(B)
309+
[simplification(60)]
294310
endmodule

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,19 @@ module LEMMAS-WITHOUT-SLOT-UPDATES [symbolic]
132132
// Hardcoded #addrFromPrivateKey simplifications, see: https://github.com/runtimeverification/haskell-backend/issues/3573
133133
rule #addrFromPrivateKey("0x0000000000000000000000000000000000000000000000000000000000000001") => 721457446580647751014191829380889690493307935711 [priority(40), concrete]
134134

135+
// ########################
136+
// List Reasoning
137+
// ########################
138+
139+
// List membership check simplification for lists with a single element
140+
rule KI:KItem in ListItem(KI:KItem) => true [simplification]
141+
rule KI:KItem in ListItem(KJ:KItem) => KI ==K KJ [simplification]
142+
143+
// Recursive list membership check for lists with multiple elements
144+
rule KI:KItem in (ListItem(KI) _REST) => true [simplification]
145+
rule KI:KItem in (ListItem(KJ) REST) => KI in REST requires KI =/=K KJ [simplification]
146+
rule _KI:KItem in .List => false [simplification]
147+
135148
// ########################
136149
// Memory
137150
// ########################

tests/specs/functional/lemmas-spec.k

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ module LEMMAS-SPEC
148148
</k>
149149
requires X =/=K Y
150150

151+
// List simplifications
152+
// --------------------
153+
154+
claim [list-in-simplification]:
155+
<k> runLemma ( b"\xd3V\x97\x17" in ListItem ( b"Y\xecK\x01" +Bytes #buf ( 32 , W:Int ) ) ) => doneLemma ( false ) ... </k>
156+
requires #rangeUInt(256, W)
151157

152158
// Memory update simplifications
153159
// ----------------------------
@@ -366,6 +372,13 @@ module LEMMAS-SPEC
366372
=> doneLemma(true) ... </k>
367373
requires lengthBytes ( BYTES:Bytes ) <Int 32
368374

375+
// Symbolic bytes lookup simplification
376+
// -------------------
377+
claim [lookup-symbolic-bytes]:
378+
<k> runLemma ( b"`\xa0`@R4\x80\x15a\x00\x10W`\x00" +Bytes #buf ( 32 , W:Int ) [ 0 ] )
379+
=> doneLemma ( 96 ) ... </k>
380+
requires #rangeUInt(256, W)
381+
369382
// #buf simplification
370383
// -------------------
371384
claim [bufExtractPadding]: <k> runLemma ( #asWord ( ( #range( #buf ( 32 , X ), 0, 28 ) ):Bytes ) ) => doneLemma ( 0 ) ... </k> requires #rangeUInt(32, X)

0 commit comments

Comments
 (0)