From af4a3b0f9fea88195564e5462a2aa1d2689abed2 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 10 Feb 2025 09:18:25 +0800 Subject: [PATCH 1/2] core/vm: implement BLOBBASEFEE opcode 0x4a (#28098) --- core/vm/eips.go | 17 +++++++++++++++++ core/vm/jump_table.go | 1 + core/vm/opcodes.go | 3 +++ 3 files changed, 21 insertions(+) diff --git a/core/vm/eips.go b/core/vm/eips.go index 99b25c5252..c229dd25aa 100644 --- a/core/vm/eips.go +++ b/core/vm/eips.go @@ -256,6 +256,23 @@ func opMcopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]by return nil, nil } +// opBlobBaseFee implements BLOBBASEFEE opcode +func opBlobBaseFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + blobBaseFee := new(uint256.Int) + scope.Stack.push(blobBaseFee) + return nil, nil +} + +// enable7516 applies EIP-7516 (BLOBBASEFEE opcode) +func enable7516(jt *JumpTable) { + jt[BLOBBASEFEE] = &operation{ + execute: opBlobBaseFee, + constantGas: GasQuickStep, + minStack: minStack(0, 1), + maxStack: maxStack(0, 1), + } +} + // enable6780 applies EIP-6780 (deactivate SELFDESTRUCT) func enable6780(jt *JumpTable) { jt[SELFDESTRUCT] = &operation{ diff --git a/core/vm/jump_table.go b/core/vm/jump_table.go index 3797b01cac..667778e73a 100644 --- a/core/vm/jump_table.go +++ b/core/vm/jump_table.go @@ -82,6 +82,7 @@ func validate(jt JumpTable) JumpTable { func newCancunInstructionSet() JumpTable { instructionSet := newEip1559InstructionSet() + enable7516(&instructionSet) // EIP-7516 (BLOBBASEFEE opcode) enable1153(&instructionSet) // EIP-1153 "Transient Storage" enable5656(&instructionSet) // EIP-5656 (MCOPY opcode) enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction diff --git a/core/vm/opcodes.go b/core/vm/opcodes.go index c2e7bba897..75a0e31d41 100644 --- a/core/vm/opcodes.go +++ b/core/vm/opcodes.go @@ -100,6 +100,7 @@ const ( CHAINID OpCode = 0x46 SELFBALANCE OpCode = 0x47 BASEFEE OpCode = 0x48 + BLOBBASEFEE OpCode = 0x4a ) // 0x50 range - 'storage' and execution. @@ -284,6 +285,7 @@ var opCodeToString = [256]string{ CHAINID: "CHAINID", SELFBALANCE: "SELFBALANCE", BASEFEE: "BASEFEE", + BLOBBASEFEE: "BLOBBASEFEE", // 0x50 range - 'storage' and execution. POP: "POP", @@ -458,6 +460,7 @@ var stringToOp = map[string]OpCode{ "GASLIMIT": GASLIMIT, "SELFBALANCE": SELFBALANCE, "BASEFEE": BASEFEE, + "BLOBBASEFEE": BLOBBASEFEE, "POP": POP, "MLOAD": MLOAD, "MSTORE": MSTORE, From 0dd3d532fcc17a488d6a901e4bd42481fce406a1 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Mon, 10 Feb 2025 09:44:42 +0800 Subject: [PATCH 2/2] eth: add eth_blobBaseFee RPC (#29140) --- eth/api_backend.go | 4 ++++ internal/ethapi/api.go | 5 +++++ internal/ethapi/backend.go | 1 + internal/ethapi/transaction_args_test.go | 5 +++++ internal/jsre/deps/web3.js | 5 +++++ les/api_backend.go | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/eth/api_backend.go b/eth/api_backend.go index 183a0f1f44..3a11fe9f1a 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -353,6 +353,10 @@ func (b *EthApiBackend) FeeHistory(ctx context.Context, blockCount uint64, lastB return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) } +func (b *EthApiBackend) BlobBaseFee(ctx context.Context) *big.Int { + return new(big.Int) +} + func (b *EthApiBackend) ChainDb() ethdb.Database { return b.eth.ChainDb() } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index a8d360a23e..b306553f09 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -138,6 +138,11 @@ func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount hexutil.U return results, nil } +// BlobBaseFee returns the base fee for blob gas at the current head. +func (s *PublicEthereumAPI) BlobBaseFee(ctx context.Context) *hexutil.Big { + return (*hexutil.Big)(new(big.Int)) +} + // ProtocolVersion returns the current Ethereum protocol version this node supports func (s *PublicEthereumAPI) ProtocolVersion() hexutil.Uint { return hexutil.Uint(s.b.ProtocolVersion()) diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 560119df78..32a2c545f7 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -48,6 +48,7 @@ type Backend interface { ProtocolVersion() int SuggestGasTipCap(ctx context.Context) (*big.Int, error) FeeHistory(ctx context.Context, blockCount uint64, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) + BlobBaseFee(ctx context.Context) *big.Int ChainDb() ethdb.Database AccountManager() *accounts.Manager RPCGasCap() uint64 // global gas cap for eth_call over rpc: DoS protection diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 7e7f249994..411b4fde4e 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -291,6 +291,11 @@ func (b *backendMock) SyncProgress() ethereum.SyncProgress { return ethereum.Syn func (b *backendMock) FeeHistory(context.Context, uint64, rpc.BlockNumber, []float64) (*big.Int, [][]*big.Int, []*big.Int, []float64, error) { return nil, nil, nil, nil, nil } + +func (b *backendMock) BlobBaseFee(ctx context.Context) *big.Int { + return new(big.Int) +} + func (b *backendMock) ChainDb() ethdb.Database { return nil } func (b *backendMock) AccountManager() *accounts.Manager { return nil } func (b *backendMock) ExtRPCEnabled() bool { return false } diff --git a/internal/jsre/deps/web3.js b/internal/jsre/deps/web3.js index 83cbc36e78..4547be3281 100644 --- a/internal/jsre/deps/web3.js +++ b/internal/jsre/deps/web3.js @@ -5586,6 +5586,11 @@ var properties = function () { getter: 'eth_gasPrice', outputFormatter: formatters.outputBigNumberFormatter }), + new Property({ + name: 'blobBaseFee', + getter: 'eth_blobBaseFee', + outputFormatter: formatters.outputBigNumberFormatter + }), new Property({ name: 'accounts', getter: 'eth_accounts' diff --git a/les/api_backend.go b/les/api_backend.go index fe8371c5a2..be4fd4e000 100644 --- a/les/api_backend.go +++ b/les/api_backend.go @@ -286,6 +286,10 @@ func (b *LesApiBackend) FeeHistory(ctx context.Context, blockCount uint64, lastB return b.gpo.FeeHistory(ctx, blockCount, lastBlock, rewardPercentiles) } +func (b *LesApiBackend) BlobBaseFee(ctx context.Context) *big.Int { + return new(big.Int) +} + func (b *LesApiBackend) ChainDb() ethdb.Database { return b.eth.chainDb }