Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

This article examines EIP-3198, which introduces the BASEFEE (0x48) opcode to retrieve the base fee of the block currently being executed.

This article translates, summarizes, and supplements the material linked below.

I have also covered other EIPs.

Overview

The proposal introduces a new Ethereum Virtual Machine (EVM) opcode, BASEFEE, identified by 0x48. It returns the base fee of the current execution block.

See the following resource for more information about Ethereum opcodes.

Ethereum transaction fees under EIP-1559 consist of a base fee and a priority fee (tip), subject to the transaction's fee limits. The base fee adjusts automatically for each block according to network demand. It increases when the preceding block's gas usage exceeds the target and decreases when usage is below the target.

The addition of BASEFEE allows smart contracts to read the current block's base fee directly. Contracts can therefore implement more flexible gas-price strategies, for example executing a particular function only when the fee exceeds a specified threshold.

This is useful for developers because it provides an additional input for estimating execution costs and responding to changes in gas prices.

Motivation

The proposal identifies several potential use cases for the BASEFEE opcode.

Smart Contracts That Set Rewards

Some contracts need to reward external actors for performing a poke, an action or transaction that triggers a particular operation.

A reward expressed as BASEFEE + x or BASEFEE * (1 + x), where x represents an additional incentive, can adjust to changing market conditions. The formulas illustrate how rewards can track the base fee; their adequacy still depends on factors such as gas usage and the priority fee.

This makes the incentive mechanism more responsive to market conditions.

Implementing Gas Futures

Access to BASEFEE makes it possible to construct financial products or contracts based on future gas prices. The proposal envisages a more direct and reliable reference for gas futures than gas tokens that exploit changes in gas prices.

Improving Security for State Channels, Plasma, and Optimistic Rollups

These systems rely on fraud proofs and include challenge periods during which the validity of a transaction can be disputed.

If the system detects a high BASEFEE, it could automatically extend a challenge period to help maintain security when the network is congested.

These examples illustrate how the opcode can improve contract functionality and efficiency, especially responsiveness to market conditions and the security of fraud-proof mechanisms.

Specification

The proposal introduces the new EVM opcode BASEFEE at hexadecimal opcode value 0x48. It retrieves the current execution block's base fee.

Op Input Output Cost
0x48 0 1 2
  • Op
    • 0x48 identifies the BASEFEE opcode.
  • Input
    • The opcode consumes no stack arguments.
  • Output
    • It pushes one value onto the stack: the current block's base fee.
  • Cost
    • Its gas cost is G_base, which is 2 gas.

Smart contracts can therefore directly retrieve the base fee and plan gas-price strategies around it.

Additional Notes

The gas cost reflects the simplicity of the operation. Different Ethereum operations consume different amounts of gas according to their resource requirements.

The current block's base fee has already been calculated and is available before transaction execution. Retrieving it does not require complex additional computations or storage reads and writes.

Consequently, the opcode is assigned the relatively low G_base cost, the standard EVM cost for basic operations. Its cost of 2 gas reflects the fact that it retrieves information that is already available.

Compatibility

The proposal identifies no backward-compatibility issues with this opcode.

Security

Consider a simple execution example in which the current block's base fee is 7 wei.

Bytecode: 0x4800 consists of the BASEFEE opcode (0x48) followed by the STOP opcode (0x00). BASEFEE pushes the current block's base fee onto the stack, and STOP halts execution.

Pc Op Cost Stack RStack
0 BASEFEE 2 [] []
1 STOP 0 [7] []
  • Pc
    • Program counter, identifying the instruction position.
  • Op
    • The opcode being executed.
  • Cost
    • Gas cost: 2 for BASEFEE and 0 for STOP.
  • Stack
    • The stack at the indicated instruction. After BASEFEE executes, the value 7 is present.
  • RStack
    • Return stack, unused in this example.

Output: 0x indicates empty output, and Consumed gas: 2 indicates the total gas consumed by this program.

The example demonstrates how BASEFEE pushes the base fee onto the stack at low cost.

Security

The base fee is already publicly available in the block header. Retrieving it through the opcode does not expose additional confidential information.

Sensitive blockchain information includes private keys or confidential transaction data that could be misused if disclosed. The base fee, by contrast, is a publicly defined indicator of network conditions, adjusted for each block. It does not contain private information about particular users or transactions.

The proposal therefore identifies no security risk from exposing the base fee itself. The opcode merely gives contracts information about current market conditions; applications must still assess the security of their own use of that information.

Citation

Abdelhamid Bakhta (@abdelhamidbakhta), Vitalik Buterin (@vbuterin), "EIP-3198: BASEFEE opcode," Ethereum Improvement Proposals, no. 3198, January 2021. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-3198.

Conclusion

This article examined EIP-3198 and the BASEFEE opcode.

If you have questions, feel free to contact me on Twitter.

Twitter @cardene777

I also publish articles on the following platforms.

https://chaldene.net/