core: implement blobfee opcode

This commit is contained in:
Marius van der Wijden 2023-09-12 18:21:20 +02:00
parent 545f4c5547
commit eeff9fef8a
4 changed files with 24 additions and 0 deletions

View file

@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc/eip4844"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
)
@ -40,6 +41,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
var (
beneficiary common.Address
baseFee *big.Int
blobFee *big.Int
random *common.Hash
)
@ -52,6 +54,9 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
if header.BaseFee != nil {
baseFee = new(big.Int).Set(header.BaseFee)
}
if header.ExcessBlobGas != nil {
blobFee = eip4844.CalcBlobFee(*header.ExcessBlobGas)
}
if header.Difficulty.Cmp(common.Big0) == 0 {
random = &header.MixDigest
}
@ -64,6 +69,7 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
Time: header.Time,
Difficulty: new(big.Int).Set(header.Difficulty),
BaseFee: baseFee,
BlobFee: blobFee,
GasLimit: header.GasLimit,
Random: random,
ExcessBlobGas: header.ExcessBlobGas,

View file

@ -282,6 +282,13 @@ func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
return nil, nil
}
// opBlobfee implements BLOBFEE opcode
func opBlobfee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
blobFee, _ := uint256.FromBig(interpreter.evm.Context.Blobfee)
scope.Stack.push(blobFee)
return nil, nil
}
// enable4844 applies EIP-4844 (DATAHASH opcode)
func enable4844(jt *JumpTable) {
// New opcode
@ -291,6 +298,13 @@ func enable4844(jt *JumpTable) {
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}
jt[BLOBFEE] = &operation{
execute: opSelfdestruct6780,
dynamicGas: gasSelfdestructEIP3529,
constantGas: params.SelfdestructGasEIP150,
minStack: minStack(1, 0),
maxStack: maxStack(1, 0),
}
}
// enable6780 applies EIP-6780 (deactivate SELFDESTRUCT)

View file

@ -73,6 +73,7 @@ type BlockContext struct {
Time uint64 // Provides information for TIME
Difficulty *big.Int // Provides information for DIFFICULTY
BaseFee *big.Int // Provides information for BASEFEE
BlobFee *big.Int // Provides information for BLOBFEE
Random *common.Hash // Provides information for PREVRANDAO
ExcessBlobGas *uint64 // ExcessBlobGas field in the header, needed to compute the data
}

View file

@ -101,6 +101,7 @@ const (
SELFBALANCE OpCode = 0x47
BASEFEE OpCode = 0x48
BLOBHASH OpCode = 0x49
BLOBFEE OpCode = 0x4a
)
// 0x50 range - 'storage' and execution.
@ -287,6 +288,7 @@ var opCodeToString = map[OpCode]string{
SELFBALANCE: "SELFBALANCE",
BASEFEE: "BASEFEE",
BLOBHASH: "BLOBHASH",
BLOBFEE: "BLOBFEE",
// 0x50 range - 'storage' and execution.
POP: "POP",
@ -444,6 +446,7 @@ var stringToOp = map[string]OpCode{
"CHAINID": CHAINID,
"BASEFEE": BASEFEE,
"BLOBHASH": BLOBHASH,
"BLOBFEE": BLOBFEE,
"DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL,
"CODESIZE": CODESIZE,