<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paul Martin on Medium]]></title>
        <description><![CDATA[Stories by Paul Martin on Medium]]></description>
        <link>https://medium.com/@paulmartin_5672?source=rss-3fa12a8aff30------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ztKBrSE35QZWjJJ0.</url>
            <title>Stories by Paul Martin on Medium</title>
            <link>https://medium.com/@paulmartin_5672?source=rss-3fa12a8aff30------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 17:20:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@paulmartin_5672/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How Bitcoin Actually Works]]></title>
            <link>https://medium.com/@paulmartin_5672/how-bitcoin-actually-works-2cde8b098833?source=rss-3fa12a8aff30------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cde8b098833</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[bitcoin-mining]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[bitcoin]]></category>
            <dc:creator><![CDATA[Paul Martin]]></dc:creator>
            <pubDate>Wed, 13 Dec 2017 05:55:32 GMT</pubDate>
            <atom:updated>2017-12-13T05:55:32.793Z</atom:updated>
            <content:encoded><![CDATA[<p>Everyone’s news feeds are covered with Bitcoin articles lately. Whether it’s news organisations, viral content sites, financial investment advice pages, Bitcoin talk generates a lot of clicks. Unfortunately this means a lot of click-bait. One common type of click bait is about the volatility of Bitcoin prices. In the last few days of November, there were headlines about Bitcoin rising $3,000 to go above the $10,000 milestone. There were plenty of comments underneath about how it’s a bubble that’s about to bust. A few hours later there was a correction and it dropped by $2,000. The headlines and articles portrayed it as if the bubble really had burst. There were a lot of smug comments from people who thought that they had been vindicated, that they were smarter than everyone else. In reality the Bitcoin price was still up from where it had been 24 hours earlier. Within a couple of days it was back up to $11,000 and the viral content sites, and financial news sites who should know better, had another field day.</p><p>The other type of article is the one that promises to show how Bitcoin works. There are plenty of technology writers out there who need to get those clicks and promising to teach people about Bitcoin is a good way to do it. But it’s clear that many of these writers don’t really understand it. Key points are not emphasized, and terms like proof-of-work and change addresses are thrown around without really explaining why they are necessary.</p><p>If you have read plenty about Bitcoin and still don’t understand it, don’t worry. In my case, I was so frustrated by various articles repeating the same points that don’t really explain anything that I had to dig into the source code of various Bitcoin libraries to see for myself what is going on. In this article I will try to turn that code into a language that I hope everyone can understand.</p><p>There are two main parts to understanding how Bitcoin works: regular users creating transactions, and miners verifying those transactions.</p><h3>How transactions are created</h3><p><strong>Transaction: </strong>Sending Bitcoin from one or more bitcoin addresses to one or more Bitcoin addresses.</p><p>Central to understanding how transactions work is that when you spend Bitcoin, you are not spending Bitcoin out of an account balance, instead you are spending the outputs of previous Bitcoin transactions, known as UTXOs.</p><p><strong>UTXO</strong>: Unspent transaction output. When someone sends you Bitcoin, it’s in the form of a transaction output. This is marked as an unspent and thus is a UTXO which the receiver can spend by using it as the input to a future transaction. A UTXO can only be spent once and the full value must be spent at once. Once it is used as an input to a future transaction, it is marked as spent and is no longer a UTXO.</p><p>A ledger of all transactions in the history of Bitcoin is stored in the Blockchain. We’ll go into the Blockchain in more detail in the mining section. For now understand that the Blockchain does not keep track of account balances. Instead it keeps track of all previous transactions, the outputs of those transactions, and whether or not those transaction outputs have been spent.</p><p>In this sense Bitcoin is more like cash than internet banking. With internet banking, if Alice has €40 and wants to send Bob €15.99, that amount is simply deducted from Alice’s account and added to Bob’s balance. Plenty of people using Bitcoin for the first time via a typical desktop wallet will think of it as working this way because the wallet abstracts a lot of the details, but this is an incorrect interpretation.</p><p>With cash, imagine Alice has previously received €40 via two €20 notes. The two €20 notes are UTXOs (unspent transaction outputs). Each note, or output, can only be spent once and must be spent in total. So if she wants to give Bob €15.99, she has to give her one of her €20 notes. Bob then gives her back €4.01 in change.</p><p>With Bitcoin, transactions consist of inputs and outputs. The inputs point to UTXOs owned by the person who pushed the transaction to the network (the sender) while the outputs are addresses to which the Bitcoin network should distribute new UTXOs to. From a Bitcoin perspective, the €20 note is the input pointing to a UTXO received in a previous transaction. The €15.99 to Bob and €4.01 change returned to Alice are the two outputs.</p><p>The primary difference with Bitcoin is that the change does not come from Bob, but is simply given directly to Alice as a new UTXO. So with Bitcoin, Bob would be left with a €15.99 note and Alice with a €4.01 note, while the €20 note is removed from circulation.</p><p>Imagine Alice has a UTXO worth 2 Bitcoins. Like a cash note, there are two key rules:</p><ol><li>Each UTXO can only be spent once</li><li>The full value of the UTXO must be spent when it is used as an input.</li></ol><p>So if Alice wants to send 0.1 Bitcoin to Bob, she still has to spend all of her 2 Bitcoins. The input to the transaction will point to the 2 Bitcoin UTXO. The two outputs are the 0.1 to Bob’s Bitcoin address, and 1.9 Bitcoins back to Alice’s address (or another address Alice owns, known as a change address). Alice’s previous UTXO of 2 bitcoins is marked as spent (thus, any attempt to spend it again will be rejected), and she now has a new 1.9 Bitcoin UTXO, while Bob has an additional 0.1 Bitcoin UTXO. The vast majority of Bitcoin transactions will have two outputs: one to the receiver and one for the change back to the sender. But there can be more than two outputs. Perhaps the 2 Bitcoin input could have three outputs: 0.1 to Bob, 0.5 to Charlie, and 1.4 back to Alice. If the amount to be sent is the same as the value of the inputs (minus the miner’s fee, discussed later), then no change output is needed.</p><p>UTXOs can be grouped together as inputs to the next transaction. So if Bob already had a UTXO of 0.2 Bitcoins, he can include that UTXO and the 0.1 UTXO received from Alice in his next transaction, allowing him to create outputs worth 0.3 Bitcoins.</p><p>Here’s an example of a transaction which gives two outputs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6vHhw98uO5g6yYk1STtr0w.jpeg" /></figure><p>In this transaction, the address 1EdiP4L8Sey8Wi4dfSXysVZxqHkKfoZAto has received an output worth 0.007961 BTC. This is now available as a UTXO to be spent in a future transaction, and so is marked as unspent.</p><p>Here is the transaction where this UTXO was spent:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ijPeTAFSZ1EZKy-W5m6OA.jpeg" /></figure><p>The owner of the address 1EdiP4L8Sey8Wi4dfSXysVZxqHkKfoZAto used the UTXO worth 0.007961 BTC to create outputs to two different addresses who now have a new UTXO each, one worth 0.001 BTC and the other worth 0.006389 BTC. Now that the transaction output worth 0.007961 BTC was used as an input here and so it is no longer a UTXO and is now marked as spent in the previous transaction (where it was originally received):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3_0JMT-w0g4w9URQlFtchw.jpeg" /></figure><p>How does someone prove they have the right to spend their Bitcoin (or to be more exact, UTXOs belonging to an address)?</p><p><strong>Public Key Cryptography: </strong>This is a common form of encryption where each user has a private-public key pair. Bitcoin uses this to sign and verify digital signatures.</p><p><strong>Digital Signature:</strong> To verify ownership of the UTXOs belonging to an address, a bitcoin transaction (all inputs and outputs) is signed (encrypted) using a private key to create a digital signature. Other nodes can verify (de-crypt) the digital signature with the equivalent public key.</p><p><strong>Private Key: </strong>A secret key which should not be shared with anyone else. It is used to encrypt digital signatures.</p><p><strong>Public Key</strong>: A public key is derived from the private key using some quite complex mathematics. Each public key can de-crypt and read data signed by one private key, the same one from which the public key is derived. A key point is that while a public key can be quickly derived from a private key, the reverse is not possible. By some estimates, it would take a supercomputer trillions of years to reverse a Bitcoin public key into it’s equivalent private key.</p><p><strong>Hash:</strong> A form of cryptography that encodes some data in a way that is irreversible. For example, using the sha-256 hashing algorithm, “Hello” becomes:</p><p>185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969</p><p>There is no randomness in how a hash is derived. “Hello” put through the sha-256 hashing algorithm will always give the same result. It is not possible to reverse the hash string into the original string, or at the very least it may take trillions of years to do so. The most common use case of hashing outside of Bitcoin is to store and verify passwords, for example in a web application.</p><p><strong>Address:</strong> The bitcoin address is what other people use to send Bitcoin transaction outputs to. It is a hash of the public key. It is actually hashed twice using different hashing algorithms so if a vulnerability is found in one algorithm, the public key is still protected by the other algorithm.</p><p><strong>ScriptSig: </strong>This is added to each input of a transaction. Remember each input points to a UTXO, the output of a previous transaction which has not yet been spent. Each UTXO, and thus each input, has a Bitcoin address and a value. The first part of the ScriptSig is a digital signature, created by gathering up all the inputs and outputs and signing it with the private key from which the input’s address was derived (remember Private Key&gt;Public Key&gt;Address). The second part of the ScriptSig is the public key. Anyone can use the public key to unlock the contents of the digital signature to reveal the inputs and outputs. By hashing the public key they can get the address and verify it matches the address which owns the UTXO the input is pointing to. Thus, it is proven that the signer of the transaction has access to the private key from which the Bitcoin address was derived.</p><p>Some key points about public key cryptography:</p><ul><li>If the public key was not derived from the private key used to create the digital signature, the verification result will be gibberish. So in order to spend UTXOs belonging to an address the private key from which the public key (and hence address) is derived is required in order to create a digital signature.</li><li>Because the digital signature reveals all the inputs and outputs, and inputs (pointing to UTXOs) cannot be re-spent, the digital signature is unique to that transaction and cannot be re-used for a future transaction or to re-play the transaction again. Thus, the private key is needed each time a transaction is created.</li><li>The inputs or outputs cannot be modified in transit, as it is not possible to modify a digital signature without access to the underlying private key.</li><li>The private key itself is not sent in the transaction .The beauty of this is that unlike credit card details or internet banking details, which are sent over a network and stored on a server, your private key never needs to leave your own computer.</li></ul><p><strong>Wallet words:</strong> Most Bitcoin wallets give a set of “wallet words” to the user and instructs them to write it down. This is set of 12 common words from which numerous private keys can be derived. The same safety protections that must apply to a private key apply to wallet words. If someone sees your private key or wallet words, they can steal your bitcoin.</p><p>If you lose a private key (or wallet words) for addresses that hold Bitcoin, the Bitcoin is lost and there is no way to recover it. The maximum number of Bitcoins that will ever exist is 21 million, but it’s known that many of these have already been lost forever. People lose wallet words, private keys, wallet decryption passwords or computers that hold their wallets all the time. Or they die without giving access to their relatives. One estimate says 4 million Bitcoin are lost forever, which 25% of all Bitcoin currently in existence. Thus, the actual market cap of Bitcoin is most likely lower than those given on various sites which is derived from the number of Bitcoin that have ever been created.</p><p>Summary of how a transaction is created:</p><ol><li>Alice creates a private key-public key-address Bitcoin account. Using complex cryptography, the address is derived from the public key, which itself is derived from the private<strong> </strong>key.</li><li>Alice gives her address to her business associates.</li><li>Alice receives 1 bitcoin to her address in the form of outputs of a transaction sent by Charlie. This output, known as a UTXO, can now be spent.</li><li>Alice creates a transaction consisting of 1 input and 2 outputs. The input points to the unspent which she received from Charlie, which has a value of 1 bitcoin. The first output contains Bob’s address and a value of 0.2 Bitcoin. The second output is the change. It contains her own address created in step 1, and a value of 0.8 Bitcoin.</li><li>A digital signature is created using the private key and all the inputs and outputs of the transaction being created. The digital signature and her public key together make up the ScriptSig which is added to the input.</li><li>The transaction is broadcasted to all the Bitcoin nodes in the peer-to-peer network.</li></ol><h3>How Blocks Are Mined</h3><p><strong>Blockchain:</strong> The Blockchain is a public ledger which keeps a record of all transactions in the history of Bitcoin, all the way back to Satoshi Nakamoto’s genesis block on 3rd January, 2009 (just a few months after the financial crisis of 2008):</p><p><a href="https://www.blocktrail.com/BTC/tx/4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b">BLOCKTRAIL | 4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b - Bitcoin Transaction (BTC)</a></p><p>The Blockchain does not keep track of account balances. Instead it keeps track of all previous transactions, the outputs of those transactions, and whether or not those transaction outputs have been spent.</p><p>Each Bitcoin node keeps a copy of the Blockchain, sync’d with all other nodes in the network with which it agrees with.</p><p><strong>Block: </strong>A group of valid transactions. A new block is added to the Blockchain approximately once every 10 minutes (to be more exact, when the block reaches a size of 1 MB).</p><p><strong>Mining: </strong>The process of creating and broadcasting a block which the miner hopes other miners will accept as the next block in the Blockchain. If so, they get a reward.</p><p><strong>Miner:</strong> Any system running Bitcoin mining software.</p><p>To mine a block, miners first need to create a group of valid transactions.</p><p>Miners are listening for transactions broadcasted on the Bitcoin peer-to-peer network. When the miner receives a transaction they have to check that it is a valid transaction. The most important steps in validating a transaction are:</p><ol><li>Check that each input is pointing to the output of a UTXO, that is the output of a genuine previous transaction that exists in the Blockchain (or in the current block that the miner is working on),.</li><li>Check that each UTXO that the inputs are pointing to has not previously been spent (the “double spend” problem, which so much of the implementation of Bitcoin is designed to prevent).</li><li>Check that the creator of the transaction has proven they have the right to spend the unspents pointed to in the inputs, by validating the digital signature of each input.</li><li>Check the total value of the outputs is less than or equal to the total value of the inputs.</li><li>Check the outputs are to valid Bitcoin addresses.</li></ol><p>An input points to a UTXO with a transaction id and an index, starting at 0, to indicate which output of that transaction is being spent. So, 3387418aaddb4927209c5032f515aa442a6587d6e54677f08a03b8fa7789e688:1 would be the second output of the transaction with that id. Each output is initially marked as unspent by miners. When a Bitcoin user attempts to spend this output, the miners check if it has previously being spent. If it has been spent the entire transaction will be rejected.</p><p>Using the public key the miner reads the contents of the digital signature of each input. If the public key cannot be used to read the contents of the digital signature, then it was not signed with the correct private key and the transaction will be rejected. If it’s OK then they hash the public key to get the address and verify it matches the owner of the UTXO being spent. If not, the transaction will be rejected.</p><p>If the contents of the digital signature, the inputs and outputs, do not match up with the rest of the transaction, the transaction will be rejected.</p><p>The sum of the inputs need to be equal to or greater than the sum of the outputs.</p><p><strong>Miner’s fee:</strong> So what happens if the inputs total 2 Bitcoins but the outputs total 1 Bitcoin? The difference of 1 Bitcoin is given to the miner as a fee! So if you decide to create a transaction yourself using your favorite programming language, don’t forgot to include the change output. Miners can decide not to add a transaction to the block they are mining if they feel the fee is not high enough.</p><p>There are many rules and checksums built into a Bitcoin address so it is easy to check if a Bitcoin address is valid. If one character was entered incorrectly, it will most likely be detected by the miners and the transaction will be rejected.</p><p>Once the miner is happy with the transaction they add it to the block they are currently mining and mark all the unspents used in the transaction as spent.</p><p>When the block reaches the 1 MB block size limit it’s ready to be added to the Blockchain.</p><p>But there are lots of miners. They each have their own block that they’ve been working on. Most are honest, so they won’t include invalid transactions. But the exact transactions included in each miner’s block will vary depending on what fee they are willing to accept and which transactions they received first. So how do all these nodes agree on who’s block should be added to the Blockchain? To do so they each perform proof of work.</p><p><strong>Proof of Work:</strong> This is a race. The first miner to solve a computational puzzle (based on the block), gets to have their block added to the Blockchain (as long as the other nodes in the network agree that all the transactions in the block are valid). The easiest way to understand why Proof of Work is necessary is to understand what would happen without it. Lots of nodes would broadcast blocks to the Blockchain at the same time. Malicious miners may also decide to broadcast blocks containing double spends or other invalid transactions. The other nodes would have to go to a lot of effort validating blocks with no chance of being added. Even among the valid blocks, in a peer-to-peer network, who decides which one gets added?</p><p>Proof-of-work is based on Hashcash, which was developed to prevent e-mail spam. The idea was that if it takes a lot of computer power (and hence, electricity) to send an e-mail, spam would be much more expensive. With proof-of-work, computer software guesses every possible option until it finds the right answer. It takes quite a lot of computing power to do this and the difficulty increases periodically to keep up with Moore’s Law (the idea that the cost of computing power halves every two years). The reward for being the first to solve the puzzle is that the other nodes accept the block being added to the Blockchain and the miner gets a reward of newly generated Bitcoin, currently 12.5 Bitcoins (periodically, the reward halves) and all the fees for that block. Here is an example of a block reward transaction:</p><p><a href="https://blockchain.info/tx/0c2cca5e8636bf139babce946edf2e89e7ec5efa29aaf19ecdf1b67460873104">Bitcoin Transaction 0c2cca5e8636bf139babce946edf2e89e7ec5efa29aaf19ecdf1b67460873104</a></p><p>When a block is broadcasted the other miners verify the proof-of-work puzzle was solved, thus immediately rejecting any script kiddies’s attempts to manipulate the Blockchain for free. Then, they check to make sure all the transactions in the block are valid. If they think everything is OK, they will add the block to their copy of the Blockchain and start mining a new block of transactions, which they will attempt to add on top of the previous block they accepted. If they don’t accept the proof of work was done or don’t like one of the transactions in the block they throw the entire block out and continue mining on top of the previous block. This strongly disincentives miners from acting maliciously. What’s the point of using all that computer power to mine a block and solve the proof of work if there is no chance the block will be accepted and thus, no reward? One estimate put the current cost of mining a block using typical USA electricity prices ($0.12/kWh, €0.10/kWh) at $19,598.50 / €16,698.90 (that’s just the electricity cost and doesn’t include the cost of buying and maintaining the specialized mining hardware). Also, a lot of money is wasted on blocks for which other miners will solve the proof-of-work first and get the reward.</p><p><strong>Mining pool: </strong>Due to the low likelihood of mining a block these days (being the first to solve the proof-of-work puzzle), the only way to make it potentially profitable for ordinary people is to join a mining pool. This is a group of miners who work together and share any rewards.</p><p>The <a href="https://blockchain.info/">https://blockchain.info/</a> home page shows the latest blocks and which mining pool (or individual miner, sometimes unknown) mined the block.</p><p>Simply put, proof-of-work is the mechanism by which a peer-to-peer network can reach a consensus about who’s block should be added to the Blockchain next. There is enough randomness in the proof-of-work algorithm to make it extremely unlikely for one organisation to mine consecutive blocks and thus manipulate the Blockchain. To attempt to take control of the Blockchain, an individual miner would need 51% of the total mining power, which thanks to proof-of-work is prohibitively expensive.</p><p><strong>Confirmation: </strong>Blockchain explorers often list the number of confirmations a transaction has. The first confirmation is the most important. It means a block containing the transaction has been added to the Blockchain. Each additional block added on top of that one counts as an additional confirmation of the transactions in that block. By deciding to add a block on top of a previous block, a miner is adding an additional confirmation to all transactions in the history of the Blockchain up until that point.</p><p>Summary of mining:</p><ol><li>Each miner receives transactions which have been broadcasted and verifies that they are valid. Valid transactions are collected in a block. The miner can choose which transactions to add and may have a minimum fee they are willing to accept, especially when there are a lot of transactions being broadcasted during the same time.</li><li>When the block size is close to 1 MB, all miners compete in a race to solve a computational puzzle known as proof-of-work.</li><li>The first miner to complete the proof-of-work broadcasts their block.</li><li>The other miners receive the block, check the proof-of-work was performed, check the previous block id is the same as their own, and check all the transactions in the block are valid.</li><li>If the block is OK, they add it to their copy of the Blockchain. They then throw out the block they were mining and start mining a new block with the transaction history now containing the new block which was added. If the proof-of-work was not done or any transaction is invalid, the miner will throw out the block and continue mining the block they were already working on.</li></ol><p><strong>What about all the hacks?</strong></p><p>Interestingly, any hacks you heard about with regard to Bitcoin occurred on exchanges, where people allowed online services to store their private keys for them. While some people find this convenient, it of course removes many of the benefits of using Bitcoins in the first place, primarily that it is decentralized and nobody but you has access to your private key. Most people who do use exchanges are day traders who want to be able to quickly exchange their Bitcoin for other crypto currencies. Exchanges, like any other website, can be hacked. Nobody who kept ownership of their own private key (paper wallet, desktop wallet) has ever lost their Bitcoin to a remote hacker (there is still the risk of somebody physically stealing it, just like with cash). Keep that in mind next time you hear the media over-sensationalizing a Bitcoin hack.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cde8b098833" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>