{"eip":1959,"title":"New Opcode to check if a chainID is part of the history of chainIDs","description":"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.","authors":["Ronan Sandford (@wighawag)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2019-04-20","requires":[155],"discussionsTo":"https://ethereum-magicians.org/t/eip-1959-valid-chainid-opcode/3170","repo":"EIPs","label":"EIP-1959","officialUrl":"https://eips.ethereum.org/EIPS/eip-1959","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1959.md","url":"https://eips.huatuo.xyz/eip-1959/","tldr":{"en":"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.","ja":"あるチェーン ID が現在のチェーンで一度でも有効だったかをコントラクトに教える VALID_CHAINID オペコードを提案した。チェーン ID の変更前に作られた署名も使い続けられる。","ko":"어떤 체인 ID가 현재 체인에서 한 번이라도 유효했는지 컨트랙트에 알려 주는 VALID_CHAINID opcode를 제안했다. 체인 ID가 바뀌기 전에 만든 서명도 계속 쓸 수 있다.","zh":"提出了 VALID_CHAINID 操作码，用于告诉合约某个链 ID 是否曾经对当前链有效，使链 ID 变更之前生成的签名依然可用。"},"tags":["opcode","chain-id","replay-protection","signatures","evm"],"explainers":{"en":{"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"],"related":[155,1344,712,1965],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-1959/","markdown":"## What problem does it solve?\n\nOff-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.\n\nThere are two naive options, and both break around a hard fork that changes the chain ID:\n\n- **Hard-code the chain ID at deploy time:** after the fork, messages signed with the new ID are rejected.\n- **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.\n\nEIP-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.\n\n## How it works\n\n- New opcode `VALID_CHAINID`, proposed at `0x46`.\n- Takes one stack item: a 256-bit chain ID to test.\n- Pushes `1` if that value has been a chain ID of this chain at any point since genesis (including the current one), else `0`.\n- Gas cost: `G_blockhash`, with a note that it may need to rise as the history grows.\n\nWallets 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.\n\nThe 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.\n\n## Sample code\n\nHow a contract would use it, written as hypothetical Solidity (no compiler supports this opcode):\n\n```solidity\n// Hypothetical: VALID_CHAINID was never added to the EVM or to Solidity.\nfunction execute(Message calldata m, bytes calldata sig) external {\n    require(validChainId(m.chainId), \"wrong chain\"); // would compile to opcode VALID_CHAINID\n    // ... verify EIP-712 signature over m, then act\n}\n```\n\nEVM-level view:\n\n```text\nPUSH32 \u003cchainId\u003e   // value to test\nVALID_CHAINID      // pops 1 item, pushes 1 if chainId is in this chain's history, else 0\n```\n\nWhat contracts actually do today, using EIP-1344:\n\n```solidity\nrequire(m.chainId == block.chainid, \"wrong chain\");\n```\n\n## Things to know\n\n- **Status: Stagnant.** It was never adopted.\n- Opcode `0x46` was later taken by `CHAINID` from [EIP-1344](/eip-1344/), activated in Istanbul. Any revival would need a different opcode number.\n- 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.\n- 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.\n- Builds on [EIP-155](/eip-155/), which introduced chain IDs for transaction replay protection.\n"},"ja":{"lang":"ja","tldr":"あるチェーン ID が現在のチェーンで一度でも有効だったかをコントラクトに教える VALID_CHAINID オペコードを提案した。チェーン ID の変更前に作られた署名も使い続けられる。","tags":["opcode","chain-id","replay-protection","signatures","evm"],"related":[155,1344,712,1965],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-1959/","markdown":"## 何を解決するのか\n\n[EIP-712](/eip-712/) の注文、メタトランザクション、ステートチャネルの更新など、オフチェーンで署名されたメッセージには、別のチェーンでリプレイされないようにチェーン ID が含まれます。コントラクトは、そのチェーン ID を確認する必要があります。\n\n素朴な方法は 2 つありますが、どちらもチェーン ID を変更するハードフォークの前後で破綻します。\n\n- **デプロイ時にチェーン ID をハードコードする:** フォークの後、新しい ID で署名されたメッセージが拒否されます。\n- **現在のチェーン ID と比較する**（[EIP-1344](/eip-1344/) の `CHAINID` オペコード）: フォークの後、それ*以前*に署名されたメッセージはすべて拒否されます。ステートチャネルでは、資金に手が届かなくなる可能性があります。\n\nEIP-1959 は、署名された時点で有効だったメッセージは有効であり続けるべきだと主張し、コントラクトはそのチェーン自身の履歴にあるどのチェーン ID も受け入れるべきだとしています。\n\n## 仕組み\n\n- 新しいオペコード `VALID_CHAINID`。`0x46` が提案されました。\n- スタックから 1 項目、テスト対象の 256 ビットのチェーン ID を取ります。\n- その値が、ジェネシス以降のどの時点でも（現在のものを含め）このチェーンのチェーン ID であったなら `1` を、そうでなければ `0` をプッシュします。\n- ガスコスト: `G_blockhash`。履歴が増えるにつれて引き上げる必要があるかもしれないという注記があります。\n\nウォレットは引き続き最新のチェーン ID で署名するため、分岐して両方が ID を変更した 2 つのチェーンは、互いの新しいメッセージをリプレイできません。分岐前に署名されたメッセージは、フォーク前の状態が共有されるのと同じように、両方で有効なままです。\n\n仕様書は 1 つの穴を認めています。少数派がフォークして分かれ、多数派がチェーン ID を変更*しない*場合、多数派の新しいメッセージを少数派のフォークでリプレイできてしまいます。著者は、そのようなフォークはほとんど支持を得ないと想定して、これを受け入れています。\n\n## サンプルコード\n\nコントラクトでの使い方を、仮想的な Solidity として書いたもの（このオペコードをサポートするコンパイラはありません）:\n\n```solidity\n// Hypothetical: VALID_CHAINID was never added to the EVM or to Solidity.\nfunction execute(Message calldata m, bytes calldata sig) external {\n    require(validChainId(m.chainId), \"wrong chain\"); // would compile to opcode VALID_CHAINID\n    // ... verify EIP-712 signature over m, then act\n}\n```\n\nEVM レベルでの見え方:\n\n```text\nPUSH32 \u003cchainId\u003e   // value to test\nVALID_CHAINID      // pops 1 item, pushes 1 if chainId is in this chain's history, else 0\n```\n\n現在のコントラクトが実際にやっていること（EIP-1344 を使用）:\n\n```solidity\nrequire(m.chainId == block.chainid, \"wrong chain\");\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant。** 採用されたことはありません。\n- オペコード `0x46` は、のちに [EIP-1344](/eip-1344/) の `CHAINID` に使われ、Istanbul で有効化されました。復活させるなら、別のオペコード番号が必要になります。\n- 同じ著者の [EIP-1965](/eip-1965/) は、関連する、やはり Stagnant の亜種で、チェーン ID が特定のブロック番号の時点で有効だったかを確認します。\n- 実際には、コントラクトは `block.chainid` を読み取り、ドメインセパレーターにそれが含まれている場合は、チェーン ID が変わったらセパレーターを再計算します。メインネットはチェーン ID を変更していないため、この問題はほぼ理論上のものにとどまりました。\n- チェーン ID をトランザクションのリプレイ保護のために導入した [EIP-155](/eip-155/) を土台にしています。\n"},"ko":{"lang":"ko","tldr":"어떤 체인 ID가 현재 체인에서 한 번이라도 유효했는지 컨트랙트에 알려 주는 VALID_CHAINID opcode를 제안했다. 체인 ID가 바뀌기 전에 만든 서명도 계속 쓸 수 있다.","tags":["opcode","chain-id","replay-protection","signatures","evm"],"related":[155,1344,712,1965],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-1959/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-712](/eip-712/) 주문, 메타 트랜잭션, 스테이트 채널 업데이트처럼 오프체인에서 서명된 메시지에는 다른 체인에서 재사용(리플레이)되지 않도록 체인 ID가 들어 있습니다. 그러면 컨트랙트는 그 체인 ID를 확인해야 합니다.\n\n순진한 방법은 두 가지인데, 둘 다 체인 ID를 바꾸는 하드 포크를 전후로 깨집니다.\n\n- **배포할 때 체인 ID를 하드코딩:** 포크 이후 새 ID로 서명한 메시지가 거부됩니다.\n- **현재 체인 ID와 비교**([EIP-1344](/eip-1344/)의 `CHAINID` opcode): 포크 이후에는 그 *이전*에 서명한 모든 메시지가 거부됩니다. 스테이트 채널의 경우 자금에 접근할 수 없게 될 수 있습니다.\n\nEIP-1959는 서명 당시 유효했던 메시지는 계속 유효해야 하므로, 컨트랙트가 그 체인 자체의 역사에 있는 어떤 체인 ID든 받아들여야 한다고 주장합니다.\n\n## 어떻게 동작하나요?\n\n- 새 opcode `VALID_CHAINID`. `0x46`이 제안되었습니다.\n- 스택에서 항목 하나, 즉 테스트할 256비트 체인 ID를 받습니다.\n- 그 값이 제네시스 이후 어느 시점에든(현재 것을 포함해) 이 체인의 체인 ID였다면 `1`을, 아니면 `0`을 푸시합니다.\n- 가스 비용: `G_blockhash`. 역사가 늘어남에 따라 올려야 할 수도 있다는 메모가 있습니다.\n\n지갑은 여전히 최신 체인 ID로 서명하므로, 갈라져서 둘 다 ID를 바꾼 두 체인은 서로의 새 메시지를 리플레이할 수 없습니다. 갈라지기 전에 서명한 메시지는 포크 이전 상태가 공유되는 것과 마찬가지로 양쪽에서 계속 유효합니다.\n\n명세는 한 가지 빈틈을 인정합니다. 소수가 포크해 나가는데 다수가 체인 ID를 바꾸지 *않으면*, 다수의 새 메시지를 소수 포크에서 리플레이할 수 있습니다. 저자는 그런 포크는 지지를 거의 얻지 못할 것이라고 가정하고 이를 받아들입니다.\n\n## 샘플 코드\n\n컨트랙트가 이를 어떻게 쓸지를 가상의 Solidity로 쓴 것입니다(이 opcode를 지원하는 컴파일러는 없습니다).\n\n```solidity\n// Hypothetical: VALID_CHAINID was never added to the EVM or to Solidity.\nfunction execute(Message calldata m, bytes calldata sig) external {\n    require(validChainId(m.chainId), \"wrong chain\"); // would compile to opcode VALID_CHAINID\n    // ... verify EIP-712 signature over m, then act\n}\n```\n\nEVM 수준에서 본 모습:\n\n```text\nPUSH32 \u003cchainId\u003e   // value to test\nVALID_CHAINID      // pops 1 item, pushes 1 if chainId is in this chain's history, else 0\n```\n\n오늘날 컨트랙트가 실제로 하는 방식(EIP-1344 사용):\n\n```solidity\nrequire(m.chainId == block.chainid, \"wrong chain\");\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** 채택된 적이 없습니다.\n- opcode `0x46`은 이후 [EIP-1344](/eip-1344/)의 `CHAINID`가 차지했고 Istanbul에서 활성화되었습니다. 되살리려면 다른 opcode 번호가 필요합니다.\n- 같은 저자의 [EIP-1965](/eip-1965/)는 관련된, 역시 Stagnant 상태인 변형으로, 체인 ID가 특정 블록 번호에서 유효했는지를 확인합니다.\n- 실제로 컨트랙트는 `block.chainid`를 읽고, 도메인 구분자에 그것이 포함된 경우 체인 ID가 바뀌면 구분자를 다시 계산합니다. 메인넷은 체인 ID를 바꾼 적이 없으므로 이 문제는 대체로 이론에 머물렀습니다.\n- 트랜잭션 리플레이 방지를 위해 체인 ID를 도입한 [EIP-155](/eip-155/)를 기반으로 합니다.\n"},"zh":{"lang":"zh","tldr":"提出了 VALID_CHAINID 操作码，用于告诉合约某个链 ID 是否曾经对当前链有效，使链 ID 变更之前生成的签名依然可用。","tags":["opcode","chain-id","replay-protection","signatures","evm"],"related":[155,1344,712,1965],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-1959/","markdown":"## 它解决什么问题？\n\n链下签名的消息，例如 [EIP-712](/eip-712/) 订单、元交易和状态通道更新，都包含链 ID，以免被在另一条链上重放。合约随后需要检查这个链 ID。\n\n有两种朴素的做法，二者在更改链 ID 的硬分叉前后都会出问题：\n\n- **在部署时硬编码链 ID：** 分叉之后，用新 ID 签名的消息会被拒绝。\n- **与当前链 ID 比较**（[EIP-1344](/eip-1344/) 的 `CHAINID` 操作码）：分叉之后，*此前*签名的每条消息都会被拒绝。对状态通道来说，这可能意味着资金无法取出。\n\nEIP-1959 认为，签名时有效的消息应当一直有效，因此合约应当接受该链自身历史中的任何链 ID。\n\n## 它如何运作\n\n- 新操作码 `VALID_CHAINID`，提议的编号为 `0x46`。\n- 从栈中取一项：要测试的 256 位链 ID。\n- 如果该值自创世以来的任何时刻（包括当前）曾是这条链的链 ID，就压入 `1`，否则压入 `0`。\n- gas 成本：`G_blockhash`，并注明随着历史增长可能需要提高。\n\n钱包仍然使用最新的链 ID 签名，因此两条分裂且都更改了 ID 的链，无法互相重放对方的新消息。分裂之前签名的消息在两条链上都仍然有效，就像分叉前的状态是共享的一样。\n\n规范承认存在一个缺口。如果一小部分少数派分叉出去，而多数派*没有*更改链 ID，那么多数派的新消息就可以在少数派的分叉上被重放。作者接受这一点，假设这样的分叉难以获得支持。\n\n## 示例代码\n\n合约会如何使用它，以假想的 Solidity 写出（没有任何编译器支持这个操作码）：\n\n```solidity\n// Hypothetical: VALID_CHAINID was never added to the EVM or to Solidity.\nfunction execute(Message calldata m, bytes calldata sig) external {\n    require(validChainId(m.chainId), \"wrong chain\"); // would compile to opcode VALID_CHAINID\n    // ... verify EIP-712 signature over m, then act\n}\n```\n\nEVM 层面的视图：\n\n```text\nPUSH32 \u003cchainId\u003e   // value to test\nVALID_CHAINID      // pops 1 item, pushes 1 if chainId is in this chain's history, else 0\n```\n\n如今合约实际的做法，使用 EIP-1344：\n\n```solidity\nrequire(m.chainId == block.chainid, \"wrong chain\");\n```\n\n## 需要注意\n\n- **状态：Stagnant。** 它从未被采用。\n- 操作码 `0x46` 后来被 [EIP-1344](/eip-1344/) 的 `CHAINID` 占用，并在 Istanbul 中激活。任何复活该提案的尝试都需要使用不同的操作码编号。\n- 同一作者的 [EIP-1965](/eip-1965/) 是一个相关的、同样已停滞的变体，用于检查某个链 ID 在特定区块号时是否有效。\n- 实际上，合约读取 `block.chainid`，当域分隔符包含它时，如果链 ID 发生变化，就重新计算分隔符。主网没有更改过它的链 ID，因此这个问题基本上停留在理论层面。\n- 它建立在 [EIP-155](/eip-155/) 之上，后者为交易重放保护引入了链 ID。\n"}}}
