EIP-7516 · Final · Core · 2023-09-11
EIP-7516: BLOBBASEFEE instruction
Adds the BLOBBASEFEE opcode (0x4a), which lets a contract read the current blob base fee from EIP-4844, just as BASEFEE exposes the normal base fee.
What problem does it solve?
EIP-4844 introduced blob-carrying transactions with their own fee market: blob gas has a separate base fee that rises and falls with blob demand, independent of the regular EIP-1559 base fee. Contracts could already read the regular base fee through BASEFEE (EIP-3198), but had no way to see the blob price.
Rollups pay for blob data and often want to account for or reimburse those costs on-chain. Without the price inside the EVM they had to trust an off-chain oracle or a relayer's word. EIP-7516 closes that gap, and also makes it possible to build things like blob-gas hedging or futures contracts on-chain.
How it works
- New opcode
BLOBBASEFEEat0x4a. - Takes no stack inputs and pushes one value: the blob base fee of the current block, in wei per unit of blob gas.
- The value is exactly
get_blob_gasprice(header)as defined in EIP-4844, computed from the block header'sexcess_blob_gas. - Gas cost is 2, the same as
BASEFEE, because the value is already known before execution starts and needs no state access.
Example from the spec: if the blob base fee is 7 wei, the bytecode 0x4a00 (BLOBBASEFEE, STOP) leaves 7 on the stack and uses 2 gas.
The opcode shipped in the Cancun execution-layer upgrade (Dencun) together with EIP-4844.
Sample code
Solidity exposes it as block.blobbasefee (compiler support added for the Cancun EVM target):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;
contract BlobCostMeter {
uint256 constant GAS_PER_BLOB = 131072; // 2**17, from EIP-4844
/// Estimated cost in wei of posting `blobs` blobs in this block.
function blobCost(uint256 blobs) external view returns (uint256) {
return blobs * GAS_PER_BLOB * block.blobbasefee;
}
/// Same value via inline assembly.
function rawBlobBaseFee() external view returns (uint256 fee) {
assembly { fee := blobbasefee() }
}
}
Reading it off-chain with ethers v6, for comparison:
const block = await provider.send("eth_getBlockByNumber", ["latest", false]);
console.log("excessBlobGas:", BigInt(block.excessBlobGas));
// The contract above returns the derived blob base fee directly.
Things to know
- Status: Final, live on mainnet since Cancun.
- The value applies to the block being executed. In an
eth_callagainstlatest, clients evaluate it for a pending context, so results can differ from what a later transaction sees. - Compile with
evmVersionset tocancunor later; on older chains or L2s that have not adopted Cancun,0x4ais an invalid opcode. - The blob base fee can be as low as 1 wei when blob demand is below target, and it can rise quickly when demand is sustained above target, so do not hard-code expectations.