{"eip":5732,"title":"Commit Interface","description":"A simple but general commit interface to support commit-reveal scheme.","authors":["Zainan Victor Zhou (@xinbenlv)","Matt Stam (@mattstam)"],"status":"Final","type":"Standards Track","category":"ERC","created":"2022-09-29","requires":[165,1271],"discussionsTo":"https://ethereum-magicians.org/t/erc-5732-simple-commit-interface-to-support-commit-reveal-schemes/11115","repo":"ERCs","label":"ERC-5732","officialUrl":"https://eips.ethereum.org/EIPS/eip-5732","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-5732.md","url":"https://eips.huatuo.xyz/eip-5732/","tldr":{"en":"A minimal commit interface for commit-reveal schemes: contracts standardize only `commit`, and reveal through any method they like, which helps with private voting and resisting front-running.","ja":"commit-reveal 方式のための最小限の commit インターフェース。コントラクトが標準化するのは `commit` だけで、reveal は好きなメソッドで行う。プライベート投票やフロントランニング対策に役立つ。","ko":"commit-reveal 방식을 위한 최소 commit 인터페이스. 컨트랙트는 `commit`만 표준화하고 reveal은 원하는 메서드로 하며, 비공개 투표와 프런트러닝 방어에 도움이 된다.","zh":"用于 commit-reveal 方案的最小 commit 接口：合约只标准化 `commit`，揭示则通过任何它们喜欢的方法完成，有助于私密投票和抵御抢跑。"},"tags":["commit-reveal","front-running","voting","privacy","interface"],"explainers":{"en":{"lang":"en","tldr":"A minimal commit interface for commit-reveal schemes: contracts standardize only `commit`, and reveal through any method they like, which helps with private voting and resisting front-running.","tags":["commit-reveal","front-running","voting","privacy","interface"],"related":[1271,712,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5732/","markdown":"## What problem does it solve?\n\nEverything you send to Ethereum is public before it is executed. If you submit a vote, a bid, or a domain name you want to register, others can see it in the mempool and react: copy it, front-run it, or change their own vote.\n\nThe classic fix is **commit-reveal**. First you publish only a hash of your action plus a secret salt (the commitment). Later you publish the action and the salt, and the contract checks they match the hash. ENS registration has used this for years. ERC-5732 standardizes the commit half, so wallets and tools can support commitments in the same way across many applications.\n\n## How it works\n\nThe standard deliberately defines **only a commit method, no reveal method**. Revealing is left to the application, so it can be a `vote`, `transfer`, `register` or anything else that carries the salt.\n\nTwo interfaces:\n\n- `IERC_COMMIT_CORE` (required, ERC-165 id `0xf14fcbc8`): `commit(bytes32 commitment) payable`. This single-argument form matches what ENS already used.\n- `IERC_COMMIT_GENERAL` (recommended, id `0x67b2ec2c`): `commitFrom(address from, bytes32 commitment, bytes extraData) payable returns (uint256 timePoint)` and a `Commit(timePoint, from, commitment, extraData)` event.\n\nRules worth knowing:\n\n- If a contract implements the general interface, `commit(c)` must behave like `commitFrom(msg.sender, c, \"\")`.\n- `timePoint` orders commitments: a later commitment always has a value greater than or equal to an earlier one. `block.timestamp` or `block.number` are suggested.\n- `commitFrom` lets a relayer submit a commitment on someone else's behalf. When `from` is not the transaction sender, the contract should verify a signature from `from` ([ERC-1271](/eip-1271/) for smart-contract wallets).\n- The reveal must have some way to pass the secret salt. Its size and position are left open.\n\n## Sample code\n\nA sealed-vote contract that uses `commit` and reveals through `vote`:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SealedVote {\n    event Commit(uint256 indexed timePoint, address indexed from, bytes32 indexed commitment, bytes extraData);\n\n    mapping(address =\u003e bytes32) public commitments;\n    mapping(uint8 =\u003e uint256) public tally;\n\n    function commit(bytes32 commitment) external payable {\n        commitments[msg.sender] = commitment;\n        emit Commit(block.number, msg.sender, commitment, \"\");\n    }\n\n    // Reveal: the hash must match what was committed earlier.\n    function vote(uint8 option, bytes32 salt) external {\n        bytes32 c = keccak256(abi.encode(block.chainid, address(this), msg.sender, option, salt));\n        require(c != bytes32(0) \u0026\u0026 commitments[msg.sender] == c, \"bad reveal\");\n        delete commitments[msg.sender]; // prevent replay\n        tally[option] += 1;\n    }\n}\n```\n\nBuilding the commitment off-chain (ethers v6):\n\n```ts\nimport { AbiCoder, keccak256, hexlify, randomBytes } from \"ethers\";\n\nconst salt = hexlify(randomBytes(32)); // keep secret until reveal\nconst commitment = keccak256(\n  AbiCoder.defaultAbiCoder().encode(\n    [\"uint256\", \"address\", \"address\", \"uint8\", \"bytes32\"],\n    [chainId, contractAddress, voterAddress, 2, salt],\n  ),\n);\nawait sealedVote.commit(commitment);\n```\n\n## Things to know\n\n- **Status: Final.**\n- The salt must be long, random and never reused. Anyone who learns it before the reveal can recover the hidden action.\n- Include the chain id (and ideally the contract address) in the commitment to avoid replay across chains or forks. The spec suggests [EIP-712](/eip-712/) style structured hashing for higher-risk cases.\n- Two commits in the same block can share the same `block.number` or `block.timestamp`. If you need strictly increasing time points, keep your own counter.\n- Leave enough time between commit and reveal; commit-reveal only helps against front-running if the reveal cannot happen in the same moment as the commit.\n"},"ja":{"lang":"ja","tldr":"commit-reveal 方式のための最小限の commit インターフェース。コントラクトが標準化するのは `commit` だけで、reveal は好きなメソッドで行う。プライベート投票やフロントランニング対策に役立つ。","tags":["commit-reveal","front-running","voting","privacy","interface"],"related":[1271,712,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5732/","markdown":"## 何を解決するのか\n\nEthereum に送るものはすべて、実行される前に公開されます。投票、入札、登録したいドメイン名を送信すると、他の人が mempool でそれを見て反応できます。コピーしたり、フロントランしたり、自分の投票を変えたりできます。\n\n古典的な解決策は **commit-reveal** です。まず、行動とシークレットソルトのハッシュだけを公開します（コミットメント）。後で行動とソルトを公開し、コントラクトがそれらがハッシュと一致することを確認します。ENS の登録は何年も前からこれを使っています。ERC-5732 は commit の半分を標準化し、ウォレットやツールが多くのアプリケーションで同じようにコミットメントをサポートできるようにします。\n\n## 仕組み\n\nこの標準は意図的に **commit メソッドだけを定義し、reveal メソッドは定義しません**。reveal はアプリケーションに委ねられるため、`vote`、`transfer`、`register`、あるいはソルトを運べる他の何であってもかまいません。\n\n2 つのインターフェース:\n\n- `IERC_COMMIT_CORE`（必須、ERC-165 ID `0xf14fcbc8`）: `commit(bytes32 commitment) payable`。この単一引数の形式は ENS が既に使っていたものに合わせています。\n- `IERC_COMMIT_GENERAL`（推奨、ID `0x67b2ec2c`）: `commitFrom(address from, bytes32 commitment, bytes extraData) payable returns (uint256 timePoint)` と、`Commit(timePoint, from, commitment, extraData)` イベント。\n\n知っておくべきルール:\n\n- コントラクトが general インターフェースを実装する場合、`commit(c)` は `commitFrom(msg.sender, c, \"\")` と同じ動作をしなければなりません。\n- `timePoint` はコミットメントの順序を表します。後のコミットメントは常に、先のものより大きいか等しい値を持ちます。`block.timestamp` または `block.number` が推奨されています。\n- `commitFrom` により、リレイヤーが他人に代わってコミットメントを送信できます。`from` がトランザクションの送信者でない場合、コントラクトは `from` の署名を検証すべきです（スマートコントラクトウォレットなら [ERC-1271](/eip-1271/)）。\n- reveal には、シークレットソルトを渡す何らかの方法が必要です。そのサイズと位置は定められていません。\n\n## サンプルコード\n\n`commit` を使い、`vote` で reveal する封印投票コントラクト:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SealedVote {\n    event Commit(uint256 indexed timePoint, address indexed from, bytes32 indexed commitment, bytes extraData);\n\n    mapping(address =\u003e bytes32) public commitments;\n    mapping(uint8 =\u003e uint256) public tally;\n\n    function commit(bytes32 commitment) external payable {\n        commitments[msg.sender] = commitment;\n        emit Commit(block.number, msg.sender, commitment, \"\");\n    }\n\n    // Reveal: the hash must match what was committed earlier.\n    function vote(uint8 option, bytes32 salt) external {\n        bytes32 c = keccak256(abi.encode(block.chainid, address(this), msg.sender, option, salt));\n        require(c != bytes32(0) \u0026\u0026 commitments[msg.sender] == c, \"bad reveal\");\n        delete commitments[msg.sender]; // prevent replay\n        tally[option] += 1;\n    }\n}\n```\n\nオフチェーンでコミットメントを作る（ethers v6）:\n\n```ts\nimport { AbiCoder, keccak256, hexlify, randomBytes } from \"ethers\";\n\nconst salt = hexlify(randomBytes(32)); // keep secret until reveal\nconst commitment = keccak256(\n  AbiCoder.defaultAbiCoder().encode(\n    [\"uint256\", \"address\", \"address\", \"uint8\", \"bytes32\"],\n    [chainId, contractAddress, voterAddress, 2, salt],\n  ),\n);\nawait sealedVote.commit(commitment);\n```\n\n## 知っておくべきこと\n\n- **ステータス: Final。**\n- ソルトは長く、ランダムで、再利用してはなりません。reveal の前にそれを知った人は誰でも、隠された行動を復元できます。\n- チェーン間やフォーク間のリプレイを避けるため、コミットメントにチェーン ID（できればコントラクトアドレスも）を含めてください。仕様は、よりリスクの高い場合には [EIP-712](/eip-712/) 形式の構造化ハッシュを推奨しています。\n- 同じブロック内の 2 つのコミットは、同じ `block.number` や `block.timestamp` を共有することがあります。厳密に増加する time point が必要なら、独自のカウンターを持ってください。\n- commit と reveal の間には十分な時間を空けてください。reveal を commit と同じタイミングで行えない場合にのみ、commit-reveal はフロントランニングへの対策になります。\n"},"ko":{"lang":"ko","tldr":"commit-reveal 방식을 위한 최소 commit 인터페이스. 컨트랙트는 `commit`만 표준화하고 reveal은 원하는 메서드로 하며, 비공개 투표와 프런트러닝 방어에 도움이 된다.","tags":["commit-reveal","front-running","voting","privacy","interface"],"related":[1271,712,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5732/","markdown":"## 어떤 문제를 해결하나요?\n\n이더리움에 보내는 모든 것은 실행되기 전에 공개됩니다. 투표, 입찰, 등록하려는 도메인 이름을 제출하면 다른 사람들이 mempool에서 이를 보고 반응할 수 있습니다. 복사하거나, 프런트러닝하거나, 자신의 투표를 바꿀 수 있습니다.\n\n고전적인 해결책은 **commit-reveal**입니다. 먼저 행동과 비밀 salt의 해시(커밋먼트)만 공개합니다. 나중에 행동과 salt를 공개하면 컨트랙트가 그것들이 해시와 일치하는지 확인합니다. ENS 등록은 오래전부터 이를 사용해 왔습니다. ERC-5732는 commit 절반을 표준화하여, 지갑과 도구가 여러 애플리케이션에서 같은 방식으로 커밋먼트를 지원할 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n이 표준은 의도적으로 **commit 메서드만 정의하고 reveal 메서드는 정의하지 않습니다**. reveal은 애플리케이션에 맡겨지므로 `vote`, `transfer`, `register` 또는 salt를 실을 수 있는 다른 무엇이든 될 수 있습니다.\n\n인터페이스 두 개:\n\n- `IERC_COMMIT_CORE`(필수, ERC-165 id `0xf14fcbc8`): `commit(bytes32 commitment) payable`. 이 단일 인자 형태는 ENS가 이미 쓰던 것과 맞춘 것입니다.\n- `IERC_COMMIT_GENERAL`(권장, id `0x67b2ec2c`): `commitFrom(address from, bytes32 commitment, bytes extraData) payable returns (uint256 timePoint)`와 `Commit(timePoint, from, commitment, extraData)` 이벤트.\n\n알아둘 만한 규칙:\n\n- 컨트랙트가 general 인터페이스를 구현한다면 `commit(c)`는 `commitFrom(msg.sender, c, \"\")`처럼 동작해야 합니다.\n- `timePoint`는 커밋먼트의 순서를 정합니다. 나중 커밋먼트는 항상 이전 것보다 크거나 같은 값을 가집니다. `block.timestamp` 또는 `block.number`를 권장합니다.\n- `commitFrom`을 쓰면 릴레이어가 다른 사람을 대신해 커밋먼트를 제출할 수 있습니다. `from`이 트랜잭션 전송자가 아니라면 컨트랙트는 `from`의 서명을 검증해야 합니다(스마트 컨트랙트 지갑은 [ERC-1271](/eip-1271/)).\n- reveal에는 비밀 salt를 전달할 방법이 있어야 합니다. 그 크기와 위치는 정해져 있지 않습니다.\n\n## 샘플 코드\n\n`commit`을 사용하고 `vote`로 reveal하는 봉인 투표 컨트랙트:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SealedVote {\n    event Commit(uint256 indexed timePoint, address indexed from, bytes32 indexed commitment, bytes extraData);\n\n    mapping(address =\u003e bytes32) public commitments;\n    mapping(uint8 =\u003e uint256) public tally;\n\n    function commit(bytes32 commitment) external payable {\n        commitments[msg.sender] = commitment;\n        emit Commit(block.number, msg.sender, commitment, \"\");\n    }\n\n    // Reveal: the hash must match what was committed earlier.\n    function vote(uint8 option, bytes32 salt) external {\n        bytes32 c = keccak256(abi.encode(block.chainid, address(this), msg.sender, option, salt));\n        require(c != bytes32(0) \u0026\u0026 commitments[msg.sender] == c, \"bad reveal\");\n        delete commitments[msg.sender]; // prevent replay\n        tally[option] += 1;\n    }\n}\n```\n\n오프체인에서 커밋먼트 만들기(ethers v6):\n\n```ts\nimport { AbiCoder, keccak256, hexlify, randomBytes } from \"ethers\";\n\nconst salt = hexlify(randomBytes(32)); // keep secret until reveal\nconst commitment = keccak256(\n  AbiCoder.defaultAbiCoder().encode(\n    [\"uint256\", \"address\", \"address\", \"uint8\", \"bytes32\"],\n    [chainId, contractAddress, voterAddress, 2, salt],\n  ),\n);\nawait sealedVote.commit(commitment);\n```\n\n## 알아둘 점\n\n- **상태: Final.**\n- salt는 길고 무작위여야 하며 절대 재사용하면 안 됩니다. reveal 전에 이를 알게 된 사람은 누구든 숨겨진 행동을 복원할 수 있습니다.\n- 체인이나 포크 간 리플레이를 막기 위해 커밋먼트에 체인 id(가능하면 컨트랙트 주소도)를 포함하세요. 위험도가 높은 경우 사양은 [EIP-712](/eip-712/) 스타일의 구조화된 해싱을 권합니다.\n- 같은 블록의 커밋 두 개는 같은 `block.number`나 `block.timestamp`를 가질 수 있습니다. 엄격하게 증가하는 time point가 필요하다면 자체 카운터를 유지하세요.\n- commit과 reveal 사이에 충분한 시간을 두세요. commit-reveal은 reveal이 commit과 같은 순간에 일어날 수 없을 때만 프런트러닝에 도움이 됩니다.\n"},"zh":{"lang":"zh","tldr":"用于 commit-reveal 方案的最小 commit 接口：合约只标准化 `commit`，揭示则通过任何它们喜欢的方法完成，有助于私密投票和抵御抢跑。","tags":["commit-reveal","front-running","voting","privacy","interface"],"related":[1271,712,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5732/","markdown":"## 它解决什么问题？\n\n你发送到以太坊的一切在被执行之前都是公开的。如果你提交投票、出价或想注册的域名，其他人可以在 mempool 中看到并作出反应：复制它、抢跑，或改变自己的投票。\n\n经典的解决办法是 **commit-reveal**。首先，你只公布你的操作加上一个秘密盐值的哈希（承诺）。之后，你公布操作和盐值，合约检查它们是否与哈希匹配。ENS 注册多年来一直使用这种方式。ERC-5732 标准化了 commit 这一半，让钱包和工具可以在许多应用中以相同方式支持承诺。\n\n## 它如何运作\n\n该标准有意**只定义 commit 方法，不定义 reveal 方法**。揭示留给应用自行实现，因此它可以是 `vote`、`transfer`、`register`，或任何其他携带盐值的方法。\n\n两个接口：\n\n- `IERC_COMMIT_CORE`（必需，ERC-165 id `0xf14fcbc8`）：`commit(bytes32 commitment) payable`。这种单参数形式与 ENS 已有的用法一致。\n- `IERC_COMMIT_GENERAL`（推荐，id `0x67b2ec2c`）：`commitFrom(address from, bytes32 commitment, bytes extraData) payable returns (uint256 timePoint)` 以及 `Commit(timePoint, from, commitment, extraData)` 事件。\n\n值得了解的规则：\n\n- 如果合约实现了 general 接口，`commit(c)` 的行为必须与 `commitFrom(msg.sender, c, \"\")` 相同。\n- `timePoint` 用于给承诺排序：较晚的承诺其值总是大于或等于较早的承诺。建议使用 `block.timestamp` 或 `block.number`。\n- `commitFrom` 允许中继者代表他人提交承诺。当 `from` 不是交易发送者时，合约应当验证来自 `from` 的签名（智能合约钱包使用 [ERC-1271](/eip-1271/)）。\n- 揭示必须有某种方式传递秘密盐值。其大小和位置不作规定。\n\n## 示例代码\n\n一个使用 `commit` 并通过 `vote` 揭示的密封投票合约：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract SealedVote {\n    event Commit(uint256 indexed timePoint, address indexed from, bytes32 indexed commitment, bytes extraData);\n\n    mapping(address =\u003e bytes32) public commitments;\n    mapping(uint8 =\u003e uint256) public tally;\n\n    function commit(bytes32 commitment) external payable {\n        commitments[msg.sender] = commitment;\n        emit Commit(block.number, msg.sender, commitment, \"\");\n    }\n\n    // Reveal: the hash must match what was committed earlier.\n    function vote(uint8 option, bytes32 salt) external {\n        bytes32 c = keccak256(abi.encode(block.chainid, address(this), msg.sender, option, salt));\n        require(c != bytes32(0) \u0026\u0026 commitments[msg.sender] == c, \"bad reveal\");\n        delete commitments[msg.sender]; // prevent replay\n        tally[option] += 1;\n    }\n}\n```\n\n在链下构造承诺（ethers v6）：\n\n```ts\nimport { AbiCoder, keccak256, hexlify, randomBytes } from \"ethers\";\n\nconst salt = hexlify(randomBytes(32)); // keep secret until reveal\nconst commitment = keccak256(\n  AbiCoder.defaultAbiCoder().encode(\n    [\"uint256\", \"address\", \"address\", \"uint8\", \"bytes32\"],\n    [chainId, contractAddress, voterAddress, 2, salt],\n  ),\n);\nawait sealedVote.commit(commitment);\n```\n\n## 需要注意\n\n- **状态：Final。**\n- 盐值必须足够长、随机，并且绝不重复使用。任何在揭示前得知它的人都可以还原被隐藏的操作。\n- 请在承诺中包含链 id（最好还有合约地址），以避免跨链或跨分叉的重放。对于风险较高的场景，规范建议使用 [EIP-712](/eip-712/) 风格的结构化哈希。\n- 同一区块内的两次 commit 可能具有相同的 `block.number` 或 `block.timestamp`。如果需要严格递增的时间点，请自行维护计数器。\n- 在 commit 与 reveal 之间留出足够的时间；只有当揭示不可能与承诺同时发生时，commit-reveal 才能抵御抢跑。\n"}}}
