Skip to content
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
40 changes: 36 additions & 4 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ In the comments next to each cell, we've marked which component of the YellowPap
<pc> 0p256 </pc> // \mu_pc
<gas> $GAS:Gas </gas> // \mau_g
<memoryUsed> 0 </memoryUsed> // \mu_i
<logUsed> 0 </logUsed>
<callGas> 0:Gas </callGas>

<static> $STATIC:Bool </static>
Expand Down Expand Up @@ -1841,6 +1842,7 @@ Overall Gas
// ------------------------------------------------------
rule <k> #gas [ OP , AOP ]
=> #memory [ OP , AOP ]
~> #log [ OP , AOP ]
~> #gas [ AOP ]
~> #access [ OP , AOP, #isAccess(ACCT, AOP) ]
...
Expand All @@ -1854,15 +1856,26 @@ Overall Gas
<memoryUsed> MU </memoryUsed>
requires #usesMemory(OP)

rule <k> #memory [ _ , _ ] => .K ... </k> [owise]
rule <k> #memory [ _ , _ ] => .K ... </k> [owise]

syntax InternalOp ::= "#gas" "[" OpCode "]" | "#deductGas" | "#deductMemoryGas"
rule <k> #log [ OP , AOP ] => #log(AOP, LU) ~> #deductLog ... </k>
<logUsed> LU </logUsed>
requires #usesLog(OP)

rule <k> #log [ _ , _ ] => .K ... </k> [owise]

syntax InternalOp ::= "#gas" "[" OpCode "]" | "#deductGas" | "#deductMemoryGas" | "#deductLogGas"
| "#memory" "[" OpCode "," OpCode "]" | "#deductMemory"
// ---------------------------------------------------------------------------
| "#log" "[" OpCode "," OpCode "]" | "#deductLog"
// ---------------------------------------------------------------------------------------------------
rule <k> MU':Int ~> #deductMemory => (Cmem(SCHED, MU') -Int Cmem(SCHED, MU)) ~> #deductMemoryGas ... </k>
<memoryUsed> MU => MU' </memoryUsed> <schedule> SCHED </schedule>

rule <k> LU':Int ~> #deductLog => (Clog(SCHED, LU') -Int Clog(SCHED, LU)) ~> #deductLogGas ... </k>
<logUsed> LU => LU' </logUsed> <schedule> SCHED </schedule>

rule <k> _G:Gas ~> (#deductMemoryGas => #deductGas) ... </k> //Required for verification
rule <k> _G:Gas ~> (#deductLogGas => #deductGas) ... </k> //Required for verification
rule <k> G:Gas ~> #deductGas => #end EVMC_OUT_OF_GAS ... </k> <gas> GAVAIL </gas> requires GAVAIL <Gas G
rule <k> G:Gas ~> #deductGas => .K ... </k> <gas> GAVAIL => GAVAIL -Gas G </gas> requires G <=Gas GAVAIL

Expand Down Expand Up @@ -1941,6 +1954,25 @@ In the YellowPaper, each opcode is defined to consume zero gas unless specified
rule #memoryUsageUpdate(MU, START, WIDTH) => maxInt(MU, (START +Int WIDTH) up/Int 32) requires 0 <Int WIDTH [concrete]
```

Total Log Size
------------------

The total size of logs written is tracked to determine the appropriate amount of gas to charge for each log operation.

- `#log` computes the new total log size given the old size and next operator (with its arguments).

```k
syntax Int ::= #log ( OpCode , Int ) [symbol(#log), function, total]
// --------------------------------------------------------------------
rule #log ( LOG(_) _ WIDTH , LU ) => LU +Int MInt2Unsigned(WIDTH) requires 0 <Int MInt2Unsigned(WIDTH)
rule #log ( _ , LU ) => LU [owise]

syntax Bool ::= #usesLog ( OpCode ) [symbol(#usesLog), function, total]
// -----------------------------------------------------------------------
rule #usesLog(_:LogOp) => true
rule #usesLog(_) => false [owise]
```

Access List Gas
---------------

Expand Down Expand Up @@ -2019,7 +2051,7 @@ The intrinsic gas calculation mirrors the style of the YellowPaper (appendix H).
rule <k> #gasExec(SCHED, CODECOPY _ _ WIDTH) => Gverylow < SCHED > +Int (Gcopy < SCHED > *Int (MInt2Unsigned(WIDTH) up/Int 32)) ... </k>
rule <k> #gasExec(SCHED, MCOPY _ _ WIDTH) => Gverylow < SCHED > +Int (Gcopy < SCHED > *Int (MInt2Unsigned(WIDTH) up/Int 32)) ... </k>

rule <k> #gasExec(SCHED, LOG(N) _ WIDTH) => (Glog < SCHED > +Int (Glogdata < SCHED > *Int MInt2Unsigned(WIDTH)) +Int (N *Int Glogtopic < SCHED >)) ... </k>
rule <k> #gasExec(SCHED, LOG(N) _ _) => (Glog < SCHED > +Int (N *Int Glogtopic < SCHED >)) ... </k>

syntax Exp ::= #handleCallGas(Schedule, acctNonExistent: BExp, cap: Gas, avail: Gas, value: Int, acct:Int, AccountInfo) [strict(2)]
// ------------------------------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ module GAS-FEES
| Cnew ( Schedule , Bool , Int ) [symbol(Cnew), function, total, smtlib(gas_Cnew) ]
| Cxfer ( Schedule , Int ) [symbol(Cxfer), function, total, smtlib(gas_Cxfer) ]
| Cmem ( Schedule , Int ) [symbol(Cmem), function, total, smtlib(gas_Cmem), memo ]
| Clog ( Schedule , Int ) [symbol(Clog), function, total, smtlib(gas_Clog), memo ]
| Caddraccess ( Schedule , Bool ) [symbol(Caddraccess), function, total, smtlib(gas_Caddraccess) ]
| Cstorageaccess ( Schedule , Bool ) [symbol(Cstorageaccess), function, total, smtlib(gas_Cstorageaccess) ]
| Csload ( Schedule , Bool ) [symbol(Csload), function, total, smtlib(gas_Csload) ]
Expand Down Expand Up @@ -184,6 +185,13 @@ module GAS-FEES

rule [Cmem]: Cmem(SCHED, N) => (N *Int Gmemory < SCHED >) +Int ((N *Int N) /Int Gquadcoeff < SCHED >) [concrete]

rule [Clog.short]: Clog(SCHED, N) => N *Int Glogdata < SCHED >
requires (notBool Ghasmip001 << SCHED >>) orBool (N <=Int Gloglimit < SCHED >)
[concrete]
rule [Clog.long] : Clog(SCHED, N) => (Gloglimit < SCHED > *Int Glogdata < SCHED >) +Int ((N -Int Gloglimit < SCHED >) *Int (N -Int Gloglimit < SCHED >))
requires Ghasmip001 <<SCHED >> andBool N >Int Gloglimit < SCHED >
[concrete]

rule [Cdelegationaccess]: Cdelegationaccess(SCHED, ISDELEGATION, ISWARM) => #if ISDELEGATION #then Caddraccess(SCHED, ISWARM) #else 0 #fi
rule [Caddraccess]: Caddraccess(SCHED, ISWARM) => #if ISWARM #then Gwarmstorageread < SCHED > #else Gcoldaccountaccess < SCHED > #fi
rule [Cstorageaccess]: Cstorageaccess(SCHED, ISWARM) => #if ISWARM #then Gwarmstorageread < SCHED > #else Gcoldsload < SCHED > #fi
Expand Down
Loading