Live data from Hacker News

Bitcoin From Scratch – Part 1

monokh.com

51–60 of 77 posts

Re: Bitcoin From Scratch – Part 1

#51

I wrote a toy (but working) implementation of the Bitcoin algorithm here: https://github.com/tlrobinson/tomcoin The main logic is a few hundred lines of code: https://github.com/tlrobinson/tomcoin/blob/master/src/node.j... A somewhat unique aspect is since it's written in JavaScript a node can run on the server or the browser, which makes for easy demos: 1. Open https://tomcoin.herokuapp.com/ and https://tomcoin1.her…

This is great. I especially like that it follows the protocol's implementation for the most part. i.e. you still have utxos and script verification even if it doesn't actually support the array of script op codes.

There is a fully compatible JavaScript implementation that you could use as reference to extend yours: https://github.com/bcoin-org/bcoin

With my post, I tried to boil down the concepts as much as possible to save some mental bandwidth and make understanding the overall easier. We will see how that turns out

Re: Bitcoin From Scratch – Part 1

#52
post #9
post #4

Earlier quoted context omitted.

(author here) Absolutely. Thanks for pointing this out. If difficulty adjusted in factors of two, the ability of the network to accurately maintain its 10 mins blocktime become impaired. I try to keep these concepts rather simplified to ease the reading and learning process. Perhaps there should be a note for these situations.

In defense of the explanation, sometimes it's asking for an unnecessary mental leap of the reader to think of a bit array as a number, especially if the reader is not accustomed to thinking in base-2 or base-16 number systems.

You could easily explain the basic principles in human-sized numbers (ie, less than 1024).

Re: Bitcoin From Scratch – Part 1

#54
post #16

Earlier quoted context omitted.

The hash is just a number regardless-- surely no one has any problem understanding any other number in the protocol as a number! :)

Even this sentence is just a number.

Really it’s not because it’s a sequence of glyphs first and foremost. It can be mapped to a number though.

Re: Bitcoin From Scratch – Part 1

#56
Mining part is confusing for me. Is POW is essentially to achieve difficulty level ? You do in this while loop until you have achieved this difficulty level ? Is this the primary factor that differentiates having various protocol in crypto ?

Re: Bitcoin From Scratch – Part 1

#57

Mining part is confusing for me. Is POW is essentially to achieve difficulty level ? You do in this while loop until you have achieved this difficulty level ? Is this the primary factor that differentiates having various protocol in crypto ?

Yes. Proof of Work is required so that there is a global limit on the rate at which new coins are created.

Re: Bitcoin From Scratch – Part 1

#58
post #49
post #47

Earlier quoted context omitted.

const { mine, sign, verify, hash, validateProofOfWork, stripTxSignatures, generatePrivateKey, getPublicKey } = require("./util"); What does this do? And will this really run in a browser? I think brosers don't have require()?

You can see what your functions do by opening the file called util.js in the same directory. And, yes you can run this in the browser by either polyfilling "require" or transpiling it

By that logic, everything runs in a browser. The principle of computational equivalence tells us that one turing complete language can do what any other can.

So yes, everything can be polyfilled or transpiled.

But that does not really meet my understanding of "Runs in the browser".

Re: Bitcoin From Scratch – Part 1

#60
post #2

> The PoW is suffice if the hash begins with a certain number of 0s This is a common explanation of PoW, but is actually incorrect. If you think about it, this would mean that the PoW difficulty could only increase (or decrease) by a factor of two. In reality, the block hash is simply interpreted as a (very large) number, and this number must be less than some other very large number (the "target"). So you do end up…

TIL. I wonder why that myth is so commonly perpetuated.

It’s not a myth. It’s a useful simplification.
Post reply on HN