Overview
Curated: · Written: · Reviewed:
Cryptographic Primitives for Blockchain
In one line
A hash binds exact bytes, a signature binds those bytes to a key, and a Merkle root binds leaves to a block. Reach for this set whenever you must say what a block, transaction or state root proves, and what it leaves unproven.
Key definitions
- Preimage resistance: given a digest, no input is found that produces it.
- Second-preimage resistance: given one message, no different message shares its digest.
- Collision resistance: no two distinct messages share a digest. For an ideal n-bit hash, the work is about 2^(n/2).
- Domain separation: a prefix or structure that stops a valid value in one context being accepted in another.
- Low-S: the rule s <= n/2. It removes one of the two valid ECDSA forms, (r, s) and (r, n-s).
- Merkle membership proof: sibling hashes and their left/right orientation that recompute a root you already trust.
Formulas and complexity
For a 256-bit ideal digest, collision work is about 2^128 hashes, so a root committed under that digest inherits 128-bit collision security. Preimage stays near 2^256. A tree with 2^20 leaves needs 20 sibling hashes.
How it works
- Canonicalise the fields: fixed order, length prefixes, fixed integer width and endianness, NFC text.
- Prefix a domain tag (network, message type, version), then hash the bytes with the chain's exact algorithm.
- Sign the digest. The verifier rebuilds the digest from its own encoding before checking the signature.
- Leaf hashes fold into a Merkle root. The block header commits to that root and to its parent's header hash.
When to use and when not to
| Need | Use | Watch for |
|---|---|---|
| Bind a block to its contents | Root in header, parent-hash link | A root does not prove the leaves are available |
| Prove membership | Merkle membership path | Absence needs a sorted or sparse tree with explicit absence semantics |
| Authenticate a request | Ed25519, or secp256k1 where the chain requires it | Signatures do not encrypt and do not prove a human intended the action |
| Verify many signatures | Schnorr or Ed25519 batch verification | ECDSA batches gain nothing |
| Long-lived keys | Algorithm IDs and a migration plan | Discrete-log signatures fall to a quantum computer |
Traps interviewers probe
- Claiming 256-bit collision security. The fix: state 128-bit collision and 256-bit preimage, and say which one a root inherits.
- Hashing concatenated fields with no length prefix. Different messages then share bytes. The fix: length-prefix every variable field and check test vectors across every implementation.
- Treating a valid proof as proof of inclusion. A proof against an attacker-supplied root proves only internal consistency. The fix: anchor the root to consensus, a trusted checkpoint, a block, a network and a finality state.
- Re-signing a block and assuming it stands. The fix: check the child's parent hash. A changed header breaks that link, whatever the signature says.
- Reusing or biasing ECDSA nonces. Two signatures with the same k reveal the key by the algebra above. The fix: RFC 6979 or a CSPRNG with a unique k per message.
Interview tips
Open with the chain of evidence: "The hash binds these exact bytes, the signature binds them to this key, and the root binds them to this block. None of that shows the data is available or that the key belongs to a person."
Expect these follow-ups:
- How you rotate a compromised key on an immutable ledger. Old signatures stay verifiable; future authority moves by policy.
- How a light client gets a trusted root. It needs consensus, a checkpoint or another explicit anchor.
- Why a valid proof against an attacker's root proves nothing.
- What changes at billions of leaves. Proof size grows only logarithmically (40 hashes for 2^40 leaves), but storage grows linearly.
30-second outline:
- Claim: what the artifact proves, in terms of bytes, key and root.
- Mechanism: canonical encoding, domain-tagged digest, signature, then a path to a trusted root.
- Limits: no availability, no identity or intent, no non-membership without absence semantics.
- Failure: name the specific break, such as nonce reuse, a collision at 2^128 work, or a missing domain tag.
Feedback on this overview
Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.