EIP-3198 Add the BASEFEE opcode (BASEFEE opcode)
Final · EVM & execution · EIP status Final · created 2021-01-13
Adds the BASEFEE (0x48) opcode to the EVM so that smart contracts can read the base fee of the block currently being executed.
Why it is needed
The base fee introduced by EIP-1559 is the minimum fee set for each block. This value is published in the block header, but smart contracts running inside a block had no way to read it directly. This put contracts that need to track fee market conditions at a disadvantage. For example, in a design where someone is rewarded for sending a transaction that wakes a contract up, a fixed reward may mean nobody sends the transaction when fees are high. If a contract can read the base fee, it can tie the reward to the base fee and guarantee a sufficient amount under any market conditions. It also allows more accurate financial products such as gas futures, and state channels or rollups that rely on fraud proofs can automatically lengthen the challenge period when fees are high, improving security.
What changes
Today
- The base fee exists only in the block header and contracts cannot read it
- There is no way to adjust a contract's reward to fee market conditions
- Products linked to gas prices depend on indirect means such as gas tokens
After EIP-3198
- The BASEFEE opcode reads the current block's base fee directly
- Set the reward to BASEFEE + x or BASEFEE * (1 + x) to guarantee a sufficient amount regardless of market conditions
- Build gas futures based on the base fee, and have fraud proof systems lengthen the challenge period when fees are high
Who is affected
- Contract developer: This enables designs such as rewards that respond to the fee market, gas futures, and variable challenge periods.
- L2s and fraud proof systems: When the base fee is high, the challenge period can be lengthened automatically to improve security.
- Client teams: One opcode, 0x48, must be added to the EVM. The value is already used in block processing, so the implementation burden is small.
- Ordinary users: There is no change users notice directly, but apps that use this opcode will track the fee market more reliably.
In depth
Opcode specification: 0x48, 0 inputs, 1 output
The BASEFEE opcode is added at 0x48. It takes 0 inputs from the stack and pushes 1 output, which is the base fee of the block currently being executed. The gas cost is G_base, that is, 2. Per the test case, the value is pushed onto the stack as a left padded byte32.
Rationale for setting the gas cost to G_base (2)
The base fee value is needed to process transactions, so it is already available before any EVM code runs. This opcode creates no additional complexity and no separate read or write operations. For that reason, G_base was chosen as the gas cost, the cheapest tier, which is used by opcodes that read environment values such as ADDRESS and ORIGIN.
Three intended use cases
First, a contract that waits for an outside party to wake it with a transaction can set the reward to BASEFEE + x or BASEFEE * (1 + x). Because it always pays a sufficient amount regardless of market conditions, the mechanism becomes more trustworthy. Second, gas futures can be implemented based on the base fee, and these are more precise than gas tokens. Third, fraud proof based solutions such as state channels, Plasma, and Optimistic Rollups can take BASEFEE as an input and, when they see that the base fee is high, automatically lengthen the challenge period to improve security.
Test case: bytecode 0x4800
When the current block's base fee is 7 wei, executing bytecode 0x4800 (BASEFEE, STOP) has BASEFEE consume 2 gas and push 7 onto the stack as a left padded byte32, and STOP terminates with 0 gas. The final stack is [7], the output is 0x, and total gas consumed is 2.
Backwards compatibility and security
There are no known backwards compatibility issues. The base fee value is not sensitive information and is published in the block header, so there are no known security implications from this opcode either. This EIP is in Final status with its specification fixed, and it lists EIP-1559 as a prerequisite (requires).