Homework 1 · Part 2

From Wallet Seed to Ethereum Address: Hashing, Key Derivation and Cryptographic Primitives

Twelve words become a 0x… address through six standards. This page takes the pipeline apart. For each step it shows what kind of operation it is (generation, derivation, public-key cryptography, hashing, checksum or encoding), runs it live in the browser, and measures its statistical behaviour.

01

The pipeline at a glance

Boxes are data, arrows are operations. Every arrow is deterministic except the first. After the entropy is drawn, the whole wallet (every key, every address) can be recomputed from the words alone.

  1. Entropy128–256 random bits
  2. CSPRNGkey generation
  3. Mnemonic12–24 words
  4. BIP-39 append SHA-256 checksum bits, split into 11-bit word indicesencodingchecksum
  5. Seed512 bits
  6. BIP-39 PBKDF2-HMAC-SHA512, 2048 rounds, salt "mnemonic" + passphrasekey derivation
  7. Master key + chain code256 + 256 bits
  8. BIP-32 child derivation along the BIP-44 path m/44'/60'/0'/0/ikey derivation
  9. Private key k256 bits, 1 ≤ k < n
  10. secp256k1 Q = kGpublic-key crypto
  11. Public key64 bytes, X ‖ Y
  12. Keccak-256, keep the last 20 byteshashing
  13. Address20 bytes, 40 hex digits
  14. EIP-55 uppercase hex letters chosen by Keccak-256(address)checksumencoding
  15. Checksummed address0xf39Fd6e5…b92266
02

Six kinds of operation, kept apart

Key generation

Creating secret material from randomness. It is the only non-deterministic step: a CSPRNG draws 128–256 bits. Its quality bounds everything after it, because nothing downstream can add entropy.

Pipeline: entropy for the mnemonic. Property: unpredictable and uniform.

Key derivation

Computing new keys deterministically from existing secrets with a keyed pseudo-random function (HMAC-SHA512). It adds no entropy. It spreads one secret into many keys that look independent.

Pipeline: PBKDF2 seed stretching, BIP-32 child keys along the BIP-44 path.

Public-key cryptography

A one-way relation between a private and a public key (Q = kG) that also supports signatures: anyone can verify, only the holder of k can sign.

Pipeline: secp256k1 public key; ECDSA signatures on every transaction.

Hashing

Unkeyed map from arbitrary input to a fixed-size digest that behaves like a random function. Preimage, second-preimage and collision resistance, plus the avalanche effect.

Pipeline: Keccak-256 for the address. SHA-256 and SHA-512 inside the BIP-39 checksum, HMAC and PBKDF2.

Checksums

Redundancy that detects accidental errors (typos, swapped words). Not a security mechanism against an adversary: anyone can compute a valid checksum.

Pipeline: the last 4–8 bits of a BIP-39 phrase, the letter case of an EIP-55 address.

Encoding

A reversible change of representation with no secret and no loss: bits ↔ words, bytes ↔ hex, a mixed-case display. It provides no confidentiality.

Pipeline: the BIP-39 wordlist, hexadecimal addresses, EIP-55 capitalisation.

Generation vs derivation: generation answers "where does the secret come from?" (randomness). Derivation answers "how do I get more keys out of it?" (a deterministic function). A wallet does one generation and unlimited derivations. That is why backing up 12 words backs up every account the wallet will ever create.

03

Live demo: run the pipeline

Test phrases only. The demo generates new phrases or loads public test phrases, and runs entirely in the browser. Never type a real recovery phrase into any website.

  1. 1 · Entropy

    key generation

    Random bits from crypto.getRandomValues (a CSPRNG). For the test phrases, the bits are recovered from the words.

    hex
  2. 2 · Mnemonic (BIP-39)

    encodingchecksum

    ENT bits + CS = ENT/32 bits of SHA-256(entropy), cut into 11-bit groups. Each group indexes one of 2048 words. Click a word to replace it with a random one and watch the checksum fail (it survives about 1 time in 16).

  3. 3 · Seed

    key derivation

    PBKDF2(HMAC-SHA512, password = mnemonic, salt = "mnemonic" + passphrase, 2048 rounds, 64 bytes). The rounds slow down brute force. The passphrase has no checksum: every passphrase opens a valid but different wallet.

    seed

  4. 4 · HD derivation (BIP-32 along a BIP-44 path)

    key derivation

    Master: I = HMAC-SHA512("Bitcoin seed", seed). Each child: I = HMAC-SHA512(chain code, data), child key = (IL + parent key) mod n. A prime ′ marks a hardened index (≥ 2³¹), whose data is the parent private key. Normal indices hash the parent public key.

    PathLevel (BIP-44)HardenedPrivate keyChain code
  5. 5 · Private key

    key derivation (result)
    k
  6. 6 · Public key (secp256k1)

    public-key crypto

    Q = kG on y² = x³ + 7 over Fp, p = 2²⁵⁶ − 2³² − 977. This is the same computation as Part 1 on a curve of size ≈ 2²⁵⁶. It is written as 04 ‖ X ‖ Y.

    04 ‖ X ‖ Y
  7. 7 · Keccak-256 → address

    hashing

    Hash the 64 bytes X ‖ Y (without the 04 prefix) and keep the last 20 bytes, highlighted below.

    Keccak-256
    address
  8. 8 · EIP-55 checksum

    checksumencoding

    Hash the lowercase hex text with Keccak-256. Each letter a–f is uppercased when the hash nibble at the same position is ≥ 8. Digits 0–9 carry no information.

    Checksummed address
