Skip to content

Commit 892ef68

Browse files
committed
eip-7823: modexp upper bounds
1 parent 1be2418 commit 892ef68

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,6 +2254,19 @@ Precompiled Contracts
22542254
rule <k> MODEXP => #end EVMC_SUCCESS ... </k>
22552255
<callData> DATA </callData>
22562256
<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>
2257+
<schedule> SCHED </schedule>
2258+
requires notBool Ghaseip7823 << SCHED >>
2259+
orBool modexpUBCheck(#asWord(#range(DATA, 0, 32)), #asWord(#range(DATA, 32, 32)), #asWord(#range(DATA, 64, 32)))
2260+
2261+
rule <k> MODEXP => #end EVMC_PRECOMPILE_FAILURE ... </k>
2262+
<callData> DATA </callData>
2263+
<schedule> SCHED </schedule>
2264+
requires Ghaseip7823 << SCHED >>
2265+
andBool notBool modexpUBCheck(#asWord(#range(DATA, 0, 32)), #asWord(#range(DATA, 32, 32)), #asWord(#range(DATA, 64, 32)))
2266+
2267+
syntax Bool ::= modexpUBCheck (Int , Int , Int) [symbol(modexpUBCheck), function, total]
2268+
// ----------------------------------------------------------------------------------------
2269+
rule modexpUBCheck(BASELEN, EXPLEN, MODLEN) => BASELEN <=Int 1024 andBool EXPLEN <=Int 1024 andBool MODLEN <=Int 1024
22572270
22582271
syntax Bytes ::= #modexp1 ( Int , Int , Int , Bytes ) [symbol(#modexp1), function]
22592272
| #modexp2 ( Int , Int , Int , Bytes ) [symbol(#modexp2), function]

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,15 @@ module GAS-FEES
205205
rule [Cextcodecopy.old]: Cextcodecopy(SCHED, WIDTH) => Gextcodecopy < SCHED > +Int (Gcopy < SCHED > *Int (WIDTH up/Int 32)) requires notBool Ghasaccesslist << SCHED >> [concrete]
206206
207207
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 >
208-
requires notBool ( Ghasaccesslist << SCHED >> orBool Ghaseip7883 << SCHED >>)
208+
requires notBool ( Ghasaccesslist << SCHED >> orBool Ghaseip7823 << SCHED >>)
209209
[concrete]
210210
211211
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 > )
212-
requires Ghasaccesslist << SCHED >> andBool notBool Ghaseip7883 << SCHED >>
212+
requires Ghasaccesslist << SCHED >> andBool notBool Ghaseip7823 << SCHED >>
213213
[concrete]
214214
215-
rule [Cmodexp.7883]: Cmodexp(SCHED, DATA, BASELEN, EXPLEN, MODLEN) => maxInt(Gmodexpmin < SCHED >, #multComplexityEIP7883(maxInt(BASELEN, MODLEN)) *Int maxInt(#adjustedExpLength(BASELEN, EXPLEN, DATA, Gmodexpmultiplier < SCHED >), 1))
216-
requires Ghaseip7883 << SCHED >>
215+
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)))
216+
requires Ghaseip7823 << SCHED >>
217217
[concrete]
218218
219219
rule [Cinitcode.new]: Cinitcode(SCHED, INITCODELEN) => Ginitcodewordcost < SCHED > *Int ( INITCODELEN up/Int 32 ) requires Ghasmaxinitcodesize << SCHED >> [concrete]

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module SCHEDULE
3131
| "Ghaswarmcoinbase" | "Ghaswithdrawals" | "Ghastransient" | "Ghasmcopy"
3232
| "Ghasbeaconroot" | "Ghaseip6780" | "Ghasblobbasefee" | "Ghasblobhash"
3333
| "Ghasbls12msmdiscount" | "Ghashistory" | "Ghasrequests" | "Ghasauthority"
34-
| "Ghasfloorcost" | "Ghasclz" | "Ghaseip7883"
34+
| "Ghasfloorcost" | "Ghasclz" | "Ghaseip7823"
3535
// --------------------------------------------------------------------------------------
3636
```
3737

@@ -186,7 +186,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
186186
rule [GhasauthorityDefault]: Ghasauthority << DEFAULT >> => false
187187
rule [GhasfloorcostDefault]: Ghasfloorcost << DEFAULT >> => false
188188
rule [GhasclzDefault]: Ghasclz << DEFAULT >> => false
189-
rule [Ghaseip7883Default]: Ghaseip7883 << DEFAULT >> => false
189+
rule [Ghaseip7823Default]: Ghaseip7823 << DEFAULT >> => false
190190
```
191191

192192
### Frontier Schedule
@@ -510,15 +510,17 @@ A `ScheduleConst` is a constant determined by the fee schedule.
510510
// -----------------------------------------------------------------------
511511
rule [GmodexpmultiplierOsaka]: Gmodexpmultiplier < OSAKA > => 16
512512
rule [GmodexpminOsaka]: Gmodexpmin < OSAKA > => 500
513+
rule [GquaddivisorOsaka]: Gquaddivisor < OSAKA > => 1
513514
rule [SCHEDCONSTOsaka]: SCHEDCONST < OSAKA > => SCHEDCONST < PRAGUE >
514515
requires notBool ( SCHEDCONST ==K Gmodexpmultiplier
515-
orBool SCHEDCONST ==K Gmodexpmin )
516+
orBool SCHEDCONST ==K Gmodexpmin
517+
orBool SCHEDCONST ==K Gquaddivisor )
516518
517-
rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
518-
rule [Ghaseip7883Osaka]: Ghaseip7883 << OSAKA >> => true
519-
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
519+
rule [GhasclzOsaka]: Ghasclz << OSAKA >> => true
520+
rule [Ghaseip7823Osaka]: Ghaseip7823 << OSAKA >> => true
521+
rule [SCHEDFLAGOsaka]: SCHEDFLAG << OSAKA >> => SCHEDFLAG << PRAGUE >>
520522
requires notBool ( SCHEDFLAG ==K Ghasclz
521-
orBool SCHEDFLAG ==K Ghaseip7883 )
523+
orBool SCHEDFLAG ==K Ghaseip7823 )
522524
523525
```
524526

0 commit comments

Comments
 (0)