---
eip: 2645
label: ERC-2645
title: Hierarchical Deterministic Wallet for Layer-2
status: Stagnant
type: Standards Track
category: ERC
created: 2020-05-13
official: https://eips.ethereum.org/EIPS/eip-2645
source: https://github.com/ethereum/ERCs/blob/master/ERCS/erc-2645.md
canonical: https://eips.huatuo.xyz/eip-2645/
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]
---

# ERC-2645: Hierarchical Deterministic Wallet for Layer-2

> 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.

**TL;DR:** 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.

## What problem does it solve?

Validity-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.

ERC-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.

## How it works

The derivation path (BIP-43 compatible) is:

```
m / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index
```

| Level | Value |
| --- | --- |
| `purpose` | `2645` (the EIP number) |
| `layer` | lowest 31 bits of `sha256(layerName)`, e.g. `"starkex"` → `579218131` |
| `application` | lowest 31 bits of `sha256(appName)`, e.g. `"starkexdvf"` → `1393043894` |
| `eth_address_1` | lowest 31 bits of the user's Ethereum address |
| `eth_address_2` | the next 31 bits of the address |
| `index` | allows several keys per address (non-hardened) |

So for address `0x00…00`, DeversiFi and index 0, the path is `m/2645'/579218131'/1393043894'/0'/0'/0`.

BIP-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⁻⁵.

## Sample code

Path construction and grinding in Python (the BIP-32 step is left to a library):

```python
import hashlib

MASK31 = (1 << 31) - 1

def low31(name: str) -> int:
    return int.from_bytes(hashlib.sha256(name.encode()).digest(), "big") & MASK31

def eip2645_path(layer: str, app: str, eth_address: str, index: int = 0) -> str:
    addr = int(eth_address, 16)
    a1 = addr & MASK31
    a2 = (addr >> 31) & MASK31
    return f"m/2645'/{low31(layer)}'/{low31(app)}'/{a1}'/{a2}'/{index}"

def grind_key(root_key: bytes, curve_order: int) -> int:
    N = 2 ** 256
    limit = N - (N % curve_order)
    i = 0
    while True:
        # spec: key = sha256(root_key | i)
        k = int.from_bytes(hashlib.sha256(root_key + i.to_bytes(1, "big")).digest(), "big")
        if k < limit:
            return k % curve_order
        i += 1

print(eip2645_path("starkex", "starkexdvf", "0x" + "00" * 20))
# m/2645'/579218131'/1393043894'/0'/0'/0
```

## Things to know

- **Status: Stagnant.** The ERC did not advance to Final; check each wallet or L2 for whether it follows this exact path.
- 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).
- Keys are bound to one L1 address. Using a different L1 account produces a completely different L2 key.
- For BLS keys used by Ethereum validators, a separate scheme exists: [EIP-2333](/eip-2333/).


---

This is an unofficial plain-language summary. Read the full specification: https://eips.ethereum.org/EIPS/eip-2645
