Introduction

Hi, I'm cardene, a software engineer and technical writer focused on blockchain and AI.

I've also authored Japanese technical books on specification-driven development with LLMs and decentralized application (DApp) development.

I also build and publish a variety of tools, libraries, and open-source projects.

ERC-2335 proposes a JSON-based keystore format for securely storing and decrypting BLS12-381 private keys in a chain-neutral manner.

This article translates, summarizes, and expands on the following specification.

More EIP and ERC explainers are available here:

Overview

ERC-2335 defines a standard JSON format for securely storing and transferring private keys used in BLS12-381 signatures. A keystore encrypts the private key so that it remains protected until the user supplies the password. The encrypted file can also be transferred between devices, subject to appropriate password and file protection.

The specification is not limited to Ethereum 2.0. It is intended for other projects and ecosystems using BLS12-381 signatures, with the eventual aim of moving the standard to a more neutral venue.

ERC-2335 builds on EIP-2333 and ERC-2334.

For EIP-2333, see the following article.

EIP-2333: BLS key derivation for the post-quantum era

For ERC-2334, see the following article.

EIP-2334: Purpose-specific derivation paths for BLS keys

Motivation

When users manage their own private keys, secure storage and transfer are essential. A keystore lets users control access to their private keys.

Ethereum 1.0 used the Web3 Secret Storage Definition for this purpose, but the proposal identifies two limitations for future use.

  • Dependence on Keccak-256

Ethereum 1 keystores use Keccak-256 to compute checksums. Although this fits Ethereum, BLS12-381 keys and signatures are intended to be chain-neutral. Depending on a hash function associated with a particular ecosystem undermines that goal.

  • Lack of abstraction

The Ethereum 1 keystore specification accumulated features over time without a consistent abstraction across its design. A more abstract structure can accommodate future cryptographic algorithms and key characteristics.

ERC-2335 therefore aims to provide a neutral, flexible keystore standard.

Specification

ERC-2335 defines a JSON format for securely storing and decrypting BLS12-381 private keys.

Decryption process

Decrypting a private key involves three steps:

  • Derive the decryption key.
  • Verify the password.
  • Decrypt the private key.

Each step uses cryptographic functions and parameters described by modules in the keystore file.

Password processing

Password format

A password may contain arbitrary Unicode characters. Before processing it:

  1. Normalize it using Unicode NFKD.
  2. Remove control characters.
  3. Encode it as UTF-8.

Removing control characters

The following control characters must be removed:

  • C0 controls
    • 0x00 through 0x1F, including newlines and tabs.
  • C1 controls
    • 0x80 through 0x9F.
  • Delete
    • 0x7F.

Spaces (0x20) are permitted.

Module structure

ERC-2335 organizes cryptographic operations into modules. Each module contains three fields:

  • function
    • The cryptographic algorithm.
  • params
    • Parameters required by that function.
  • message
    • The data associated with the operation.

This structure allows algorithms to be replaced without changing the overall format.

Deriving the decryption key (KDF)

The decryption key is derived from the user's password and the function and parameters specified in the kdf module. It is used both for password verification and decryption.

Supported key derivation functions include:

  • pbkdf2
    • RFC 2898, with parameters such as iteration count, derived key length, and salt.
  • scrypt
    • RFC 7914, with parameters such as memory cost, parallelization, and salt.

Password verification

The password is verified as follows:

  1. Extract bytes at offsets 16 through 31 of the derived key (the slice DK[16:32]), called DK_slice.
  2. Concatenate DK_slice with cipher.message to construct pre_image.
  3. Compute its SHA-256 hash and compare it with checksum.message.
  4. A match indicates successful password verification.

The hash function used here is sha256 (RFC 6234).

Private key decryption

The encrypted private key (cipher.message) is decrypted using the specified cipher and parameters. The cipher uses the initial portion of the derived key: the first 16 bytes for AES-128.

The supported cipher in version 4 is:

  • aes-128-ctr (counter mode)
    • Parameter
      • iv (initialization vector).
    • Specification
      • RFC 3686.

Additional fields

  • description

    An optional descriptive string identifying the keystore or its purpose in a user interface.

  • pubkey

    The corresponding public key. It can be inspected without supplying the password and follows the BLS12-381 encoding conventions.

  • path

    The position in the key hierarchy defined by ERC-2334, for example m/12381/3600/0/0/0. An unspecified path is represented by an empty string ("").

  • uuid

    A 128-bit identifier conforming to RFC 4122, used to uniquely identify the keystore.

  • version

    The format version is fixed at 4 in this specification.

JSON schema

The keystore is represented in JSON with the following fields:

json
{
  "crypto": {
    "kdf": { "function": "...", "params": {...}, "message": "..." },
    "checksum": { "function": "...", "params": {...}, "message": "..." },
    "cipher": { "function": "...", "params": {...}, "message": "..." }
  },
  "description": "...",
  "pubkey": "...",
  "path": "...",
  "uuid": "...",
  "version": 4
}

Each cryptographic module (kdf, checksum, and cipher) contains the function, parameters, and message fields.

Additional considerations

The design follows the same general approach as the earlier Ethereum 1 keystore specification, with two important differences.

  • No Keccak-256 checksum

Ethereum 1 keystores use Keccak-256 to calculate checksums. ERC-2335 does not use it, reflecting the goal of a chain-neutral standard.

  • Module abstraction

ERC-2335 represents key derivation, checksums, and encryption through the same module structure. Each component can therefore be replaced independently, making the format easier to design, implement, and extend.

The version number is set to 4 to avoid collisions with the earlier Ethereum 1 keystore version numbers.

Compatibility

ERC-2335 is not backward-compatible with the existing Ethereum 1 keystore format because it does not include the Keccak-256 checksum mechanism.

Although the modular structure could theoretically accommodate a Keccak-256 checksum, doing so would undermine the proposal's goal of chain neutrality.

The format is therefore designed to serve a broader community of BLS12-381 users and blockchain ecosystems rather than being specific to Ethereum.

Citation

Carl Beekhuizen (@CarlBeek) carl@ethereum.org, "ERC-2335: BLS12-381 Keystore [DRAFT]," Ethereum Improvement Proposals, no. 2335, September 2019. [Online serial]. Available: https://eips.ethereum.org/EIPS/eip-2335.

Conclusion

ERC-2335 standardizes a JSON-based format for storing and decrypting BLS12-381 private keys securely and in a chain-neutral manner.

Questions are welcome via Twitter @cardene777.

Other publications:

https://chaldene.net/