Skip to content

Upstream symbolic bytes lookup, List membership lemmas #2702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,20 @@ module BYTES-SIMPLIFICATION [symbolic]
rule #asWord ( #ecrec ( _ , _ , _ , _ ) ) <Int pow160 => true
[simplification, smt-lemma]

// Symbolic bytes lookup

rule [bytes-concat-lookup-left]:
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B1 [ I ]
requires 0 <=Int I andBool I <Int lengthBytes(B1)
[simplification(40), preserves-definedness]

rule [bytes-concat-lookup-right]:
( B1:Bytes +Bytes B2:Bytes ) [ I:Int ] => B2 [ I -Int lengthBytes(B1) ]
requires lengthBytes(B1) <=Int I
[simplification(40), preserves-definedness]

rule [lookup-as-asWord]:
B:Bytes [ I:Int ] => #asWord ( #range ( B, I, 1 ) )
requires 0 <=Int I andBool I <=Int lengthBytes(B)
[simplification(60)]
endmodule
13 changes: 13 additions & 0 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/lemmas/lemmas.k
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,19 @@ module LEMMAS-WITHOUT-SLOT-UPDATES [symbolic]
// Hardcoded #addrFromPrivateKey simplifications, see: https://github.com/runtimeverification/haskell-backend/issues/3573
rule #addrFromPrivateKey("0x0000000000000000000000000000000000000000000000000000000000000001") => 721457446580647751014191829380889690493307935711 [priority(40), concrete]

// ########################
// List Reasoning
// ########################

// List membership check simplification for lists with a single element
rule KI:KItem in ListItem(KI:KItem) => true [simplification]
rule KI:KItem in ListItem(KJ:KItem) => KI ==K KJ [simplification]

// Recursive list membership check for lists with multiple elements
rule KI:KItem in (ListItem(KI) _REST) => true [simplification]
rule KI:KItem in (ListItem(KJ) REST) => KI in REST requires KI =/=K KJ [simplification]
rule _KI:KItem in .List => false [simplification]

// ########################
// Memory
// ########################
Expand Down
13 changes: 13 additions & 0 deletions tests/specs/functional/lemmas-spec.k
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,12 @@ module LEMMAS-SPEC
</k>
requires X =/=K Y

// List simplifications
// --------------------

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

// Memory update simplifications
// ----------------------------
Expand Down Expand Up @@ -366,6 +372,13 @@ module LEMMAS-SPEC
=> doneLemma(true) ... </k>
requires lengthBytes ( BYTES:Bytes ) <Int 32

// Symbolic bytes lookup simplification
// -------------------
claim [lookup-symbolic-bytes]:
<k> runLemma ( b"`\xa0`@R4\x80\x15a\x00\x10W`\x00" +Bytes #buf ( 32 , W:Int ) [ 0 ] )
=> doneLemma ( 96 ) ... </k>
requires #rangeUInt(256, W)

// #buf simplification
// -------------------
claim [bufExtractPadding]: <k> runLemma ( #asWord ( ( #range( #buf ( 32 , X ), 0, 28 ) ):Bytes ) ) => doneLemma ( 0 ) ... </k> requires #rangeUInt(32, X)
Expand Down