From eeff9fef8a3dc548984def3366cf9ced685a95cc Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 12 Sep 2023 18:21:20 +0200 Subject: [PATCH] core: implement blobfee opcode --- core/evm.go | 6 ++++++ core/vm/eips.go | 14 ++++++++++++++ core/vm/evm.go | 1 + core/vm/opcodes.go | 3 +++ 4 files changed, 24 insertions(+) diff --git a/core/evm.go b/core/evm.go index 104f2c09dc..1ef777b769 100644 --- a/core/evm.go +++ b/core/evm.go @@ -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, diff --git a/core/vm/eips.go b/core/vm/eips.go index 704c1ce127..a89d4c410b 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -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) diff --git a/core/vm/evm.go b/core/vm/evm.go index 40e2f3554f..3ed8b19aa9 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -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 } diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index 2929b8ce92..6c570c10eb 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -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,