{"eip":191,"title":"Signed Data Standard","description":"This ERC proposes a specification about how to handle signed data in Ethereum contracts.","authors":["Martin Holst Swende (@holiman)","Nick Johnson \u003carachnid@notdot.net\u003e"],"status":"Final","type":"Standards Track","category":"ERC","created":"2016-01-20","discussionsTo":"https://github.com/ethereum/EIPs/issues/191","repo":"ERCs","label":"ERC-191","officialUrl":"https://eips.ethereum.org/EIPS/eip-191","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-191.md","url":"https://eips.huatuo.xyz/eip-191/","tldr":{"en":"Defines the 0x19-prefixed format for signed data, so an off-chain signature can never be mistaken for a transaction or replayed against the wrong contract; it underlies personal_sign and EIP-712.","ja":"署名データの 0x19 プレフィックス形式を定義し、オフチェーン署名がトランザクションと取り違えられたり、別のコントラクトに対してリプレイされたりしないようにする。personal_sign と EIP-712 の土台になっている。","ko":"서명 데이터의 0x19 접두사 형식을 정의해, 오프체인 서명이 트랜잭션으로 오인되거나 엉뚱한 컨트랙트에 재생되지 않도록 한다. personal_sign과 EIP-712의 기반이다.","zh":"定义以 0x19 为前缀的签名数据格式，使链下签名不会被误认为交易，也不会被重放到错误的合约上；它是 personal_sign 和 EIP-712 的基础。"},"tags":["signatures","signing","security","wallet","standard"],"explainers":{"en":{"lang":"en","tldr":"Defines the 0x19-prefixed format for signed data, so an off-chain signature can never be mistaken for a transaction or replayed against the wrong contract; it underlies personal_sign and EIP-712.","tags":["signatures","signing","security","wallet","standard"],"related":[712,1271,155,4361],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-191/","markdown":"## What problem does it solve?\n\nMultisig wallets and other contracts often accept **presigned** messages: some bytes plus a signature `(v, r, s)` that the contract checks with `ecrecover`. Early on, nobody defined what those bytes should contain, and this caused two problems:\n\n- **A signature could double as a transaction.** If the signed bytes happened to be a valid RLP-encoded Ethereum transaction, the message signature could be broadcast as a real transaction.\n- **A signature could be replayed on another contract.** If users A and B co-own multisig X and also multisig Y, a signature they gave X could be submitted to Y.\n\nEIP-191 fixes both with a fixed prefix and a version byte.\n\n## How it works\n\nEvery signed payload has this shape:\n\n```\n0x19 \u003c1-byte version\u003e \u003cversion-specific data\u003e \u003cdata to sign\u003e\n```\n\n`0x19` was picked because it **cannot start a valid RLP-encoded transaction**. In RLP, a single byte below `0x80` encodes itself, so the payload would read as a one-byte item followed by trailing data. No transaction is shaped like that.\n\nThe version byte says how to read the rest:\n\n| Version | Defined in | Meaning |\n| --- | --- | --- |\n| `0x00` | EIP-191 | Data with an intended validator. The next 20 bytes are the address of the contract that should accept it |\n| `0x01` | [EIP-712](/eip-712/) | Typed structured data |\n| `0x45` (`E`) | EIP-191 | `personal_sign` messages |\n\nVersion `0x45` explains the familiar string `\"\\x19Ethereum Signed Message:\\n\" + len(message)`. The `E` of \"Ethereum\" is the version byte, and `thereum Signed Message:\\n\u003clen\u003e` is the version-specific data. Wallets used this string before EIP-191 was written, and the standard adopted it.\n\n## Sample code\n\nVerifying a version `0x00` signature bound to this contract (Solidity):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Validator {\n    address public owner;\n    mapping(uint256 =\u003e bool) public used;\n\n    constructor(address _owner) { owner = _owner; }\n\n    function execute(uint256 nonce, bytes calldata payload, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 hash = keccak256(\n            abi.encodePacked(bytes1(0x19), bytes1(0x00), address(this), nonce, payload)\n        );\n        require(ecrecover(hash, v, r, s) == owner, \"bad sig\");\n        require(!used[nonce], \"replayed\");\n        used[nonce] = true;\n        // ... act on payload\n    }\n}\n```\n\nProducing that signature, plus an ordinary `0x45` message (ethers v6):\n\n```ts\nimport { Wallet, solidityPackedKeccak256, hashMessage, verifyMessage } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!);\n\n// Version 0x00: sign the raw digest, with no extra prefix\nconst digest = solidityPackedKeccak256(\n  [\"bytes1\", \"bytes1\", \"address\", \"uint256\", \"bytes\"],\n  [\"0x19\", \"0x00\", validatorAddress, 1n, \"0x1234\"],\n);\nconst sig00 = wallet.signingKey.sign(digest); // { r, s, v }\n\n// Version 0x45: signMessage adds \"\\x19Ethereum Signed Message:\\n\u003clen\u003e\"\nconst sig45 = await wallet.signMessage(\"hello\");\nconsole.log(hashMessage(\"hello\"));            // the digest actually signed\nconsole.log(verifyMessage(\"hello\", sig45));   // recovers wallet.address\n```\n\n## Things to know\n\n- EIP-191 does not prevent replay **within** the same contract. Add a nonce (as above) or a deadline. It also does not bind a signature to a chain. Include `block.chainid` if that matters, or use [EIP-712](/eip-712/), whose domain separator covers both.\n- Never sign a raw 32-byte hash that a dapp gives you without a prefix. Without the prefix, it might be a transaction hash or a digest for some other contract.\n- Smart-contract wallets validate these signatures through [ERC-1271](/eip-1271/), not `ecrecover`.\n- [ERC-4361](/eip-4361/) (Sign-In with Ethereum) uses `personal_sign` (`0x45`) messages.\n"},"ja":{"lang":"ja","tldr":"署名データの 0x19 プレフィックス形式を定義し、オフチェーン署名がトランザクションと取り違えられたり、別のコントラクトに対してリプレイされたりしないようにする。personal_sign と EIP-712 の土台になっている。","tags":["signatures","signing","security","wallet","standard"],"related":[712,1271,155,4361],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-191/","markdown":"## 何を解決するのか\n\nマルチシグウォレットなどのコントラクトは、**事前署名（presigned）**されたメッセージを受け付けることがよくあります。これは、ある任意のバイト列と署名 `(v, r, s)` の組で、コントラクトが `ecrecover` で検証します。初期にはそのバイト列に何を含めるべきか誰も定義しておらず、2 つの問題が起きました。\n\n- **署名がトランザクションとして使えてしまう。** 署名されたバイト列がたまたま有効な RLP エンコード済み Ethereum トランザクションだった場合、そのメッセージ署名を本物のトランザクションとしてブロードキャストできてしまいます。\n- **署名が別のコントラクトでリプレイされる。** ユーザー A と B がマルチシグ X を共同所有し、マルチシグ Y も共同所有している場合、X に渡した署名を Y に提出できてしまいます。\n\nEIP-191 は、固定のプレフィックスとバージョンバイトでこの 2 つを解決します。\n\n## 仕組み\n\n署名されるペイロードはすべて次の形をしています。\n\n```\n0x19 \u003c1-byte version\u003e \u003cversion-specific data\u003e \u003cdata to sign\u003e\n```\n\n`0x19` が選ばれたのは、**有効な RLP エンコード済みトランザクションの先頭にはなり得ない**からです。RLP では `0x80` 未満の単一バイトはそれ自身を表すため、このペイロードは 1 バイトの項目の後に余分なデータが続くものとして読まれます。そのような形のトランザクションは存在しません。\n\nバージョンバイトは、残りをどう読むかを示します。\n\n| バージョン | 定義場所 | 意味 |\n| --- | --- | --- |\n| `0x00` | EIP-191 | 意図された検証者を持つデータ。次の 20 バイトは、それを受け入れるべきコントラクトのアドレス |\n| `0x01` | [EIP-712](/eip-712/) | 型付き構造化データ |\n| `0x45`（`E`） | EIP-191 | `personal_sign` メッセージ |\n\nバージョン `0x45` は、おなじみの文字列 `\"\\x19Ethereum Signed Message:\\n\" + len(message)` を説明します。\"Ethereum\" の `E` がバージョンバイトで、`thereum Signed Message:\\n\u003clen\u003e` がバージョン固有データです。ウォレットは EIP-191 が書かれる前からこの文字列を使っており、標準がそれを取り込みました。\n\n## サンプルコード\n\nこのコントラクトに紐づくバージョン `0x00` の署名を検証する（Solidity）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Validator {\n    address public owner;\n    mapping(uint256 =\u003e bool) public used;\n\n    constructor(address _owner) { owner = _owner; }\n\n    function execute(uint256 nonce, bytes calldata payload, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 hash = keccak256(\n            abi.encodePacked(bytes1(0x19), bytes1(0x00), address(this), nonce, payload)\n        );\n        require(ecrecover(hash, v, r, s) == owner, \"bad sig\");\n        require(!used[nonce], \"replayed\");\n        used[nonce] = true;\n        // ... act on payload\n    }\n}\n```\n\nその署名の作成と、通常の `0x45` メッセージ（ethers v6）:\n\n```ts\nimport { Wallet, solidityPackedKeccak256, hashMessage, verifyMessage } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!);\n\n// Version 0x00: sign the raw digest, with no extra prefix\nconst digest = solidityPackedKeccak256(\n  [\"bytes1\", \"bytes1\", \"address\", \"uint256\", \"bytes\"],\n  [\"0x19\", \"0x00\", validatorAddress, 1n, \"0x1234\"],\n);\nconst sig00 = wallet.signingKey.sign(digest); // { r, s, v }\n\n// Version 0x45: signMessage adds \"\\x19Ethereum Signed Message:\\n\u003clen\u003e\"\nconst sig45 = await wallet.signMessage(\"hello\");\nconsole.log(hashMessage(\"hello\"));            // the digest actually signed\nconsole.log(verifyMessage(\"hello\", sig45));   // recovers wallet.address\n```\n\n## 知っておくべきこと\n\n- EIP-191 は、同じコントラクト**内**でのリプレイは防ぎません。nonce（上記のように）や期限を追加してください。また、署名をチェーンに紐づけることもしません。それが必要なら `block.chainid` を含めるか、ドメインセパレーターで両方をカバーする [EIP-712](/eip-712/) を使ってください。\n- dapp から渡された生の 32 バイトハッシュに、プレフィックスなしで署名してはいけません。プレフィックスがないと、それはトランザクションハッシュや別のコントラクト向けのダイジェストかもしれません。\n- スマートコントラクトウォレットは、`ecrecover` ではなく [ERC-1271](/eip-1271/) でこれらの署名を検証します。\n- [ERC-4361](/eip-4361/)（Sign-In with Ethereum）は `personal_sign`（`0x45`）メッセージを使います。\n"},"ko":{"lang":"ko","tldr":"서명 데이터의 0x19 접두사 형식을 정의해, 오프체인 서명이 트랜잭션으로 오인되거나 엉뚱한 컨트랙트에 재생되지 않도록 한다. personal_sign과 EIP-712의 기반이다.","tags":["signatures","signing","security","wallet","standard"],"related":[712,1271,155,4361],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-191/","markdown":"## 어떤 문제를 해결하나요?\n\n멀티시그 지갑 같은 컨트랙트는 **사전 서명(presigned)** 메시지를 받는 경우가 많습니다. 바이트열 하나와 서명 `(v, r, s)`를 컨트랙트가 `ecrecover`로 검증하는 방식입니다. 초기에는 이 바이트열에 무엇이 들어가야 하는지 아무도 정의하지 않았고, 그 때문에 두 가지 문제가 생겼습니다.\n\n- **서명이 트랜잭션으로도 쓰일 수 있었습니다.** 서명된 바이트가 우연히 유효한 RLP 인코딩 이더리움 트랜잭션이라면, 메시지 서명이 실제 트랜잭션으로 브로드캐스트될 수 있습니다.\n- **서명이 다른 컨트랙트에서 재생될 수 있었습니다.** 사용자 A와 B가 멀티시그 X를 공동 소유하고 멀티시그 Y도 공동 소유한다면, X에 준 서명을 Y에 제출할 수 있습니다.\n\nEIP-191은 고정된 접두사와 버전 바이트로 두 문제를 모두 해결합니다.\n\n## 어떻게 동작하나요?\n\n서명되는 모든 페이로드는 다음 형태입니다.\n\n```\n0x19 \u003c1-byte version\u003e \u003cversion-specific data\u003e \u003cdata to sign\u003e\n```\n\n`0x19`가 선택된 이유는 **유효한 RLP 인코딩 트랜잭션의 시작이 될 수 없기** 때문입니다. RLP에서 `0x80`보다 작은 단일 바이트는 자기 자신을 나타내므로, 이 페이로드는 한 바이트짜리 항목 뒤에 불필요한 데이터가 붙은 것으로 읽힙니다. 이런 모양의 트랜잭션은 없습니다.\n\n버전 바이트는 나머지를 어떻게 읽을지 알려줍니다.\n\n| 버전 | 정의된 곳 | 의미 |\n| --- | --- | --- |\n| `0x00` | EIP-191 | 의도된 검증자가 있는 데이터. 다음 20바이트는 이를 받아들여야 하는 컨트랙트의 주소 |\n| `0x01` | [EIP-712](/eip-712/) | 타입이 지정된 구조화 데이터 |\n| `0x45`(`E`) | EIP-191 | `personal_sign` 메시지 |\n\n버전 `0x45`는 익숙한 문자열 `\"\\x19Ethereum Signed Message:\\n\" + len(message)`를 설명해 줍니다. \"Ethereum\"의 `E`가 버전 바이트이고, `thereum Signed Message:\\n\u003clen\u003e`이 버전별 데이터입니다. 지갑들은 EIP-191이 작성되기 전부터 이 문자열을 썼고, 표준이 이를 채택했습니다.\n\n## 샘플 코드\n\n이 컨트랙트에 묶인 버전 `0x00` 서명 검증하기(Solidity):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Validator {\n    address public owner;\n    mapping(uint256 =\u003e bool) public used;\n\n    constructor(address _owner) { owner = _owner; }\n\n    function execute(uint256 nonce, bytes calldata payload, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 hash = keccak256(\n            abi.encodePacked(bytes1(0x19), bytes1(0x00), address(this), nonce, payload)\n        );\n        require(ecrecover(hash, v, r, s) == owner, \"bad sig\");\n        require(!used[nonce], \"replayed\");\n        used[nonce] = true;\n        // ... act on payload\n    }\n}\n```\n\n해당 서명을 만드는 방법과 일반적인 `0x45` 메시지(ethers v6):\n\n```ts\nimport { Wallet, solidityPackedKeccak256, hashMessage, verifyMessage } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!);\n\n// Version 0x00: sign the raw digest, with no extra prefix\nconst digest = solidityPackedKeccak256(\n  [\"bytes1\", \"bytes1\", \"address\", \"uint256\", \"bytes\"],\n  [\"0x19\", \"0x00\", validatorAddress, 1n, \"0x1234\"],\n);\nconst sig00 = wallet.signingKey.sign(digest); // { r, s, v }\n\n// Version 0x45: signMessage adds \"\\x19Ethereum Signed Message:\\n\u003clen\u003e\"\nconst sig45 = await wallet.signMessage(\"hello\");\nconsole.log(hashMessage(\"hello\"));            // the digest actually signed\nconsole.log(verifyMessage(\"hello\", sig45));   // recovers wallet.address\n```\n\n## 알아둘 점\n\n- EIP-191은 같은 컨트랙트 **안에서의** 재생은 막지 못합니다. (위처럼) nonce나 만료 시간을 추가하세요. 서명을 체인에 묶어 주지도 않습니다. 그것이 중요하다면 `block.chainid`를 포함하거나, 도메인 구분자가 둘 다 다루는 [EIP-712](/eip-712/)를 사용하세요.\n- dapp이 주는 32바이트 원시 해시에 접두사 없이 서명하지 마세요. 접두사가 없으면 트랜잭션 해시이거나 다른 컨트랙트용 다이제스트일 수 있습니다.\n- 스마트 컨트랙트 지갑은 `ecrecover`가 아니라 [ERC-1271](/eip-1271/)을 통해 이러한 서명을 검증합니다.\n- [ERC-4361](/eip-4361/)(Sign-In with Ethereum)은 `personal_sign`(`0x45`) 메시지를 사용합니다.\n"},"zh":{"lang":"zh","tldr":"定义以 0x19 为前缀的签名数据格式，使链下签名不会被误认为交易，也不会被重放到错误的合约上；它是 personal_sign 和 EIP-712 的基础。","tags":["signatures","signing","security","wallet","standard"],"related":[712,1271,155,4361],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-191/","markdown":"## 它解决什么问题？\n\n多签钱包等合约经常接受**预签名（presigned）**消息：一段字节加上一个签名 `(v, r, s)`，由合约用 `ecrecover` 校验。早期没有人规定这些字节应包含什么，由此引出两个问题：\n\n- **签名可能同时充当交易。** 如果被签名的字节恰好是一笔有效的、经 RLP 编码的以太坊交易，这个消息签名就可能被当作真实交易广播出去。\n- **签名可能被重放到另一个合约上。** 如果用户 A 和 B 共同拥有多签 X，同时也共同拥有多签 Y，那么他们给 X 的签名可以被提交给 Y。\n\nEIP-191 通过固定前缀和版本字节解决了这两个问题。\n\n## 它如何运作\n\n每个被签名的载荷都具有如下形状：\n\n```\n0x19 \u003c1-byte version\u003e \u003cversion-specific data\u003e \u003cdata to sign\u003e\n```\n\n选择 `0x19` 是因为它**不可能作为有效的、经 RLP 编码的交易的开头**。在 RLP 中，小于 `0x80` 的单个字节表示它自身，因此该载荷会被解读为一个单字节项后面跟着多余数据。没有任何交易是这种形状。\n\n版本字节说明如何解读其余部分：\n\n| 版本 | 定义于 | 含义 |\n| --- | --- | --- |\n| `0x00` | EIP-191 | 带有指定验证者的数据。接下来的 20 字节是应当接受它的合约地址 |\n| `0x01` | [EIP-712](/eip-712/) | 类型化结构数据 |\n| `0x45`（`E`） | EIP-191 | `personal_sign` 消息 |\n\n版本 `0x45` 解释了大家熟悉的字符串 `\"\\x19Ethereum Signed Message:\\n\" + len(message)`。“Ethereum”的 `E` 就是版本字节，`thereum Signed Message:\\n\u003clen\u003e` 是该版本特有的数据。钱包在 EIP-191 出现之前就在使用这个字符串，标准采纳了它。\n\n## 示例代码\n\n验证绑定到本合约的版本 `0x00` 签名（Solidity）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Validator {\n    address public owner;\n    mapping(uint256 =\u003e bool) public used;\n\n    constructor(address _owner) { owner = _owner; }\n\n    function execute(uint256 nonce, bytes calldata payload, uint8 v, bytes32 r, bytes32 s) external {\n        bytes32 hash = keccak256(\n            abi.encodePacked(bytes1(0x19), bytes1(0x00), address(this), nonce, payload)\n        );\n        require(ecrecover(hash, v, r, s) == owner, \"bad sig\");\n        require(!used[nonce], \"replayed\");\n        used[nonce] = true;\n        // ... act on payload\n    }\n}\n```\n\n生成该签名，以及一条普通的 `0x45` 消息（ethers v6）：\n\n```ts\nimport { Wallet, solidityPackedKeccak256, hashMessage, verifyMessage } from \"ethers\";\n\nconst wallet = new Wallet(process.env.PRIVATE_KEY!);\n\n// Version 0x00: sign the raw digest, with no extra prefix\nconst digest = solidityPackedKeccak256(\n  [\"bytes1\", \"bytes1\", \"address\", \"uint256\", \"bytes\"],\n  [\"0x19\", \"0x00\", validatorAddress, 1n, \"0x1234\"],\n);\nconst sig00 = wallet.signingKey.sign(digest); // { r, s, v }\n\n// Version 0x45: signMessage adds \"\\x19Ethereum Signed Message:\\n\u003clen\u003e\"\nconst sig45 = await wallet.signMessage(\"hello\");\nconsole.log(hashMessage(\"hello\"));            // the digest actually signed\nconsole.log(verifyMessage(\"hello\", sig45));   // recovers wallet.address\n```\n\n## 需要注意\n\n- EIP-191 不能防止在同一个合约**内部**的重放。请添加 nonce（如上所示）或截止时间。它也不会把签名绑定到某条链。如果这一点很重要，请包含 `block.chainid`，或使用域分隔符同时涵盖两者的 [EIP-712](/eip-712/)。\n- 不要对 dapp 给你的、没有前缀的原始 32 字节哈希签名。没有前缀的话，它可能是一个交易哈希，或某个其他合约的摘要。\n- 智能合约钱包通过 [ERC-1271](/eip-1271/) 而不是 `ecrecover` 来验证这些签名。\n- [ERC-4361](/eip-4361/)（Sign-In with Ethereum）使用 `personal_sign`（`0x45`）消息。\n"}},"requiredBy":[712,1077,1078,1484,3224,4361,5791,7405,7739,7749,7871,8126,8196]}
