{"eip":5283,"title":"Semaphore for Reentrancy Protection","description":"A Precompile-based parallelizable reentrancy protection using the call stack","authors":["Sergio D. Lerner (@SergioDemianLerner)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2022-07-17","requires":[20,1283,1352],"discussionsTo":"https://ethereum-magicians.org/t/eip-5283-a-semaphore-for-parallelizable-reentrancy-protection/10236","repo":"EIPs","label":"EIP-5283","officialUrl":"https://eips.ethereum.org/EIPS/eip-5283","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-5283.md","url":"https://eips.huatuo.xyz/eip-5283/","tldr":{"en":"Proposed a precompile that reverts if the caller already appears in the call stack, giving contracts a reentrancy guard that never writes storage and so stays compatible with parallel EVM execution.","ja":"呼び出し元が既にコールスタックに現れている場合に revert するプリコンパイルを提案した。ストレージに書き込まないリエントランシーガードをコントラクトに与え、並列 EVM 実行との互換性を保つ。","ko":"호출자가 이미 콜 스택에 나타나면 revert하는 프리컴파일을 제안했다. 스토리지에 쓰지 않는 재진입 방지 장치를 컨트랙트에 제공하여 병렬 EVM 실행과의 호환성을 유지한다.","zh":"提出一个预编译合约：如果调用者已经出现在调用栈中就 revert，为合约提供一种从不写入存储的重入保护，因此与并行 EVM 执行保持兼容。"},"tags":["reentrancy","precompile","parallel-execution","core","security"],"explainers":{"en":{"lang":"en","tldr":"Proposed a precompile that reverts if the caller already appears in the call stack, giving contracts a reentrancy guard that never writes storage and so stays compatible with parallel EVM execution.","tags":["reentrancy","precompile","parallel-execution","core","security"],"related":[1153,1352,1283,4844],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-5283/","markdown":"## What problem does it solve?\n\nThe standard reentrancy guard, OpenZeppelin's `ReentrancyGuard`, stores a flag. On entry it checks the slot and sets it, and on exit it resets it. That read-then-write on one storage slot conflicts with **parallel transaction execution**. The most effective parallel EVM designs detect conflicts per storage slot, and a guard slot touched by every call to a popular token or protocol serializes everything that uses it.\n\nEIP-5283 proposes a reentrancy guard with no storage access at all, so contracts written today would stay parallelizable later.\n\n## How it works\n\nThe proposal adds a precompile, `Semaphore`, at address `0x0A`. It was the next free address in the range reserved by [EIP-1352](/eip-1352/) when the EIP was written.\n\n- When called, it checks whether the **caller's address appears more than once in the current call stack**.\n- If it does, which means the contract has been re-entered, the precompile behaves like an immediate `REVERT`, so the `CALL` returns `0`.\n- Otherwise it returns `1`.\n- It costs a flat **100 gas**, sized for scanning a nearly full call stack of about 400 addresses.\n\nA contract calls it at the start of a protected function and reverts if the call fails. No cleanup is needed on exit, because the call stack unwinds by itself.\n\nThe rationale also compares other options. Transient storage (`TLOAD`/`TSTORE`), a `SSTORE_COUNT` opcode and a `LOCKCALL` opcode would all need new opcodes. A precompile avoids changes to compilers and tools.\n\n## Sample code\n\nThe modifier from the EIP, cleaned up:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nabstract contract SemaphoreGuard {\n    address constant SEMAPHORE = address(0x0A);   // as proposed; never deployed\n\n    modifier nonReentrant() {\n        assembly {\n            if iszero(staticcall(1000, SEMAPHORE, 0, 0, 0, 0)) { revert(0, 0) }\n        }\n        _;\n    }\n}\n\ncontract Test is SemaphoreGuard {\n    function second() external nonReentrant {}\n    function first() external nonReentrant { this.second(); } // reverts: Test is on the stack twice\n}\n```\n\nWith the EIP active, calling `second()` directly succeeds and calling `first()` reverts.\n\n## Things to know\n\n- **Status: Stagnant.** It was never scheduled for a hard fork, and the activation block was never set. Security Considerations were still marked \"needs discussion\".\n- Address `0x0A` was later taken by the KZG point evaluation precompile from [EIP-4844](/eip-4844/). **Do not** use the sample above on any real chain.\n- The problem was largely solved another way. **Transient storage** ([EIP-1153](/eip-1153/)), live on mainnet since the Cancun upgrade, lets a reentrancy flag live in per-transaction memory that is never written to state. OpenZeppelin provides `ReentrancyGuardTransient`.\n- The author pointed out that a precompile call costs about 800 gas in total. That is more than the roughly 200 gas a storage guard costs thanks to [EIP-1283](/eip-1283/)-style net metering, unless precompile call costs are reduced.\n- A guard only helps new contracts. Contracts already deployed with storage-based guards would not become parallelizable.\n"},"ja":{"lang":"ja","tldr":"呼び出し元が既にコールスタックに現れている場合に revert するプリコンパイルを提案した。ストレージに書き込まないリエントランシーガードをコントラクトに与え、並列 EVM 実行との互換性を保つ。","tags":["reentrancy","precompile","parallel-execution","core","security"],"related":[1153,1352,1283,4844],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-5283/","markdown":"## 何を解決するのか\n\n標準的なリエントランシーガードである OpenZeppelin の `ReentrancyGuard` は、フラグを保存します。入るときにスロットを確認してセットし、出るときにリセットします。1 つのストレージスロットに対するこの読み取り後の書き込みは、**並列トランザクション実行**と衝突します。最も効果的な並列 EVM の設計はストレージスロット単位で衝突を検出するため、人気のトークンやプロトコルへのあらゆる呼び出しが触れるガードスロットは、それを使うすべての処理を直列化してしまいます。\n\nEIP-5283 は、ストレージアクセスをまったく行わないリエントランシーガードを提案します。これにより、今日書かれたコントラクトも後で並列化可能なままです。\n\n## 仕組み\n\nこの提案は、アドレス `0x0A` に `Semaphore` というプリコンパイルを追加します。これは、この EIP が書かれた時点で、[EIP-1352](/eip-1352/) が予約した範囲で次に空いていたアドレスでした。\n\n- 呼び出されると、**呼び出し元のアドレスが現在のコールスタックに 2 回以上現れるか**を確認します。\n- 現れる場合、つまりコントラクトが再入された場合、プリコンパイルは即座の `REVERT` のように動作し、`CALL` は `0` を返します。\n- そうでなければ `1` を返します。\n- コストは一律 **100 gas** で、約 400 アドレスのほぼ満杯のコールスタックを走査できる大きさに設定されています。\n\nコントラクトは、保護対象の関数の冒頭でこれを呼び出し、呼び出しが失敗したら revert します。コールスタックは自然に巻き戻るため、終了時の後始末は不要です。\n\nrationale では他の選択肢も比較しています。トランジェントストレージ（`TLOAD`/`TSTORE`）、`SSTORE_COUNT` opcode、`LOCKCALL` opcode は、いずれも新しい opcode が必要になります。プリコンパイルなら、コンパイラやツールの変更を避けられます。\n\n## サンプルコード\n\nEIP のモディファイアを整理したもの:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nabstract contract SemaphoreGuard {\n    address constant SEMAPHORE = address(0x0A);   // as proposed; never deployed\n\n    modifier nonReentrant() {\n        assembly {\n            if iszero(staticcall(1000, SEMAPHORE, 0, 0, 0, 0)) { revert(0, 0) }\n        }\n        _;\n    }\n}\n\ncontract Test is SemaphoreGuard {\n    function second() external nonReentrant {}\n    function first() external nonReentrant { this.second(); } // reverts: Test is on the stack twice\n}\n```\n\nEIP が有効な場合、`second()` を直接呼べば成功し、`first()` を呼べば revert します。\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant。** ハードフォークにスケジュールされたことはなく、アクティベーションブロックも設定されませんでした。Security Considerations は「要議論」のままでした。\n- アドレス `0x0A` は、のちに [EIP-4844](/eip-4844/) の KZG ポイント評価プリコンパイルに使われました。上記のサンプルを実際のチェーンで使っては**いけません**。\n- この問題は、主に別の方法で解決されました。**トランジェントストレージ**（[EIP-1153](/eip-1153/)）は Cancun アップグレード以降メインネットで稼働しており、リエントランシーフラグを、状態に書き込まれないトランザクション単位のメモリに置けます。OpenZeppelin は `ReentrancyGuardTransient` を提供しています。\n- 著者は、プリコンパイルの呼び出しは合計で約 800 gas かかると指摘しました。これは、[EIP-1283](/eip-1283/) 方式のネットメータリングによりストレージガードにかかる約 200 gas よりも高く、プリコンパイルの呼び出しコストが下がらない限りそうなります。\n- ガードが役立つのは新しいコントラクトだけです。ストレージベースのガードでデプロイ済みのコントラクトは、並列化可能にはなりません。\n"},"ko":{"lang":"ko","tldr":"호출자가 이미 콜 스택에 나타나면 revert하는 프리컴파일을 제안했다. 스토리지에 쓰지 않는 재진입 방지 장치를 컨트랙트에 제공하여 병렬 EVM 실행과의 호환성을 유지한다.","tags":["reentrancy","precompile","parallel-execution","core","security"],"related":[1153,1352,1283,4844],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-5283/","markdown":"## 어떤 문제를 해결하나요?\n\n표준 재진입 방지 장치인 OpenZeppelin의 `ReentrancyGuard`는 플래그를 저장합니다. 진입할 때 슬롯을 확인하고 설정하며, 나갈 때 초기화합니다. 하나의 스토리지 슬롯에 대한 이런 읽고 쓰기는 **병렬 트랜잭션 실행**과 충돌합니다. 가장 효과적인 병렬 EVM 설계는 스토리지 슬롯 단위로 충돌을 감지하므로, 인기 있는 토큰이나 프로토콜에 대한 모든 호출이 건드리는 가드 슬롯은 그것을 쓰는 모든 것을 직렬화합니다.\n\nEIP-5283은 스토리지에 전혀 접근하지 않는 재진입 방지 장치를 제안하여, 오늘 작성된 컨트랙트도 나중에 병렬화할 수 있게 합니다.\n\n## 어떻게 동작하나요?\n\n이 제안은 주소 `0x0A`에 `Semaphore`라는 프리컴파일을 추가합니다. 이 EIP가 작성될 당시 [EIP-1352](/eip-1352/)가 예약한 범위에서 다음으로 비어 있던 주소였습니다.\n\n- 호출되면 **호출자의 주소가 현재 콜 스택에 두 번 이상 나타나는지** 확인합니다.\n- 그렇다면, 즉 컨트랙트가 재진입되었다면 프리컴파일은 즉시 `REVERT`처럼 동작하여 `CALL`이 `0`을 반환합니다.\n- 그렇지 않으면 `1`을 반환합니다.\n- 비용은 일정하게 **100 gas**이며, 약 400개 주소로 거의 가득 찬 콜 스택을 스캔하는 것을 기준으로 정해졌습니다.\n\n컨트랙트는 보호할 함수의 시작 부분에서 이를 호출하고, 호출이 실패하면 revert합니다. 콜 스택은 저절로 풀리므로 종료할 때 정리할 것이 없습니다.\n\nrationale에서는 다른 선택지도 비교합니다. 트랜지언트 스토리지(`TLOAD`/`TSTORE`), `SSTORE_COUNT` opcode, `LOCKCALL` opcode는 모두 새 opcode가 필요합니다. 프리컴파일은 컴파일러와 도구를 바꾸지 않아도 됩니다.\n\n## 샘플 코드\n\nEIP의 modifier를 정리한 것:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nabstract contract SemaphoreGuard {\n    address constant SEMAPHORE = address(0x0A);   // as proposed; never deployed\n\n    modifier nonReentrant() {\n        assembly {\n            if iszero(staticcall(1000, SEMAPHORE, 0, 0, 0, 0)) { revert(0, 0) }\n        }\n        _;\n    }\n}\n\ncontract Test is SemaphoreGuard {\n    function second() external nonReentrant {}\n    function first() external nonReentrant { this.second(); } // reverts: Test is on the stack twice\n}\n```\n\nEIP가 활성화되어 있다면 `second()`를 직접 호출하면 성공하고 `first()`를 호출하면 revert됩니다.\n\n## 알아둘 점\n\n- **상태: Stagnant.** 하드포크에 예정된 적이 없고 활성화 블록도 정해진 적이 없습니다. Security Considerations는 계속 \"논의 필요\"로 표시되어 있었습니다.\n- 주소 `0x0A`는 이후 [EIP-4844](/eip-4844/)의 KZG 포인트 평가 프리컴파일이 차지했습니다. 위 샘플을 실제 체인에서 사용해서는 **안 됩니다**.\n- 이 문제는 대체로 다른 방식으로 해결되었습니다. **트랜지언트 스토리지**([EIP-1153](/eip-1153/))는 Cancun 업그레이드 이후 메인넷에서 동작하며, 재진입 플래그를 상태에 기록되지 않는 트랜잭션 단위 메모리에 둘 수 있게 합니다. OpenZeppelin은 `ReentrancyGuardTransient`를 제공합니다.\n- 저자는 프리컴파일 호출이 합쳐서 약 800 gas가 든다고 지적했습니다. 이는 [EIP-1283](/eip-1283/) 방식의 순 계량 덕분에 스토리지 가드에 드는 약 200 gas보다 많으며, 프리컴파일 호출 비용이 줄어들지 않는 한 그렇습니다.\n- 가드는 새 컨트랙트에만 도움이 됩니다. 스토리지 기반 가드로 이미 배포된 컨트랙트는 병렬화할 수 없게 됩니다.\n"},"zh":{"lang":"zh","tldr":"提出一个预编译合约：如果调用者已经出现在调用栈中就 revert，为合约提供一种从不写入存储的重入保护，因此与并行 EVM 执行保持兼容。","tags":["reentrancy","precompile","parallel-execution","core","security"],"related":[1153,1352,1283,4844],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-5283/","markdown":"## 它解决什么问题？\n\n标准的重入保护，即 OpenZeppelin 的 `ReentrancyGuard`，会存储一个标志位。进入时检查该槽并设置它，退出时再重置。对同一个存储槽先读后写，会与**并行交易执行**冲突。最有效的并行 EVM 设计按存储槽检测冲突，而一个被热门代币或协议的每次调用都触及的保护槽，会让所有使用它的操作串行化。\n\nEIP-5283 提出一种完全不访问存储的重入保护，让今天编写的合约日后仍可并行化。\n\n## 它如何运作\n\n该提案在地址 `0x0A` 添加一个名为 `Semaphore` 的预编译合约。在撰写这个 EIP 时，它是 [EIP-1352](/eip-1352/) 所保留范围内的下一个空闲地址。\n\n- 被调用时，它检查**调用者地址是否在当前调用栈中出现多次**。\n- 如果是，也就是合约被重入了，预编译的行为就像立即执行 `REVERT`，于是 `CALL` 返回 `0`。\n- 否则返回 `1`。\n- 它的费用固定为 **100 gas**，大小是按扫描一个近乎满载的、约 400 个地址的调用栈来定的。\n\n合约在受保护函数的开头调用它，如果调用失败就 revert。退出时无需任何清理，因为调用栈会自行展开。\n\nrationale 还比较了其他方案。瞬态存储（`TLOAD`/`TSTORE`）、`SSTORE_COUNT` opcode 和 `LOCKCALL` opcode 都需要新增 opcode。预编译则避免了对编译器和工具的改动。\n\n## 示例代码\n\nEIP 中的 modifier，经过整理：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.0;\n\nabstract contract SemaphoreGuard {\n    address constant SEMAPHORE = address(0x0A);   // as proposed; never deployed\n\n    modifier nonReentrant() {\n        assembly {\n            if iszero(staticcall(1000, SEMAPHORE, 0, 0, 0, 0)) { revert(0, 0) }\n        }\n        _;\n    }\n}\n\ncontract Test is SemaphoreGuard {\n    function second() external nonReentrant {}\n    function first() external nonReentrant { this.second(); } // reverts: Test is on the stack twice\n}\n```\n\n在该 EIP 生效的情况下，直接调用 `second()` 会成功，调用 `first()` 则会 revert。\n\n## 需要注意\n\n- **状态：Stagnant。** 它从未被排入硬分叉计划，激活区块也从未设定。Security Considerations 仍被标记为\"需要讨论\"。\n- 地址 `0x0A` 后来被 [EIP-4844](/eip-4844/) 的 KZG 点求值预编译占用。**不要**在任何真实链上使用上面的示例。\n- 这个问题在很大程度上通过另一种方式解决了。**瞬态存储**（[EIP-1153](/eip-1153/)）自 Cancun 升级起已在主网上线，让重入标志可以存放在不会写入状态的单交易内存中。OpenZeppelin 提供了 `ReentrancyGuardTransient`。\n- 作者指出，一次预编译调用总共约需 800 gas。这比借助 [EIP-1283](/eip-1283/) 式净计量后存储保护约 200 gas 的成本更高，除非预编译的调用成本被降低。\n- 保护机制只对新合约有帮助。已经部署、采用基于存储的保护的合约不会因此变得可并行化。\n"}}}
