{"eip":2666,"title":"Repricing of precompiles and Keccak256 function","description":"This EIP tries to set prices of certain precompiles and built-in EVM function to be in line with their performance, consumed resources and newer changes in EVM itself.","authors":["Alex Vlasov (@shamatar)"],"status":"Stagnant","type":"Standards Track","category":"Core","created":"2020-05-22","requires":[1352,2046,2565],"discussionsTo":"https://ethereum-magicians.org/t/eip2666-global-precompiles-repricing-and-many-more-discussion-thread/4332","repo":"EIPs","label":"EIP-2666","officialUrl":"https://eips.ethereum.org/EIPS/eip-2666","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2666.md","url":"https://eips.huatuo.xyz/eip-2666/","tldr":{"en":"Proposed new, benchmark-based gas formulas for the SHA256 and RIPEMD-160 precompiles and the KECCAK256 opcode, charging per internal hash block instead of per 32-byte word.","ja":"SHA256 と RIPEMD-160 のプリコンパイル、および KECCAK256 オペコードに対して、32 バイトワードごとではなく内部のハッシュブロックごとに課金する、ベンチマークに基づく新しいガス計算式を提案した。","ko":"SHA256과 RIPEMD-160 프리컴파일, KECCAK256 옵코드에 대해 32바이트 워드가 아니라 내부 해시 블록 단위로 과금하는, 벤치마크 기반의 새로운 가스 공식을 제안했다.","zh":"为 SHA256 和 RIPEMD-160 预编译以及 KECCAK256 操作码提出了新的、基于基准测试的 gas 公式，按内部哈希块而非 32 字节字收费。"},"tags":["gas","precompile","hashing","core","repricing"],"explainers":{"en":{"lang":"en","tldr":"Proposed new, benchmark-based gas formulas for the SHA256 and RIPEMD-160 precompiles and the KECCAK256 opcode, charging per internal hash block instead of per 32-byte word.","tags":["gas","precompile","hashing","core","repricing"],"related":[2565,2046,1352,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2666/","markdown":"## What problem does it solve?\n\nThe gas costs of Ethereum's built-in hash functions were set early on and charge per 32-byte word of input. But hash functions don't work in 32-byte words. SHA-256 and RIPEMD-160 process 64-byte blocks, and Keccak-256 absorbs 136 bytes per round. The old prices therefore did not match the real CPU work, and RIPEMD in particular was very expensive.\n\nERC-2666 asked client teams to benchmark these functions and proposed formulas that follow the internal block structure. It also anticipated [EIP-2046](/eip-2046/), which would make `STATICCALL` to precompiles cheap, removing a large fixed overhead some precompile prices might have been compensating for.\n\n## How it works\n\nAfter a fork block, the costs would become (integer division throughout):\n\n| Function | Current | Proposed |\n| --- | --- | --- |\n| SHA256 precompile `0x02` | 60 + 12 per word | `10 + ((len + 8) / 64 + 1) * 9` |\n| RIPEMD-160 precompile `0x03` | 600 + 120 per word | `6 + ((len + 8) / 64 + 1) * 12` |\n| `KECCAK256` opcode `0x20` | 30 + 6 per word | `13 + (len / 136 + 1) * 15` |\n\nThe `+ 1` terms are kept separate on purpose: hashing even an empty input still runs one full round.\n\nThe coefficients were chosen from benchmarks supplied by Geth, OpenEthereum, Besu and Nethermind, combined with knowledge of each hash function's block size.\n\n## Sample code\n\nComparing old and new Keccak-256 cost, using the spec's own test cases:\n\n```ts\nconst oldKeccak = (len: number) =\u003e 30 + 6 * Math.ceil(len / 32);\nconst newKeccak = (len: number) =\u003e 13 + 15 * (Math.floor(len / 136) + 1);\n\nfor (const len of [0, 64, 160]) {\n  console.log(len, oldKeccak(len), newKeccak(len));\n}\n// 0   30 28\n// 64  42 28\n// 160 60 43\n```\n\nThe same idea for SHA256:\n\n```ts\nconst newSha256 = (len: number) =\u003e 10 + 9 * (Math.floor((len + 8) / 64) + 1);\nconsole.log(newSha256(32)); // 19 (old price: 72)\n```\n\n## Things to know\n\n- Status is **Stagnant**. None of these formulas have been adopted; the hash costs on mainnet are still the per-word ones.\n- It depends on [EIP-2046](/eip-2046/) (cheaper precompile calls) and ideally on the ModExp repricing in [EIP-2565](/eip-2565/), which did ship in Berlin. Berlin also introduced [EIP-2929](/eip-2929/), which changed how calls to precompiles are charged.\n- Lowering costs can break contracts that rely on fixed gas amounts for safety, such as re-entrancy guards based on the 2300 gas stipend. The spec argues such designs were never sound.\n"},"ja":{"lang":"ja","tldr":"SHA256 と RIPEMD-160 のプリコンパイル、および KECCAK256 オペコードに対して、32 バイトワードごとではなく内部のハッシュブロックごとに課金する、ベンチマークに基づく新しいガス計算式を提案した。","tags":["gas","precompile","hashing","core","repricing"],"related":[2565,2046,1352,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2666/","markdown":"## 何を解決するのか\n\nEthereum 組み込みのハッシュ関数のガスコストは初期に決められ、入力の 32 バイトワードごとに課金します。しかしハッシュ関数は 32 バイト単位では動作しません。SHA-256 と RIPEMD-160 は 64 バイトのブロックを処理し、Keccak-256 は 1 ラウンドあたり 136 バイトを吸収します。そのため旧来の価格は実際の CPU 作業と合わず、特に RIPEMD は非常に割高でした。\n\nERC-2666 はクライアントチームにこれらの関数のベンチマークを依頼し、内部のブロック構造に沿った計算式を提案しました。また [EIP-2046](/eip-2046/) を見越していました。これはプリコンパイルへの `STATICCALL` を安くするもので、プリコンパイルの価格の一部が補っていたかもしれない大きな固定オーバーヘッドを取り除きます。\n\n## 仕組み\n\nフォークブロックの後、コストは次のようになります（すべて整数除算）。\n\n| 関数 | 現行 | 提案 |\n| --- | --- | --- |\n| SHA256 プリコンパイル `0x02` | 60 + ワードあたり 12 | `10 + ((len + 8) / 64 + 1) * 9` |\n| RIPEMD-160 プリコンパイル `0x03` | 600 + ワードあたり 120 | `6 + ((len + 8) / 64 + 1) * 12` |\n| `KECCAK256` オペコード `0x20` | 30 + ワードあたり 6 | `13 + (len / 136 + 1) * 15` |\n\n`+ 1` の項は意図的に分けてあります。空の入力をハッシュしても、1 ラウンド分の完全な処理が走るためです。\n\n係数は、Geth、OpenEthereum、Besu、Nethermind から提供されたベンチマークと、各ハッシュ関数のブロックサイズの知識を組み合わせて選ばれました。\n\n## サンプルコード\n\n仕様自身のテストケースを使って、Keccak-256 の旧コストと新コストを比較します。\n\n```ts\nconst oldKeccak = (len: number) =\u003e 30 + 6 * Math.ceil(len / 32);\nconst newKeccak = (len: number) =\u003e 13 + 15 * (Math.floor(len / 136) + 1);\n\nfor (const len of [0, 64, 160]) {\n  console.log(len, oldKeccak(len), newKeccak(len));\n}\n// 0   30 28\n// 64  42 28\n// 160 60 43\n```\n\nSHA256 でも同じ考え方です。\n\n```ts\nconst newSha256 = (len: number) =\u003e 10 + 9 * (Math.floor((len + 8) / 64) + 1);\nconsole.log(newSha256(32)); // 19 (old price: 72)\n```\n\n## 知っておくべきこと\n\n- ステータスは **Stagnant** です。これらの計算式はどれも採用されておらず、メインネットのハッシュコストは今もワード単位のままです。\n- [EIP-2046](/eip-2046/)（プリコンパイル呼び出しの値下げ）に依存し、できれば Berlin で実際に導入された [EIP-2565](/eip-2565/) の ModExp 価格見直しにも依存します。Berlin では [EIP-2929](/eip-2929/) も導入され、プリコンパイル呼び出しの課金方法が変わりました。\n- コストの引き下げは、2300 ガスの stipend に基づく再入防止など、安全性を固定のガス量に頼るコントラクトを壊す可能性があります。仕様は、そのような設計はもともと健全ではなかったと主張しています。\n"},"ko":{"lang":"ko","tldr":"SHA256과 RIPEMD-160 프리컴파일, KECCAK256 옵코드에 대해 32바이트 워드가 아니라 내부 해시 블록 단위로 과금하는, 벤치마크 기반의 새로운 가스 공식을 제안했다.","tags":["gas","precompile","hashing","core","repricing"],"related":[2565,2046,1352,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2666/","markdown":"## 어떤 문제를 해결하나요?\n\n이더리움 내장 해시 함수의 가스 비용은 초기에 정해졌으며 입력의 32바이트 워드마다 과금합니다. 하지만 해시 함수는 32바이트 단위로 동작하지 않습니다. SHA-256과 RIPEMD-160은 64바이트 블록을 처리하고, Keccak-256은 라운드마다 136바이트를 흡수합니다. 그래서 기존 가격은 실제 CPU 작업량과 맞지 않았고, 특히 RIPEMD는 매우 비쌌습니다.\n\nERC-2666은 클라이언트 팀에 이 함수들의 벤치마크를 요청하고 내부 블록 구조를 따르는 공식을 제안했습니다. 또한 [EIP-2046](/eip-2046/)을 예상했습니다. 이는 프리컴파일에 대한 `STATICCALL`을 저렴하게 만들어, 일부 프리컴파일 가격이 보상하고 있었을 수 있는 큰 고정 오버헤드를 없애 줍니다.\n\n## 어떻게 동작하나요?\n\n포크 블록 이후 비용은 다음과 같이 바뀝니다(전부 정수 나눗셈).\n\n| 함수 | 현재 | 제안 |\n| --- | --- | --- |\n| SHA256 프리컴파일 `0x02` | 60 + 워드당 12 | `10 + ((len + 8) / 64 + 1) * 9` |\n| RIPEMD-160 프리컴파일 `0x03` | 600 + 워드당 120 | `6 + ((len + 8) / 64 + 1) * 12` |\n| `KECCAK256` 옵코드 `0x20` | 30 + 워드당 6 | `13 + (len / 136 + 1) * 15` |\n\n`+ 1` 항은 일부러 따로 둡니다. 빈 입력을 해시해도 한 라운드 전체가 실행되기 때문입니다.\n\n계수는 Geth, OpenEthereum, Besu, Nethermind가 제공한 벤치마크와 각 해시 함수의 블록 크기에 대한 지식을 결합해 정했습니다.\n\n## 샘플 코드\n\n스펙 자체의 테스트 케이스로 Keccak-256의 기존 비용과 새 비용을 비교합니다.\n\n```ts\nconst oldKeccak = (len: number) =\u003e 30 + 6 * Math.ceil(len / 32);\nconst newKeccak = (len: number) =\u003e 13 + 15 * (Math.floor(len / 136) + 1);\n\nfor (const len of [0, 64, 160]) {\n  console.log(len, oldKeccak(len), newKeccak(len));\n}\n// 0   30 28\n// 64  42 28\n// 160 60 43\n```\n\nSHA256도 같은 방식입니다.\n\n```ts\nconst newSha256 = (len: number) =\u003e 10 + 9 * (Math.floor((len + 8) / 64) + 1);\nconsole.log(newSha256(32)); // 19 (old price: 72)\n```\n\n## 알아둘 점\n\n- 상태는 **Stagnant**입니다. 이 공식 중 어느 것도 채택되지 않았으며, 메인넷의 해시 비용은 여전히 워드 단위입니다.\n- [EIP-2046](/eip-2046/)(더 저렴한 프리컴파일 호출)에 의존하며, 이상적으로는 Berlin에서 실제로 적용된 [EIP-2565](/eip-2565/)의 ModExp 가격 재조정에도 의존합니다. Berlin은 [EIP-2929](/eip-2929/)도 도입해 프리컴파일 호출의 과금 방식을 바꿨습니다.\n- 비용을 낮추면 2300 gas stipend에 기반한 재진입 방지처럼 안전을 고정된 가스량에 의존하는 컨트랙트가 깨질 수 있습니다. 스펙은 그런 설계는 애초에 건전하지 않았다고 주장합니다.\n"},"zh":{"lang":"zh","tldr":"为 SHA256 和 RIPEMD-160 预编译以及 KECCAK256 操作码提出了新的、基于基准测试的 gas 公式，按内部哈希块而非 32 字节字收费。","tags":["gas","precompile","hashing","core","repricing"],"related":[2565,2046,1352,2929],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2666/","markdown":"## 它解决什么问题？\n\n以太坊内置哈希函数的 gas 成本定得很早，按输入的每个 32 字节字收费。但哈希函数并不以 32 字节为单位工作。SHA-256 和 RIPEMD-160 处理 64 字节的块，Keccak-256 每轮吸收 136 字节。因此旧价格与真实的 CPU 工作量并不匹配，尤其是 RIPEMD 非常昂贵。\n\nERC-2666 请客户端团队对这些函数做基准测试，并提出了遵循内部块结构的公式。它还预期了 [EIP-2046](/eip-2046/)：该提案会让对预编译的 `STATICCALL` 变得便宜，从而去掉某些预编译价格可能一直在弥补的一大笔固定开销。\n\n## 它如何运作\n\n分叉区块之后，成本将变为（全程使用整数除法）：\n\n| 函数 | 当前 | 提议 |\n| --- | --- | --- |\n| SHA256 预编译 `0x02` | 60 + 每字 12 | `10 + ((len + 8) / 64 + 1) * 9` |\n| RIPEMD-160 预编译 `0x03` | 600 + 每字 120 | `6 + ((len + 8) / 64 + 1) * 12` |\n| `KECCAK256` 操作码 `0x20` | 30 + 每字 6 | `13 + (len / 136 + 1) * 15` |\n\n`+ 1` 项有意单独保留：即使对空输入做哈希，也要完整运行一轮。\n\n这些系数是根据 Geth、OpenEthereum、Besu 和 Nethermind 提供的基准测试，并结合各哈希函数的块大小选定的。\n\n## 示例代码\n\n使用规范自带的测试用例，对比 Keccak-256 的新旧成本：\n\n```ts\nconst oldKeccak = (len: number) =\u003e 30 + 6 * Math.ceil(len / 32);\nconst newKeccak = (len: number) =\u003e 13 + 15 * (Math.floor(len / 136) + 1);\n\nfor (const len of [0, 64, 160]) {\n  console.log(len, oldKeccak(len), newKeccak(len));\n}\n// 0   30 28\n// 64  42 28\n// 160 60 43\n```\n\nSHA256 的思路相同：\n\n```ts\nconst newSha256 = (len: number) =\u003e 10 + 9 * (Math.floor((len + 8) / 64) + 1);\nconsole.log(newSha256(32)); // 19 (old price: 72)\n```\n\n## 需要注意\n\n- 状态为 **Stagnant**。这些公式都没有被采纳；主网上的哈希成本仍然是按字计费。\n- 它依赖 [EIP-2046](/eip-2046/)（更便宜的预编译调用），最好还依赖 [EIP-2565](/eip-2565/) 中的 ModExp 重新定价，后者已在 Berlin 中上线。Berlin 还引入了 [EIP-2929](/eip-2929/)，改变了对预编译调用的收费方式。\n- 降低成本可能会破坏那些依赖固定 gas 量来保证安全的合约，例如基于 2300 gas stipend 的重入保护。规范认为这类设计本来就不可靠。\n"}}}
