EIP-3198: BASEFEE opcode Source

作者 Abdelhamid Bakhta, Vitalik Buterin
讨论-To https://ethereum-magicians.org/t/eip-3198-basefeeopcode/5162
状态 Final
类型 Standards Track
分类 Core
创建日期 2021-01-13
依赖 1559
英文版 https://eips.ethereum.org/EIPS/eip-3198

简述

Adds an opcode that gives the EVM access to the block’s base fee.

摘要

Add a BASEFEE (0x48) that returns the value of the base fee of the current block it is executing in.

动机

The intended use case would be for contracts to get the value of the base fee. This feature would enable or improve existing use cases, such as:

  • Contracts that need to set bounties for anyone to “poke” them with a transaction could set the bounty to be BASEFEE + x, or BASEFEE * (1 + x). This makes the mechanism more reliable, because they will always pay “enough” regardless of market conditions.
  • Gas futures can be implemented based on it. This would be more precise than gastokens.
  • Improve the security for state channels, plasma, optirolls and other fraud proof driven solutions. Having the BASEFEE as an input allows you to lengthen the challenge period automatically if you see that the BASEFEE is high.

规范

Add a BASEFEE opcode at (0x48), with gas cost G_base.

Op Input Output Cost
0x48 0 1 2

基本原理

Gas cost

The value of the base fee is needed to process transactions. That means it’s value is already available before running the EVM code. The opcode does not add extra complexity and additional read/write operations, hence the choice of G_base gas cost.

向后兼容性

There are no known backward compatibility issues with this opcode.

测试用例

Nominal case

Assuming current block base fee is 7 wei. This should push the value 7 (left padded byte32) to the stack.

Bytecode: 0x4800 (BASEFEE, STOP)

Pc Op Cost Stack RStack
0 BASEFEE 2 [] []
1 STOP 0 [7] []

Output: 0x Consumed gas: 2

Security Considerations

The value of the base fee is not sensitive and is publicly accessible in the block header. There are no known security implications with this opcode.

版权声明

Copyright and related rights waived via CC0.

参考文献

Please cite this document as:

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