{"eip":7705,"title":"NONREENTRANT and REENTRANT opcodes","description":"Opcodes to mark a contract as nonreentrant","authors":["Charles Cooper (@charles-cooper)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2024-05-09","discussionsTo":"https://ethereum-magicians.org/t/eip-7705-nonreentrant-opcodes/19957","repo":"EIPs","label":"EIP-7705","officialUrl":"https://eips.ethereum.org/EIPS/eip-7705","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-7705.md","url":"https://eips.huatuo.xyz/eip-7705/","tldr":{"en":"Proposes two opcodes, NONREENTRANT and REENTRANT, that let a contract cheaply lock itself against incoming calls for the rest of a transaction.","ja":"NONREENTRANT と REENTRANT の 2 つの opcode を提案する。コントラクトが、トランザクションの残りの間、自分自身への呼び出しを低コストでロックできるようにする。","ko":"NONREENTRANT와 REENTRANT 두 개의 opcode를 제안한다. 컨트랙트가 트랜잭션의 나머지 동안 들어오는 호출을 저렴하게 스스로 잠글 수 있게 한다.","zh":"提议新增 NONREENTRANT 和 REENTRANT 两个 opcode，让合约能以很低的成本在交易剩余期间锁定自身，拒绝传入的调用。"},"tags":["evm","opcode","security","reentrancy","core"],"explainers":{"en":{"lang":"en","tldr":"Proposes two opcodes, NONREENTRANT and REENTRANT, that let a contract cheaply lock itself against incoming calls for the rest of a transaction.","tags":["evm","opcode","security","reentrancy","core"],"related":[1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-7705/","markdown":"## What problem does it solve?\n\nReentrancy, where a contract calls out and the callee calls back in before the first call finishes, is behind a large share of stolen funds on EVM chains, including the 2016 DAO hack. The usual defence is a reentrancy guard: write a \"locked\" flag to storage on entry and clear it on exit.\n\nThat costs gas on every protected function. Transient storage ([EIP-1153](/eip-1153/)) made guards cheaper, but the author argues it is still not cheap enough for developers to use it everywhere by default. EIP-7705 proposes to make the guard a native EVM feature.\n\n## How it works\n\nTwo opcodes are added:\n\n| Opcode | Byte | Gas | Effect |\n| --- | --- | --- | --- |\n| `NONREENTRANT` | `0xF6` | 5 | Set the current contract's nonreentrancy flag |\n| `REENTRANT` | `0xF7` | 5 | Clear the flag |\n\nWhile the flag is set, any `CALL`, `STATICCALL` or `DELEGATECALL` into that contract behaves as if the callee executed a single `REVERT`.\n\nRules:\n\n- Both opcodes are idempotent (setting an already-set flag is a no-op).\n- The flag lives only for the current transaction and is cleared at the end of it.\n- If a call frame reverts or halts exceptionally, the flag rolls back to its value before that call, just like other state.\n\nThe spec mentions an alternative single-opcode design, a `NONREENTRANT` that takes a stack value to set or clear the flag, open for feedback.\n\n## Sample code\n\nToday's guard with transient storage, which the opcodes would replace:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Vault {\n    modifier nonReentrant() {\n        assembly {\n            if tload(0) { revert(0, 0) }\n            tstore(0, 1)\n        }\n        _;\n        assembly { tstore(0, 0) }\n    }\n\n    function withdraw(uint256 amount) external nonReentrant {\n        // ... update balances, then send ETH\n    }\n}\n```\n\nWhat it would look like with EIP-7705, in pseudo-assembly (no compiler supports these opcodes):\n\n```text\nNONREENTRANT        ; 0xF6 - any call back into this contract now reverts\n...                 ; checks, effects, external call\nREENTRANT           ; 0xF7 - allow calls again\n```\n\n## Things to know\n\n- **Status: Stagnant.** It has not been scheduled for any network upgrade, and its test cases, reference implementation and security considerations sections are empty.\n- Note the semantics: the lock applies to the whole contract, not to a single function, and blocks *all* incoming calls, including view-style `STATICCALL`s, while set.\n- Until something like this ships, use a well-reviewed guard (for example OpenZeppelin's `ReentrancyGuard` or its transient variant) and follow checks-effects-interactions.\n"},"ja":{"lang":"ja","tldr":"NONREENTRANT と REENTRANT の 2 つの opcode を提案する。コントラクトが、トランザクションの残りの間、自分自身への呼び出しを低コストでロックできるようにする。","tags":["evm","opcode","security","reentrancy","core"],"related":[1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-7705/","markdown":"## 何を解決するのか\n\nリエントランシー（コントラクトが外部を呼び出し、呼ばれた側が最初の呼び出しの完了前に呼び返してくる攻撃）は、2016 年の DAO ハックを含め、EVM チェーンで盗まれた資金の大きな割合の原因です。一般的な対策はリエントランシーガードで、入口でストレージに「ロック中」フラグを書き込み、出口でクリアします。\n\nこれは保護対象の関数を呼ぶたびにガスがかかります。トランジェントストレージ（[EIP-1153](/eip-1153/)）によってガードは安価になりましたが、著者は、開発者があらゆる場所でデフォルトで使えるほどにはまだ安くないと主張しています。EIP-7705 は、このガードを EVM のネイティブ機能にすることを提案しています。\n\n## 仕組み\n\n2 つの opcode が追加されます。\n\n| Opcode | バイト | ガス | 効果 |\n| --- | --- | --- | --- |\n| `NONREENTRANT` | `0xF6` | 5 | 現在のコントラクトの再入禁止フラグを設定する |\n| `REENTRANT` | `0xF7` | 5 | フラグをクリアする |\n\nフラグが設定されている間、そのコントラクトへの `CALL`、`STATICCALL`、`DELEGATECALL` は、呼ばれた側が `REVERT` を 1 回実行したかのように振る舞います。\n\nルール:\n\n- どちらの opcode も冪等です（すでに設定済みのフラグを設定しても何も起きません）。\n- フラグは現在のトランザクションの間だけ存在し、トランザクションの終了時にクリアされます。\n- コールフレームが revert または異常終了した場合、フラグはその呼び出しの前の値に巻き戻ります。他のステートと同じです。\n\n仕様には、代替案として単一 opcode の設計も記載されています。スタックの値でフラグの設定・解除を行う `NONREENTRANT` で、フィードバックを募集中です。\n\n## サンプルコード\n\nこの opcode が置き換えることになる、現在のトランジェントストレージを使ったガード:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Vault {\n    modifier nonReentrant() {\n        assembly {\n            if tload(0) { revert(0, 0) }\n            tstore(0, 1)\n        }\n        _;\n        assembly { tstore(0, 0) }\n    }\n\n    function withdraw(uint256 amount) external nonReentrant {\n        // ... update balances, then send ETH\n    }\n}\n```\n\nEIP-7705 を使った場合の擬似アセンブリ（これらの opcode をサポートするコンパイラはありません）:\n\n```text\nNONREENTRANT        ; 0xF6 - any call back into this contract now reverts\n...                 ; checks, effects, external call\nREENTRANT           ; 0xF7 - allow calls again\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant。** どのネットワークアップグレードにも予定されておらず、テストケース、リファレンス実装、セキュリティ考慮事項のセクションは空です。\n- セマンティクスに注意してください。ロックは単一の関数ではなくコントラクト全体に適用され、設定されている間は view 的な `STATICCALL` を含む*すべての*受信呼び出しをブロックします。\n- これに類するものが実装されるまでは、十分にレビューされたガード（たとえば OpenZeppelin の `ReentrancyGuard` やそのトランジェント版）を使い、checks-effects-interactions パターンに従ってください。\n"},"ko":{"lang":"ko","tldr":"NONREENTRANT와 REENTRANT 두 개의 opcode를 제안한다. 컨트랙트가 트랜잭션의 나머지 동안 들어오는 호출을 저렴하게 스스로 잠글 수 있게 한다.","tags":["evm","opcode","security","reentrancy","core"],"related":[1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-7705/","markdown":"## 어떤 문제를 해결하나요?\n\n재진입(reentrancy)(컨트랙트가 외부를 호출하고, 호출받은 쪽이 첫 호출이 끝나기 전에 다시 호출해 들어오는 공격)는 2016년 DAO 해킹을 비롯해 EVM 체인에서 도난당한 자금의 상당 부분의 원인입니다. 일반적인 방어책은 재진입 방지 가드로, 진입 시 스토리지에 \"잠김\" 플래그를 쓰고 종료 시 지웁니다.\n\n이는 보호되는 함수마다 가스가 듭니다. 트랜지언트 스토리지([EIP-1153](/eip-1153/))로 가드가 저렴해졌지만, 저자는 개발자가 모든 곳에서 기본으로 쓸 만큼 충분히 저렴하지는 않다고 주장합니다. EIP-7705는 이 가드를 EVM의 네이티브 기능으로 만들자고 제안합니다.\n\n## 어떻게 동작하나요?\n\n두 개의 opcode가 추가됩니다.\n\n| Opcode | 바이트 | 가스 | 효과 |\n| --- | --- | --- | --- |\n| `NONREENTRANT` | `0xF6` | 5 | 현재 컨트랙트의 재진입 금지 플래그를 설정 |\n| `REENTRANT` | `0xF7` | 5 | 플래그를 해제 |\n\n플래그가 설정되어 있는 동안, 해당 컨트랙트로 들어오는 `CALL`, `STATICCALL`, `DELEGATECALL`은 호출받은 쪽이 `REVERT`를 한 번 실행한 것처럼 동작합니다.\n\n규칙:\n\n- 두 opcode 모두 멱등입니다(이미 설정된 플래그를 다시 설정해도 아무 일도 일어나지 않습니다).\n- 플래그는 현재 트랜잭션 동안에만 존재하며 트랜잭션이 끝나면 해제됩니다.\n- 호출 프레임이 revert되거나 비정상 종료되면, 플래그는 다른 상태와 마찬가지로 그 호출 이전의 값으로 롤백됩니다.\n\n명세에는 대안으로 단일 opcode 설계도 언급되어 있습니다. 스택 값을 받아 플래그를 설정하거나 해제하는 `NONREENTRANT`이며, 피드백을 받고 있습니다.\n\n## 샘플 코드\n\n오늘날 트랜지언트 스토리지로 구현하는 가드이며, 이 opcode들이 대체하게 됩니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Vault {\n    modifier nonReentrant() {\n        assembly {\n            if tload(0) { revert(0, 0) }\n            tstore(0, 1)\n        }\n        _;\n        assembly { tstore(0, 0) }\n    }\n\n    function withdraw(uint256 amount) external nonReentrant {\n        // ... update balances, then send ETH\n    }\n}\n```\n\nEIP-7705를 사용하면 의사 어셈블리로 다음과 같이 됩니다(이 opcode를 지원하는 컴파일러는 없습니다).\n\n```text\nNONREENTRANT        ; 0xF6 - any call back into this contract now reverts\n...                 ; checks, effects, external call\nREENTRANT           ; 0xF7 - allow calls again\n```\n\n## 알아둘 점\n\n- **상태: Stagnant.** 어떤 네트워크 업그레이드에도 예정되어 있지 않으며, 테스트 케이스, 레퍼런스 구현, 보안 고려 사항 섹션은 비어 있습니다.\n- 의미론에 유의하세요. 잠금은 개별 함수가 아니라 컨트랙트 전체에 적용되며, 설정되어 있는 동안 view 성격의 `STATICCALL`을 포함해 들어오는 *모든* 호출을 막습니다.\n- 이와 같은 기능이 도입되기 전까지는 충분히 검토된 가드(예: OpenZeppelin의 `ReentrancyGuard` 또는 그 트랜지언트 버전)를 사용하고 checks-effects-interactions 패턴을 따르세요.\n"},"zh":{"lang":"zh","tldr":"提议新增 NONREENTRANT 和 REENTRANT 两个 opcode，让合约能以很低的成本在交易剩余期间锁定自身，拒绝传入的调用。","tags":["evm","opcode","security","reentrancy","core"],"related":[1153],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-7705/","markdown":"## 它解决什么问题？\n\n重入（合约调用外部，被调用方在第一次调用结束之前又回调进来）是 EVM 链上大量资金被盗的原因，包括 2016 年的 DAO 事件。常见的防御手段是重入保护：进入时向存储写入\"已锁定\"标志，退出时清除。\n\n这会让每个受保护的函数都消耗 gas。瞬态存储（[EIP-1153](/eip-1153/)）让保护变得更便宜，但作者认为它仍然没有便宜到让开发者可以默认在所有地方使用。EIP-7705 提议把这种保护变成 EVM 的原生功能。\n\n## 它如何运作\n\n新增两个 opcode：\n\n| Opcode | 字节 | Gas | 效果 |\n| --- | --- | --- | --- |\n| `NONREENTRANT` | `0xF6` | 5 | 设置当前合约的禁止重入标志 |\n| `REENTRANT` | `0xF7` | 5 | 清除该标志 |\n\n标志被设置期间，任何对该合约的 `CALL`、`STATICCALL` 或 `DELEGATECALL` 都表现得就像被调用方执行了一条 `REVERT`。\n\n规则：\n\n- 两个 opcode 都是幂等的（对已设置的标志再次设置不会有任何效果）。\n- 标志只在当前交易内有效，并在交易结束时清除。\n- 如果某个调用帧 revert 或异常终止，标志会回滚到该调用之前的值，与其他状态一样。\n\n规范中还提到一种替代的单 opcode 设计：`NONREENTRANT` 从栈中取一个值来设置或清除标志，欢迎反馈。\n\n## 示例代码\n\n目前使用瞬态存储的保护写法，这两个 opcode 将取代它：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.24;\n\ncontract Vault {\n    modifier nonReentrant() {\n        assembly {\n            if tload(0) { revert(0, 0) }\n            tstore(0, 1)\n        }\n        _;\n        assembly { tstore(0, 0) }\n    }\n\n    function withdraw(uint256 amount) external nonReentrant {\n        // ... update balances, then send ETH\n    }\n}\n```\n\n使用 EIP-7705 后的写法，以伪汇编表示（目前没有编译器支持这些 opcode）：\n\n```text\nNONREENTRANT        ; 0xF6 - any call back into this contract now reverts\n...                 ; checks, effects, external call\nREENTRANT           ; 0xF7 - allow calls again\n```\n\n## 需要注意\n\n- **状态：Stagnant。** 它尚未被安排进任何网络升级，其测试用例、参考实现和安全考虑部分都是空的。\n- 注意其语义：锁作用于整个合约，而不是单个函数，并且在设置期间会阻止*所有*传入调用，包括 view 类的 `STATICCALL`。\n- 在类似机制上线之前，请使用经过充分审查的保护（例如 OpenZeppelin 的 `ReentrancyGuard` 或其瞬态版本），并遵循 checks-effects-interactions 模式。\n"}}}
