EIPs Explained

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:

  • 1 means the top-level call succeeded and its state changes were applied.
  • 0 means it failed for any reason that reverts the transaction, such as REVERT, 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 0 still 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_call or 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).

#receipts #transactions #core #byzantium

Details

Authors
Nick Johnson <[email protected]>
Status
Final
Type
Standards Track / Core
Created
2017-06-30
Requires
Required by

Machine-readable: Markdown · JSON