Skip to content
Open
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
13 changes: 13 additions & 0 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/evm.md
Original file line number Diff line number Diff line change
Expand Up @@ -2254,6 +2254,19 @@ Precompiled Contracts
rule <k> MODEXP => #end EVMC_SUCCESS ... </k>
<callData> DATA </callData>
<output> _ => #modexp1(#asWord(#range(DATA, 0, 32)), #asWord(#range(DATA, 32, 32)), #asWord(#range(DATA, 64, 32)), #range(DATA, 96, maxInt(0, lengthBytes(DATA) -Int 96))) </output>
<schedule> SCHED </schedule>
requires notBool Ghaseip7823 << SCHED >>
orBool modexpUBCheck(#asWord(#range(DATA, 0, 32)), #asWord(#range(DATA, 32, 32)), #asWord(#range(DATA, 64, 32)))

rule <k> MODEXP => #end EVMC_PRECOMPILE_FAILURE ... </k>
<callData> DATA </callData>
<schedule> SCHED </schedule>
requires Ghaseip7823 << SCHED >>
andBool notBool modexpUBCheck(#asWord(#range(DATA, 0, 32)), #asWord(#range(DATA, 32, 32)), #asWord(#range(DATA, 64, 32)))

syntax Bool ::= modexpUBCheck (Int , Int , Int) [symbol(modexpUBCheck), function, total]
// ----------------------------------------------------------------------------------------
rule modexpUBCheck(BASELEN, EXPLEN, MODLEN) => BASELEN <=Int 1024 andBool EXPLEN <=Int 1024 andBool MODLEN <=Int 1024

syntax Bytes ::= #modexp1 ( Int , Int , Int , Bytes ) [symbol(#modexp1), function]
| #modexp2 ( Int , Int , Int , Bytes ) [symbol(#modexp2), function]
Expand Down
30 changes: 19 additions & 11 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/gas.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,16 @@ module GAS-FEES
rule [Cextcodecopy.new]: Cextcodecopy(SCHED, WIDTH) => Gcopy < SCHED > *Int (WIDTH up/Int 32) requires Ghasaccesslist << SCHED >> [concrete]
rule [Cextcodecopy.old]: Cextcodecopy(SCHED, WIDTH) => Gextcodecopy < SCHED > +Int (Gcopy < SCHED > *Int (WIDTH up/Int 32)) requires notBool Ghasaccesslist << SCHED >> [concrete]

rule [Cmodexp.old]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => #multComplexity(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA), 1) /Int Gquaddivisor < SCHED >
requires notBool Ghasaccesslist << SCHED >>
rule [Cmodexp.old]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => #multComplexity(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA, Gmodexpmultiplier < SCHED >), 1) /Int Gquaddivisor < SCHED >
requires notBool ( Ghasaccesslist << SCHED >> orBool Ghaseip7823 << SCHED >>)
[concrete]

rule [Cmodexp.new]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => maxInt(200, (#newMultComplexity(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA), 1)) /Int Gquaddivisor < SCHED > )
requires Ghasaccesslist << SCHED >>
rule [Cmodexp.new]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => maxInt(Gmodexpmin < SCHED >, (#newMultComplexity(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA, Gmodexpmultiplier < SCHED >), 1)) /Int Gquaddivisor < SCHED > )
requires Ghasaccesslist << SCHED >> andBool notBool Ghaseip7823 << SCHED >>
[concrete]

rule [Cmodexp.osaka]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => maxInt(Gmodexpmin < SCHED >, (#multComplexityEIP7883(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA, Gmodexpmultiplier < SCHED >), 1)))
requires Ghaseip7823 << SCHED >>
[concrete]

rule [Cinitcode.new]: Cinitcode(SCHED, INITCODELEN) => Ginitcodewordcost < SCHED > *Int ( INITCODELEN up/Int 32 ) requires Ghasmaxinitcodesize << SCHED >> [concrete]
Expand Down Expand Up @@ -259,19 +263,23 @@ module GAS-FEES
// -----------------------------------------------------------------------
rule G*(GAVAIL, GLIMIT, REFUND, SCHED) => GAVAIL +Gas minGas((GLIMIT -Gas GAVAIL) /Gas Rmaxquotient < SCHED >, REFUND)

syntax Int ::= #multComplexity(Int) [symbol(#multComplexity), function]
| #newMultComplexity(Int) [symbol(#newMultComplexity), function]
// -----------------------------------------------------------------------------
syntax Int ::= #multComplexity(Int) [symbol(#multComplexity), function]
| #newMultComplexity(Int) [symbol(#newMultComplexity), function]
| #multComplexityEIP7883(Int) [symbol(#multComplexityEIP7883), function]
// -------------------------------------------------------------------------------------
rule #multComplexity(X) => X *Int X requires X <=Int 64
rule #multComplexity(X) => X *Int X /Int 4 +Int 96 *Int X -Int 3072 requires X >Int 64 andBool X <=Int 1024
rule #multComplexity(X) => X *Int X /Int 16 +Int 480 *Int X -Int 199680 requires X >Int 1024

rule #newMultComplexity(X) => (X up/Int 8) ^Int 2

syntax Int ::= #adjustedExpLength(Int, Int, Bytes) [symbol(#adjustedExpLength), function]
| #adjustedExpLength(Int) [symbol(#adjustedExpLengthAux), function]
// --------------------------------------------------------------------------------------------
rule #adjustedExpLength(BASELEN, EXPLEN, DATA) => #if EXPLEN <=Int 32 #then 0 #else 8 *Int (EXPLEN -Int 32) #fi +Int #adjustedExpLength(#asInteger(#range(DATA, 96 +Int BASELEN, minInt(EXPLEN, 32))))
rule #multComplexityEIP7883(X) => 16 requires X <=Int 32
rule #multComplexityEIP7883(X) => 2 *Int (((X +Int 7) /Int 8) ^Int 2) requires 32 <Int X

syntax Int ::= #adjustedExpLength(Int, Int, Bytes, Int) [symbol(#adjustedExpLength), function]
| #adjustedExpLength(Int) [symbol(#adjustedExpLengthAux), function]
// -------------------------------------------------------------------------------------------------
rule #adjustedExpLength(BASELEN, EXPLEN, DATA, MODEXPMULTIPLIER) => #if EXPLEN <=Int 32 #then 0 #else MODEXPMULTIPLIER *Int (EXPLEN -Int 32) #fi +Int #adjustedExpLength(#asInteger(#range(DATA, 96 +Int BASELEN, minInt(EXPLEN, 32))))

rule #adjustedExpLength(0) => 0
rule #adjustedExpLength(1) => 0
Expand Down
30 changes: 21 additions & 9 deletions kevm-pyk/src/kevm_pyk/kproj/evm-semantics/schedule.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ module SCHEDULE
| "Ghaswarmcoinbase" | "Ghaswithdrawals" | "Ghastransient" | "Ghasmcopy"
| "Ghasbeaconroot" | "Ghaseip6780" | "Ghasblobbasefee" | "Ghasblobhash"
| "Ghasbls12msmdiscount" | "Ghashistory" | "Ghasrequests" | "Ghasauthority"
| "Ghasfloorcost" | "Ghasclz"
// -------------------------------------------------------------
| "Ghasfloorcost" | "Ghasclz" | "Ghaseip7823"
// --------------------------------------------------------------------------------------
```

### Schedule Constants
Expand All @@ -53,8 +53,8 @@ A `ScheduleConst` is a constant determined by the fee schedule.
| "Gaccessliststoragekey" | "Rmaxquotient" | "Ginitcodewordcost" | "maxInitCodeSize" | "Gwarmstoragedirtystore"
| "Gpointeval" | "Gmaxblobgas" | "Gminbasefee" | "Gtargetblobgas" | "Gperblob" | "Blobbasefeeupdatefraction"
| "Gbls12g1add" | "Gbls12g1mul" | "Gbls12g2add" | "Gbls12g2mul" | "Gbls12mapfptog1" | "Gbls12PairingCheckMul"
| "Gbls12PairingCheckAdd" | "Gauthbase" | "Gbls12mapfp2tog2" | "Gtxdatafloor"
// -------------------------------------------------------------------------------------------------------------------------------------------------------
| "Gbls12PairingCheckAdd" | "Gauthbase" | "Gbls12mapfp2tog2" | "Gtxdatafloor" | "Gmodexpmultiplier" | "Gmodexpmin"
// --------------------------------------------------------------------------------------------------------------------------------------------------------------
```

### Default Schedule
Expand Down Expand Up @@ -149,6 +149,9 @@ A `ScheduleConst` is a constant determined by the fee schedule.
rule [Gbls12mapfptog1Default]: Gbls12mapfptog1 < DEFAULT > => 0
rule [Gbls12mapfp2tog2Default]: Gbls12mapfp2tog2 < DEFAULT > => 0

rule [GmodexpmultiplierDefault]: Gmodexpmultiplier < DEFAULT > => 8
rule [GmodexpminDefault]: Gmodexpmin < DEFAULT > => 200

rule [GselfdestructnewaccountDefault]: Gselfdestructnewaccount << DEFAULT >> => false
rule [GstaticcalldepthDefault]: Gstaticcalldepth << DEFAULT >> => true
rule [GemptyisnonexistentDefault]: Gemptyisnonexistent << DEFAULT >> => false
Expand Down Expand Up @@ -183,6 +186,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
rule [GhasauthorityDefault]: Ghasauthority << DEFAULT >> => false
rule [GhasfloorcostDefault]: Ghasfloorcost << DEFAULT >> => false
rule [GhasclzDefault]: Ghasclz << DEFAULT >> => false
rule [Ghaseip7823Default]: Ghaseip7823 << DEFAULT >> => false
```

### Frontier Schedule
Expand Down Expand Up @@ -504,11 +508,19 @@ A `ScheduleConst` is a constant determined by the fee schedule.
```k
syntax Schedule ::= "OSAKA" [symbol(OSAKA_EVM), smtlib(schedule_OSAKA)]
// -----------------------------------------------------------------------
rule [SCHEDCONSTOsaka]: SCHEDCONST < OSAKA > => SCHEDCONST < PRAGUE >

rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
requires notBool ( SCHEDFLAG ==K Ghasclz )
rule [GmodexpmultiplierOsaka]: Gmodexpmultiplier < OSAKA > => 16
rule [GmodexpminOsaka]: Gmodexpmin < OSAKA > => 500
rule [GquaddivisorOsaka]: Gquaddivisor < OSAKA > => 1
rule [SCHEDCONSTOsaka]: SCHEDCONST < OSAKA > => SCHEDCONST < PRAGUE >
requires notBool ( SCHEDCONST ==K Gmodexpmultiplier
orBool SCHEDCONST ==K Gmodexpmin
orBool SCHEDCONST ==K Gquaddivisor )

rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
rule [Ghaseip7823Osaka]: Ghaseip7823 << OSAKA >> => true
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
requires notBool ( SCHEDFLAG ==K Ghasclz
orBool SCHEDFLAG ==K Ghaseip7823 )

```

Expand Down
Loading