04

The standards and primitives

StandardYearRole and purposeKind
BIP-392013Turns entropy into a phrase humans can write down and re-type, with a checksum against transcription errors. Stretches the phrase into a seed.encoding, checksum, derivation
BIP-322012Hierarchical deterministic wallets: a tree of keys from one seed. Extended public keys (xpub) derive child public keys without any private key (watch-only wallets).derivation
BIP-442014A convention for which branch of the tree to use: m / purpose′ / coin_type′ / account′ / change / index. Ethereum is coin type 60 (SLIP-44). This lets different wallets find the same accounts.derivation (layout)
secp256k12000 (SEC 2)Elliptic curve y² = x³ + 7 used for the key pair and ECDSA signatures. Ownership of an account is the ability to sign with k.public-key crypto
Keccak-2562008 / 2012Ethereum's general hash. Here it compresses the 64-byte public key into a uniform-looking identifier and drives the EIP-55 checksum.hashing
EIP-552016Backward-compatible checksum: uses the case of hex letters, which old software ignores, to catch typos in addresses.checksum, encoding
05

Statistical properties, step by step

StageDistribution / entropyStatistical fact worth knowing
EntropyUniform on {0,1}ENT, ENT = 128 or 256All later uniformity is inherited from here. A biased RNG cannot be repaired downstream: a "uniform-looking" address from 32 bits of entropy is still brute-forceable.
Mnemonic204812 = 2132 word sequences, 2128 validA random 12-word sequence has a valid checksum with probability 2−4 = 1/16 (24 words: 2−8). The first 11 words are free. Given them, only 128 of the 2048 possible last words are valid.
SeedPseudo-random 512 bitsPBKDF2 adds ~11 bits of work (211 rounds) but no entropy. A wrong passphrase is undetectable: it gives a different, equally random-looking wallet.
BIP-32 child keys≈ uniform on [1, n−1]Child keys look independent of each other and of the parent: knowing one account key reveals nothing about the others (for hardened levels).
Public keyUniform over the 2256-point group, not over 512-bit stringsX takes only about half the values below p, and Y is determined by X up to sign. 64 bytes carry about 256 bits of entropy. As in Part 1, the structure is there by design.
Keccak-256 / address≈ uniform on {0,1}160Avalanche: one flipped input bit changes ≈ 128 ± 8 of the 256 output bits. 160-bit addresses give ~280 collision resistance (birthday bound) and 2160 for a second preimage.
EIP-55Letter count L ~ Binomial(40, 6/16), mean 15Each letter carries one check bit, so a random error passes with probability E[2−L] = (10/16 + 6/16 · ½)40 = (13/16)40 ≈ 0.0247%, the figure quoted in EIP-55. All-lowercase and all-uppercase input carry no check at all. By the same formula, about 2 · 0.0247% ≈ 0.05% of addresses have a correct EIP-55 form that is single-case, so validators cannot tell them from unchecked input.
06

Experiments: measure it

Monte Carlo estimates of the probabilities above, using the same code as the demo. Intervals are 95% Wilson score intervals. The experiments start when this section scrolls into view and take a few seconds. A 95% interval misses the true value 1 time in 20, so an occasional "outside" is expected. Press run again and it should move.

A · BIP-39 checksum: how often does a wrong phrase pass?

B · EIP-55: how often does a typo pass?

A random address gets one character replaced and is checked against its EIP-55 checksum. Each letter a–f carries one check bit, so a typo passes only when all the letter cases still happen to match: about (13/16)40 ≈ 0.0247% of the time.

Letters per address

number of a–f characters in random addresses vs Binomial(40, 6/16)

C · Keccak-256 avalanche

Changed output bits after flipping one input bit

Input: random 64-byte strings, the size of an uncompressed public key without prefix. Flip one random bit and compare the two digests.

