{"eip":196,"title":"Precompiled contracts for addition and scalar multiplication on the elliptic curve alt_bn128","description":"Precompiled contracts for elliptic curve operations are required in order to perform zkSNARK verification within the block gas limit.","authors":["Christian Reitwiessner \u003cchris@ethereum.org\u003e"],"status":"Final","type":"Standards Track","category":"Core","created":"2017-02-02","repo":"EIPs","label":"EIP-196","officialUrl":"https://eips.ethereum.org/EIPS/eip-196","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-196.md","url":"https://eips.huatuo.xyz/eip-196/","tldr":{"en":"Added precompiled contracts at 0x06 and 0x07 for point addition and scalar multiplication on the alt_bn128 curve, making zkSNARK verification affordable on Ethereum.","ja":"alt_bn128 曲線上の点の加算とスカラー倍算のためのプリコンパイルコントラクトを 0x06 と 0x07 に追加し、Ethereum 上での zkSNARK 検証を現実的なコストにした。","ko":"alt_bn128 곡선의 점 덧셈과 스칼라 곱셈을 위한 프리컴파일 컨트랙트를 0x06과 0x07에 추가해, 이더리움에서 zkSNARK 검증을 감당할 만한 비용으로 만들었다.","zh":"在 0x06 和 0x07 添加预编译合约，用于 alt_bn128 曲线上的点加法和标量乘法，使以太坊上验证 zkSNARK 的成本变得可承受。"},"tags":["precompile","cryptography","zk","core","byzantium"],"explainers":{"en":{"lang":"en","tldr":"Added precompiled contracts at 0x06 and 0x07 for point addition and scalar multiplication on the alt_bn128 curve, making zkSNARK verification affordable on Ethereum.","tags":["precompile","cryptography","zk","core","byzantium"],"related":[197,1108,198,609],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-196/","markdown":"## What problem does it solve?\n\nzkSNARKs let someone prove a statement is true without revealing why. On Ethereum that means privacy (hidden inputs) and scaling (a small proof that stands for a lot of work). Verifying a proof needs elliptic-curve arithmetic. Written in EVM bytecode, that arithmetic was far too expensive to fit in a block.\n\nEIP-196 builds the two most basic curve operations into the protocol as precompiled contracts. Together with the pairing check in [EIP-197](/eip-197/), they make on-chain SNARK verification practical. Both shipped in the Byzantium upgrade ([EIP-609](/eip-609/)).\n\n## How it works\n\nThe curve is `alt_bn128` (also called BN254), `y² = x³ + 3` over a prime field whose modulus `p` is given in the spec. It was chosen because it is pairing-friendly and shares tooling with Zcash.\n\n| Address | Operation | Input (bytes) | Output (bytes) |\n| --- | --- | --- | --- |\n| `0x06` | ECADD: `P + Q` | `x1, y1, x2, y2` (128) | `x, y` (64) |\n| `0x07` | ECMUL: `s · P` | `x, y, s` (96) | `x, y` (64) |\n\nEncoding rules:\n\n- Every field element and scalar is a 32-byte big-endian integer. A point is `(x, y)`, and the point at infinity is `(0, 0)`.\n- Short input is padded with zeros on the right. Extra input is ignored.\n- If a point is not on the curve, or a coordinate is `\u003e= p`, the call **fails and consumes all gas** it was given. The scalar may be any 256-bit value.\n\nThe original gas costs were 500 for ECADD and 40,000 for ECMUL.\n\n## Sample code\n\nCalling the precompiles from Solidity:\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    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x06).staticcall(abi.encode(p.x, p.y, q.x, q.y));\n        require(ok, \"ecAdd failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x07).staticcall(abi.encode(p.x, p.y, s));\n        require(ok, \"ecMul failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n}\n\n// Generator of G1 is (1, 2); mul(G1(1, 2), 2) returns 2·G\n```\n\n## Things to know\n\n- Gas prices were cut by [EIP-1108](/eip-1108/) in the Istanbul upgrade to 150 (ECADD) and 6,000 (ECMUL). Do not hard-code the original numbers.\n- Invalid input burns all forwarded gas. Forward only a bounded amount if your contract handles untrusted points.\n- The precompiles only cover the G1 group. Pairing checks, which use G2 points, are in [EIP-197](/eip-197/).\n- BN254 is estimated to give somewhat less than its originally assumed 128-bit security. Newer designs often prefer BLS12-381, but BN254 remains widely used by deployed SNARK verifiers on Ethereum.\n"},"ja":{"lang":"ja","tldr":"alt_bn128 曲線上の点の加算とスカラー倍算のためのプリコンパイルコントラクトを 0x06 と 0x07 に追加し、Ethereum 上での zkSNARK 検証を現実的なコストにした。","tags":["precompile","cryptography","zk","core","byzantium"],"related":[197,1108,198,609],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-196/","markdown":"## 何を解決するのか\n\nzkSNARK を使うと、ある主張が真であることを、その理由を明かさずに証明できます。Ethereum では、プライバシー（入力を隠せる）とスケーリング（多くの計算を表す小さな証明）を意味します。証明の検証には楕円曲線の演算が必要です。EVM バイトコードで書くと、その演算はブロックに収まらないほど高価でした。\n\nEIP-196 は、最も基本的な 2 つの曲線演算を、プリコンパイルコントラクトとしてプロトコルに組み込みます。[EIP-197](/eip-197/) のペアリングチェックと合わせて、オンチェーンでの SNARK 検証が現実的になります。どちらも Byzantium アップグレード（[EIP-609](/eip-609/)）で出荷されました。\n\n## 仕組み\n\n曲線は `alt_bn128`（BN254 とも呼ばれる）で、仕様書に記された素数 `p` を法とする素体上の `y² = x³ + 3` です。ペアリングに適していて、Zcash とツールを共有できることから選ばれました。\n\n| アドレス | 演算 | 入力（バイト） | 出力（バイト） |\n| --- | --- | --- | --- |\n| `0x06` | ECADD: `P + Q` | `x1, y1, x2, y2`（128） | `x, y`（64） |\n| `0x07` | ECMUL: `s · P` | `x, y, s`（96） | `x, y`（64） |\n\nエンコードのルール:\n\n- すべての体の元とスカラーは 32 バイトのビッグエンディアン整数です。点は `(x, y)` で、無限遠点は `(0, 0)` です。\n- 入力が短い場合は右側がゼロで埋められます。余分な入力は無視されます。\n- 点が曲線上にない場合、または座標が `\u003e= p` の場合、呼び出しは**失敗し、渡されたガスをすべて消費します**。スカラーは任意の 256 ビット値でかまいません。\n\n当初のガスコストは ECADD が 500、ECMUL が 40,000 でした。\n\n## サンプルコード\n\nSolidity からプリコンパイルを呼び出す例:\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    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x06).staticcall(abi.encode(p.x, p.y, q.x, q.y));\n        require(ok, \"ecAdd failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x07).staticcall(abi.encode(p.x, p.y, s));\n        require(ok, \"ecMul failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n}\n\n// Generator of G1 is (1, 2); mul(G1(1, 2), 2) returns 2·G\n```\n\n## 知っておくべきこと\n\n- ガス価格は Istanbul アップグレードの [EIP-1108](/eip-1108/) で、150（ECADD）と 6,000（ECMUL）に引き下げられました。当初の数値をハードコードしないでください。\n- 不正な入力は転送したガスをすべて燃やします。コントラクトが信頼できない点を扱う場合は、転送するガスを有限の量に限ってください。\n- プリコンパイルが扱うのは G1 群だけです。G2 の点を使うペアリングチェックは [EIP-197](/eip-197/) にあります。\n- BN254 のセキュリティは、当初想定された 128 ビットをやや下回ると見積もられています。新しい設計では BLS12-381 が好まれることが多いものの、BN254 は Ethereum 上にデプロイされた SNARK 検証器で今も広く使われています。\n"},"ko":{"lang":"ko","tldr":"alt_bn128 곡선의 점 덧셈과 스칼라 곱셈을 위한 프리컴파일 컨트랙트를 0x06과 0x07에 추가해, 이더리움에서 zkSNARK 검증을 감당할 만한 비용으로 만들었다.","tags":["precompile","cryptography","zk","core","byzantium"],"related":[197,1108,198,609],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-196/","markdown":"## 어떤 문제를 해결하나요?\n\nzkSNARK를 사용하면 어떤 명제가 참임을 그 이유를 드러내지 않고 증명할 수 있습니다. 이더리움에서는 프라이버시(입력 숨기기)와 확장성(많은 계산을 대표하는 작은 증명)을 의미합니다. 증명을 검증하려면 타원 곡선 연산이 필요합니다. EVM 바이트코드로 작성하면 이 연산은 한 블록에 들어가기엔 너무 비쌌습니다.\n\nEIP-196은 가장 기본적인 두 곡선 연산을 프리컴파일 컨트랙트로 프로토콜에 내장합니다. [EIP-197](/eip-197/)의 페어링 검사와 함께 쓰면 온체인 SNARK 검증이 현실적이 됩니다. 둘 다 Byzantium 업그레이드([EIP-609](/eip-609/))에서 배포되었습니다.\n\n## 어떻게 동작하나요?\n\n곡선은 `alt_bn128`(BN254라고도 함)이며, 명세서에 제시된 소수 `p`를 법으로 하는 소수체 위의 `y² = x³ + 3`입니다. 페어링에 적합하고 Zcash와 도구를 공유한다는 이유로 선택되었습니다.\n\n| 주소 | 연산 | 입력(바이트) | 출력(바이트) |\n| --- | --- | --- | --- |\n| `0x06` | ECADD: `P + Q` | `x1, y1, x2, y2` (128) | `x, y` (64) |\n| `0x07` | ECMUL: `s · P` | `x, y, s` (96) | `x, y` (64) |\n\n인코딩 규칙:\n\n- 모든 체의 원소와 스칼라는 32바이트 빅 엔디언 정수입니다. 점은 `(x, y)`이고 무한원점은 `(0, 0)`입니다.\n- 입력이 짧으면 오른쪽에 0이 채워집니다. 남는 입력은 무시됩니다.\n- 점이 곡선 위에 있지 않거나 좌표가 `\u003e= p`이면, 호출은 **실패하고 받은 gas를 모두 소비합니다**. 스칼라는 어떤 256비트 값이어도 됩니다.\n\n처음의 gas 비용은 ECADD가 500, ECMUL이 40,000이었습니다.\n\n## 샘플 코드\n\nSolidity에서 프리컴파일 호출하기:\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    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x06).staticcall(abi.encode(p.x, p.y, q.x, q.y));\n        require(ok, \"ecAdd failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x07).staticcall(abi.encode(p.x, p.y, s));\n        require(ok, \"ecMul failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n}\n\n// Generator of G1 is (1, 2); mul(G1(1, 2), 2) returns 2·G\n```\n\n## 알아둘 점\n\n- gas 가격은 Istanbul 업그레이드의 [EIP-1108](/eip-1108/)로 150(ECADD)과 6,000(ECMUL)으로 낮아졌습니다. 최초의 수치를 하드코딩하지 마세요.\n- 잘못된 입력은 전달한 gas를 모두 태웁니다. 컨트랙트가 신뢰할 수 없는 점을 다룬다면 제한된 양만 전달하세요.\n- 이 프리컴파일은 G1 군만 다룹니다. G2 점을 사용하는 페어링 검사는 [EIP-197](/eip-197/)에 있습니다.\n- BN254의 보안 강도는 처음 가정했던 128비트보다 다소 낮은 것으로 추정됩니다. 최신 설계는 BLS12-381을 선호하는 경우가 많지만, BN254는 이더리움에 배포된 SNARK 검증기에서 여전히 널리 쓰입니다.\n"},"zh":{"lang":"zh","tldr":"在 0x06 和 0x07 添加预编译合约，用于 alt_bn128 曲线上的点加法和标量乘法，使以太坊上验证 zkSNARK 的成本变得可承受。","tags":["precompile","cryptography","zk","core","byzantium"],"related":[197,1108,198,609],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-196/","markdown":"## 它解决什么问题？\n\nzkSNARK 让人可以在不透露原因的情况下证明某个陈述为真。在以太坊上，这意味着隐私（隐藏输入）和扩容（用一个很小的证明代表大量计算）。验证证明需要椭圆曲线运算。用 EVM 字节码来写，这些运算的成本高得无法放进一个区块。\n\nEIP-196 把两个最基本的曲线运算作为预编译合约内置到协议中。与 [EIP-197](/eip-197/) 中的配对检查一起，它们让链上 SNARK 验证变得可行。两者都随 Byzantium 升级（[EIP-609](/eip-609/)）上线。\n\n## 它如何运作\n\n所用曲线是 `alt_bn128`（也称 BN254），即在素数域上的 `y² = x³ + 3`，素数模 `p` 在规范中给出。选择它是因为它适合配对运算，并且与 Zcash 共用工具。\n\n| 地址 | 运算 | 输入（字节） | 输出（字节） |\n| --- | --- | --- | --- |\n| `0x06` | ECADD: `P + Q` | `x1, y1, x2, y2`（128） | `x, y`（64） |\n| `0x07` | ECMUL: `s · P` | `x, y, s`（96） | `x, y`（64） |\n\n编码规则：\n\n- 每个域元素和标量都是 32 字节的大端整数。点表示为 `(x, y)`，无穷远点为 `(0, 0)`。\n- 输入过短时，在右侧用零补齐。多余的输入会被忽略。\n- 如果某个点不在曲线上，或某个坐标 `\u003e= p`，调用会**失败并消耗其获得的全部 gas**。标量可以是任意 256 位的值。\n\n最初的 gas 费用是 ECADD 为 500，ECMUL 为 40,000。\n\n## 示例代码\n\n在 Solidity 中调用这些预编译合约：\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    function add(G1 memory p, G1 memory q) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x06).staticcall(abi.encode(p.x, p.y, q.x, q.y));\n        require(ok, \"ecAdd failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n\n    function mul(G1 memory p, uint256 s) internal view returns (G1 memory r) {\n        (bool ok, bytes memory out) = address(0x07).staticcall(abi.encode(p.x, p.y, s));\n        require(ok, \"ecMul failed\");\n        (r.x, r.y) = abi.decode(out, (uint256, uint256));\n    }\n}\n\n// Generator of G1 is (1, 2); mul(G1(1, 2), 2) returns 2·G\n```\n\n## 需要注意\n\n- 在 Istanbul 升级中，[EIP-1108](/eip-1108/) 把 gas 价格降低到 150（ECADD）和 6,000（ECMUL）。不要硬编码最初的数字。\n- 无效输入会烧掉转发的全部 gas。如果你的合约要处理不可信的点，只转发有限数量的 gas。\n- 这些预编译合约只覆盖 G1 群。使用 G2 点的配对检查在 [EIP-197](/eip-197/) 中。\n- 据估计，BN254 的安全强度略低于最初设想的 128 位。较新的设计通常更倾向于 BLS12-381，但 BN254 仍被以太坊上已部署的 SNARK 验证器广泛使用。\n"}},"requiredBy":[609,1108,1922,1923]}
