web3.path

PHASE 01 Foundations · ~2 hours

Foundations Refresh

Blockchain is ≈ networking + crypto + a replicated state machine. Before we touch a block, make sure TCP, HTTP, and hashing are razor-sharp.

Goal — you can explain TLS in a sentence, compute a SHA-256, verify a digital signature, and sketch how packets move from curl to a server.
Contents
  1. The network under everything
  2. Hashing: the integrity primitive
  3. Symmetric vs asymmetric
  4. Digital signatures
  5. Mini-project: hash + sign CLI
  6. Quiz

1. The network under everything

Blockchain nodes talk peer-to-peer over TCP/IP. You already know this; the new thing is that there is no server — every node is both client and server.

Analogy — think of gossip in a WhatsApp group vs a company Slack. Slack is centralized (one server, everyone connects). A blockchain is a WhatsApp broadcast where everyone forwards messages to their contacts until the message saturates the network.

2. Hashing — the integrity primitive

A hash is a deterministic one-way function: same input → same output; change one bit → output changes completely (avalanche). You've seen them as ETags, Git commit IDs, and password storage.

Analogy — a hash is a fingerprint. Two PDFs with different bytes can't share one. Git's abc123... commit hash is exactly this: a SHA-1 of (tree + parent + author + message).
import hashlib
h = hashlib.sha256(b"hello").hexdigest()
# '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824'
const { createHash } = require('crypto');
const h = createHash('sha256').update('hello').digest('hex');
echo -n "hello" | openssl dgst -sha256

Properties to memorize

PropertyMeansWhy blockchain cares
Pre-image resistanceGiven h, can't find xCommit-reveal schemes
Second pre-imageGiven x, can't find x' with same hBlock integrity
Collision resistanceCan't find any x, x' with same hMerkle trees
Avalanche1-bit change → ~50% output bits flipPoW mining

3. Symmetric vs asymmetric

Two families, both needed.

SymmetricAsymmetric
Keys1 shared secretKeypair (public, private)
SpeedFast (AES, ChaCha20)~1000× slower (RSA, ECC)
Used forBulk dataKey exchange, signatures
Blockchain useRare (wallet encryption)Ubiquitous (tx signing)
Analogy — TLS uses asymmetric crypto to agree on an AES key, then switches to AES because RSA is too slow for streaming a Netflix episode. Blockchain mostly skips the symmetric part; every transaction is asymmetric.

4. Digital signatures

A signature lets Alice prove to Bob that a message came from her, without sharing her private key. Every Ethereum transaction is a signature over the tx payload.

priv_key ─► sign(msg) ─► signature msg + signature + pub_key ─► verify() ─► true/false

Ethereum uses ECDSA on secp256k1 (same curve as Bitcoin). You do not choose; this is fixed.

Show: sign & verify in Python (ECDSA)
from ecdsa import SigningKey, SECP256k1
sk = SigningKey.generate(curve=SECP256k1)
vk = sk.verifying_key
msg = b"pay bob 10 eth"
sig = sk.sign(msg)
print(vk.verify(sig, msg))  # True

5. Mini-project — a hash + sign CLI

Build a 30-line Python script that (a) takes a file, (b) prints its SHA-256, (c) signs the hash with a locally generated keypair, and (d) verifies the signature.

Deliverablepython sign.py hash file.txt, python sign.py sign file.txt, python sign.py verify file.txt sig.bin pub.pem. This is the exact mental model of how a wallet signs a transaction.
Starter (expand after you try)
import sys, hashlib
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.hazmat.primitives import hashes, serialization

cmd = sys.argv[1]
if cmd == "hash":
    print(hashlib.sha256(open(sys.argv[2],"rb").read()).hexdigest())
elif cmd == "keygen":
    sk = ec.generate_private_key(ec.SECP256K1())
    open("priv.pem","wb").write(sk.private_bytes(
        serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8,
        serialization.NoEncryption()))
    open("pub.pem","wb").write(sk.public_key().public_bytes(
        serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo))
# ... sign / verify left as exercise

Quiz

Q. Why can't we use a fast symmetric cipher (AES) to sign Ethereum transactions?
Signatures require a public/private split so verifiers don't need the signing secret. Symmetric crypto fails this: if Bob can verify, Bob can forge.
← Home Phase 2: Advanced Cryptography →