{"id":332,"date":"2012-09-14T01:00:00","date_gmt":"2012-09-13T23:00:00","guid":{"rendered":"https:\/\/www.fussylogic.co.uk\/blog\/?p=332"},"modified":"2012-11-17T10:46:51","modified_gmt":"2012-11-17T10:46:51","slug":"bitcoin-explained-ii","status":"publish","type":"post","link":"https:\/\/www.fussylogic.co.uk\/blog\/?p=332","title":{"rendered":"Bitcoin Explained (II)"},"content":{"rendered":"<p>This is <a href=\"?p=332\">part II<\/a> in my \u00e2\u20ac\u0153Bitcoin Explained\u00e2\u20ac\u009d series.<\/p>\n<p>The problem we left at the end of <a href=\"?p=329\">part I<\/a> was that the construction of a valid chain of payload-storing blocks is trivial (for a computer) to create. For a financial system we want it to not be trivial, we want it to be incredibly hard to recreate a chain, so hard in fact that there can be only one chain.<\/p>\n<p>The solution that Bitcoin uses is a <em>proof of work<\/em> system. Here \u00e2\u20ac\u0153work\u00e2\u20ac\u009d means computational work. It\u00e2\u20ac\u2122s worth noting that the work we choose must have two very important properties:<\/p>\n<ol style=\"list-style-type: decimal\">\n<li>It must be very hard to do (this is the \u00e2\u20ac\u0153work\u00e2\u20ac\u009d part)<\/li>\n<li>It must be very easy to verify (this is the \u00e2\u20ac\u0153proof\u00e2\u20ac\u009d part)<\/li>\n<\/ol>\n<p>There is no point in a proof of work system that requires as much work to check that it is valid as it did to create the work. This is what renders suggestions that Bitcoin should use <a href=\"http:\/\/folding.stanford.edu\/\">folding@home<\/a> or <a href=\"http:\/\/setiathome.berkeley.edu\/\">SETI@home<\/a> as its computational work, invalid. While the work done by those two systems is indeed hard to do (meeting criteria #1), there is no way to verify the correctness of that work other than by repeating it (failing criteria #2).<\/p>\n<p>The proof of work system used by Bitcoin is one that combines nicely with the block chain system it already has. An additional piece of data is stored in each block. This data has no purpose other than to alter the final cryptographic hash of the block (any change of input alters a hash significantly). It\u00e2\u20ac\u2122s called the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Cryptographic_nonce\">nonce<\/a>; it\u00e2\u20ac\u2122s not (for UK readers) a paedophile, its use comes from the noun \u00e2\u20ac\u0153nonce\u00e2\u20ac\u009d, <a href=\"http:\/\/en.wiktionary.org\/wiki\/nonce\">meaning<\/a> \u00e2\u20ac\u0153The one or single occasion; the present reason or purpose (now only in for the nonce)\u00e2\u20ac\u009d. Strangely, given the purpose of a cryptographic hash, the nonce\u00e2\u20ac\u2122s job in a block is to be a use-once number that effectively brute-forces the block hash to a particular value.<\/p>\n<p>That brute forcing of block hash is hard work, but, (drumroll) is easily verified. Exactly what we want for our proof of work system.<\/p>\n<p>The \u00e2\u20ac\u0153particular value\u00e2\u20ac\u009d of hash being searched for is any hash less than a pre-determined <em>target<\/em>; we\u00e2\u20ac\u2122ll come to how that target is determined later, but for now simply accept that there is a hash-target, and that target is itself listed in the block (i.e.\u00c2\u00a0changing it would also change the hash). Finding a nonce is hard because there is no way to know without recalculating what effect any value of nonce will have on the final hash (if there were then the cryptographic hash would be a failure). If we\u00e2\u20ac\u2122re looking for a nonce that results in the hash being numerically less than some defined target value, there is only one way to find it: we have to try many different values of nonce, one by one. However, once we have found one, it\u00e2\u20ac\u2122s easy for someone else to do the same calculation using that found nonce to see that it really does result in a hash less than the claimed target.<\/p>\n<p>I, as a Bitcoin node, get sent a block by my peer. I do not trust that peer, since it is just some computer on the Internet, it could be feeding me bogus data. I perform two initial checks on that received block:<\/p>\n<ul>\n<li>I calculate this new block\u00e2\u20ac\u2122s hash, that calculation uses both the <em>nonce<\/em> and the <em>target<\/em> values. If the hash that I calculate is less than the target value the block claims, then I can believe that its creation was \u00e2\u20ac\u0153hard\u00e2\u20ac\u009d to the level described by <em>target<\/em>.<\/li>\n<li>Is it part of my previously accepted and \u00e2\u20ac\u0153trusted\u00e2\u20ac\u009d chain? I do this by positioning it in my ever-increasing block chain. Provided the new block claims as its parent a block I have previously accepted as trustworthy, then that new block is part of the chain.<\/li>\n<\/ul>\n<p>Our node can now reconstruct a chain, and estimate how hard it was to create that chain. It can do that without needing to trust the nodes that fed it those blocks. If bogus blocks are fed then they can be rejected because they aren\u00e2\u20ac\u2122t really part of the true chain, or because they weren\u00e2\u20ac\u2122t as hard to create as they claim to be. (\u00e2\u20ac\u0153Bogus\u00e2\u20ac\u009d here is going to mean \u00e2\u20ac\u0153not agreed on by a majority of nodes\u00e2\u20ac\u009d)<\/p>\n<p>We\u00e2\u20ac\u2122re left with a similar problem to the one we started with. Constructing an arbitrary chain is trivially easy, so we required that it is not trivially easy by use of the verified <em>target<\/em> value. What is to stop us creating a valid chain that honestly claims to be easy, and is? Provided no block has a <em>target<\/em> that doesn\u00e2\u20ac\u2122t verify, isn\u00e2\u20ac\u2122t that chain valid; and couldn\u00e2\u20ac\u2122t I include a \u00e2\u20ac\u0153pay lots of money to me\u00e2\u20ac\u009d entry in my easily-created, but valid looking chain? Well yes. Our defence against that is going to be that we don\u00e2\u20ac\u2122t allow easy chains. To do that we have yet to talk about how <em>target<\/em> is determined.<\/p>\n<p>We\u00e2\u20ac\u2122ll come to that in <a href=\"?p=335\">part III<\/a>, when we discuss <em>mining<\/em>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is part II in my \u00e2\u20ac\u0153Bitcoin Explained\u00e2\u20ac\u009d series. The problem we left at the end of part I was that the construction of a valid chain of payload-storing blocks is trivial (for a computer) to create. For a financial system we want it to not be trivial, we want it to be incredibly hard\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.fussylogic.co.uk\/blog\/?p=332\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[24,1,53],"tags":[20],"_links":{"self":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332"}],"collection":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=332"}],"version-history":[{"count":9,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions"}],"predecessor-version":[{"id":956,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=\/wp\/v2\/posts\/332\/revisions\/956"}],"wp:attachment":[{"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=332"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=332"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.fussylogic.co.uk\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=332"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}