Skip to content

Commit 4e68a3d

Browse files
Check valid jump dests on demand
1 parent 1b557af commit 4e68a3d

File tree

1 file changed

+15
-10
lines changed
  • kevm-pyk/src/kevm_pyk/kproj/evm-semantics

1 file changed

+15
-10
lines changed

kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md

+15-10
Original file line numberDiff line numberDiff line change
@@ -1023,12 +1023,12 @@ The `JUMP*` family of operations affect the current program counter.
10231023
// ---------------------------
10241024
rule <k> JUMP DEST => #endBasicBlock... </k>
10251025
<pc> _ => DEST </pc>
1026-
<jumpDests> DESTS </jumpDests>
1027-
requires DEST in DESTS
1026+
<program> PGM </program>
1027+
requires #isValidJumpDest(PGM, DEST)
10281028
10291029
rule <k> JUMP DEST => #end EVMC_BAD_JUMP_DESTINATION ... </k>
1030-
<jumpDests> DESTS </jumpDests>
1031-
requires notBool DEST in DESTS
1030+
<program> PGM </program>
1031+
requires notBool #isValidJumpDest(PGM, DEST)
10321032
10331033
syntax BinStackOp ::= "JUMPI"
10341034
// -----------------------------
@@ -1306,7 +1306,6 @@ The various `CALL*` (and other inter-contract control flow) operations will be d
13061306
// -------------------------------------
13071307
rule <k> #loadProgram BYTES => . ... </k>
13081308
<program> _ => BYTES </program>
1309-
<jumpDests> _ => #computeValidJumpDests(BYTES) </jumpDests>
13101309
13111310
syntax KItem ::= "#touchAccounts" Account | "#touchAccounts" Account Account
13121311
// ----------------------------------------------------------------------------
@@ -1341,15 +1340,21 @@ The various `CALL*` (and other inter-contract control flow) operations will be d
13411340
syntax Set ::= #computeValidJumpDests(Bytes) [function, memo, total]
13421341
| #computeValidJumpDests(Bytes, Int, List) [function, klabel(#computeValidJumpDestsAux)]
13431342
// -----------------------------------------------------------------------------------------------------
1344-
rule #computeValidJumpDests(PGM) => #computeValidJumpDests(PGM, 0, .List)
1343+
rule #computeValidJumpDests(PGM) => .Set
1344+
rule #computeValidJumpDests(PGM, I, RESULT) => .Set
1345+
13451346
13461347
syntax Set ::= #computeValidJumpDestsWithinBound(Bytes, Int, List) [function]
13471348
// -----------------------------------------------------------------------------
1348-
rule #computeValidJumpDests(PGM, I, RESULT) => List2Set(RESULT) requires I >=Int lengthBytes(PGM)
1349-
rule #computeValidJumpDests(PGM, I, RESULT) => #computeValidJumpDestsWithinBound(PGM, I, RESULT) requires I <Int lengthBytes(PGM)
1349+
rule #computeValidJumpDestsWithinBound(PGM, I, RESULT) => .Set
1350+
1351+
1352+
syntax Bool ::= #isValidJumpDest ( Bytes, Int ) [function, total]
1353+
1354+
rule #isValidJumpDest(PGM, I) => PGM [ I ] ==Int 91 requires 0 <=Int I andBool I <Int lengthBytes(PGM)
1355+
rule #isValidJumpDest(PGM, I) => false [owise]
13501356
1351-
rule #computeValidJumpDestsWithinBound(PGM, I, RESULT) => #computeValidJumpDests(PGM, I +Int 1, RESULT ListItem(I)) requires PGM [ I ] ==Int 91
1352-
rule #computeValidJumpDestsWithinBound(PGM, I, RESULT) => #computeValidJumpDests(PGM, I +Int #widthOpCode(PGM [ I ]), RESULT) requires notBool PGM [ I ] ==Int 91
1357+
rule
13531358
```
13541359

13551360
```k

0 commit comments

Comments
 (0)