{"eip":1108,"title":"Reduce alt_bn128 precompile gas costs","description":"The elliptic curve arithmetic precompiles are currently overpriced. Re-pricing the precompiles would greatly assist a number of privacy solutions and scaling solutions on Ethereum.","authors":["Antonio Salazar Cardozo (@shadowfiend)","Zachary Williamson (@zac-williamson)"],"status":"Final","type":"Standards Track","category":"Core","created":"2018-05-21","requires":[196,197],"discussionsTo":"https://ethereum-magicians.org/t/eip-1108-reduce-alt-bn128-precompile-gas-costs/3206","repo":"EIPs","label":"EIP-1108","officialUrl":"https://eips.ethereum.org/EIPS/eip-1108","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1108.md","url":"https://eips.huatuo.xyz/eip-1108/","tldr":{"en":"Cut the gas price of the alt_bn128 elliptic-curve precompiles (add, multiply, pairing) by roughly 3–7×, making on-chain zk-SNARK verification and privacy protocols far cheaper.","ja":"alt_bn128 楕円曲線プリコンパイル（加算、乗算、ペアリング）の gas 価格をおよそ 3〜7 分の 1 に引き下げ、オンチェーンでの zk-SNARK 検証やプライバシープロトコルをはるかに安価にした。","ko":"alt_bn128 타원곡선 프리컴파일(덧셈, 곱셈, 페어링)의 gas 가격을 대략 3~7배 낮춰, 온체인 zk-SNARK 검증과 프라이버시 프로토콜을 훨씬 저렴하게 만들었다.","zh":"把 alt_bn128 椭圆曲线预编译（加法、乘法、配对）的 gas 价格大致降低了 3 到 7 倍，使链上 zk-SNARK 验证和隐私协议便宜得多。"},"tags":["gas","precompile","cryptography","zk","istanbul"],"explainers":{"en":{"lang":"en","tldr":"Cut the gas price of the alt_bn128 elliptic-curve precompiles (add, multiply, pairing) by roughly 3–7×, making on-chain zk-SNARK verification and privacy protocols far cheaper.","tags":["gas","precompile","cryptography","zk","istanbul"],"related":[196,197,1829,2537],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-1108/","markdown":"## What problem does it solve?\n\n[EIP-196](/eip-196/) and [EIP-197](/eip-197/) added precompiled contracts for arithmetic on the `alt_bn128` (BN254) curve. They are the building blocks for verifying zk-SNARK proofs (for example Groth16) inside a smart contract. Their gas prices were set in 2017 based on the client code of the time.\n\nDuring 2018–2019 both Geth (which switched to Cloudflare's bn256 library) and Parity (optimised `bn` crate) became much faster at these operations, roughly an order of magnitude for Geth. The gas prices no longer matched the real cost, so privacy tools, rollups and other SNARK-based systems were paying far more than the computation deserved. EIP-1108 brings the prices back in line. It shipped in the Istanbul upgrade.\n\n## How it works\n\nOnly the gas schedule changes; the precompiles' inputs, outputs and behaviour stay exactly the same.\n\n| Precompile | Address | Before | After |\n| --- | --- | --- | --- |\n| `ECADD` | `0x06` | 500 | 150 |\n| `ECMUL` | `0x07` | 40,000 | 6,000 |\n| Pairing check | `0x08` | 80,000·k + 100,000 | 34,000·k + 45,000 |\n\n`k` is the number of point pairs passed to the pairing check.\n\nThe new numbers were derived from benchmarks of the slower client (Parity). The authors took `ecrecover` (3,000 gas, ~116 µs) as a \"fair\" reference, giving about 25.86 gas per microsecond, then split measured pairing time into a fixed part and a per-pairing part.\n\nA typical Groth16 verification uses 4 pairings, so the pairing step alone drops from 420,000 gas to 181,000 gas, plus the much cheaper `ECMUL`/`ECADD` calls used to build the public-input point.\n\n## Sample code\n\nCalling `ECADD` directly from Solidity. Most projects use a generated verifier (snarkjs, gnark, etc.) that wraps these calls, but they all compile down to `staticcall`s like this:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary BN254 {\n    struct G1 { uint256 x; uint256 y; }\n\n    /// Point addition via the 0x06 precompile (150 gas since EIP-1108).\n    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        uint256[4] memory input = [p.x, p.y, q.x, q.y];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x06, input, 0x80, r, 0x40)\n        }\n        require(ok, \"ecAdd failed\");\n    }\n\n    /// Scalar multiplication via the 0x07 precompile (6,000 gas since EIP-1108).\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        uint256[3] memory input = [p.x, p.y, s];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x07, input, 0x60, r, 0x40)\n        }\n        require(ok, \"ecMul failed\");\n    }\n}\n```\n\nEstimating the pairing cost before and after:\n\n```ts\nconst pairingGas = (k: number, istanbul = true) =\u003e\n  istanbul ? 34_000 * k + 45_000 : 80_000 * k + 100_000;\n\nconsole.log(pairingGas(4));        // 181000\nconsole.log(pairingGas(4, false)); // 420000\n```\n\n## Things to know\n\n- The rationale text quotes a rounded \"~35,000·k + 45,000\"; the normative table, and what clients implement, is **34,000·k + 45,000**.\n- Nothing about the cryptography changed, so existing verifier contracts kept working and simply became cheaper.\n- BN254 offers roughly 100 bits of security by current estimates, below its original 128-bit target. Newer designs often prefer BLS12-381, which got its own precompiles in [EIP-2537](/eip-2537/).\n- The proposal was framed as a stop-gap alongside the more general curve precompile [EIP-1829](/eip-1829/), which never advanced.\n"},"ja":{"lang":"ja","tldr":"alt_bn128 楕円曲線プリコンパイル（加算、乗算、ペアリング）の gas 価格をおよそ 3〜7 分の 1 に引き下げ、オンチェーンでの zk-SNARK 検証やプライバシープロトコルをはるかに安価にした。","tags":["gas","precompile","cryptography","zk","istanbul"],"related":[196,197,1829,2537],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-1108/","markdown":"## 何を解決するのか\n\n[EIP-196](/eip-196/) と [EIP-197](/eip-197/) は、`alt_bn128`（BN254）曲線上の演算のためのプリコンパイルドコントラクトを追加しました。これらは、スマートコントラクト内で zk-SNARK の証明（たとえば Groth16）を検証するための部品です。その gas 価格は 2017 年に、当時のクライアントのコードに基づいて決められました。\n\n2018〜2019 年にかけて、Geth（Cloudflare の bn256 ライブラリに切り替え）と Parity（最適化された `bn` クレート）の両方が、これらの演算を大幅に高速化し、Geth ではおよそ 1 桁の改善となりました。gas 価格は実際のコストと合わなくなり、プライバシーツール、ロールアップ、その他の SNARK ベースのシステムは、計算に見合う額よりはるかに多く支払っていました。EIP-1108 は価格を実態に合わせ直します。Istanbul アップグレードで導入されました。\n\n## 仕組み\n\n変更されるのは gas スケジュールだけです。プリコンパイルの入力、出力、挙動はまったく同じままです。\n\n| プリコンパイル | アドレス | 変更前 | 変更後 |\n| --- | --- | --- | --- |\n| `ECADD` | `0x06` | 500 | 150 |\n| `ECMUL` | `0x07` | 40,000 | 6,000 |\n| ペアリングチェック | `0x08` | 80,000·k + 100,000 | 34,000·k + 45,000 |\n\n`k` は、ペアリングチェックに渡される点のペアの数です。\n\n新しい数値は、遅い方のクライアント（Parity）のベンチマークから導かれました。作者たちは `ecrecover`（3,000 gas、約 116 µs）を「公正な」基準として採用し、1 マイクロ秒あたり約 25.86 gas を得ました。そして、測定したペアリング時間を固定部分とペアリングごとの部分に分けました。\n\n典型的な Groth16 の検証では 4 回のペアリングを使うため、ペアリングの段階だけで 420,000 gas から 181,000 gas に下がります。さらに、公開入力の点を構築するための `ECMUL`/`ECADD` の呼び出しもはるかに安くなります。\n\n## サンプルコード\n\nSolidity から `ECADD` を直接呼び出す例です。ほとんどのプロジェクトは、これらの呼び出しをラップする生成済みの検証コントラクト（snarkjs、gnark など）を使いますが、いずれも最終的にはこのような `staticcall` にコンパイルされます。\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary BN254 {\n    struct G1 { uint256 x; uint256 y; }\n\n    /// Point addition via the 0x06 precompile (150 gas since EIP-1108).\n    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        uint256[4] memory input = [p.x, p.y, q.x, q.y];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x06, input, 0x80, r, 0x40)\n        }\n        require(ok, \"ecAdd failed\");\n    }\n\n    /// Scalar multiplication via the 0x07 precompile (6,000 gas since EIP-1108).\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        uint256[3] memory input = [p.x, p.y, s];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x07, input, 0x60, r, 0x40)\n        }\n        require(ok, \"ecMul failed\");\n    }\n}\n```\n\n変更前後のペアリングコストの見積もり:\n\n```ts\nconst pairingGas = (k: number, istanbul = true) =\u003e\n  istanbul ? 34_000 * k + 45_000 : 80_000 * k + 100_000;\n\nconsole.log(pairingGas(4));        // 181000\nconsole.log(pairingGas(4, false)); // 420000\n```\n\n## 知っておくべきこと\n\n- 根拠の説明文には丸めた「~35,000·k + 45,000」が引用されていますが、規範となる表、そしてクライアントが実装しているのは **34,000·k + 45,000** です。\n- 暗号技術自体は何も変わらなかったため、既存の検証コントラクトはそのまま動作し、ただ安くなりました。\n- BN254 のセキュリティは、現在の見積もりでおよそ 100 ビットで、当初の 128 ビットという目標を下回ります。新しい設計では BLS12-381 が好まれることが多く、それには [EIP-2537](/eip-2537/) で専用のプリコンパイルが追加されました。\n- この提案は、より汎用的な曲線プリコンパイルである [EIP-1829](/eip-1829/) と並ぶ暫定措置として位置づけられていましたが、後者は進展しませんでした。\n"},"ko":{"lang":"ko","tldr":"alt_bn128 타원곡선 프리컴파일(덧셈, 곱셈, 페어링)의 gas 가격을 대략 3~7배 낮춰, 온체인 zk-SNARK 검증과 프라이버시 프로토콜을 훨씬 저렴하게 만들었다.","tags":["gas","precompile","cryptography","zk","istanbul"],"related":[196,197,1829,2537],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-1108/","markdown":"## 어떤 문제를 해결하나요?\n\n[EIP-196](/eip-196/)과 [EIP-197](/eip-197/)은 `alt_bn128`(BN254) 곡선 연산을 위한 프리컴파일 컨트랙트를 추가했습니다. 이들은 스마트 컨트랙트 안에서 zk-SNARK 증명(예: Groth16)을 검증하는 기본 구성 요소입니다. gas 가격은 2017년에 당시의 클라이언트 코드를 기준으로 정해졌습니다.\n\n2018~2019년에 Geth(Cloudflare의 bn256 라이브러리로 전환)와 Parity(최적화된 `bn` 크레이트) 모두 이 연산이 훨씬 빨라졌고, Geth는 대략 한 자릿수 배(order of magnitude) 빨라졌습니다. gas 가격이 실제 비용과 맞지 않게 되어, 프라이버시 도구, 롤업, 그 밖의 SNARK 기반 시스템은 연산에 걸맞은 수준보다 훨씬 많은 비용을 내고 있었습니다. EIP-1108은 가격을 다시 실제에 맞춥니다. Istanbul 업그레이드에서 적용되었습니다.\n\n## 어떻게 동작하나요?\n\n바뀌는 것은 gas 일정뿐이며, 프리컴파일의 입력, 출력, 동작은 완전히 그대로입니다.\n\n| 프리컴파일 | 주소 | 변경 전 | 변경 후 |\n| --- | --- | --- | --- |\n| `ECADD` | `0x06` | 500 | 150 |\n| `ECMUL` | `0x07` | 40,000 | 6,000 |\n| 페어링 검사 | `0x08` | 80,000·k + 100,000 | 34,000·k + 45,000 |\n\n`k`는 페어링 검사에 전달되는 점 쌍의 개수입니다.\n\n새 수치는 더 느린 클라이언트(Parity)의 벤치마크에서 도출되었습니다. 작성자들은 `ecrecover`(3,000 gas, 약 116 µs)를 \"공정한\" 기준으로 삼아 마이크로초당 약 25.86 gas를 얻었고, 측정된 페어링 시간을 고정 부분과 페어링당 부분으로 나누었습니다.\n\n일반적인 Groth16 검증은 페어링을 4번 사용하므로, 페어링 단계만으로 420,000 gas에서 181,000 gas로 줄어듭니다. 여기에 공개 입력 점을 만드는 데 쓰이는 `ECMUL`/`ECADD` 호출도 훨씬 저렴해집니다.\n\n## 샘플 코드\n\nSolidity에서 `ECADD`를 직접 호출하는 예입니다. 대부분의 프로젝트는 이 호출들을 감싸는 생성된 검증기(snarkjs, gnark 등)를 쓰지만, 모두 결국 이런 `staticcall`로 컴파일됩니다.\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary BN254 {\n    struct G1 { uint256 x; uint256 y; }\n\n    /// Point addition via the 0x06 precompile (150 gas since EIP-1108).\n    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        uint256[4] memory input = [p.x, p.y, q.x, q.y];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x06, input, 0x80, r, 0x40)\n        }\n        require(ok, \"ecAdd failed\");\n    }\n\n    /// Scalar multiplication via the 0x07 precompile (6,000 gas since EIP-1108).\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        uint256[3] memory input = [p.x, p.y, s];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x07, input, 0x60, r, 0x40)\n        }\n        require(ok, \"ecMul failed\");\n    }\n}\n```\n\n변경 전후의 페어링 비용 추정:\n\n```ts\nconst pairingGas = (k: number, istanbul = true) =\u003e\n  istanbul ? 34_000 * k + 45_000 : 80_000 * k + 100_000;\n\nconsole.log(pairingGas(4));        // 181000\nconsole.log(pairingGas(4, false)); // 420000\n```\n\n## 알아둘 점\n\n- 근거 설명 텍스트에는 반올림한 \"~35,000·k + 45,000\"이 인용되어 있지만, 규범적인 표와 클라이언트가 구현한 값은 **34,000·k + 45,000**입니다.\n- 암호학적으로는 아무것도 바뀌지 않았으므로 기존 검증기 컨트랙트는 계속 동작했고 단지 더 저렴해졌습니다.\n- 현재 추정으로 BN254는 약 100비트의 보안성을 제공하며, 원래 목표였던 128비트보다 낮습니다. 새로운 설계는 BLS12-381을 선호하는 경우가 많고, 이는 [EIP-2537](/eip-2537/)에서 자체 프리컴파일을 얻었습니다.\n- 이 제안은 더 범용적인 곡선 프리컴파일인 [EIP-1829](/eip-1829/)와 나란히 놓인 임시방편으로 제시되었으나, 후자는 진전되지 못했습니다.\n"},"zh":{"lang":"zh","tldr":"把 alt_bn128 椭圆曲线预编译（加法、乘法、配对）的 gas 价格大致降低了 3 到 7 倍，使链上 zk-SNARK 验证和隐私协议便宜得多。","tags":["gas","precompile","cryptography","zk","istanbul"],"related":[196,197,1829,2537],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-1108/","markdown":"## 它解决什么问题？\n\n[EIP-196](/eip-196/) 和 [EIP-197](/eip-197/) 添加了用于 `alt_bn128`（BN254）曲线运算的预编译合约。它们是在智能合约内验证 zk-SNARK 证明（例如 Groth16）的基础构件。它们的 gas 价格是 2017 年根据当时的客户端代码设定的。\n\n在 2018 至 2019 年间，Geth（改用了 Cloudflare 的 bn256 库）和 Parity（优化后的 `bn` crate）执行这些运算都变得快得多，Geth 大约快了一个数量级。gas 价格不再与真实成本相符，因此隐私工具、rollup 和其他基于 SNARK 的系统支付的费用远高于这些计算应有的水平。EIP-1108 让价格重新回到合理水平。它随 Istanbul 升级上线。\n\n## 它如何运作\n\n只有 gas 价目表发生变化；预编译合约的输入、输出和行为完全保持不变。\n\n| 预编译 | 地址 | 之前 | 之后 |\n| --- | --- | --- | --- |\n| `ECADD` | `0x06` | 500 | 150 |\n| `ECMUL` | `0x07` | 40,000 | 6,000 |\n| 配对检查 | `0x08` | 80,000·k + 100,000 | 34,000·k + 45,000 |\n\n`k` 是传给配对检查的点对数量。\n\n新的数字来自对较慢客户端（Parity）的基准测试。作者以 `ecrecover`（3,000 gas，约 116 µs）作为\"公平\"的参照，得到约每微秒 25.86 gas，然后把测得的配对时间拆分为固定部分和每个配对的部分。\n\n一次典型的 Groth16 验证使用 4 次配对，因此仅配对这一步就从 420,000 gas 降到 181,000 gas，另外用于构造公共输入点的 `ECMUL`/`ECADD` 调用也便宜得多。\n\n## 示例代码\n\n直接从 Solidity 调用 `ECADD`。大多数项目使用封装这些调用的生成式验证器（snarkjs、gnark 等），但它们最终都会编译成这样的 `staticcall`：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary BN254 {\n    struct G1 { uint256 x; uint256 y; }\n\n    /// Point addition via the 0x06 precompile (150 gas since EIP-1108).\n    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        uint256[4] memory input = [p.x, p.y, q.x, q.y];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x06, input, 0x80, r, 0x40)\n        }\n        require(ok, \"ecAdd failed\");\n    }\n\n    /// Scalar multiplication via the 0x07 precompile (6,000 gas since EIP-1108).\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        uint256[3] memory input = [p.x, p.y, s];\n        bool ok;\n        assembly {\n            ok := staticcall(gas(), 0x07, input, 0x60, r, 0x40)\n        }\n        require(ok, \"ecMul failed\");\n    }\n}\n```\n\n估算改动前后的配对成本：\n\n```ts\nconst pairingGas = (k: number, istanbul = true) =\u003e\n  istanbul ? 34_000 * k + 45_000 : 80_000 * k + 100_000;\n\nconsole.log(pairingGas(4));        // 181000\nconsole.log(pairingGas(4, false)); // 420000\n```\n\n## 需要注意\n\n- 原理说明文字中引用了取整后的\"~35,000·k + 45,000\"；规范性的表格以及客户端实际实现的是 **34,000·k + 45,000**。\n- 密码学本身没有任何变化，因此现有的验证器合约继续正常工作，只是变得更便宜了。\n- 按目前的估计，BN254 提供大约 100 位的安全性，低于其最初 128 位的目标。较新的设计往往更青睐 BLS12-381，它在 [EIP-2537](/eip-2537/) 中获得了自己的预编译。\n- 该提案被定位为与更通用的曲线预编译 [EIP-1829](/eip-1829/) 并行的权宜之计，而后者始终没有推进。\n"}},"requiredBy":[1679,3068]}
