Noding a Blockchain

Noding a Blockchain

Blockchains and cryptocurrency are all the hot rage these days. But if you're like me, it all seems like a bunch of voodoo magic math and super complicated algorithms.

So I decided the best way to de-mystify and learn it was to build my own blockchain and cryptocurrency. And of course, I started with Node! I'm going to walk you through some of my code and show a few bits of intermediate-to-advanced Node that I had to tackle to build my blockchain.

Topics covered will include: efficient asynchronous logic, SHA256 hashing and RSA cryptography, mesh communications via UDP and TCP messages, streams, offloading work to child processes, and persisting data in Git.

35761e3936deba2f8189c2d20982c771?s=128

Kyle Simpson

April 19, 2018
Tweet

Transcript

  1. NODING A BLOCKCHAIN KYLE SIMPSON GETIFY@GMAIL.COM

  2. Private Databases

  3. None
  4. • Read/write access is private • Data is (usually) mutated

    • Sharing and backups:
 replication • All stakeholders are trusted
  5. • Private/sensitive data • "Single" point of failure (SPOF) •

    Target for hacking • Load balancing, eventual
 consistency
  6. Public Databases

  7. None
  8. • Read/write access is public • Data is never mutated

    • No stakeholders are trusted
  9. • Public data • Trust based on math • Essentially

    zero failure • "50% + 1" weakness • Never consistent, consensus
 complications
  10. What is a blockchain?

  11. 0 1 2 3 A chain of blocks.

  12. 0 1 B22D1D8...89E2B87 BCC29FC...E03F7E0 B22D1D8...89E2B87

  13. 0 1 B22D1D8...89E2B87 { index: 1, hash: "BCC29FC...E03F7E0, prevHash: "B22D1D8...89E2B87",

    data: ... , timestamp: 1524029051480, }
  14. { index: 1, prevHash: "B22D1D8...89E2B87", data: ... , timestamp: 1524029051480,

    } SHA256( ); // "BCC29FC...E03F7E0" MATH!
  15. 0 1 B22D1D8...89E2B87 BCC29FC...E03F7E0 B22D1D8...89E2B87

  16. { index: 1, prevHash: "B22D1D8...89E2B87", data: ... , timestamp: 1524029051480,

    }
  17. { index: 1, prevHash: "B22D1D8...89E2B87", data: ... , timestamp: 1524029051480,

    } data: [ { hash: "C37AF10...0040A18", data: ... , timestamp: ... , ... }, { hash: "B9DC4FC...91F59BD", data: ... , timestamp: ... , ... }, ... , ], { index: 1, prevHash: "B22D1D8...89E2B87", timestamp: 1524029051480, }
  18. Timestamps In blockchains, purely informational

  19. Code!

  20. None
  21. None
  22. None
  23. None
  24. None
  25. Hashes

  26. Rewrite history? Recompute All Hashes!

  27. Chaos

  28. Make recomputation of all hashes in the whole chain "hard"!

    (aka "not worth it")
  29. Consensus 50% + 1

  30. Proof of Work Proof of Stake ...

  31. "Hard" math problem Solution: brute force "Mining"

  32. None
  33. Transactions

  34. Authorization

  35. Private Key Public
 Key Asymmetric Cryptography

  36. Private Key Public
 Key Asymmetric Cryptography

  37. Private Key Public
 Key "some secret text" Encrypt Decrypt "some

    secret text" "jn4ra...bBH3/sKn" What I always thought...
  38. Private Key Public
 Key "some secret text" Encrypt Decrypt "some

    secret text" "jn4ra...bBH3/sKn" How it actually works...
  39. Public
 Key Private Key "some public text" Sign Verify "c7/De0...fhJjK3"

    Digital Signatures ✓
  40. None
  41. None
  42. Node Code!

  43. None
  44. None
  45. None
  46. github.com/getify/CAF

  47. None
  48. None
  49. None
  50. None
  51. NODING A BLOCKCHAIN KYLE SIMPSON GETIFY@GMAIL.COM THANKS!!!!