EIP-7889 · Stagnant · Core · 2025-02-20
EIP-7889: Emit log on revert
Proposes that every REVERT with data automatically emits a log carrying the revert message, so wallets and explorers can read failure reasons over standard RPC instead of re-tracing the transaction.
What problem does it solve?
When a transaction fails, the reason ("insufficient balance", a custom error, etc.) is passed to the REVERT opcode (EIP-140), but it is not stored anywhere a normal RPC call can read it. The receipt only says the transaction failed (EIP-658 status 0). To find out why, a user or tool has to ask a node to trace the transaction, which means replaying it in full to recover a few bytes of data. Many public RPC providers restrict or charge for tracing.
Some smart-wallet developers work around this by emitting their own log right before reverting, but that is ad hoc and cannot be relied on by libraries or block explorers. EIP-7889 proposes making this behaviour part of the protocol.
How it works
- Whenever
REVERTis executed with a non-zero data size, the EVM emits a log equivalent to aLOG1. - The single topic is a fixed constant
REVERTTOPIC. - The log data is the raw revert bytes (the ABI-encoded
Error(string)or custom error), truncated toDATA_LIMIT. - Both
REVERTTOPICandDATA_LIMITare still marked TBD in the spec.
Because a reverted transaction normally keeps no logs, the visible change is that a reverted transaction's receipt can now contain up to one log. Clients and indexers read it with the existing eth_getTransactionReceipt / eth_getLogs, so no new RPC method or opcode is needed.
Pseudocode for the proposed rule:
def op_revert(evm, offset, size):
data = evm.memory[offset:offset + size]
if size > 0:
emit_log(address=evm.address,
topics=[REVERTTOPIC], # constant, value TBD
data=data[:DATA_LIMIT]) # limit TBD
evm.halt_with_revert(data)
Sample code
A contract that reverts with a custom error. Under this proposal the encoded error would appear as log data in the failed transaction's receipt:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract Vault {
error InsufficientBalance(uint256 available, uint256 required);
mapping(address => uint256) public balance;
function withdraw(uint256 amount) external {
uint256 bal = balance[msg.sender];
if (bal < amount) revert InsufficientBalance(bal, amount);
balance[msg.sender] = bal - amount;
payable(msg.sender).transfer(amount);
}
}
How a client could then decode it from the receipt (ethers v6), once a topic value is fixed:
import { Interface } from "ethers";
const iface = new Interface(["error InsufficientBalance(uint256 available, uint256 required)"]);
const receipt = await provider.getTransactionReceipt(txHash);
const log = receipt!.logs.find((l) => l.topics[0] === REVERT_TOPIC); // REVERT_TOPIC not yet defined
if (log) console.log(iface.parseError(log.data)); // InsufficientBalance(…)
Things to know
- Status: Stagnant. The proposal has not progressed and its key parameters (
REVERTTOPIC,DATA_LIMIT) were never set. Nothing on mainnet emits these logs today; you still needdebug_traceTransactionor a re-simulation witheth_callto recover revert reasons. - The authors argue it does not add a storage-bloat vector: a reverted transaction already costs at least 21,000 gas, far more than a
LOG1. It would, however, increase the average number of logs. - Only reverts with data would produce a log; a bare
revert()with zero size would not. - Tools that assume "failed transaction ⇒ no logs" would need to be updated if this were ever adopted.