{"eip":2645,"title":"Hierarchical Deterministic Wallet for Layer-2","description":"In the context of Computation Integrity Proof (CIP) Layer-2 solutions such as ZK-Rollups, users are required to sign messages on new elliptic curves optimized for those environments.","authors":["Tom Brand \u003ctom@starkware.co\u003e","Louis Guthmann \u003clouis@starkware.co\u003e"],"status":"Stagnant","type":"Standards Track","category":"ERC","created":"2020-05-13","discussionsTo":"https://ethereum-magicians.org/t/hierarchical-deterministic-wallet-for-computation-integrity-proof-cip-layer-2/4286","repo":"ERCs","label":"ERC-2645","officialUrl":"https://eips.ethereum.org/EIPS/eip-2645","sourceUrl":"https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2645.md","url":"https://eips.huatuo.xyz/eip-2645/","tldr":{"en":"A BIP-32/44-style derivation path for Layer-2 keys on non-secp256k1 curves (such as STARK keys), deriving them from the same seed as your Ethereum wallet and tying them to your L1 address.","ja":"secp256k1 以外の曲線（STARK 鍵など）を使うレイヤー 2 の鍵のための、BIP-32/44 形式の導出パス。Ethereum ウォレットと同じシードから導出し、L1 アドレスに結び付ける。","ko":"secp256k1이 아닌 곡선(예: STARK 키)을 쓰는 레이어 2 키를 위한 BIP-32/44 방식의 파생 경로. 이더리움 지갑과 같은 시드에서 파생하고 L1 주소와 연결한다.","zh":"一种 BIP-32/44 风格的派生路径，用于非 secp256k1 曲线的 Layer-2 密钥（如 STARK 密钥）：从与以太坊钱包相同的种子派生，并与你的 L1 地址绑定。"},"tags":["wallet","keys","layer-2","hd-wallet","starkex"],"explainers":{"en":{"lang":"en","tldr":"A BIP-32/44-style derivation path for Layer-2 keys on non-secp256k1 curves (such as STARK keys), deriving them from the same seed as your Ethereum wallet and tying them to your L1 address.","tags":["wallet","keys","layer-2","hd-wallet","starkex"],"related":[2333],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/eip-2645/","markdown":"## What problem does it solve?\n\nValidity-proof Layer-2 systems such as ZK-rollups often ask users to sign with keys on elliptic curves that are cheap to verify inside a proof, not on Ethereum's secp256k1. Users already back up a single BIP-39 seed phrase for their Ethereum wallet; asking them to manage a second, unrelated secret for each L2 is both inconvenient and risky.\n\nERC-2645 defines a standard way to derive these L2 private keys from the existing seed using the well-tested BIP-32/BIP-44 machinery, with clean separation between different L2 technologies and applications. Losing the L2 key then reduces to losing the L1 wallet, which users already know how to protect.\n\n## How it works\n\nThe derivation path (BIP-43 compatible) is:\n\n```\nm / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index\n```\n\n| Level | Value |\n| --- | --- |\n| `purpose` | `2645` (the EIP number) |\n| `layer` | lowest 31 bits of `sha256(layerName)`, e.g. `\"starkex\"` → `579218131` |\n| `application` | lowest 31 bits of `sha256(appName)`, e.g. `\"starkexdvf\"` → `1393043894` |\n| `eth_address_1` | lowest 31 bits of the user's Ethereum address |\n| `eth_address_2` | the next 31 bits of the address |\n| `index` | allows several keys per address (non-hardened) |\n\nSo for address `0x00…00`, DeversiFi and index 0, the path is `m/2645'/579218131'/1393043894'/0'/0'/0`.\n\nBIP-32 produces a 256-bit secp256k1 key, but the L2 curve has a different order `n`. To map it to a uniformly distributed key, the spec uses **grinding**: hash the BIP-32 key with a counter until the result falls below the largest multiple of `n` that fits in 256 bits, then reduce mod `n`. This avoids the bias a plain `key % n` would introduce. The spec notes each round fails with probability below 2⁻⁵.\n\n## Sample code\n\nPath construction and grinding in Python (the BIP-32 step is left to a library):\n\n```python\nimport hashlib\n\nMASK31 = (1 \u003c\u003c 31) - 1\n\ndef low31(name: str) -\u003e int:\n    return int.from_bytes(hashlib.sha256(name.encode()).digest(), \"big\") \u0026 MASK31\n\ndef eip2645_path(layer: str, app: str, eth_address: str, index: int = 0) -\u003e str:\n    addr = int(eth_address, 16)\n    a1 = addr \u0026 MASK31\n    a2 = (addr \u003e\u003e 31) \u0026 MASK31\n    return f\"m/2645'/{low31(layer)}'/{low31(app)}'/{a1}'/{a2}'/{index}\"\n\ndef grind_key(root_key: bytes, curve_order: int) -\u003e int:\n    N = 2 ** 256\n    limit = N - (N % curve_order)\n    i = 0\n    while True:\n        # spec: key = sha256(root_key | i)\n        k = int.from_bytes(hashlib.sha256(root_key + i.to_bytes(1, \"big\")).digest(), \"big\")\n        if k \u003c limit:\n            return k % curve_order\n        i += 1\n\nprint(eip2645_path(\"starkex\", \"starkexdvf\", \"0x\" + \"00\" * 20))\n# m/2645'/579218131'/1393043894'/0'/0'/0\n```\n\n## Things to know\n\n- **Status: Stagnant.** The ERC did not advance to Final; check each wallet or L2 for whether it follows this exact path.\n- The spec writes the grinding input as `root_key|i` without fixing how `i` is encoded; implementations must agree on that detail (the snippet above assumes a single byte).\n- Keys are bound to one L1 address. Using a different L1 account produces a completely different L2 key.\n- For BLS keys used by Ethereum validators, a separate scheme exists: [EIP-2333](/eip-2333/).\n"},"ja":{"lang":"ja","tldr":"secp256k1 以外の曲線（STARK 鍵など）を使うレイヤー 2 の鍵のための、BIP-32/44 形式の導出パス。Ethereum ウォレットと同じシードから導出し、L1 アドレスに結び付ける。","tags":["wallet","keys","layer-2","hd-wallet","starkex"],"related":[2333],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ja/eip-2645/","markdown":"## 何を解決するのか\n\nZK ロールアップのような validity proof 型のレイヤー 2 システムでは、Ethereum の secp256k1 ではなく、証明の内部で検証しやすい楕円曲線の鍵で署名するよう求められることがよくあります。ユーザーはすでに Ethereum ウォレット用に BIP-39 のシードフレーズを 1 つバックアップしています。L2 ごとに無関係な 2 つ目の秘密を管理させるのは、不便で危険でもあります。\n\nERC-2645 は、十分に検証された BIP-32/BIP-44 の仕組みを使い、既存のシードからこれらの L2 秘密鍵を導出する標準的な方法を定義します。L2 技術やアプリケーションごとにきれいに分離されます。これにより、L2 の鍵を失うことは L1 ウォレットを失うことと同じになり、ユーザーはその守り方をすでに知っています。\n\n## 仕組み\n\n導出パス（BIP-43 互換）は次のとおりです。\n\n```\nm / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index\n```\n\n| レベル | 値 |\n| --- | --- |\n| `purpose` | `2645`（EIP 番号） |\n| `layer` | `sha256(layerName)` の下位 31 ビット。例: `\"starkex\"` → `579218131` |\n| `application` | `sha256(appName)` の下位 31 ビット。例: `\"starkexdvf\"` → `1393043894` |\n| `eth_address_1` | ユーザーの Ethereum アドレスの下位 31 ビット |\n| `eth_address_2` | アドレスのその次の 31 ビット |\n| `index` | 1 つのアドレスに複数の鍵を持たせるためのもの（非 hardened） |\n\nしたがって、アドレス `0x00…00`、DeversiFi、インデックス 0 の場合、パスは `m/2645'/579218131'/1393043894'/0'/0'/0` になります。\n\nBIP-32 は 256 ビットの secp256k1 鍵を生成しますが、L2 の曲線は位数 `n` が異なります。これを一様分布の鍵に対応付けるために、仕様は **grinding** を使います。BIP-32 の鍵をカウンターとともにハッシュし、結果が 256 ビットに収まる `n` の最大の倍数を下回るまで繰り返し、その後 `n` で剰余を取ります。これにより、単純な `key % n` が持ち込むバイアスを避けられます。仕様は、各ラウンドが失敗する確率は 2⁻⁵ 未満だと述べています。\n\n## サンプルコード\n\nPython によるパスの構築と grinding（BIP-32 のステップはライブラリに任せています）:\n\n```python\nimport hashlib\n\nMASK31 = (1 \u003c\u003c 31) - 1\n\ndef low31(name: str) -\u003e int:\n    return int.from_bytes(hashlib.sha256(name.encode()).digest(), \"big\") \u0026 MASK31\n\ndef eip2645_path(layer: str, app: str, eth_address: str, index: int = 0) -\u003e str:\n    addr = int(eth_address, 16)\n    a1 = addr \u0026 MASK31\n    a2 = (addr \u003e\u003e 31) \u0026 MASK31\n    return f\"m/2645'/{low31(layer)}'/{low31(app)}'/{a1}'/{a2}'/{index}\"\n\ndef grind_key(root_key: bytes, curve_order: int) -\u003e int:\n    N = 2 ** 256\n    limit = N - (N % curve_order)\n    i = 0\n    while True:\n        # spec: key = sha256(root_key | i)\n        k = int.from_bytes(hashlib.sha256(root_key + i.to_bytes(1, \"big\")).digest(), \"big\")\n        if k \u003c limit:\n            return k % curve_order\n        i += 1\n\nprint(eip2645_path(\"starkex\", \"starkexdvf\", \"0x\" + \"00\" * 20))\n# m/2645'/579218131'/1393043894'/0'/0'/0\n```\n\n## 知っておくべきこと\n\n- **ステータス: Stagnant（停滞）。** この ERC は Final に進んでいません。各ウォレットや L2 がこの正確なパスに従っているかを確認してください。\n- 仕様は grinding の入力を `root_key|i` と書いていますが、`i` のエンコード方法は定めていません。実装間でこの細部を合わせる必要があります（上のスニペットは 1 バイトを仮定しています）。\n- 鍵は 1 つの L1 アドレスに結び付けられます。別の L1 アカウントを使うと、まったく異なる L2 鍵が生成されます。\n- Ethereum バリデーターが使う BLS 鍵には別の方式があります: [EIP-2333](/eip-2333/)。\n"},"ko":{"lang":"ko","tldr":"secp256k1이 아닌 곡선(예: STARK 키)을 쓰는 레이어 2 키를 위한 BIP-32/44 방식의 파생 경로. 이더리움 지갑과 같은 시드에서 파생하고 L1 주소와 연결한다.","tags":["wallet","keys","layer-2","hd-wallet","starkex"],"related":[2333],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/ko/eip-2645/","markdown":"## 어떤 문제를 해결하나요?\n\nZK 롤업 같은 유효성 증명 기반 레이어 2 시스템은 이더리움의 secp256k1이 아니라 증명 안에서 검증하기 저렴한 타원 곡선의 키로 서명하라고 요구하는 경우가 많습니다. 사용자는 이미 이더리움 지갑용 BIP-39 시드 구문 하나를 백업해 둡니다. L2마다 서로 무관한 두 번째 비밀을 관리하게 하는 것은 불편하고 위험하기도 합니다.\n\nERC-2645는 충분히 검증된 BIP-32/BIP-44 방식을 사용해 기존 시드에서 이러한 L2 개인 키를 파생하는 표준 방법을 정의하며, L2 기술과 애플리케이션 사이를 깔끔하게 분리합니다. 그러면 L2 키를 잃는 일은 L1 지갑을 잃는 일로 환원되고, 사용자는 이를 지키는 방법을 이미 알고 있습니다.\n\n## 어떻게 동작하나요?\n\n파생 경로(BIP-43 호환)는 다음과 같습니다.\n\n```\nm / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index\n```\n\n| 레벨 | 값 |\n| --- | --- |\n| `purpose` | `2645`(EIP 번호) |\n| `layer` | `sha256(layerName)`의 하위 31비트. 예: `\"starkex\"` → `579218131` |\n| `application` | `sha256(appName)`의 하위 31비트. 예: `\"starkexdvf\"` → `1393043894` |\n| `eth_address_1` | 사용자 이더리움 주소의 하위 31비트 |\n| `eth_address_2` | 주소의 그다음 31비트 |\n| `index` | 주소 하나에 여러 키를 허용(non-hardened) |\n\n따라서 주소 `0x00…00`, DeversiFi, 인덱스 0의 경로는 `m/2645'/579218131'/1393043894'/0'/0'/0`입니다.\n\nBIP-32는 256비트 secp256k1 키를 만들지만 L2 곡선은 위수 `n`이 다릅니다. 이를 균일 분포의 키로 매핑하기 위해 명세는 **grinding**을 사용합니다. BIP-32 키를 카운터와 함께 해시하여, 결과가 256비트에 들어가는 `n`의 가장 큰 배수보다 작아질 때까지 반복한 뒤 `n`으로 나머지를 구합니다. 이렇게 하면 단순한 `key % n`이 만드는 편향을 피할 수 있습니다. 명세는 각 라운드가 실패할 확률이 2⁻⁵ 미만이라고 밝힙니다.\n\n## 샘플 코드\n\nPython으로 경로 구성과 grinding(BIP-32 단계는 라이브러리에 맡김):\n\n```python\nimport hashlib\n\nMASK31 = (1 \u003c\u003c 31) - 1\n\ndef low31(name: str) -\u003e int:\n    return int.from_bytes(hashlib.sha256(name.encode()).digest(), \"big\") \u0026 MASK31\n\ndef eip2645_path(layer: str, app: str, eth_address: str, index: int = 0) -\u003e str:\n    addr = int(eth_address, 16)\n    a1 = addr \u0026 MASK31\n    a2 = (addr \u003e\u003e 31) \u0026 MASK31\n    return f\"m/2645'/{low31(layer)}'/{low31(app)}'/{a1}'/{a2}'/{index}\"\n\ndef grind_key(root_key: bytes, curve_order: int) -\u003e int:\n    N = 2 ** 256\n    limit = N - (N % curve_order)\n    i = 0\n    while True:\n        # spec: key = sha256(root_key | i)\n        k = int.from_bytes(hashlib.sha256(root_key + i.to_bytes(1, \"big\")).digest(), \"big\")\n        if k \u003c limit:\n            return k % curve_order\n        i += 1\n\nprint(eip2645_path(\"starkex\", \"starkexdvf\", \"0x\" + \"00\" * 20))\n# m/2645'/579218131'/1393043894'/0'/0'/0\n```\n\n## 알아둘 점\n\n- **상태: Stagnant(정체).** 이 ERC는 Final로 진행되지 않았습니다. 각 지갑이나 L2가 이 경로를 정확히 따르는지 확인하세요.\n- 명세는 grinding 입력을 `root_key|i`로 적었을 뿐 `i`를 어떻게 인코딩하는지는 정하지 않았습니다. 구현끼리 이 세부 사항을 맞춰야 합니다(위 스니펫은 1바이트를 가정합니다).\n- 키는 L1 주소 하나에 묶입니다. 다른 L1 계정을 쓰면 완전히 다른 L2 키가 만들어집니다.\n- 이더리움 검증자가 쓰는 BLS 키에는 별도의 방식이 있습니다: [EIP-2333](/eip-2333/).\n"},"zh":{"lang":"zh","tldr":"一种 BIP-32/44 风格的派生路径，用于非 secp256k1 曲线的 Layer-2 密钥（如 STARK 密钥）：从与以太坊钱包相同的种子派生，并与你的 L1 地址绑定。","tags":["wallet","keys","layer-2","hd-wallet","starkex"],"related":[2333],"updated":"2026-10-19","url":"https://eips.huatuo.xyz/zh/eip-2645/","markdown":"## 它解决什么问题？\n\nZK-rollup 之类的有效性证明 Layer-2 系统，常常要求用户使用在证明内部验证成本低的椭圆曲线密钥签名，而不是以太坊的 secp256k1。用户已经为以太坊钱包备份了一份 BIP-39 助记词；要求他们为每个 L2 再管理一个互不相关的秘密，既不方便又有风险。\n\nERC-2645 定义了一种标准方式，利用经过充分检验的 BIP-32/BIP-44 机制，从现有种子派生出这些 L2 私钥，并在不同 L2 技术和应用之间做到清晰隔离。这样，丢失 L2 密钥就归结为丢失 L1 钱包，而用户已经知道如何保护它。\n\n## 它如何运作\n\n派生路径（兼容 BIP-43）为：\n\n```\nm / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index\n```\n\n| 层级 | 取值 |\n| --- | --- |\n| `purpose` | `2645`（即 EIP 编号） |\n| `layer` | `sha256(layerName)` 的低 31 位，例如 `\"starkex\"` → `579218131` |\n| `application` | `sha256(appName)` 的低 31 位，例如 `\"starkexdvf\"` → `1393043894` |\n| `eth_address_1` | 用户以太坊地址的低 31 位 |\n| `eth_address_2` | 地址的接下来 31 位 |\n| `index` | 允许每个地址有多个密钥（非硬化） |\n\n因此，对于地址 `0x00…00`、DeversiFi 和索引 0，路径为 `m/2645'/579218131'/1393043894'/0'/0'/0`。\n\nBIP-32 生成的是 256 位的 secp256k1 密钥，但 L2 曲线的阶 `n` 不同。为了把它映射成均匀分布的密钥，规范使用了 **grinding**：把 BIP-32 密钥与计数器一起哈希，直到结果小于 256 位内能容纳的 `n` 的最大倍数，然后对 `n` 取模。这样可以避免简单的 `key % n` 引入的偏差。规范指出每一轮失败的概率低于 2⁻⁵。\n\n## 示例代码\n\n用 Python 构造路径并进行 grinding（BIP-32 这一步交给库来完成）：\n\n```python\nimport hashlib\n\nMASK31 = (1 \u003c\u003c 31) - 1\n\ndef low31(name: str) -\u003e int:\n    return int.from_bytes(hashlib.sha256(name.encode()).digest(), \"big\") \u0026 MASK31\n\ndef eip2645_path(layer: str, app: str, eth_address: str, index: int = 0) -\u003e str:\n    addr = int(eth_address, 16)\n    a1 = addr \u0026 MASK31\n    a2 = (addr \u003e\u003e 31) \u0026 MASK31\n    return f\"m/2645'/{low31(layer)}'/{low31(app)}'/{a1}'/{a2}'/{index}\"\n\ndef grind_key(root_key: bytes, curve_order: int) -\u003e int:\n    N = 2 ** 256\n    limit = N - (N % curve_order)\n    i = 0\n    while True:\n        # spec: key = sha256(root_key | i)\n        k = int.from_bytes(hashlib.sha256(root_key + i.to_bytes(1, \"big\")).digest(), \"big\")\n        if k \u003c limit:\n            return k % curve_order\n        i += 1\n\nprint(eip2645_path(\"starkex\", \"starkexdvf\", \"0x\" + \"00\" * 20))\n# m/2645'/579218131'/1393043894'/0'/0'/0\n```\n\n## 需要注意\n\n- **状态：Stagnant（停滞）。** 该 ERC 没有推进到 Final；请逐个确认各钱包或 L2 是否遵循这个确切的路径。\n- 规范把 grinding 的输入写成 `root_key|i`，但没有规定 `i` 如何编码；各实现必须在这个细节上保持一致（上面的代码片段假定为单个字节）。\n- 密钥与某一个 L1 地址绑定。使用不同的 L1 账户会得到完全不同的 L2 密钥。\n- 对于以太坊验证者使用的 BLS 密钥，另有一套方案：[EIP-2333](/eip-2333/)。\n"}}}
