EIP-658 · Final · Core · 2017-06-30
EIP-658: Embedding transaction status code in receipts
Replaced the intermediate state root in transaction receipts with a status code (1 = success, 0 = failure), giving every client a reliable way to tell whether a transaction succeeded.
What problem does it solve?
Before Byzantium, a common heuristic was "if a transaction used all its gas, it failed". EIP-140 added the REVERT opcode, which undoes state changes and refunds the remaining gas. After that, a failed transaction could look like a cheap, successful one.
Full nodes could replay a transaction to find out what happened. Fast-synced nodes could do that only for recent blocks, and light clients could not do it at all. Wallets and dapps needed the result recorded in consensus data.
How it works
Each receipt used to contain an intermediate state root: the state trie root right after that transaction. That field had already been made obsolete by an earlier proposal, EIP-98.
From the Byzantium fork on, that field holds a status code instead:
1means the top-level call succeeded and its state changes were applied.0means it failed for any reason that reverts the transaction, such asREVERT, out-of-gas or an invalid opcode.
The receipt still contains cumulative gas used, the logs bloom and the logs, so the change is a single field. Because receipts are committed in the block header's receipts root, light clients can verify the status with a Merkle proof.
Sample code
Receipt as RLP, before and after:
pre-Byzantium: [post_state_root (32 bytes), cumulative_gas_used, logs_bloom, logs]
post-Byzantium: [status (0x01 or empty for 0), cumulative_gas_used, logs_bloom, logs]
Checking the status (ethers v6):
import { JsonRpcProvider } from "ethers";
const provider = new JsonRpcProvider(process.env.RPC_URL);
const receipt = await provider.getTransactionReceipt(txHash);
if (receipt?.status === 1) {
console.log("success");
} else if (receipt?.status === 0) {
console.log("reverted");
}
In JSON-RPC, eth_getTransactionReceipt returns "status": "0x1" or "0x0". Pre-Byzantium receipts return a root field instead.
Things to know
- The status describes only the top-level call. A transaction can succeed even if an internal call failed and the contract caught the failure.
- A status of
0still means the sender paid for the gas used and the nonce was consumed. - The status code does not include the revert reason or return data. Read those with
eth_callor tracing. EIP-211 made return data available inside the EVM. - Typed transactions (EIP-2718) keep the status field in their receipts.
- Shipped in Byzantium (EIP-609).