Skip to content

Commit 0f07bcd

Browse files
Upstream symbolic bytes lookup, List membership lemmas (#2702)
* Add bytes lookup lemmas * Add test for the symbolic bytes index lookup lemma * Add List membership lemmas * Fix sign in `lookup-as-asWord` lemma
1 parent bdd3942 commit 0f07bcd

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
@@ -285,4 +285,20 @@ module BYTES-SIMPLIFICATION [symbolic]
285285
rule #asWord ( #ecrec ( _ , _ , _ , _ ) ) <Int pow160 => true
286286
[simplification, smt-lemma]
287287

288+
// Symbolic bytes lookup
289+
290+
rule [bytes-concat-lookup-left]:
291+
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B1 [ I ]
292+
requires 0 <=Int I andBool I <Int lengthBytes(B1)
293+
[simplification(40), preserves-definedness]
294+
295+
rule [bytes-concat-lookup-right]:
296+
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B2 [ I -Int lengthBytes(B1) ]
297+
requires lengthBytes(B1) <=Int I
298+
[simplification(40), preserves-definedness]
299+
300+
rule [lookup-as-asWord]:
301+
B:Bytes [ I:Int ] => #asWord ( #range ( B, I, 1 ) )
302+
requires 0 <=Int I andBool I <Int lengthBytes(B)
303+
[simplification(60)]
288304
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)