ERC-2335 · Review · ERC · 2019-09-30
ERC-2335: BLS12-381 Keystore
A password-encrypted JSON keystore format for BLS12-381 keys, used by Ethereum validators, built from swappable KDF, checksum and cipher modules and free of Keccak.
What problem does it solve?
People who hold their own keys need a safe way to store them on disk and move them between devices. Ethereum already had the "Web3 Secret Storage" keystore (version 3) for secp256k1 account keys, but it has two drawbacks for BLS keys:
- It uses Keccak-256 for its checksum. BLS keys and signatures are meant to be a cross-chain standard, and Keccak is Ethereum-specific.
- It grew feature by feature and lacks a clean abstraction for its building blocks.
ERC-2335 defines a new keystore ("version": 4) for BLS12-381 secrets. It is the format validator tooling uses for keystore-*.json files, alongside ERC-2333 (key derivation) and ERC-2334 (key paths).
How it works
The crypto section is made of three modules, each with a function, its params and a message:
| Module | Allowed functions | Role |
|---|---|---|
kdf |
scrypt, pbkdf2 (HMAC-SHA256) |
Turns the password into a 32-byte decryption key |
checksum |
sha256 |
Verifies the password is correct |
cipher |
aes-128-ctr |
Holds the encrypted secret in message |
Decrypting takes three steps:
- Normalize the password: convert to NFKD, strip C0 (
0x00–0x1F), C1 (0x80–0x9F) and0x7Fcontrol codes, then UTF-8 encode. Spaces are kept. - Derive and check: run the KDF to get
decryption_key. ComputeSHA256(decryption_key[16:32] | cipher.message)and compare it tochecksum.message. A mismatch means a wrong password. - Decrypt: use
decryption_key[0:16]as the AES-128-CTR key withcipher.params.ivto recover the secret.
Other top-level fields:
pubkey: the public key, so tools can show it without asking for the password. Required when the secret is a private key.path: the ERC-2334 derivation path, or""if unknown.uuid: a random RFC 4122 UUID.description: an optional human label (not guaranteed unique).version: always4, chosen so it cannot be confused with the older v3 keystore.
Sample code
Shape of a keystore (values shortened; see the spec's test vectors for full ones):
{
"crypto": {
"kdf": {
"function": "scrypt",
"params": { "dklen": 32, "n": 262144, "p": 1, "r": 8, "salt": "d4e5…8fa3" },
"message": ""
},
"checksum": { "function": "sha256", "params": {}, "message": "d221…a484" },
"cipher": {
"function": "aes-128-ctr",
"params": { "iv": "264d…4fe6" },
"message": "06ae…e20f"
}
},
"description": "validator key",
"pubkey": "9612…0d07",
"path": "m/12381/3600/0/0/0",
"uuid": "1d85ae20-35c5-4611-98e8-aa14a633906f",
"version": 4
}
Password check and decryption (Node.js, scrypt case):
import { scryptSync, createHash, createDecipheriv } from "node:crypto";
function decrypt(ks: any, password: string): Buffer {
const pw = Buffer.from(
password.normalize("NFKD").replace(/[\u0000-\u001f\u007f-\u009f]/g, ""),
"utf8",
);
const { n, r, p, dklen, salt } = ks.crypto.kdf.params;
const dk = scryptSync(pw, Buffer.from(salt, "hex"), dklen, { N: n, r, p, maxmem: 512 * 1024 * 1024 });
const cipherMsg = Buffer.from(ks.crypto.cipher.message, "hex");
const checksum = createHash("sha256").update(Buffer.concat([dk.subarray(16, 32), cipherMsg])).digest("hex");
if (checksum !== ks.crypto.checksum.message) throw new Error("wrong password");
const iv = Buffer.from(ks.crypto.cipher.params.iv, "hex");
const d = createDecipheriv("aes-128-ctr", dk.subarray(0, 16), iv);
return Buffer.concat([d.update(cipherMsg), d.final()]); // 32-byte BLS secret key
}
Things to know
- Status is Review: the format is widely used in practice by validator tooling, but the ERC itself is not yet Final.
- It is deliberately not compatible with the v3 Web3 Secret Storage format; a v3 parser will not read these files.
- The keystore only protects the key as well as the password and KDF parameters allow. Use a strong password and do not lower scrypt/PBKDF2 work factors to save time.
- Because
pubkeyis stored in clear, anyone holding the file can see which validator it belongs to, even without the password.