Skip to content
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

Optimizations for stack checks when no over/under flow is present #2709

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
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
Prev Previous commit
kevm-pyk/evm.md: optimize for non-underflow stack check
ehildenb committed Mar 5, 2025
commit 51deb06da1a957f2deb388b6740f82fb900c2543
11 changes: 10 additions & 1 deletion kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md
Original file line number Diff line number Diff line change
@@ -380,7 +380,16 @@ The `#next [_]` operator initiates execution by:
syntax Bool ::= #stackUnderflow ( WordStack , OpCode ) [symbol(#stackUnderflow), function, total]
| #stackOverflow ( WordStack , OpCode ) [symbol(#stackOverflow), function, total]
// ------------------------------------------------------------------------------------------------
rule #stackUnderflow(WS, OP:OpCode) => #sizeWordStack(WS) <Int #stackNeeded(OP)
rule #stackUnderflow( _WS , _POP:PushOp ) => false
rule #stackUnderflow( _WS , _IOP:InvalidOp ) => false
rule #stackUnderflow( _WS , _NOP:NullStackOp ) => false
rule #stackUnderflow( _W0 : _WS , _UOP:UnStackOp ) => false
rule #stackUnderflow( _W0 : _W1 : _WS , BOP:BinStackOp ) => false requires notBool isLogOp(BOP)
rule #stackUnderflow( _W0 : _W1 : _W2 : _WS , _TOP:TernStackOp ) => false
rule #stackUnderflow( _W0 : _W1 : _W2 : _W3 : _WS , _QOP:QuadStackOp ) => false
rule #stackUnderflow( _W0 : _W1 : _W2 : _W3 : _W4 : _W5 : _W6 : _WS , _CSOP:CallSixOp ) => false
rule #stackUnderflow( _W0 : _W1 : _W2 : _W3 : _W4 : _W5 : _W6 : _W7 : _WS , COP:CallOp ) => false requires notBool isCallSixOp(COP)
rule #stackUnderflow(WS, OP:OpCode) => #sizeWordStack(WS) <Int #stackNeeded(OP) [owise]

rule #stackOverflow(_WS, OP) => false requires #stackDelta(OP) <=Int 0
rule #stackOverflow(WS, OP) => 1024 <Int #sizeWordStack(WS) +Int #stackDelta(OP) [owise]