{"eip":1884,"title":"Repricing for trie-size-dependent opcodes","description":"This EIP proposes repricing certain opcodes, to obtain a good balance between gas expenditure and resource consumption.","authors":["Martin Holst Swende (@holiman)"],"status":"Final","type":"Standards Track","category":"Core","created":"2019-03-28","requires":[150,1052],"discussionsTo":"https://ethereum-magicians.org/t/opcode-repricing/3024","repo":"EIPs","label":"EIP-1884","officialUrl":"https://eips.ethereum.org/EIPS/eip-1884","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1884.md","url":"https://eips.huatuo.xyz/eip-1884/","tldr":{"en":"Istanbul-era repricing that raised SLOAD, BALANCE and EXTCODEHASH gas costs to match the real cost of reading a growing state trie, and added the cheap SELFBALANCE opcode.","ja":"Istanbul 時代の再価格設定。成長し続けるステートトライを読み取る実際のコストに合わせて SLOAD、BALANCE、EXTCODEHASH のガスコストを引き上げ、安価な SELFBALANCE opcode を追加した。","ko":"상태 트라이를 읽는 실제 비용에 맞추어 SLOAD, BALANCE, EXTCODEHASH의 가스 비용을 올리고 저렴한 SELFBALANCE opcode를 추가한, Istanbul 시기의 가격 재조정.","zh":"伊斯坦布尔时期的重新定价：提高 SLOAD、BALANCE 和 EXTCODEHASH 的 gas 成本，使其与读取不断增长的状态树的实际成本相符，并新增了廉价的 SELFBALANCE 操作码。"},"tags":["gas","opcodes","state","core","istanbul"],"explainers":{"en":{"lang":"en","tldr":"Istanbul-era repricing that raised SLOAD, BALANCE and EXTCODEHASH gas costs to match the real cost of reading a growing state trie, and added the cheap SELFBALANCE opcode.","tags":["gas","opcodes","state","core","istanbul"],"related":[150,1052,2929,2200,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-1884/","markdown":"## What problem does it solve?\n\nOpcodes that read the state trie got slower as Ethereum's state grew, but their gas prices stayed the same. Measurements from go-ethereum full syncs showed storage and account reads dominating block processing time. `SLOAD` had become more than twice as slow per unit of gas as it was right after its last repricing in [EIP-150](/eip-150/).\n\nUnderpriced operations are dangerous: an attacker can fill blocks with them and make blocks slow to process. They also make processing time per gas uneven, which limits how high the block gas limit can safely go.\n\n## How it works\n\nActivated in the Istanbul hard fork:\n\n| Opcode | Before | After |\n| --- | --- | --- |\n| `SLOAD` (`0x54`) | 200 | **800** |\n| `BALANCE` (`0x31`) | 400 | **700** |\n| `EXTCODEHASH` (`0x3f`) | 400 | **700** |\n| `SELFBALANCE` (`0x47`, new) | — | **5** |\n\n- `BALANCE` was raised to 700 to match `EXTCODESIZE`, which already cost 700.\n- `EXTCODEHASH` ([EIP-1052](/eip-1052/)) was priced the same as `BALANCE` because it performs the same account lookup, so it rose too.\n- `SELFBALANCE` takes no arguments and pushes the current contract's balance. Checking your own balance is cheap because the account is already loaded, so it no longer needs to pay the price of an arbitrary lookup. It sits at `0x47` because the `0x3X` range was full, and costs 5 rather than 2 because balance can change during execution and still needs a cached lookup.\n\n## Sample code\n\nSolidity compilers targeting Istanbul or later compile `address(this).balance` to `SELFBALANCE` automatically. In inline assembly it is available directly:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    function myBalance() external view returns (uint256 bal) {\n        assembly {\n            bal := selfbalance() // 5 gas, vs. balance(address()) for an external lookup\n        }\n    }\n}\n```\n\nThe fallback-function pitfall this EIP exposed:\n\n```solidity\ncontract Fragile {\n    uint256 public counter;\n    // Called via transfer()/send(), which forward only a 2300 gas stipend.\n    // An SLOAD (and SSTORE) here can exceed the stipend after a repricing -\u003e the transfer reverts.\n    receive() external payable { counter += 1; }\n}\n```\n\n## Things to know\n\n- Status is **Final**. It shipped in Istanbul alongside other changes such as [EIP-2200](/eip-2200/) net gas metering.\n- It was a breaking change for contracts that assumed fixed gas costs. Fallback functions that read storage could run out of gas under the 2300 stipend forwarded by `transfer`/`send`. This is a main reason those methods are now discouraged in favour of `call`.\n- The spec checked [ERC-165](/eip-165/)'s 30,000-gas limit for `supportsInterface` and judged that typical implementations would stay well within it.\n- These prices were reworked again in Berlin by [EIP-2929](/eip-2929/), which introduced cold/warm access pricing (for example, a cold `SLOAD` costs 2100 and a warm one 100).\n"},"ja":{"lang":"ja","tldr":"Istanbul 時代の再価格設定。成長し続けるステートトライを読み取る実際のコストに合わせて SLOAD、BALANCE、EXTCODEHASH のガスコストを引き上げ、安価な SELFBALANCE opcode を追加した。","tags":["gas","opcodes","state","core","istanbul"],"related":[150,1052,2929,2200,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-1884/","markdown":"## 何を解決するのか\n\nステートトライを読み取る opcode は、Ethereum のステートが大きくなるにつれて遅くなりましたが、ガス価格は変わりませんでした。go-ethereum のフル同期での計測では、ストレージとアカウントの読み取りがブロック処理時間を支配していることがわかりました。`SLOAD` は、[EIP-150](/eip-150/) での直近の再価格設定の直後と比べて、ガス 1 単位あたり 2 倍以上遅くなっていました。\n\n価格が低すぎる操作は危険です。攻撃者がそれらでブロックを埋め、ブロックの処理を遅くできるからです。また、ガスあたりの処理時間が不均一になり、ブロックのガスリミットを安全に引き上げられる上限も制限されます。\n\n## 仕組み\n\nIstanbul ハードフォークで有効化されました。\n\n| Opcode | 変更前 | 変更後 |\n| --- | --- | --- |\n| `SLOAD`（`0x54`） | 200 | **800** |\n| `BALANCE`（`0x31`） | 400 | **700** |\n| `EXTCODEHASH`（`0x3f`） | 400 | **700** |\n| `SELFBALANCE`（`0x47`、新規） | — | **5** |\n\n- `BALANCE` は、すでに 700 だった `EXTCODESIZE` に合わせて 700 に引き上げられました。\n- `EXTCODEHASH`（[EIP-1052](/eip-1052/)）は `BALANCE` と同じアカウント参照を行うため同じ価格が設定され、同じく上がりました。\n- `SELFBALANCE` は引数を取らず、現在のコントラクトの残高をプッシュします。自分自身の残高の確認は、アカウントがすでにロードされているため安価で済み、任意の参照の価格を払う必要がなくなります。`0x3X` の範囲が埋まっていたため `0x47` に置かれ、コストは 2 ではなく 5 です。実行中に残高が変わり得て、やはりキャッシュ済みの参照が必要だからです。\n\n## サンプルコード\n\nIstanbul 以降を対象とする Solidity コンパイラは、`address(this).balance` を自動的に `SELFBALANCE` にコンパイルします。インラインアセンブリでは直接使えます。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    function myBalance() external view returns (uint256 bal) {\n        assembly {\n            bal := selfbalance() // 5 gas, vs. balance(address()) for an external lookup\n        }\n    }\n}\n```\n\nこの EIP が露わにした、フォールバック関数の落とし穴:\n\n```solidity\ncontract Fragile {\n    uint256 public counter;\n    // Called via transfer()/send(), which forward only a 2300 gas stipend.\n    // An SLOAD (and SSTORE) here can exceed the stipend after a repricing -\u003e the transfer reverts.\n    receive() external payable { counter += 1; }\n}\n```\n\n## 知っておくべきこと\n\n- ステータスは **Final** です。[EIP-2200](/eip-2200/) のネットガス計測など他の変更とともに Istanbul で出荷されました。\n- ガスコストが固定だと仮定していたコントラクトにとっては破壊的変更でした。ストレージを読むフォールバック関数は、`transfer`/`send` が渡す 2300 のスティペンドではガス切れになる可能性がありました。これが、現在それらのメソッドが `call` に比べて推奨されない主な理由です。\n- 仕様は、[ERC-165](/eip-165/) の `supportsInterface` の 30,000 ガスという上限を確認し、一般的な実装はそれを十分に下回ると判断しました。\n- これらの価格は、Berlin で [EIP-2929](/eip-2929/) によって再び見直され、コールド/ウォームのアクセス価格が導入されました（たとえば、コールドの `SLOAD` は 2100、ウォームは 100）。\n"},"ko":{"lang":"ko","tldr":"상태 트라이를 읽는 실제 비용에 맞추어 SLOAD, BALANCE, EXTCODEHASH의 가스 비용을 올리고 저렴한 SELFBALANCE opcode를 추가한, Istanbul 시기의 가격 재조정.","tags":["gas","opcodes","state","core","istanbul"],"related":[150,1052,2929,2200,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-1884/","markdown":"## 어떤 문제를 해결하나요?\n\n상태 트라이를 읽는 opcode는 이더리움의 상태가 커지면서 느려졌지만 가스 가격은 그대로였습니다. go-ethereum 풀 싱크 측정 결과, 스토리지와 계정 읽기가 블록 처리 시간을 지배하고 있었습니다. `SLOAD`는 [EIP-150](/eip-150/)의 마지막 가격 재조정 직후와 비교해 가스 단위당 두 배 넘게 느려져 있었습니다.\n\n가격이 낮게 책정된 연산은 위험합니다. 공격자가 그런 연산으로 블록을 채워 블록 처리를 느리게 만들 수 있기 때문입니다. 또한 가스당 처리 시간이 고르지 않게 되어 블록 가스 한도를 안전하게 올릴 수 있는 한계를 제약합니다.\n\n## 어떻게 동작하나요?\n\nIstanbul 하드 포크에서 활성화되었습니다.\n\n| Opcode | 이전 | 이후 |\n| --- | --- | --- |\n| `SLOAD`(`0x54`) | 200 | **800** |\n| `BALANCE`(`0x31`) | 400 | **700** |\n| `EXTCODEHASH`(`0x3f`) | 400 | **700** |\n| `SELFBALANCE`(`0x47`, 신규) | — | **5** |\n\n- `BALANCE`는 이미 700이던 `EXTCODESIZE`와 맞추기 위해 700으로 올랐습니다.\n- `EXTCODEHASH`([EIP-1052](/eip-1052/))는 `BALANCE`와 같은 계정 조회를 수행하므로 같은 가격이 매겨졌고, 그래서 함께 올랐습니다.\n- `SELFBALANCE`는 인자가 없고 현재 컨트랙트의 잔액을 푸시합니다. 자기 잔액을 확인하는 일은 계정이 이미 로드되어 있어 저렴하므로 임의 조회의 가격을 치를 필요가 없습니다. `0x3X` 범위가 가득 차 있어 `0x47`에 있고, 실행 중에 잔액이 바뀔 수 있어 캐시된 조회가 여전히 필요하기 때문에 비용은 2가 아니라 5입니다.\n\n## 샘플 코드\n\nIstanbul 이상을 대상으로 하는 Solidity 컴파일러는 `address(this).balance`를 자동으로 `SELFBALANCE`로 컴파일합니다. 인라인 어셈블리에서는 직접 사용할 수 있습니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    function myBalance() external view returns (uint256 bal) {\n        assembly {\n            bal := selfbalance() // 5 gas, vs. balance(address()) for an external lookup\n        }\n    }\n}\n```\n\n이 EIP가 드러낸 폴백 함수의 함정:\n\n```solidity\ncontract Fragile {\n    uint256 public counter;\n    // Called via transfer()/send(), which forward only a 2300 gas stipend.\n    // An SLOAD (and SSTORE) here can exceed the stipend after a repricing -\u003e the transfer reverts.\n    receive() external payable { counter += 1; }\n}\n```\n\n## 알아둘 점\n\n- 상태는 **Final**입니다. [EIP-2200](/eip-2200/) 순 가스 계량 같은 다른 변경과 함께 Istanbul에서 출시되었습니다.\n- 가스 비용이 고정되어 있다고 가정한 컨트랙트에는 호환성을 깨는 변경이었습니다. 스토리지를 읽는 폴백 함수는 `transfer`/`send`가 전달하는 2300 스타이펜드로는 가스가 부족해질 수 있었습니다. 이것이 지금 이 메서드들 대신 `call`이 권장되는 주된 이유입니다.\n- 명세는 [ERC-165](/eip-165/)의 `supportsInterface` 30,000 가스 제한을 확인하고, 일반적인 구현은 그 한도를 충분히 밑돌 것이라고 판단했습니다.\n- 이 가격들은 Berlin에서 [EIP-2929](/eip-2929/)에 의해 다시 손봐졌고, 콜드/웜 접근 가격이 도입되었습니다(예: 콜드 `SLOAD`는 2100, 웜은 100).\n"},"zh":{"lang":"zh","tldr":"伊斯坦布尔时期的重新定价：提高 SLOAD、BALANCE 和 EXTCODEHASH 的 gas 成本，使其与读取不断增长的状态树的实际成本相符，并新增了廉价的 SELFBALANCE 操作码。","tags":["gas","opcodes","state","core","istanbul"],"related":[150,1052,2929,2200,165],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-1884/","markdown":"## 它解决什么问题？\n\n随着以太坊状态的增长，读取状态树的操作码变得越来越慢，但它们的 gas 价格却没有变。来自 go-ethereum 全量同步的测量表明，存储和账户读取占据了区块处理时间的大头。`SLOAD` 每单位 gas 的耗时，已经是它在 [EIP-150](/eip-150/) 中上一次重新定价之后的两倍多。\n\n定价过低的操作很危险：攻击者可以用它们填满区块，使区块处理变慢。它们还会让每单位 gas 的处理时间不均衡，从而限制区块 gas 上限能安全提高到多高。\n\n## 它如何运作\n\n在伊斯坦布尔硬分叉中激活：\n\n| 操作码 | 之前 | 之后 |\n| --- | --- | --- |\n| `SLOAD`（`0x54`） | 200 | **800** |\n| `BALANCE`（`0x31`） | 400 | **700** |\n| `EXTCODEHASH`（`0x3f`） | 400 | **700** |\n| `SELFBALANCE`（`0x47`，新增） | — | **5** |\n\n- `BALANCE` 提高到 700，以与原本就是 700 的 `EXTCODESIZE` 一致。\n- `EXTCODEHASH`（[EIP-1052](/eip-1052/)）与 `BALANCE` 执行相同的账户查找，所以定价相同，也随之上涨。\n- `SELFBALANCE` 不接受参数，把当前合约的余额压入栈。检查自己的余额很便宜，因为该账户已经加载，所以不必再支付任意查找的价格。它位于 `0x47`，因为 `0x3X` 区段已满；它的成本是 5 而不是 2，因为余额可能在执行期间变化，仍然需要一次缓存查找。\n\n## 示例代码\n\n面向伊斯坦布尔及之后版本的 Solidity 编译器会自动把 `address(this).balance` 编译成 `SELFBALANCE`。在内联汇编中可以直接使用：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\ncontract Vault {\n    function myBalance() external view returns (uint256 bal) {\n        assembly {\n            bal := selfbalance() // 5 gas, vs. balance(address()) for an external lookup\n        }\n    }\n}\n```\n\n这份 EIP 暴露出的回退函数陷阱：\n\n```solidity\ncontract Fragile {\n    uint256 public counter;\n    // Called via transfer()/send(), which forward only a 2300 gas stipend.\n    // An SLOAD (and SSTORE) here can exceed the stipend after a repricing -\u003e the transfer reverts.\n    receive() external payable { counter += 1; }\n}\n```\n\n## 需要注意\n\n- 状态为 **Final**。它与 [EIP-2200](/eip-2200/) 净 gas 计量等其他变更一起，随伊斯坦布尔上线。\n- 对于假定 gas 成本固定的合约，这是一次破坏性变更。读取存储的回退函数，在 `transfer`/`send` 转发的 2300 补贴下可能会耗尽 gas。这是如今不再提倡这些方法、转而推荐 `call` 的主要原因。\n- 规范核查了 [ERC-165](/eip-165/) 对 `supportsInterface` 的 30,000 gas 限制，认为典型实现会远低于该限制。\n- 这些价格在 Berlin 中又被 [EIP-2929](/eip-2929/) 重新调整，它引入了冷/热访问定价（例如，冷 `SLOAD` 为 2100，热的为 100）。\n"}},"requiredBy":[1679]}
