RIP-7767: Gas to Ether precompile
A precompile that burns gas and returns a portion of the gas burned to the caller as Ether
Abstract
This proposal describes a precompile that allows the caller to burn a specific amount of gas, and returns a portion of the gas burned to the caller as Ether.
To facilitate adoption, this precompile may be either implemented as a CREATE2
preinstall or as a precompile at the core layer.
Motivation
Contract Secured Revenue (CSR) is a way of enabling smart contract developers to claim a percentage of the gas fees paid by users when using their smart contracts.
CSR enables new revenues streams in a composable, interoperable, and enforceable way. It works with any existing token standard and onchain applications. It does not require developers to break or create new smart contract standards for the sake of capturing value.
However, CSR can lead to developers intentionally writing bloated smart contracts, sometimes with gas guzzling loops. This can result in unnecessary state bloat and undesirable network congestion.
Having a precompile that burns gas with a low constant compute cost removes the bad externalities, while keeping the benefits of CSR.
With this proposal, the more efficient developers can make their smart contracts, the more gas room they have for the constant cost precompile.
Specification
For nomenclature, we will refer to this precompile as the GASBACK
precompile.
Behavior
The GASBACK
precompile takes in calldata input that represents the amount of gas to burn, bytes32(uint256(gasToBurn))
.
This amount is a suggestion, and the precompile may choose to burn a different amount to manage network congestion and sequencer fees.
The precompile MUST be constant in state and compute consumption with respect to the amount of gas burned.
It is RECOMMENDED that the precompile adds a flat overhead gas that will be burned without being converted to Ether.
It is RECOMMENDED that the precompile reduces the amount of gas burned if the basefee ges too high.
The resultant Ether from the gas burned MUST be forced transferred to the caller of the precompile, similar to the Ether force transfer behavior of SELFDESTRUCT
.
The resultant Ether from the gas burned MUST not exceed basefee * actualGasBurned
, where actualGasBurned
is the actual amount of gas burned by the precompile after adjustments.
The precompile MUST revert (and MUST NOT transfer any Ether) in the following cases:
- Input calldata is not exactly 32 bytes long.
- Arithmetic error (overflow, division by zero).
In the case where the precompile can be executed safely and Ether has been transferred to the caller, the precompile MUST return bytes32(uint256(etherMintedInWei))
.
Precompile Address
The PRECOMPILED_ADDRESS
for GASBACK
is chosen to be TBD
as it is the next available precompiled address set that is reserved for the RIP precompiles.
Preinstall
A preinstall may be used instead of a precompile.
The precompile MUST be deployed at address 0x0000000000005533198cFd0b749148d5e3bd685d
using Nick's Factory (0x4e59b44847b379578588920cA78FbF26c0B4956C
) with salt 0x0000000000000000000000000000000000000000d3a6e641651beb027832a915
.
The registry can be deployed to any EVM-compatible chain using the following transaction:
Rationale
Force transfer of Ether
This is so that the transfer will not be blocked in the case of a contract that does not implement a fallback function, and to keep transfer costs constant regardless of contract code.
Reverting on error
This is to enable calling smart contracts to differentiate between actual errors versus receiving zero Ether.
Backwards Compatibility
This precompile is backwards compatible with EIP-6968. The gas fees burned in the precompile and preinstall will not overlap with the regular CSR fees.
Reference Implementation
The Solidity implementation of the preinstall is provided.
This example serves as a reference for implementation of the precompile which will be implemented in op-geth.
Security Considerations
Implementers must make sure that the precompile does not cause a net increase in the total amount of Ether on the network.
EVM chains hosting any retroactive funding based on gas burned metrics should subtract the total amount of gas burned via the GASBACK
precompile.
Copyright
Copyright and related rights waived via CC0.