from Hacker News

Show HN: An educational blockchain implementation in Python

by jre on 12/17/17, 12:32 PM with 41 comments

  • by magnat on 12/17/17, 1:42 PM

    > It is NOT secure neither a real blockchain and you should NOT use this for anything else than educational purposes.

    It would be nice if non-secure parts of implementation or design were clearly marked.

    What's the point of education article, if bad examples aren't clearly marked as bad? If MD5 usage is the only issue, author could easily replace it with SHA and get rid of the warning at the start. If there are other issues, how can a reader know which parts to trust?

    Even if fixing bad/insecure parts are "left as an exercise for the reader", learning value of the article would be much greater if those parts would be at least pointed at.

  • by h4l0 on 12/17/17, 1:30 PM

    For the last couple of months, there have been many educational, simple implementations that explains blockchain technology, I guess thanks to crypto bubble. I wish these were around when we were doing our senior design project on blockchains in 2014. Back then, I only could find basiccoin[0], which was purely minified to just fit in 1000 loc.

    After that, I decided to re-implement everything from scratch. My foremost constraint was to write readable code so that anyone could read the codebase and have an idea of how blockchain works.

    My current draft of implementation can be found on https://github.com/halilozercan/halocoin , which currently lacks detailed README and documentation. However, you can still experiment with it by using API or CLI. I'm running a dedicated server to have an always online peer you can connect to.

    [0]: https://github.com/zack-bitcoin/basiccoin

    Edit: a word

  • by westurner on 12/17/17, 2:01 PM

    Thanks! Simplest explanation I've seen.

    Here's an nbviewer link (which, like base58, works on/over a phone): https://nbviewer.jupyter.org/github/julienr/ipynb_playground...

    Note that Bitcoin does two rounds of SHA256 rather than one round of MD5. There's also a "P2P DHT" (peer-to-peer distributed hash table) for storing and retrieving blocks from the blockchain; instead of traditional database multi-master replication and secured offline backups.

    > ERROR:root:Invalid transaction signature, trying to spend someone else's money ?

    This could be more specific. Where would these types of error messages log to?

  • by geraldbauer on 12/17/17, 2:59 PM

    FYI: Great blockchain (from sratch) starter article. At the Awesome Blockchains page [1] I collect starter blockchains and articles (in Python, Ruby, JavaScript, etc.) the idea is the best way to learn about blockchains is to do-it-yoursef - build your own blockchains from scratch. Great example. Keep it up. Cheers. [1] https://github.com/openblockchains/awesome-blockchains
  • by heynk on 12/17/17, 3:28 PM

    This is great. Just last weekend I did the same thing, coding a very basic blockchain in Python for educational purposes. You tackled wallets, which I didn't get to yet, so that was really helpful.

    I'm still a little unsure around exactly how miners and nodes communicate with each other. Especially things like broadcasting transactions and new blocks. Any good resources for that?

  • by ivan_ah on 12/17/17, 1:33 PM

    Very good writeup that shows all the steps.

    Note it uses MD5 hash instead of SHA256 so not exactly bitcoin. I wonder how much more work would be to make the code fully implement bitcoin. Will it still be readable? Or Etherium? Would be great value for understanding even if Python would be inefficient to run in prod.

  • by vinn124 on 12/17/17, 3:32 PM

    nice walkthrough.

    also, not sure why folks are nitpicking about minor things like security disclaimers, number of sha256 hashes, md5, etc. while ignoring nontrivial gaps (eg no merkle dags, one of the cornerstone concepts).

  • by jobeirne on 12/18/17, 5:08 AM

    Something from a few months back that's a bit closer to Bitcoin's actual implementation but at a similar level of readability: https://github.com/jamesob/tinychain
  • by brodo on 12/17/17, 2:53 PM

    Coll project. I think having educational * implementations in Python is great in general. Better then having just an article about it...
  • by antman on 12/17/17, 10:03 PM

    So is there a non educational implementation of blockhain that someone could use/parametrize/configure? Something that is not educational but more industrial strength? What must someone do to convert an educational implementation to a serious one?
  • by satellitec4t on 12/17/17, 3:34 PM

    Why is this all contained in one big json document? Am I that out of touch with modern coding??
  • by partycoder on 12/17/17, 8:51 PM

    Educational implementation, brilliant. Now some startup will give it a name and make an ICO.