{"eip":152,"title":"Add BLAKE2 compression function `F` precompile","description":"This EIP will enable the BLAKE2b hash function and other higher-round 64-bit BLAKE2 variants to run cheaply on the EVM, allowing easier interoperability between Ethereum and Zcash as well as other Equihash-based PoW coins.","authors":["Tjaden Hess \u003ctah83@cornell.edu\u003e","Matt Luongo (@mhluongo)","Piotr Dyraga (@pdyraga)","James Hancock (@MadeOfTin)"],"status":"Final","type":"Standards Track","category":"Core","created":"2016-10-04","discussionsTo":"https://github.com/ethereum/EIPs/issues/152","repo":"EIPs","label":"EIP-152","officialUrl":"https://eips.ethereum.org/EIPS/eip-152","sourceUrl":"https://github.com/ethereum/EIPs/blob/master/EIPS/eip-152.md","url":"https://eips.huatuo.xyz/eip-152/","tldr":{"en":"Added a precompile at address 0x09 that runs the BLAKE2b compression function F, so contracts can verify BLAKE2-based data such as Zcash headers cheaply.","ja":"アドレス 0x09 に BLAKE2b の圧縮関数 F を実行するプリコンパイルを追加し、Zcash のヘッダーのような BLAKE2 ベースのデータをコントラクトが低コストで検証できるようにした。","ko":"주소 0x09에 BLAKE2b 압축 함수 F를 실행하는 프리컴파일을 추가해, 컨트랙트가 Zcash 헤더 같은 BLAKE2 기반 데이터를 저렴하게 검증할 수 있게 했다.","zh":"在地址 0x09 新增一个运行 BLAKE2b 压缩函数 F 的预编译，使合约能以较低成本验证 Zcash 区块头等基于 BLAKE2 的数据。"},"tags":["precompile","cryptography","hashing","blake2","istanbul"],"explainers":{"en":{"lang":"en","tldr":"Added a precompile at address 0x09 that runs the BLAKE2b compression function F, so contracts can verify BLAKE2-based data such as Zcash headers cheaply.","tags":["precompile","cryptography","hashing","blake2","istanbul"],"related":[1679,198,196],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-152/","markdown":"## What problem does it solve?\n\nBLAKE2 is a fast, widely used hash function. Zcash's Equihash proof of work depends on BLAKE2b, and so do other projects such as Filecoin and Handshake. To verify a Zcash block header inside an Ethereum contract (for a BTC-Relay-style light client or a trustless cross-chain swap), you need many BLAKE2b runs per header.\n\nBLAKE2b is built for 64-bit, little-endian CPUs. The EVM works with 256-bit, big-endian words, so a pure Solidity version is very expensive in gas. A precompile lets clients run native code instead.\n\n## How it works\n\nRather than a full \"BLAKE2b hash\" precompile, the authors chose to expose only the core **compression function `F`** from RFC 7693. Projects need different BLAKE2 features (personalization, salts, keyed hashing, tree hashing, varied output lengths). With `F` available, a contract can build any of these itself.\n\nThe precompile lives at address `0x09`. Its input must be **exactly 213 bytes**:\n\n| Bytes | Field | Encoding |\n| --- | --- | --- |\n| 4 | `rounds` | big-endian uint32 |\n| 64 | `h` state vector | 8 × little-endian uint64 |\n| 128 | `m` message block | 16 × little-endian uint64 |\n| 8 + 8 | `t_0`, `t_1` offset counters | little-endian uint64 |\n| 1 | `f` final-block flag | must be `0` or `1` |\n\nAny other length, or an `f` value other than 0 or 1, is an error. The output is the updated 64-byte state `h`, still little-endian. Gas cost is simply **1 gas per round**. Standard BLAKE2b uses 12 rounds, but callers may ask for more.\n\n## Sample code\n\nA thin Solidity wrapper (adapted from the pattern in the spec):\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Blake2F {\n    function compress(\n        uint32 rounds,\n        bytes32[2] memory h,   // 64-byte state\n        bytes32[4] memory m,   // 128-byte message block\n        bytes8[2] memory t,    // offset counters\n        bool f                 // final block?\n    ) internal view returns (bytes32[2] memory out) {\n        bytes memory input = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);\n        // input.length == 213\n        assembly {\n            if iszero(staticcall(gas(), 0x09, add(input, 32), 213, out, 64)) {\n                revert(0, 0)\n            }\n        }\n    }\n}\n```\n\n`abi.encodePacked` encodes `bool` as a single byte, `0x00` or `0x01`, which is exactly what the precompile expects.\n\n## Things to know\n\n- This proposal is Final. It went live in the Istanbul upgrade ([EIP-1679](/eip-1679/)) in 2019.\n- Watch the byte order. `rounds` is big-endian, but every other field is little-endian. Getting this wrong is the most common bug when you call `F`.\n- The precompile gives you the compression step only. Padding, counters and the final-block flag are your code's job, as RFC 7693 describes.\n- Like other precompiles, its address is fixed, so contracts that call it work only on chains that enabled Istanbul-era precompiles.\n"},"ja":{"lang":"ja","tldr":"アドレス 0x09 に BLAKE2b の圧縮関数 F を実行するプリコンパイルを追加し、Zcash のヘッダーのような BLAKE2 ベースのデータをコントラクトが低コストで検証できるようにした。","tags":["precompile","cryptography","hashing","blake2","istanbul"],"related":[1679,198,196],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-152/","markdown":"## 何を解決するのか\n\nBLAKE2 は高速で広く使われているハッシュ関数です。Zcash の Equihash プルーフ・オブ・ワークは BLAKE2b に依存しており、Filecoin や Handshake などの他のプロジェクトも同様です。Zcash のブロックヘッダーを Ethereum のコントラクト内で検証する（BTC-Relay 型のライトクライアントや、信頼不要のクロスチェーンスワップのため）には、ヘッダー 1 つにつき BLAKE2b を何度も実行する必要があります。\n\nBLAKE2b は 64 ビット・リトルエンディアンの CPU 向けに作られています。一方、EVM は 256 ビット・ビッグエンディアンのワードを扱うため、純粋な Solidity 実装はガスが非常に高くつきます。プリコンパイルを使えば、クライアントがネイティブコードで実行できます。\n\n## 仕組み\n\n著者らは、完全な「BLAKE2b ハッシュ」のプリコンパイルではなく、RFC 7693 の中核である**圧縮関数 `F`** だけを公開することにしました。プロジェクトごとに必要な BLAKE2 の機能（パーソナライズ、ソルト、鍵付きハッシュ、ツリーハッシュ、さまざまな出力長）が異なるためです。`F` が使えれば、コントラクト側でこれらを自分で組み立てられます。\n\nプリコンパイルはアドレス `0x09` にあります。入力は**ちょうど 213 バイト**でなければなりません。\n\n| バイト数 | フィールド | エンコーディング |\n| --- | --- | --- |\n| 4 | `rounds` | ビッグエンディアン uint32 |\n| 64 | `h` 状態ベクトル | 8 × リトルエンディアン uint64 |\n| 128 | `m` メッセージブロック | 16 × リトルエンディアン uint64 |\n| 8 + 8 | `t_0`, `t_1` オフセットカウンター | リトルエンディアン uint64 |\n| 1 | `f` 最終ブロックフラグ | `0` または `1` でなければならない |\n\nそれ以外の長さ、または 0 と 1 以外の `f` の値はエラーになります。出力は更新後の 64 バイトの状態 `h` で、こちらもリトルエンディアンです。ガスコストは単純に**ラウンドごとに 1 ガス**です。標準の BLAKE2b は 12 ラウンドですが、呼び出し側はそれ以上を指定できます。\n\n## サンプルコード\n\n薄い Solidity ラッパー（仕様書のパターンを基にしています）:\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Blake2F {\n    function compress(\n        uint32 rounds,\n        bytes32[2] memory h,   // 64-byte state\n        bytes32[4] memory m,   // 128-byte message block\n        bytes8[2] memory t,    // offset counters\n        bool f                 // final block?\n    ) internal view returns (bytes32[2] memory out) {\n        bytes memory input = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);\n        // input.length == 213\n        assembly {\n            if iszero(staticcall(gas(), 0x09, add(input, 32), 213, out, 64)) {\n                revert(0, 0)\n            }\n        }\n    }\n}\n```\n\n`abi.encodePacked` は `bool` を `0x00` または `0x01` の 1 バイトとしてエンコードします。これはプリコンパイルが期待する形式とちょうど一致します。\n\n## 知っておくべきこと\n\n- この提案は Final です。2019 年の Istanbul アップグレード（[EIP-1679](/eip-1679/)）で有効になりました。\n- バイトオーダーに注意してください。`rounds` はビッグエンディアンですが、それ以外のフィールドはすべてリトルエンディアンです。`F` を呼ぶときに最も多いバグは、これを間違えることです。\n- プリコンパイルが提供するのは圧縮ステップだけです。パディング、カウンター、最終ブロックフラグの扱いは、RFC 7693 に記載のとおり、あなたのコードの仕事です。\n- 他のプリコンパイルと同様にアドレスは固定なので、これを呼ぶコントラクトは Istanbul 世代のプリコンパイルを有効にしたチェーンでしか動作しません。\n"},"ko":{"lang":"ko","tldr":"주소 0x09에 BLAKE2b 압축 함수 F를 실행하는 프리컴파일을 추가해, 컨트랙트가 Zcash 헤더 같은 BLAKE2 기반 데이터를 저렴하게 검증할 수 있게 했다.","tags":["precompile","cryptography","hashing","blake2","istanbul"],"related":[1679,198,196],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-152/","markdown":"## 어떤 문제를 해결하나요?\n\nBLAKE2는 빠르고 널리 쓰이는 해시 함수입니다. Zcash의 Equihash 작업 증명은 BLAKE2b에 의존하며, Filecoin이나 Handshake 같은 다른 프로젝트도 마찬가지입니다. Zcash 블록 헤더를 이더리움 컨트랙트 안에서 검증하려면(BTC-Relay 방식의 라이트 클라이언트나 신뢰가 필요 없는 크로스체인 스왑을 위해), 헤더 하나당 BLAKE2b를 여러 번 실행해야 합니다.\n\nBLAKE2b는 64비트 리틀 엔디언 CPU에 맞게 설계되었습니다. 반면 EVM은 256비트 빅 엔디언 워드로 동작하므로 순수 Solidity 구현은 가스 비용이 매우 큽니다. 프리컴파일을 쓰면 클라이언트가 네이티브 코드로 실행할 수 있습니다.\n\n## 어떻게 동작하나요?\n\n저자들은 완전한 \"BLAKE2b 해시\" 프리컴파일 대신 RFC 7693의 핵심인 **압축 함수 `F`**만 노출하기로 했습니다. 프로젝트마다 필요한 BLAKE2 기능(퍼스널라이제이션, 솔트, 키 해시, 트리 해시, 다양한 출력 길이)이 다르기 때문입니다. `F`를 쓸 수 있으면 컨트랙트가 이런 기능을 직접 구성할 수 있습니다.\n\n프리컴파일은 주소 `0x09`에 있습니다. 입력은 **정확히 213바이트**여야 합니다.\n\n| 바이트 | 필드 | 인코딩 |\n| --- | --- | --- |\n| 4 | `rounds` | 빅 엔디언 uint32 |\n| 64 | `h` 상태 벡터 | 8 × 리틀 엔디언 uint64 |\n| 128 | `m` 메시지 블록 | 16 × 리틀 엔디언 uint64 |\n| 8 + 8 | `t_0`, `t_1` 오프셋 카운터 | 리틀 엔디언 uint64 |\n| 1 | `f` 마지막 블록 플래그 | 반드시 `0` 또는 `1` |\n\n그 밖의 길이이거나 `f`가 0과 1이 아닌 값이면 오류입니다. 출력은 갱신된 64바이트 상태 `h`이며, 역시 리틀 엔디언입니다. 가스 비용은 단순하게 **라운드당 1 가스**입니다. 표준 BLAKE2b는 12라운드를 쓰지만, 호출자는 더 많은 라운드를 요청할 수 있습니다.\n\n## 샘플 코드\n\n얇은 Solidity 래퍼입니다(명세의 패턴을 바탕으로 했습니다).\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Blake2F {\n    function compress(\n        uint32 rounds,\n        bytes32[2] memory h,   // 64-byte state\n        bytes32[4] memory m,   // 128-byte message block\n        bytes8[2] memory t,    // offset counters\n        bool f                 // final block?\n    ) internal view returns (bytes32[2] memory out) {\n        bytes memory input = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);\n        // input.length == 213\n        assembly {\n            if iszero(staticcall(gas(), 0x09, add(input, 32), 213, out, 64)) {\n                revert(0, 0)\n            }\n        }\n    }\n}\n```\n\n`abi.encodePacked`는 `bool`을 `0x00` 또는 `0x01`의 1바이트로 인코딩하며, 이는 프리컴파일이 기대하는 형식과 정확히 일치합니다.\n\n## 알아둘 점\n\n- 이 제안은 Final 상태입니다. 2019년 Istanbul 업그레이드([EIP-1679](/eip-1679/))에서 적용되었습니다.\n- 바이트 순서에 주의하세요. `rounds`는 빅 엔디언이지만 나머지 필드는 모두 리틀 엔디언입니다. `F`를 호출할 때 가장 흔한 버그가 이 순서를 잘못 쓰는 것입니다.\n- 프리컴파일이 제공하는 것은 압축 단계뿐입니다. 패딩, 카운터, 마지막 블록 플래그 처리는 RFC 7693에 설명된 대로 여러분의 코드가 맡아야 합니다.\n- 다른 프리컴파일과 마찬가지로 주소가 고정되어 있으므로, 이를 호출하는 컨트랙트는 Istanbul 시대의 프리컴파일을 활성화한 체인에서만 동작합니다.\n"},"zh":{"lang":"zh","tldr":"在地址 0x09 新增一个运行 BLAKE2b 压缩函数 F 的预编译，使合约能以较低成本验证 Zcash 区块头等基于 BLAKE2 的数据。","tags":["precompile","cryptography","hashing","blake2","istanbul"],"related":[1679,198,196],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-152/","markdown":"## 它解决什么问题？\n\nBLAKE2 是一种快速且应用广泛的哈希函数。Zcash 的 Equihash 工作量证明依赖 BLAKE2b，Filecoin、Handshake 等其他项目也是如此。要在以太坊合约中验证 Zcash 区块头（用于 BTC-Relay 式的轻客户端，或无需信任的跨链兑换），每个区块头都需要多次运行 BLAKE2b。\n\nBLAKE2b 是为 64 位、小端序的 CPU 设计的。而 EVM 使用 256 位、大端序的字，因此纯 Solidity 实现的 gas 开销非常高。预编译让客户端可以改用原生代码来运行。\n\n## 它如何运作\n\n作者没有选择完整的\"BLAKE2b 哈希\"预编译，而是只公开 RFC 7693 中的核心**压缩函数 `F`**。不同项目需要 BLAKE2 的不同特性（个性化、盐、带密钥哈希、树哈希、不同的输出长度）。有了 `F`，合约就可以自己构建这些功能。\n\n该预编译位于地址 `0x09`。输入必须**恰好为 213 字节**：\n\n| 字节数 | 字段 | 编码 |\n| --- | --- | --- |\n| 4 | `rounds` | 大端序 uint32 |\n| 64 | `h` 状态向量 | 8 × 小端序 uint64 |\n| 128 | `m` 消息块 | 16 × 小端序 uint64 |\n| 8 + 8 | `t_0`、`t_1` 偏移计数器 | 小端序 uint64 |\n| 1 | `f` 最终块标志 | 必须为 `0` 或 `1` |\n\n任何其他长度，或 `f` 取 0 和 1 以外的值，都会报错。输出是更新后的 64 字节状态 `h`，同样是小端序。gas 成本很简单：**每轮 1 gas**。标准 BLAKE2b 使用 12 轮，但调用者可以要求更多。\n\n## 示例代码\n\n一个简单的 Solidity 封装（改编自规范中的写法）：\n\n```solidity\n// SPDX-License-Identifier: MIT\npragma solidity ^0.8.20;\n\nlibrary Blake2F {\n    function compress(\n        uint32 rounds,\n        bytes32[2] memory h,   // 64-byte state\n        bytes32[4] memory m,   // 128-byte message block\n        bytes8[2] memory t,    // offset counters\n        bool f                 // final block?\n    ) internal view returns (bytes32[2] memory out) {\n        bytes memory input = abi.encodePacked(rounds, h[0], h[1], m[0], m[1], m[2], m[3], t[0], t[1], f);\n        // input.length == 213\n        assembly {\n            if iszero(staticcall(gas(), 0x09, add(input, 32), 213, out, 64)) {\n                revert(0, 0)\n            }\n        }\n    }\n}\n```\n\n`abi.encodePacked` 会把 `bool` 编码为单个字节 `0x00` 或 `0x01`，这正是预编译所期望的。\n\n## 需要注意\n\n- 该提案状态为 Final。它在 2019 年的 Istanbul 升级（[EIP-1679](/eip-1679/)）中上线。\n- 注意字节序。`rounds` 是大端序，其余所有字段都是小端序。调用 `F` 时最常见的错误就是搞错这一点。\n- 预编译只提供压缩这一步。填充、计数器和最终块标志需要由你的代码处理，具体见 RFC 7693。\n- 与其他预编译一样，它的地址是固定的，因此调用它的合约只能在启用了 Istanbul 时代预编译的链上运行。\n"}},"requiredBy":[1679,8200]}
