Skip to content

Commit

Permalink
Delete useGas cell (#4)
Browse files Browse the repository at this point in the history
Having this cell in the configuration provides a ripe target for buffer
overflows, which might attempt to set the value of the useGas cell to
false in order to obtain free computation. We are not planning on ever
using it with a value of false, so we delete it.
  • Loading branch information
Dwight Guth authored and Robertorosmaninho committed Sep 12, 2024
1 parent a8be9f2 commit ab0e2c2
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 95 deletions.
3 changes: 1 addition & 2 deletions kevm-pyk/src/kevm_pyk/gst_to_kore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from typing import TYPE_CHECKING

from pyk.cli.utils import file_path
from pyk.kore.prelude import BOOL, INT, SORT_JSON, SORT_K_ITEM, bool_dv, inj, int_dv, json_to_kore, top_cell_initializer
from pyk.kore.prelude import INT, SORT_JSON, SORT_K_ITEM, inj, int_dv, json_to_kore, top_cell_initializer
from pyk.kore.syntax import App, SortApp

from .cli import KEVMCLIArgs
Expand Down Expand Up @@ -39,7 +39,6 @@ def kore_pgm_to_kore(pgm: Pattern, pattern_sort: SortApp, schedule: str, mode: s
'$SCHEDULE': inj(SORT_SCHEDULE, SORT_K_ITEM, _schedule_to_kore(schedule)),
'$MODE': inj(SORT_MODE, SORT_K_ITEM, _mode_to_kore(mode)),
'$CHAINID': inj(INT, SORT_K_ITEM, int_dv(chainid)),
'$USEGAS': inj(BOOL, SORT_K_ITEM, bool_dv(usegas)),
}
return top_cell_initializer(config)

Expand Down
2 changes: 0 additions & 2 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/driver.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,6 @@ Note that `TEST` is sorted here so that key `"network"` comes before key `"pre"`
rule <k> loadCallState { "code" : (CODE:OpCodes), REST } => #loadProgram #asmOpCodes(CODE) ~> loadCallState { REST } ... </k>
rule <k> loadCallState { "usegas" : (USEGAS:Bool), REST => REST } ... </k> <useGas> _ => USEGAS </useGas>
rule <k> loadCallState { KEY : ((VAL:String) => #parseWord(VAL)), _ } ... </k>
requires KEY in (SetItem("gas") SetItem("gasPrice") SetItem("value"))
Expand Down
33 changes: 7 additions & 26 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ In the comments next to each cell, we've marked which component of the YellowPap
<exit-code exit=""> 1 </exit-code>
<mode> $MODE:Mode </mode>
<schedule> $SCHEDULE:Schedule </schedule>
<useGas> $USEGAS:Bool </useGas>
<ethereum>
Expand Down Expand Up @@ -559,7 +558,6 @@ After executing a transaction, it's necessary to have the effect of the substate
<accessedStorage> _ => .Map </accessedStorage>
rule <k> #finalizeTx(false) ... </k>
<useGas> true </useGas>
<schedule> SCHED </schedule>
<gas> GAVAIL => G*(GAVAIL, GLIMIT, REFUND, SCHED) </gas>
<refund> REFUND => 0 </refund>
Expand All @@ -572,7 +570,6 @@ After executing a transaction, it's necessary to have the effect of the substate
requires REFUND =/=Int 0
rule <k> #finalizeTx(false => true) ... </k>
<useGas> true </useGas>
<baseFee> BFEE </baseFee>
<origin> ORG </origin>
<coinbase> MINER </coinbase>
Expand All @@ -599,7 +596,6 @@ After executing a transaction, it's necessary to have the effect of the substate
requires ORG =/=Int MINER
rule <k> #finalizeTx(false => true) ... </k>
<useGas> true </useGas>
<baseFee> BFEE </baseFee>
<origin> ACCT </origin>
<coinbase> ACCT </coinbase>
Expand All @@ -619,14 +615,6 @@ After executing a transaction, it's necessary to have the effect of the substate
...
</message>
rule <k> #finalizeTx(false => true) ... </k>
<useGas> false </useGas>
<txPending> ListItem(MsgId:Int) REST => REST </txPending>
<message>
<msgID> MsgId </msgID>
...
</message>
rule <k> (.K => #deleteAccounts(Set2List(ACCTS))) ~> #finalizeTx(true) ... </k>
<selfDestruct> ACCTS => .Set </selfDestruct>
requires size(ACCTS) >Int 0
Expand Down Expand Up @@ -1378,13 +1366,12 @@ The various `CALL*` (and other inter-contract control flow) operations will be d
=> #touchAccounts ACCTFROM ACCTTO ~> #accessAccounts ACCTFROM ACCTTO ~> #loadProgram BYTES ~> #initVM ~> #precompiled?(ACCTCODE, SCHED) ~> #execute
...
</k>
<useGas> USEGAS:Bool </useGas>
<callDepth> CD => CD +Int 1 </callDepth>
<callData> _ => ARGS </callData>
<callValue> _ => APPVALUE </callValue>
<id> _ => ACCTTO </id>
<gas> GAVAIL:Gas => #if USEGAS #then GCALL:Gas #else GAVAIL:Gas #fi </gas>
<callGas> GCALL:Gas => #if USEGAS #then 0:Gas #else GCALL:Gas #fi </callGas>
<gas> GAVAIL:Gas => GCALL:Gas </gas>
<callGas> GCALL:Gas => 0:Gas </callGas>
<caller> _ => ACCTFROM </caller>
<static> OLDSTATIC:Bool => OLDSTATIC orBool STATIC </static>
<schedule> SCHED </schedule>
Expand Down Expand Up @@ -1506,8 +1493,7 @@ The various `CALL*` (and other inter-contract control flow) operations will be d
syntax InternalOp ::= "#refund" Gas
| "#setLocalMem" Int Int Bytes
// --------------------------------------------------
rule [refund]: <k> #refund G:Gas => .K ... </k> <gas> GAVAIL => GAVAIL +Gas G </gas> <useGas> true </useGas>
rule [refund.noGas]: <k> #refund _ => .K ... </k> <useGas> false </useGas>
rule [refund]: <k> #refund G:Gas => .K ... </k> <gas> GAVAIL => GAVAIL +Gas G </gas>
rule <k> #setLocalMem START WIDTH WS => .K ... </k>
Expand Down Expand Up @@ -1603,11 +1589,10 @@ For each `CALL*` operation, we make a corresponding call to `#call` and a state-
=> #touchAccounts ACCTFROM ACCTTO ~> #accessAccounts ACCTFROM ACCTTO ~> #loadProgram INITCODE ~> #initVM ~> #execute
...
</k>
<useGas> USEGAS </useGas>
<schedule> SCHED </schedule>
<id> _ => ACCTTO </id>
<gas> GAVAIL => #if USEGAS #then GCALL #else GAVAIL #fi </gas>
<callGas> GCALL => #if USEGAS #then 0 #else GCALL #fi </callGas>
<gas> GAVAIL => GCALL </gas>
<callGas> GCALL => 0 </callGas>
<caller> _ => ACCTFROM </caller>
<callDepth> CD => CD +Int 1 </callDepth>
<callData> _ => .Bytes </callData>
Expand Down Expand Up @@ -1961,9 +1946,6 @@ Overall Gas
~> #access [ OP , AOP ]
...
</k>
<useGas> true </useGas>
rule <k> #gas [ _ , _ ] => .K ... </k> <useGas> false </useGas>
rule <k> #gas [ OP ] => #gasExec(SCHED, OP) ~> #deductGas ... </k>
<schedule> SCHED </schedule>
Expand All @@ -1981,9 +1963,8 @@ Overall Gas
<memoryUsed> MU => MU' </memoryUsed> <schedule> SCHED </schedule>
rule <k> _G:Gas ~> (#deductMemoryGas => #deductGas) ... </k> //Required for verification
rule <k> G:Gas ~> #deductGas => #end EVMC_OUT_OF_GAS ... </k> <gas> GAVAIL:Gas </gas> <useGas> true </useGas> requires GAVAIL <Gas G
rule <k> G:Gas ~> #deductGas => .K ... </k> <gas> GAVAIL:Gas => GAVAIL -Gas G </gas> <useGas> true </useGas> requires G <=Gas GAVAIL
rule <k> _:Gas ~> #deductGas => .K ... </k> <useGas> false </useGas>
rule <k> G:Gas ~> #deductGas => #end EVMC_OUT_OF_GAS ... </k> <gas> GAVAIL:Gas </gas> requires GAVAIL <Gas G
rule <k> G:Gas ~> #deductGas => .K ... </k> <gas> GAVAIL:Gas => GAVAIL -Gas G </gas> requires G <=Gas GAVAIL
syntax Bool ::= #inStorage ( Map , Account , Int ) [symbol(#inStorage), function, total]
| #inStorageAux1 ( KItem , Int ) [symbol(#inStorageAux1), function, total]
Expand Down
69 changes: 21 additions & 48 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/optimizations.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -31,7 +28,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => ( #if USEGAS #then ( GAVAIL -Gas Gbase < SCHED > ) #else GAVAIL #fi ) )
( GAVAIL => ( ( GAVAIL -Gas Gbase < SCHED > ) ) )
</gas>
...
</callState>
Expand All @@ -41,7 +38,7 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gbase < SCHED > <=Gas GAVAIL #else true #fi )
requires ( Gbase < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -54,9 +51,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -70,7 +64,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( ( PCOUNT +Int N ) +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -80,7 +74,7 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -93,9 +87,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -106,7 +97,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -117,7 +108,7 @@ module EVM-OPTIMIZATIONS
...
</kevm>
requires N <=Int #sizeWordStack(WS)
andBool ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
andBool ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -130,9 +121,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -143,7 +131,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -153,8 +141,8 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires N <=Int #sizeWordStack(WS)
andBool ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
requires N <=Int #sizeWordStack(W0 : WS)
andBool ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -167,9 +155,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -180,7 +165,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -190,7 +175,7 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -203,9 +188,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -216,7 +198,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -226,8 +208,8 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool (#sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
rule
Expand All @@ -239,9 +221,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -252,7 +231,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -262,7 +241,7 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand All @@ -275,9 +254,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -288,7 +264,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -298,8 +274,8 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
rule
Expand All @@ -311,9 +287,6 @@ module EVM-OPTIMIZATIONS
<schedule>
SCHED
</schedule>
<useGas>
USEGAS
</useGas>
<ethereum>
<evm>
<callState>
Expand All @@ -324,7 +297,7 @@ module EVM-OPTIMIZATIONS
( PCOUNT => ( PCOUNT +Int 1 ) )
</pc>
<gas>
( GAVAIL => #if USEGAS #then ( GAVAIL -Gas Gverylow < SCHED > ) #else GAVAIL #fi )
( GAVAIL => ( GAVAIL -Gas Gverylow < SCHED > ) )
</gas>
...
</callState>
Expand All @@ -334,7 +307,7 @@ module EVM-OPTIMIZATIONS
</ethereum>
...
</kevm>
requires ( #if USEGAS #then Gverylow < SCHED > <=Gas GAVAIL #else true #fi )
requires ( Gverylow < SCHED > <=Gas GAVAIL )
andBool ( #sizeWordStack( WS ) <=Int 1023 )
[priority(40)]
Expand Down
Loading

0 comments on commit ab0e2c2

Please sign in to comment.