ERC-2645 Hierarchical wallet key derivation for layer 2 (Hierarchical Deterministic Wallet for Layer-2)

Stagnant · Accounts & wallets · created 2020-05-13

Defines a path and method for a user to hierarchically derive, separated by technology and app, the private keys for the elliptic curves used by layer 2 (CIP) solutions like ZK-Rollups, from a single layer 1 wallet seed.

Why it is needed

To use CIP (computational integrity proof) layer 2 solutions like ZK-Rollups, messages must be signed on an elliptic curve optimized for the layer 2 environment, which differs from the general curve Ethereum uses. On the Bitcoin side, BIP32, BIP39, and BIP44 established an industry standard for safely deriving multiple private keys from a single seed, but no such standard existed for layer 2 key derivation. Without a standard, each service ends up creating keys differently, risking that keys get mixed up across different technologies or apps, and users may need to separately manage a distinct seed unrelated to their layer 1 wallet. This makes recovery unclear if a user loses their layer 2 key, and compatibility across wallet software is not guaranteed.

In depth

Derivation Path Structure

The path takes the form m / purpose' / layer' / application' / eth_address_1' / eth_address_2' / index. purpose is fixed at 2645, this EIP's number. layer is the lower 31 bits of the SHA256 hash of the layer2 technology's name; for starkex it is 579218131. application is the lower 31 bits of the SHA256 hash of the application's name; for DeversiFi (starkexdvf) as of June 2020 it is 1393043894. For example, with address 0x0000....0000, seed m, index 0, the path for DeversiFi as of June 2020 is m/2645'/579218131'/1393043894'/0'/0'/0.

Ethereum address components and index

eth_address_1 and eth_address_2 are the corresponding Ethereum address split into two 31-bit chunks. Splitting it into two path components in this way preserves a one-to-one relationship with the layer1 address. index is a value that allows multiple layer2 keys to be held under a single Ethereum address.

Grinding algorithm

N is 2 to the power of 256, and n is the order of the layer2 curve. First, derive root_key from the derivation path using BIP32. Then starting from i=0, compute key = hash(root_key|i) with SHA256; if key is less than (N - (N mod n)), return key mod n as the final key, otherwise increment i and retry. This algorithm is designed to run efficiently even on devices with limited performance, and the probability that a key exceeds the threshold and must be retried in any given round is less than 2 to the power of -5.

BIP43 compatibility

This standard is defined to be compatible with BIP43, and its path structure is directly inspired by BIP44.

Design rationale

The derivation path is designed to efficiently separate keys by technology and application while maintaining a one-to-one relationship with the layer1 wallet. As a result, losing an EIP-2645-style layer2 wallet ultimately reduces to the same situation as losing the layer1 wallet. The grinding algorithm is defined to force keys to be uniformly distributed within the elliptic curve domain.

Proposal status

This proposal is currently Stagnant, meaning it is no longer being actively discussed or has stopped progressing.

Things to watch out for

Original ERC · ← ERCs