{"eip":2098,"title":"Compact Signature Representation","description":"A compact representation of an Ethereum Signature.","authors":["Richard Moore (@ricmoo)","Nick Johnson \u003cnick@ethereum.org\u003e"],"status":"Final","type":"Standards Track","category":"ERC","created":"2019-03-14","requires":[2],"discussionsTo":"https://github.com/ethereum/EIPs/issues/2440","repo":"ERCs","label":"ERC-2098","officialUrl":"https://eips.ethereum.org/EIPS/eip-2098","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2098.md","url":"https://eips.huatuo.xyz/eip-2098/","tldr":{"en":"Packs an Ethereum signature into 64 bytes by storing the 1-bit yParity in the always-zero top bit of s, saving calldata and gas wherever signatures are passed around.","ja":"1 ビットの yParity を s の常に 0 である最上位ビットに格納することで、Ethereum の署名を 64 バイトにまとめ、署名をやり取りする場面での calldata とガスを節約する。","ko":"1비트짜리 yParity를 항상 0인 s의 최상위 비트에 저장해 이더리움 서명을 64바이트로 압축하고, 서명이 오가는 모든 곳에서 calldata와 가스를 절약한다.","zh":"把 yParity 这 1 个比特存放在 s 恒为零的最高位中，将以太坊签名打包成 64 字节，从而在所有传递签名的场景中节省 calldata 和 gas。"},"tags":["signature","ecdsa","secp256k1","gas","encoding"],"explainers":{"en":{"lang":"en","tldr":"Packs an Ethereum signature into 64 bytes by storing the 1-bit yParity in the always-zero top bit of s, saving calldata and gas wherever signatures are passed around.","tags":["signature","ecdsa","secp256k1","gas","encoding"],"related":[2,712,1271,2612],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2098/","markdown":"## What problem does it solve?\n\nA secp256k1 signature has three parts: `r` (32 bytes), `s` (32 bytes) and `v`/`yParity`, which only needs one bit but is usually sent as a whole byte (27 or 28). That makes 65 bytes, which awkwardly becomes 96 bytes when ABI-encoded into 32-byte words.\n\nContracts that accept signatures, such as meta-transactions, permits and multisigs, pay for every one of those bytes in calldata. ERC-2098 defines a 64-byte \"compact\" form that is exactly two words.\n\n## How it works\n\nTwo observations make the trick work:\n\n1. `yParity` is always 0 or 1 (27/28 are just a historical offset).\n2. Since Homestead ([EIP-2](/eip-2/)), canonical signatures use a \"low\" `s`, at most half the curve order, so the top bit of `s` is always 0.\n\nSo the parity bit is stored in that top bit:\n\n```\n[ 256-bit r ][ 1-bit yParity | 255-bit s ]   →   (r, yParityAndS), often called (r, vs)\n```\n\nDecoding is a mask and a shift: `s = vs \u0026 (2²⁵⁵ − 1)` and `yParity = vs \u003e\u003e 255`. Because the compact form is 64 bytes with two fields, it cannot be confused with the 65-byte three-field form.\n\n## Sample code\n\nRecovering a signer from a compact signature in Solidity:\n\n```solidity\nfunction recoverCompact(bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (address) {\n    bytes32 s = vs \u0026 bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n    uint8 v = uint8((uint256(vs) \u003e\u003e 255) + 27);\n    address signer = ecrecover(digest, v, r, s);\n    require(signer != address(0), \"bad signature\");\n    return signer;\n}\n```\n\nOpenZeppelin's `ECDSA` library offers the same as `ECDSA.recover(hash, r, vs)`.\n\nProducing one with ethers v6:\n\n```ts\nimport { Wallet, Signature } from \"ethers\";\n\nconst wallet = Wallet.createRandom();\nconst sigHex = await wallet.signMessage(\"Hello World\");    // 65 bytes\nconst sig = Signature.from(sigHex);\n\nconsole.log(sig.r, sig.yParityAndS);                       // the two 32-byte words\nconsole.log(sig.compactSerialized);                        // 64-byte hex string\n\n// Round-trip: Signature.from also accepts the 64-byte form\nconst back = Signature.from(sig.compactSerialized);\nconsole.log(back.v === sig.v \u0026\u0026 back.s === sig.s);         // true\n```\n\n## Things to know\n\n- **Status: Final.** It is an encoding convention, not a protocol change; contracts must explicitly accept `(r, vs)`.\n- It only works for low-`s` signatures. `ecrecover` itself also accepts high-`s` values, so normalize `s` (and flip `yParity`) before compacting a signature from an unknown source.\n- A contract that accepts both 65-byte and 64-byte forms must make sure the same signature cannot be replayed in both encodings where uniqueness matters; track used nonces rather than used signature bytes.\n- Pairs naturally with signed-message standards such as [EIP-712](/eip-712/) and [ERC-2612](/eip-2612/). Smart-contract signers ([ERC-1271](/eip-1271/)) do not use ECDSA, so the compact form does not apply to them.\n"},"ja":{"lang":"ja","tldr":"1 ビットの yParity を s の常に 0 である最上位ビットに格納することで、Ethereum の署名を 64 バイトにまとめ、署名をやり取りする場面での calldata とガスを節約する。","tags":["signature","ecdsa","secp256k1","gas","encoding"],"related":[2,712,1271,2612],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2098/","markdown":"## 何を解決するのか\n\nsecp256k1 の署名は 3 つの部分からなります。`r`（32 バイト）、`s`（32 バイト）、そして `v`/`yParity` です。`yParity` は 1 ビットで足りますが、通常は 1 バイト全体（27 または 28）で送られます。合計 65 バイトとなり、32 バイト単位のワードに ABI エンコードすると中途半端な 96 バイトになってしまいます。\n\n署名を受け取るコントラクト（メタトランザクション、permit、マルチシグなど）は、calldata のそのバイトすべてにコストを払います。ERC-2098 は、ちょうど 2 ワードに収まる 64 バイトの「コンパクト」形式を定義します。\n\n## 仕組み\n\nこのトリックは 2 つの観察に基づいています。\n\n1. `yParity` は常に 0 か 1 です（27/28 は歴史的なオフセットにすぎません）。\n2. Homestead（[EIP-2](/eip-2/)）以降、正規の署名では「低い」`s`（曲線の位数の半分以下）が使われるため、`s` の最上位ビットは常に 0 です。\n\nそこで、パリティビットをその最上位ビットに格納します。\n\n```\n[ 256-bit r ][ 1-bit yParity | 255-bit s ]   →   (r, yParityAndS), often called (r, vs)\n```\n\nデコードはマスクとシフトだけです。`s = vs \u0026 (2²⁵⁵ − 1)`、`yParity = vs \u003e\u003e 255`。コンパクト形式は 2 フィールドの 64 バイトなので、3 フィールドの 65 バイト形式と取り違えることはありません。\n\n## サンプルコード\n\nSolidity でコンパクト署名から署名者を復元する:\n\n```solidity\nfunction recoverCompact(bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (address) {\n    bytes32 s = vs \u0026 bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n    uint8 v = uint8((uint256(vs) \u003e\u003e 255) + 27);\n    address signer = ecrecover(digest, v, r, s);\n    require(signer != address(0), \"bad signature\");\n    return signer;\n}\n```\n\nOpenZeppelin の `ECDSA` ライブラリにも、同じ機能が `ECDSA.recover(hash, r, vs)` として用意されています。\n\nethers v6 でコンパクト署名を作る:\n\n```ts\nimport { Wallet, Signature } from \"ethers\";\n\nconst wallet = Wallet.createRandom();\nconst sigHex = await wallet.signMessage(\"Hello World\");    // 65 bytes\nconst sig = Signature.from(sigHex);\n\nconsole.log(sig.r, sig.yParityAndS);                       // the two 32-byte words\nconsole.log(sig.compactSerialized);                        // 64-byte hex string\n\n// Round-trip: Signature.from also accepts the 64-byte form\nconst back = Signature.from(sig.compactSerialized);\nconsole.log(back.v === sig.v \u0026\u0026 back.s === sig.s);         // true\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final。** これはエンコーディングの規約であってプロトコルの変更ではありません。コントラクト側が `(r, vs)` を明示的に受け付ける必要があります。\n- 低い `s` の署名にしか使えません。`ecrecover` 自体は高い `s` も受け付けるため、出所が不明な署名をコンパクト化する前には `s` を正規化（して `yParity` を反転）してください。\n- 65 バイト形式と 64 バイト形式の両方を受け付けるコントラクトは、一意性が重要な場面で、同じ署名が両方のエンコーディングでリプレイされないようにする必要があります。使用済みの署名バイト列ではなく、使用済みの nonce を記録してください。\n- [EIP-712](/eip-712/) や [ERC-2612](/eip-2612/) のような署名付きメッセージの標準とは自然に組み合わせられます。スマートコントラクトの署名者（[ERC-1271](/eip-1271/)）は ECDSA を使わないため、コンパクト形式は適用できません。\n"},"ko":{"lang":"ko","tldr":"1비트짜리 yParity를 항상 0인 s의 최상위 비트에 저장해 이더리움 서명을 64바이트로 압축하고, 서명이 오가는 모든 곳에서 calldata와 가스를 절약한다.","tags":["signature","ecdsa","secp256k1","gas","encoding"],"related":[2,712,1271,2612],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2098/","markdown":"## 어떤 문제를 해결하나요?\n\nsecp256k1 서명은 세 부분으로 이루어집니다. `r`(32바이트), `s`(32바이트), 그리고 `v`/`yParity`입니다. `yParity`는 1비트면 충분하지만 보통 1바이트 전체(27 또는 28)로 전송됩니다. 합쳐서 65바이트가 되고, 32바이트 워드로 ABI 인코딩하면 어정쩡하게 96바이트가 됩니다.\n\n서명을 받는 컨트랙트(메타 트랜잭션, permit, 멀티시그 등)는 calldata의 모든 바이트에 비용을 냅니다. ERC-2098은 정확히 두 워드인 64바이트 \"컴팩트\" 형식을 정의합니다.\n\n## 어떻게 동작하나요?\n\n이 방법은 두 가지 관찰에 기반합니다.\n\n1. `yParity`는 항상 0 또는 1입니다(27/28은 역사적인 오프셋일 뿐입니다).\n2. Homestead([EIP-2](/eip-2/)) 이후 정규 서명은 \"낮은\" `s`(곡선 위수의 절반 이하)를 사용하므로 `s`의 최상위 비트는 항상 0입니다.\n\n그래서 패리티 비트를 그 최상위 비트에 저장합니다.\n\n```\n[ 256-bit r ][ 1-bit yParity | 255-bit s ]   →   (r, yParityAndS), often called (r, vs)\n```\n\n디코딩은 마스크와 시프트면 됩니다. `s = vs \u0026 (2²⁵⁵ − 1)`, `yParity = vs \u003e\u003e 255`. 컴팩트 형식은 필드가 두 개인 64바이트이므로 필드가 세 개인 65바이트 형식과 혼동되지 않습니다.\n\n## 샘플 코드\n\nSolidity에서 컴팩트 서명으로 서명자 복구하기:\n\n```solidity\nfunction recoverCompact(bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (address) {\n    bytes32 s = vs \u0026 bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n    uint8 v = uint8((uint256(vs) \u003e\u003e 255) + 27);\n    address signer = ecrecover(digest, v, r, s);\n    require(signer != address(0), \"bad signature\");\n    return signer;\n}\n```\n\nOpenZeppelin의 `ECDSA` 라이브러리도 `ECDSA.recover(hash, r, vs)`로 같은 기능을 제공합니다.\n\nethers v6로 컴팩트 서명 만들기:\n\n```ts\nimport { Wallet, Signature } from \"ethers\";\n\nconst wallet = Wallet.createRandom();\nconst sigHex = await wallet.signMessage(\"Hello World\");    // 65 bytes\nconst sig = Signature.from(sigHex);\n\nconsole.log(sig.r, sig.yParityAndS);                       // the two 32-byte words\nconsole.log(sig.compactSerialized);                        // 64-byte hex string\n\n// Round-trip: Signature.from also accepts the 64-byte form\nconst back = Signature.from(sig.compactSerialized);\nconsole.log(back.v === sig.v \u0026\u0026 back.s === sig.s);         // true\n```\n\n## 알아둘 점\n\n- **상태: Final.** 인코딩 규약일 뿐 프로토콜 변경이 아닙니다. 컨트랙트가 `(r, vs)`를 명시적으로 받아들여야 합니다.\n- 낮은 `s` 서명에만 동작합니다. `ecrecover` 자체는 높은 `s` 값도 받아들이므로, 출처를 알 수 없는 서명을 컴팩트하게 만들기 전에 `s`를 정규화(하고 `yParity`를 반전)하세요.\n- 65바이트와 64바이트 형식을 모두 받는 컨트랙트는 유일성이 중요한 곳에서 같은 서명이 두 인코딩으로 재사용(replay)되지 않도록 해야 합니다. 사용된 서명 바이트가 아니라 사용된 nonce를 추적하세요.\n- [EIP-712](/eip-712/), [ERC-2612](/eip-2612/) 같은 서명 메시지 표준과 자연스럽게 어울립니다. 스마트 컨트랙트 서명자([ERC-1271](/eip-1271/))는 ECDSA를 쓰지 않으므로 컴팩트 형식이 적용되지 않습니다.\n"},"zh":{"lang":"zh","tldr":"把 yParity 这 1 个比特存放在 s 恒为零的最高位中，将以太坊签名打包成 64 字节，从而在所有传递签名的场景中节省 calldata 和 gas。","tags":["signature","ecdsa","secp256k1","gas","encoding"],"related":[2,712,1271,2612],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2098/","markdown":"## 它解决什么问题？\n\nsecp256k1 签名由三部分组成：`r`（32 字节）、`s`（32 字节）以及 `v`/`yParity`。`yParity` 只需要 1 个比特，但通常会以一个完整字节（27 或 28）发送。这样总共是 65 字节，按 32 字节字做 ABI 编码时会变成尴尬的 96 字节。\n\n接收签名的合约（例如元交易、permit 和多签）要为 calldata 中的每一个字节付费。ERC-2098 定义了一种 64 字节的\"紧凑\"格式，正好是两个字。\n\n## 它如何运作\n\n这个技巧依赖两点观察：\n\n1. `yParity` 始终是 0 或 1（27/28 只是历史遗留的偏移量）。\n2. 自 Homestead（[EIP-2](/eip-2/)）起，规范签名使用\"低位\"`s`，即不超过曲线阶的一半，因此 `s` 的最高位始终为 0。\n\n于是把奇偶位存放在这个最高位中：\n\n```\n[ 256-bit r ][ 1-bit yParity | 255-bit s ]   →   (r, yParityAndS), often called (r, vs)\n```\n\n解码只需一次掩码和一次移位：`s = vs \u0026 (2²⁵⁵ − 1)`，`yParity = vs \u003e\u003e 255`。由于紧凑格式是包含两个字段的 64 字节，不会与包含三个字段的 65 字节格式混淆。\n\n## 示例代码\n\n在 Solidity 中从紧凑签名恢复签名者：\n\n```solidity\nfunction recoverCompact(bytes32 digest, bytes32 r, bytes32 vs) internal pure returns (address) {\n    bytes32 s = vs \u0026 bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);\n    uint8 v = uint8((uint256(vs) \u003e\u003e 255) + 27);\n    address signer = ecrecover(digest, v, r, s);\n    require(signer != address(0), \"bad signature\");\n    return signer;\n}\n```\n\nOpenZeppelin 的 `ECDSA` 库以 `ECDSA.recover(hash, r, vs)` 提供了同样的功能。\n\n用 ethers v6 生成一个紧凑签名：\n\n```ts\nimport { Wallet, Signature } from \"ethers\";\n\nconst wallet = Wallet.createRandom();\nconst sigHex = await wallet.signMessage(\"Hello World\");    // 65 bytes\nconst sig = Signature.from(sigHex);\n\nconsole.log(sig.r, sig.yParityAndS);                       // the two 32-byte words\nconsole.log(sig.compactSerialized);                        // 64-byte hex string\n\n// Round-trip: Signature.from also accepts the 64-byte form\nconst back = Signature.from(sig.compactSerialized);\nconsole.log(back.v === sig.v \u0026\u0026 back.s === sig.s);         // true\n```\n\n## 需要注意\n\n- **状态：Final。** 它是一种编码约定，而不是协议变更；合约必须显式接受 `(r, vs)`。\n- 它只适用于低位 `s` 的签名。`ecrecover` 本身也接受高位 `s`，因此在压缩来源不明的签名之前，请先规范化 `s`（并翻转 `yParity`）。\n- 同时接受 65 字节和 64 字节两种格式的合约，必须确保在需要唯一性的场合，同一个签名不能以两种编码被重放；请记录已使用的 nonce，而不是已使用的签名字节。\n- 它与 [EIP-712](/eip-712/) 和 [ERC-2612](/eip-2612/) 等签名消息标准天然契合。智能合约签名者（[ERC-1271](/eip-1271/)）不使用 ECDSA，因此紧凑格式不适用于它们。\n"}},"requiredBy":[7604,8001]}
