MASTERING-BITCOIN

The Algebra Trick Behind HD Wallets

IKey Formulas

Formula Name Meaning
K=kโ‹…GK = k \cdot G Key pair identity Public key = private scalar times generator
K+tโ‹…G=(k+t)โ‹…GK + t \cdot G = (k + t) \cdot G Linearity identity Adding tโ‹…Gt \cdot G publicly equals adding tt to kk privately
kโ€ฒ=k+t,ย ย Kโ€ฒ=kโ€ฒโ‹…Gk' = k + t,\ \ K' = k' \cdot G Child key pair Derived (non-hardened) child from tweak tt
t=H(kโ€‰โˆฅโ€‰index)t = H(k \,\|\, \text{index}) Hardened tweak Mixes parent private key into the tweak so KK alone cannot derive child

IIVisualization 1: Linearity โ€” Two Paths, One Destination

The single identity K+tโ‹…G=(k+t)โ‹…GK + t \cdot G = (k + t) \cdot G is the whole trick. It says that scalar multiplication by GG is linear, so adding a tweak on the public side gives the same point as adding the tweak to the secret and multiplying after.

Below, GG is drawn as a 2D vector standing in for the elliptic-curve generator. Scalar multiplication of a vector by an integer has the same linearity property that the elliptic curve has. Watch how the public route (red then blue) and the private route (green dashed) always land on the same endpoint Kโ€ฒK'.

โš™ interactive visualization โ€” coming to this page format soon

Notice: No matter which values of kk and tt you pick, the gold star sits at exactly the same point whether you traveled there by the public route (red + blue) or the private route (green dashed). That single fact is the whole reason watch-only wallets and offline hardware signers can agree on addresses without ever sharing a secret.

IIIVisualization 2: The BIP32 Tree

BIP32 applies the tweak trick recursively. From a single master key (derived from a 12- or 24-word seed), an entire tree of child key pairs is generated โ€” accounts, receiving/change chains, and thousands of individual addresses per chain. Explore the tree below by picking an account and an address index.

โš™ interactive visualization โ€” coming to this page format soon

Reflect: The entire tree โ€” every account, every chain, every address โ€” is reproducible from the same seed phrase. One paper backup protects a lifetime of addresses. Non-hardened branches (the lower levels) allow an online machine holding only KK to derive child public keys; hardened branches (the top-level accounts, marked with an apostrophe) isolate sensitive segments so a leaked child reveals nothing upstream.

IVQuiz

Question 1

Alice holds the master private key kk and the master public key K=kโ‹…GK = k \cdot G. Bob has only KK. Bob picks a tweak t=42t = 42 and computes K+tโ‹…GK + t \cdot G.

What does Bob's result equal?

โœ… Correct! This is the linearity identity with t=42t = 42.

โŒ Not quite. Remember the identity K+tโ‹…G=(k+t)โ‹…GK + t \cdot G = (k + t) \cdot G.

Show solution

Solution:

The linearity identity says K+tโ‹…Gโ€…โ€Š=โ€…โ€Š(k+t)โ‹…G.K + t \cdot G \;=\; (k + t) \cdot G.

So with t=42t = 42, K+42โ‹…Gโ€…โ€Š=โ€…โ€Š(k+42)โ‹…G.K + 42 \cdot G \;=\; (k + 42) \cdot G.

The child private key is kโ€ฒ=k+42k' = k + 42, and the child public key is Kโ€ฒ=kโ€ฒโ‹…GK' = k' \cdot G. Bob computed Kโ€ฒK' using only public data; Alice can later compute the matching kโ€ฒk' by adding 4242 to her secret kk.

Note why the other options are wrong:

  • "k ยท (G + 42)" โ€” โŒ You cannot add the scalar 4242 to the curve point GG.
  • "(k ยท 42) ยท G" โ€” โŒ That would be 4242 times the public key, not the linearity identity.
  • "k + 42 ยท G" โ€” โŒ Mixes a scalar and a point; not a valid expression.

Question 2

True or False: A web frontend that holds only the master public key KK (and never any private key) can still generate an unlimited supply of fresh Bitcoin receiving addresses for customers, as long as it uses non-hardened derivation.

โœ… Correct! This is the watch-only wallet pattern.

โŒ Not quite. The linearity identity lets you compute child public keys from KK alone along non-hardened branches.

โŒ Not quite. Try again โ€” the hints above can help.

Show solution

Solution: True.

For each new payment the frontend picks a fresh tweak tt (often derived deterministically, e.g. from a counter or a chain code and an index) and computes Kโ€ฒ=K+tโ‹…G.K' = K + t \cdot G.

This uses only the master public key KK and the publicly-computable point tโ‹…Gt \cdot G. No secret is required on the frontend. The matching private key kโ€ฒ=k+tk' = k + t only needs to exist on the offline hardware signer when a spend is actually required.

This is exactly what powers watch-only wallets, exchange deposit address generation, and the hot/cold split in hardware-wallet setups.

(Note: hardened derivation breaks this trick on purpose โ€” but Question 3 covers that.)

Question 3

An attacker somehow learns a non-hardened child private key kโ€ฒk' and also learns the tweak tt that produced it from the parent.

What can the attacker compute?

โœ… Correct! This upward leak is exactly the reason hardened derivation exists.

โŒ Not quite. With non-hardened derivation, kโ€ฒ=k+tk' = k + t, so subtracting tt recovers kk.

Show solution

Solution:

Non-hardened derivation uses kโ€ฒ=k+tk' = k + t where tt is a publicly-computable tweak. If an attacker knows both kโ€ฒk' and tt, they can simply rearrange: k=kโ€ฒโˆ’t.k = k' - t.

This is the known downside of non-hardened derivation, and it is exactly why BIP32 also defines hardened derivation. Hardened derivation builds the tweak from a hash of the parent private key: t=H(kโ€‰โˆฅโ€‰index).t = H(k \,\|\, \text{index}).

Because an attacker with only KK (or even a leaked child key) cannot invert the hash to recover kk, hardened derivation breaks the public-side linearity trick on purpose and isolates the branch.

Rule of thumb:

  • Non-hardened โ€” use where you need watch-only address generation.
  • Hardened โ€” use at sensitive boundaries (e.g., top-level accounts) to contain the blast radius of a leak.

Question 4

Which property of elliptic-curve scalar multiplication is the single fact that makes HD wallets, watch-only wallets, and offline hardware signers all possible?

โœ… Correct! Linearity is the one property doing the heavy lifting across every HD-wallet feature.

โŒ Not quite. The other properties matter for Bitcoin, but the HD-wallet trick specifically depends on linearity.

Show solution

Solution:

The key property is linearity: K+tโ‹…Gโ€…โ€Š=โ€…โ€Š(k+t)โ‹…G.K + t \cdot G \;=\; (k + t) \cdot G.

Because adding the same tweak on each side preserves the K=kโ‹…GK = k \cdot G relationship, you can derive a valid child public key on the public side (using only KK) and the matching child private key on the private side (using only kk), and they will line up โ€” with no communication required beyond the publicly-known tweak.

The other options are all true statements about EC cryptography, but they play different roles:

  • One-wayness (option 1) is what keeps the master private key safe once the master public key is published. It's necessary for Bitcoin to work at all, but it is not what enables HD derivation.
  • The point at infinity and SHA-256 are plumbing details; neither one is what makes the public/private split of HD wallets possible.

One line of algebra carries the entire self-custody stack.

Solved: 0 / 4