Skip to content
Nat Lee

Keyboard shortcuts

Turn these off if they get in the way of a screen reader or voice control. The setting is saved in this browser.

1
Home
2
Work
3
Projects
4
About
5
Experience
/
Search projects
?
Show this panel

Backend

Spin-off · Contract work

Blockchain from Scratch

A blockchain you can take apart

Nine hands-on chapters, from hashing to a peer-to-peer network. The same Rust code powers interactive WebAssembly demonstrations in your browser.

Role
Creator & Maintainer
Period
2018 – 2026.11
Status
Completed
Categories
Infrastructure & backend
Origin
Contract work
Stack
  • Rust
  • WebAssembly
  • TypeScript
  • Docker
Blockchain from Scratch, screenshot 1

Overview

A learning project that builds a blockchain in Rust, one executable chapter at a time: hashes, blocks, mining, signatures, a mempool, networking, consensus and file proofs. Browser demonstrations compile the same Rust core to WebAssembly; Docker Compose runs a three-node network.

What it's good for

For anyone who has written a little code and wants to see what a blockchain does underneath: no cryptography background needed, and Rust newcomers get comments on ownership and async. Every exercise ships with a tested answer, so cargo test tells you whether you got it, not a forum.

Diagrams

Main paths only. The edge cases stayed in the code.

Edit block 1 and nothing after it can be trusted. Go on, try it.

Point at a box to see what it connects to.

  1. A peer sends blocks(a RESPONSE_BLOCKCHAIN message) → One block or a chain?
  2. One block or a chain? → one block: Already have this block? → whole chain: Check every block from genesis
  3. Already have this block?(stops messages looping forever) → yes, ignore: Wait for the next message → no: Fits after my latest block?
  4. Fits after my latest block? → yes: Check it, then append → newer, no fit: Ask for the whole chain → older: Wait for the next message
  5. Ask for the whole chain(QUERY_ALL: admit you're behind) → peer replies: A peer sends blocks
  6. Check it, then append(trial run on a ledger copy) → Broadcast my new latest block
  7. Check every block from genesis(hash, link, difficulty, work) → More total work than mine?
  8. More total work than mine?(work wins, not length) → yes: Replay the ledger from scratch → no, or tie: Wait for the next message
  9. Replay the ledger from scratch(every transaction must hold) → Return orphaned transactions
  10. Return orphaned transactions(rechecked; double spends dropped) → Switch to the new chain
  11. Switch to the new chain → Broadcast my new latest block
  12. Broadcast my new latest block → Wait for the next message
  13. Wait for the next message

Features

  • Nine chapters with runnable examples and exercises
  • Interactive hashing, mining and tampering demonstrations
  • Shared Rust core compiled to WebAssembly
  • Three-node Docker network and a file-proof application
Edit block 1 and it turns red; every block after it can no longer be trusted.
Edit block 1 and it turns red; every block after it can no longer be trusted.

What I learned

  • The 2018 node signed only the ciphertext, so a record's name, hash and level could be changed on the way. The rewrite signs the whole record.
  • Receiving any chain used to empty the mempool and lose queued records. Now only mined transactions leave, and ones dropped in a reorg are rechecked.
  • Rust's rsa crate has an unfixed timing advisory (RUSTSEC-2023-0071), bad news for a node that decrypts for others all day, so the rewrite uses X25519.
  • The double-spend demo after the fork heals: four nodes agree, and Bob's 50 is gone.
    The double-spend demo after the fork heals: four nodes agree, and Bob's 50 is gone.
  • FileChain: upload a certificate, mine it into a block, then find it again by name.
    FileChain: upload a certificate, mine it into a block, then find it again by name.
  • Infrastructure & backend1313 stars on GitHub

    Telepy

    One outbound reverse SSH tunnel per device gives you a browser terminal, files, remote desktop, a remote browser and the LAN behind it. No port forwarding, no VPN, no public IP.

    2024Active
  • Infrastructure & backend66 stars on GitHub

    Dev Dock Manager (Rust)

    One Docker dev box per user, with a web terminal, a noVNC desktop and optional GPU. The Django version, rewritten in Rust, partly to find out whether I could.

    2023Active
  • Infrastructure & backend1010 stars on GitHub

    Dev Dock Manager

    The original Django dev-box manager: isolated Docker environments for several users on one machine. The Rust version replaced it, but this one carried the load first.

    2022Completed