Learning Objectives:
-
Understand the cryptographic primitives used in blockchain
-
Explain hashing, digital signatures, and public-key cryptography
-
Apply cryptographic concepts to blockchain applications
1.3.1: Cryptographic Hash Functions
Definition:
A cryptographic hash function is a mathematical algorithm that maps data of arbitrary size to a fixed-size output (hash value).
Key Properties of Cryptographic Hashes:
| Property | Description | Importance |
|---|---|---|
| Deterministic | Same input always produces same output | Verification |
| Fast Computation | Hash computation is efficient | Performance |
| Pre-image Resistance | Cannot reverse hash to find input | Security |
| Second Pre-image Resistance | Cannot find different input with same hash | Integrity |
| Collision Resistance | Cannot find two inputs with same hash | Uniqueness |
| Avalanche Effect | Small change in input drastically changes output | Sensitivity |
Common Hash Functions in Blockchain:
| Hash Function | Output Size | Blockchain Use |
|---|---|---|
| SHA-256 | 256 bits | Bitcoin, many others |
| Keccak-256 (SHA-3) | 256 bits | Ethereum, zk-SNARKs |
| RIPEMD-160 | 160 bits | Bitcoin addresses |
| Blake2b | 256-512 bits | Filecoin, Zcash |
| SHA-512 | 512 bits | Some altcoins |
Mathematical Representation:
Hash Function: H: {0,1}* β {0,1}βΏ
Where:
- {0,1}* = Any binary input (arbitrary length)
- {0,1}βΏ = Fixed-length output (n bits)
Example:
H("Blockchain") = 0x8a7c8f4e... (256-bit hash)
1.3.2: Hash Function Properties in Detail
1. Pre-image Resistance
Given a hash value h, it should be computationally infeasible to find any message m such that H(m) = h.
Given: H(m) = h Goal: Find m from h Difficulty: O(2βΏ) operations (where n = output bits) For SHA-256 (n=256): 2Β²β΅βΆ operations (infeasible)
2. Second Pre-image Resistance
Given a message mβ, it should be computationally infeasible to find mβ β mβ such that H(mβ) = H(mβ).
Given: H(mβ) = h Goal: Find mβ β mβ with H(mβ) = h Difficulty: O(2βΏ) operations Implication: Cannot change a transaction without changing its hash
3. Collision Resistance
It should be computationally infeasible to find any two distinct messages mβ and mβ such that H(mβ) = H(mβ).
Goal: Find mβ β mβ with H(mβ) = H(mβ) Difficulty: O(2^(n/2)) operations (Birthday attack) For SHA-256: 2ΒΉΒ²βΈ operations (infeasible)
1.3.3: Public-Key Cryptography
Definition:
Public-key cryptography uses pairs of keys:
-
Public Key:Β Can be shared with anyone
-
Private Key:Β Must be kept secret
Key Generation:
Private Key (sk) βββ
ββββ Public Key (pk)
β
β (One-way function: pk = f(sk))
β
β Given pk, cannot find sk
βΌ
Elliptic Curve Cryptography (ECC):
Most blockchain systems use ECC because:
-
Smaller keys (256 bits vs 3072 bits for RSA)
-
Faster computations
-
Stronger security per bit
Bitcoin Address Generation:
Private Key (256 bits)
β
βΌ
Elliptic Curve Multiplication
β
βΌ
Public Key (33/65 bytes)
β
βΌ
SHA-256 Hash
β
βΌ
RIPEMD-160 Hash (20 bytes)
β
βΌ
Base58Check Encoding
β
βΌ
Bitcoin Address
1.3.4: Digital Signatures
Definition:
Digital signatures provide proof of authenticity and integrity of a message.
Signature Process:
Signing:
Message βββ
ββββ Signature Algorithm βββ Signature
Private Keyββ
Verification:
Message βββ
ββββ Verification Algorithm βββ Valid/Invalid
Public Keyββ
Signatureββ
Properties of Digital Signatures:
| Property | Description |
|---|---|
| Authenticity | Proof that signer created the signature |
| Integrity | Message cannot be changed without invalidating signature |
| Non-repudiation | Signer cannot deny signing the message |
| Verifiability | Anyone can verify with public key |
Signature Schemes in Blockchain:
| Scheme | Blockchain | Features |
|---|---|---|
| ECDSA | Bitcoin, Ethereum | Standard, widely used |
| Schnorr | Bitcoin (Taproot) | More efficient, aggregation |
| Ed25519 | Solana, Zcash | Faster, smaller signatures |
| BLS | Ethereum 2.0 | Signature aggregation |
1. SHA-256 Deep Dive
SHA-256 Algorithm Overview:
SHA-256 Processing:
1. Padding:
- Add '1' bit to end of message
- Add '0' bits until length β‘ 448 mod 512
- Add 64-bit representation of original length
2. Initialize Hash Values (8 Γ 32 bits):
hβ = 0x6a09e667
hβ = 0xbb67ae85
hβ = 0x3c6ef372
hβ = 0xa54ff53a
hβ = 0x510e527f
hβ
= 0x9b05688c
hβ = 0x1f83d9ab
hβ = 0x5be0cd19
3. Process in 512-bit chunks:
For each chunk:
a. Create 64 message schedule words (32-bit each)
b. Initialize working variables
c. Perform 64 rounds of compression
d. Add to hash values
4. Final Output:
Concatenate hβ to hβ (256-bit hash)
2. Merkle Trees
Definition:
A Merkle tree is a binary tree where each leaf node is a hash of a transaction, and each internal node is a hash of its children.
Merkle Tree Structure:
Merkle Root (Hββββ)
β
βββββββββββββββββ΄ββββββββββββββββ
β β
Hββ Hββ
β β
βββββββ΄ββββββ βββββββ΄ββββββ
β β β β
Hβ Hβ Hβ Hβ
β β β β
Txβ Txβ Txβ Txβ
Verification:
To prove Txβ is in the tree, provide:
- Hβ
- Hββ
- Merkle Root
(Logβ(n) hashes needed for proof)
Merkle Proof Size:
Proof Size = logβ(N) hashes For 1,000,000 transactions: Proof Size = logβ(1,000,000) β 20 hashes = 640 bytes This allows light clients to verify transactions efficiently
3. ECDSA Signatures
ECDSA Signing Process:
Parameters: - Curve: secp256k1 (for Bitcoin) - G = Generator point - n = Order of curve Signing: 1. Generate random k (1 β€ k β€ n-1) 2. Compute point R = k Γ G 3. r = R.x mod n 4. Compute s = kβ»ΒΉ Γ (z + r Γ priv_key) mod n 5. Signature = (r, s) Verification: 1. Check 1 β€ r β€ n-1 and 1 β€ s β€ n-1 2. Compute uβ = z Γ sβ»ΒΉ mod n 3. Compute uβ = r Γ sβ»ΒΉ mod n 4. Point = uβ Γ G + uβ Γ pub_key 5. Verify point.x == r Where z = hash(message)
4. Digital Signature Properties
Security Properties:
1. Existential Unforgeability (EUF): Cannot create valid signature without private key 2. Strong Unforgeability: Cannot create valid signature for any new message 3. Non-repudiation: Signer cannot deny signing the message 4. Message Binding: Signature is tied to the specific message 5. Key Binding: Signature is tied to the specific signer
5. Cryptographic Security Levels
| Security Level | Symmetric (AES) | RSA | ECC | Quantum Resistant? |
|---|---|---|---|---|
| 80-bit | 80 bits | 1024 bits | 160 bits | No |
| 128-bit | 128 bits | 3072 bits | 256 bits | No |
| 192-bit | 192 bits | 7680 bits | 384 bits | No |
| 256-bit | 256 bits | 15360 bits | 521 bits | Yes (with PQ) |