Skip to content

Commit 24b3dcb

Browse files
dwightguthanvacaruautomergerpr-permission-manager[bot]
authored
EIP 7516: BLOBBASEFEE opcode (#2691)
* EIP 7516: BLOBBASEFEE opcode * Update kevm-pyk/src/kevm_pyk/kproj/evm-semantics/schedule.md Co-authored-by: Andrei Văcaru <16517508+anvacaru@users.noreply.github.com> * add constants --------- Co-authored-by: Andrei Văcaru <16517508+anvacaru@users.noreply.github.com> Co-authored-by: automergerpr-permission-manager[bot] <190534181+automergerpr-permission-manager[bot]@users.noreply.github.com>
1 parent 69ca55d commit 24b3dcb

File tree

3 files changed

+42
-73
lines changed

3 files changed

+42
-73
lines changed

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

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,26 @@ These are just used by the other operators for shuffling local execution state a
875875
andBool Gemptyisnonexistent << SCHED >>
876876
```
877877

878+
- `#baseFeePerBlobGas` will compute the blob base fee as specified by EIPs 4844 and 7516
879+
880+
```k
881+
syntax Int ::= #baseFeePerBlobGas( Int ) [symbol(#baseFeePerBlobGas), function]
882+
// -------------------------------------------------------------------------------
883+
rule #baseFeePerBlobGas(BLOBGAS) => #fakeExponential(MIN_BASE_FEE_PER_BLOB_GAS, BLOBGAS, BLOB_BASE_FEE_UPDATE_FRACTION)
884+
syntax Int ::= "MIN_BASE_FEE_PER_BLOB_GAS" [macro] | "BLOB_BASE_FEE_UPDATE_FRACTION" [macro]
885+
rule MIN_BASE_FEE_PER_BLOB_GAS => 1
886+
rule BLOB_BASE_FEE_UPDATE_FRACTION => 3338477
887+
888+
syntax Int ::= #fakeExponential(Int, Int, Int) [symbol(#fakeExponential), function]
889+
| #fakeExponential(Int, Int, Int, Int, Int) [function]
890+
// -------------------------------------------------------------------
891+
rule #fakeExponential(FACTOR, NUMER, DENOM) => #fakeExponential(1, 0, FACTOR *Int DENOM, NUMER, DENOM)
892+
893+
rule #fakeExponential(I, OUTPUT, ACCUM, NUMER, DENOM)
894+
=> #fakeExponential(I +Int 1, OUTPUT +Int ACCUM, ACCUM *Int NUMER /Int (DENOM *Int I), NUMER, DENOM) requires ACCUM >Int 0
895+
rule #fakeExponential(_, OUTPUT, _, _, DENOM) => OUTPUT /Int DENOM [owise]
896+
```
897+
878898
### Invalid Operator
879899

880900
We use `INVALID` both for marking the designated invalid operator, and `UNDEFINED(_)` for garbage bytes in the input program.
@@ -1005,13 +1025,14 @@ NOTE: We have to call the opcode `OR` by `EVMOR` instead, because K has trouble
10051025
These operators make queries about the current execution state.
10061026

10071027
```k
1008-
syntax NullStackOp ::= "PC" | "GAS" | "GASPRICE" | "GASLIMIT" | "BASEFEE"
1009-
// -------------------------------------------------------------------------
1010-
rule <k> PC => PCOUNT ~> #push ... </k> <pc> PCOUNT </pc>
1011-
rule <k> GAS => gas2Int(GAVAIL) ~> #push ... </k> <gas> GAVAIL </gas>
1012-
rule <k> GASPRICE => GPRICE ~> #push ... </k> <gasPrice> GPRICE </gasPrice>
1013-
rule <k> GASLIMIT => GLIMIT ~> #push ... </k> <gasLimit> GLIMIT </gasLimit>
1014-
rule <k> BASEFEE => BFEE ~> #push ... </k> <baseFee> BFEE </baseFee>
1028+
syntax NullStackOp ::= "PC" | "GAS" | "GASPRICE" | "GASLIMIT" | "BASEFEE" | "BLOBBASEFEE"
1029+
// -----------------------------------------------------------------------------------------
1030+
rule <k> PC => PCOUNT ~> #push ... </k> <pc> PCOUNT </pc>
1031+
rule <k> GAS => gas2Int(GAVAIL) ~> #push ... </k> <gas> GAVAIL </gas>
1032+
rule <k> GASPRICE => GPRICE ~> #push ... </k> <gasPrice> GPRICE </gasPrice>
1033+
rule <k> GASLIMIT => GLIMIT ~> #push ... </k> <gasLimit> GLIMIT </gasLimit>
1034+
rule <k> BASEFEE => BFEE ~> #push ... </k> <baseFee> BFEE </baseFee>
1035+
rule <k> BLOBBASEFEE => #baseFeePerBlobGas(BLOBGAS) ~> #push ... </k> <excessBlobGas> BLOBGAS </excessBlobGas>
10151036
10161037
syntax NullStackOp ::= "COINBASE" | "TIMESTAMP" | "NUMBER" | "DIFFICULTY" | "PREVRANDAO"
10171038
// ----------------------------------------------------------------------------------------
@@ -2259,6 +2280,7 @@ The intrinsic gas calculation mirrors the style of the YellowPaper (appendix H).
22592280
rule <k> #gasExec(SCHED, PREVRANDAO) => Gbase < SCHED > ... </k>
22602281
rule <k> #gasExec(SCHED, GASLIMIT) => Gbase < SCHED > ... </k>
22612282
rule <k> #gasExec(SCHED, BASEFEE) => Gbase < SCHED > ... </k>
2283+
rule <k> #gasExec(SCHED, BLOBBASEFEE) => Gbase < SCHED > ... </k>
22622284
rule <k> #gasExec(SCHED, POP _) => Gbase < SCHED > ... </k>
22632285
rule <k> #gasExec(SCHED, PC) => Gbase < SCHED > ... </k>
22642286
rule <k> #gasExec(SCHED, PUSHZERO) => Gbase < SCHED > ... </k>
@@ -2454,6 +2476,7 @@ After interpreting the strings representing programs as a `WordStack`, it should
24542476
rule #dasmOpCode( 70, SCHED ) => CHAINID requires Ghaschainid << SCHED >>
24552477
rule #dasmOpCode( 71, SCHED ) => SELFBALANCE requires Ghasselfbalance << SCHED >>
24562478
rule #dasmOpCode( 72, SCHED ) => BASEFEE requires Ghasbasefee << SCHED >>
2479+
rule #dasmOpCode( 74, SCHED ) => BLOBBASEFEE requires Ghasblobbasefee << SCHED >>
24572480
rule #dasmOpCode( 80, _ ) => POP
24582481
rule #dasmOpCode( 81, _ ) => MLOAD
24592482
rule #dasmOpCode( 82, _ ) => MSTORE

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ module SCHEDULE
2929
| "Ghassstorestipend" | "Ghaschainid" | "Ghasaccesslist" | "Ghasbasefee"
3030
| "Ghasrejectedfirstbyte" | "Ghasprevrandao" | "Ghasmaxinitcodesize" | "Ghaspushzero"
3131
| "Ghaswarmcoinbase" | "Ghastransient" | "Ghasmcopy" | "Ghasbeaconroot"
32-
| "Ghaseip6780"
33-
// -------------------------------------
32+
| "Ghaseip6780" | "Ghasblobbasefee"
33+
// ---------------------------------------------------------------------
3434
```
3535

3636
### Schedule Constants
@@ -142,6 +142,7 @@ A `ScheduleConst` is a constant determined by the fee schedule.
142142
rule Ghaschainid << DEFAULT >> => false
143143
rule Ghasaccesslist << DEFAULT >> => false
144144
rule Ghasbasefee << DEFAULT >> => false
145+
rule Ghasblobbasefee << DEFAULT >> => false
145146
rule Ghasrejectedfirstbyte << DEFAULT >> => false
146147
rule Ghasprevrandao << DEFAULT >> => false
147148
rule Ghasmaxinitcodesize << DEFAULT >> => false
@@ -389,17 +390,19 @@ A `ScheduleConst` is a constant determined by the fee schedule.
389390
rule SCHEDCONST < CANCUN > => SCHEDCONST < SHANGHAI >
390391
requires notBool (SCHEDCONST ==K Gwarmstoragedirtystore)
391392
392-
rule Ghastransient << CANCUN >> => true
393-
rule Ghasmcopy << CANCUN >> => true
394-
rule Ghasbeaconroot << CANCUN >> => true
395-
rule Ghaseip6780 << CANCUN >> => true
393+
rule Ghastransient << CANCUN >> => true
394+
rule Ghasmcopy << CANCUN >> => true
395+
rule Ghasbeaconroot << CANCUN >> => true
396+
rule Ghaseip6780 << CANCUN >> => true
397+
rule Ghasblobbasefee << CANCUN >> => true
396398
rule SCHEDFLAG << CANCUN >> => SCHEDFLAG << SHANGHAI >>
397399
requires notBool ( SCHEDFLAG ==K Ghastransient
398400
orBool SCHEDFLAG ==K Ghasmcopy
399401
orBool SCHEDFLAG ==K Ghasbeaconroot
400402
orBool SCHEDFLAG ==K Ghaseip6780
403+
orBool SCHEDFLAG ==K Ghasblobbasefee
401404
)
402405
```
403406
```k
404407
endmodule
405-
```
408+
```

0 commit comments

Comments
 (0)