For a random function the number of changed bits is Binomial(256, ½): mean 128, standard deviation 8. The observed histogram should match the curve. A visible shift or excess spread would be a statistical defect, which is exactly what hash designers test for.

D · Are addresses uniform?

Hex digit frequencies in addresses

Share of 1s per address bit (160 bits)

07

Timeline

The milestones of the wallet pipeline, in chronological order.

  1. 1977
    RSA (Rivest, Shamir, Adleman): first practical public-key encryption and signature scheme, based on factoring.
  2. 2001
    SHA-2 family (SHA-256, SHA-512) published by NIST.
  3. 2012
    Keccak wins SHA-3 (October). BIP-32 (Wuille): hierarchical deterministic wallets.
  4. 2013
    BIP-39: mnemonic code for generating deterministic keys.
  5. 2014
    BIP-44: multi-account hierarchy and coin types. Ethereum's yellow paper specifies Keccak-256 as submitted, with the original padding. The same year NIST's draft FIPS 202 adds domain-separation bits.
  6. 2015
    SHA-3 standardized (FIPS 202, August). Ethereum mainnet launches in July with Keccak-256, so "SHA3" in Ethereum code means Keccak-256.
  7. 2016
    EIP-55: mixed-case checksum addresses.

The order explains the oddities: Ethereum adopted Keccak between the competition win and the final standard, and the Bitcoin-era wallet standards (BIP-32/39/44, all using SHA-2/HMAC) were reused unchanged for Ethereum by choosing coin type 60.

08

SHA-2 / SHA-512 vs Keccak / SHA-3

SHA-2 (SHA-256, SHA-512)Keccak / SHA-3
ConstructionMerkle–Damgård: iterate a compression function over blocksSponge: absorb into, then squeeze out of, a 1600-bit state
Length extensionVulnerable: H(m) lets you compute H(m ‖ pad ‖ x). Hence HMACNot vulnerable: the capacity part of the state is never output
256-bit variantSHA-256: 512-bit blocks, 64 roundsrate 1088 bits, capacity 512 bits, 24 rounds
In this pipelineSHA-256 (BIP-39 checksum), SHA-512 inside HMAC (PBKDF2, BIP-32)Keccak-256 (address, EIP-55)

Keccak-256 ≠ SHA3-256. Both use the same permutation and the same rate and capacity. Only the padding differs: FIPS 202 appends two domain-separation bits 01 before the pad10*1 rule, so the first padding byte is 0x06 instead of Keccak's 0x01. This one byte changes every digest. Try it:

Keccak-256
SHA3-256
SHA-256

09

Why not one algorithm for everything?

LayerWhat it must achieveChosen toolWhy another tool would not do
Key management (BIP-39/32/44)Human backup, error detection, unlimited keys from one secret, cross-wallet interoperability, watch-only xpubsWordlist encoding + SHA-256 checksum, PBKDF2 and HMAC-SHA512 derivation, a path conventionA hash alone cannot do public derivation (xpub). That needs the homomorphism of the curve: child pub = parent pub + IL·G.
Ownership (secp256k1)Anyone verifies, only the owner signsECDSA over secp256k1A hash has no key pair. RSA would need ~3072-bit keys for comparable security, against 256-bit keys on the curve.
Identifier (Keccak-256)Short, uniform, collision-resistant name for a public keyKeccak-256, truncated to 160 bitsThe public key is 64 bytes and structured (Part 1: not bit-uniform). Hashing compresses it and removes the structure.
Typing safety (EIP-55)Catch typos without changing the address formatCase-based checksumA cryptographic MAC would need a key. A new format would break existing software. Case is free redundancy that old parsers ignore.

The deep reason, linking Part 1 and Part 2: the properties conflict. Public-key cryptography and xpub derivation need algebraic structure (a homomorphism). Addresses and checksums need the absence of structure (random-function behaviour). No single primitive can be both, so the pipeline alternates between them: structured where structure is useful, hashed where it would leak or bias.

10

Try it in a real wallet

Real wallets show each standard at work. Use a separate browser profile and only the public test phrase. Never put real funds on it.

  1. Install MetaMask (or Rabby or Rainbow) in the fresh profile and choose import wallet with the Hardhat phrase test test … test junk.
  2. The first account should be 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266, the same as the demo above.
  3. Import the same phrase into a second wallet app: the same addresses appear. This is BIP-39/32/44 interoperability.

What to look for

  • Recovery phrase screen: 12 words from a fixed list of 2048, the BIP-39 encoding. A phrase with a bad checksum is rejected.
  • "Add account": a new BIP-32 child along the BIP-44 path. Nothing new needs backing up.
  • Address display: the mixed case is the EIP-55 checksum.