---
eip: 1959
label: EIP-1959
title: New Opcode to check if a chainID is part of the history of chainIDs
status: Stagnant
type: Standards Track
category: Core
created: 2019-04-20
requires: 155
official: https://eips.ethereum.org/EIPS/eip-1959
source: https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1959.md
canonical: https://eips.huatuo.xyz/eip-1959/
lang: en
tldr: Proposed a VALID_CHAINID opcode that tells a contract whether a chain ID has ever been valid for the current chain, so signatures made before a chain-ID change keep working.
tags: [opcode, chain-id, replay-protection, signatures, evm]
---

# EIP-1959: New Opcode to check if a chainID is part of the history of chainIDs

> To protect off-chain messages from being reused across different chain, a mechanism need to be given to smart contract to only accept messages for that chain. Since a chain can change its chainID, the mechanism should consider old chainID valid.

**TL;DR:** Proposed a VALID_CHAINID opcode that tells a contract whether a chain ID has ever been valid for the current chain, so signatures made before a chain-ID change keep working.

## What problem does it solve?

Off-chain signed messages, such as [EIP-712](/eip-712/) orders, meta-transactions and state-channel updates, include the chain ID so they cannot be replayed on another chain. A contract then needs to check that chain ID.

There are two naive options, and both break around a hard fork that changes the chain ID:

- **Hard-code the chain ID at deploy time:** after the fork, messages signed with the new ID are rejected.
- **Compare with the current chain ID** (the `CHAINID` opcode of [EIP-1344](/eip-1344/)): after the fork, every message signed *before* it is rejected. For a state channel that can mean funds become unreachable.

EIP-1959 argues that a message valid when signed should stay valid, so a contract should accept any chain ID from the chain's own history.

## How it works

- New opcode `VALID_CHAINID`, proposed at `0x46`.
- Takes one stack item: a 256-bit chain ID to test.
- Pushes `1` if that value has been a chain ID of this chain at any point since genesis (including the current one), else `0`.
- Gas cost: `G_blockhash`, with a note that it may need to rise as the history grows.

Wallets still sign with the latest chain ID, so two chains that split and both changed their IDs cannot replay each other's new messages. Messages signed before the split stay valid on both, the same way pre-fork state is shared.

The spec admits one gap. If a small minority forks off and the majority does *not* change its chain ID, the majority's new messages can be replayed on the minority fork. The author accepts this, assuming such forks gain little traction.

## Sample code

How a contract would use it, written as hypothetical Solidity (no compiler supports this opcode):

```solidity
// Hypothetical: VALID_CHAINID was never added to the EVM or to Solidity.
function execute(Message calldata m, bytes calldata sig) external {
    require(validChainId(m.chainId), "wrong chain"); // would compile to opcode VALID_CHAINID
    // ... verify EIP-712 signature over m, then act
}
```

EVM-level view:

```text
PUSH32 <chainId>   // value to test
VALID_CHAINID      // pops 1 item, pushes 1 if chainId is in this chain's history, else 0
```

What contracts actually do today, using EIP-1344:

```solidity
require(m.chainId == block.chainid, "wrong chain");
```

## Things to know

- **Status: Stagnant.** It was never adopted.
- Opcode `0x46` was later taken by `CHAINID` from [EIP-1344](/eip-1344/), activated in Istanbul. Any revival would need a different opcode number.
- The same author's [EIP-1965](/eip-1965/) is a related, also stagnant, variant that checks whether a chain ID was valid at a specific block number.
- In practice, contracts read `block.chainid` and, when a domain separator includes it, recompute the separator if the chain ID changes. Mainnet has not changed its chain ID, so the problem stayed largely theoretical.
- Builds on [EIP-155](/eip-155/), which introduced chain IDs for transaction replay protection.


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-1959
