Bitcoin In One Blog Post
Preface: Last year for a project I had to learn about Bitcoin and blockchain. I had made a document summarizing the big picture for my own edification. Maybe someone else will find it valuable...
Bitcoin is an effort to create a system of value manifested in a public ledger of transactions managed in a decentralized fashion using cryptography to prevent tampering. Bitcoin is a digital currency. The “coins” in the Bitcoin currency are encrypted transaction records that the users of Bitcoin choose to assign value to.
Any currency that is treated as a store of value needs to be regulated to protect against malicious manipulation. Normal “paper” currencies are regulated by an external authority like a central bank. Bitcoin is regulated by a decentralized ledger called the blockchain which records validated records of transaction blocks, while providing a mechanism to encourage use and the growth of the currency (toward a fixed limit).
An individual user in the Bitcoin system will participate in a transaction through a public and private key. The public key is an identifier of 26-35 alphanumeric characters, beginning with the number 1 that can be known. The private key is a 256-bit random number that the user must keep safe. These will likely be used only once for a transaction and then regenerated. The user will also have a wallet of some kind which manages their coins.
To transfer a coin from one user to another, the following process is employed:
- User P1 comes into possession of a coin through a transaction from some user P0.
- P1 wishes to transfer the coin to P2.
- P1 hashes P2’s public key and the transaction record that transferred the coin to them from P0, and then signs that hash with their private key.
- The transaction is now an unverified record of transfer from P1 to P2, and P2 can use P1’s public key to verify the origin of the transaction.
- The transaction also contains a record of all of the transactions from the creation of the coin all the way to its transfer to P2. These are “compacted” into a structure called a Merkle Tree.
- Coins that are transferred are recognized as spent output, while those not transferred are recognized as unspent output.
We said above that this transaction is unverified. Creating an irrefutable, honest, decentralized ledger of verified transactions is the special aspect of the Bitcoin system; it is called the blockchain. Without the blockchain, users would be free to spend a coin multiple times or engage in other malicious behavior.
The blockchain is a sequence of blocks of transactions that are considered valid and honest. The blockchain is managed by a network of special hosts called Bitcoin nodes in a way that encourages honest participation in maintaining the safety of the currency.
Transactions are considered valid when the network of Bitcoin nodes reaches consensus. Consensus is the result of constructing a blockchain of valid blocks of transactions. With many nodes in the network, it is possible to create many chains - the one that is the longest is considered the authoritative chain.
Bitcoin has a feature that prevent nodes from casually appending blocks to a chain. This is called proof-of-work. Without proof-of-work, it would be impossible to discriminate malicious behavior from legitimate.
The Bitcoin network synchronizes itself every ten minutes with new validated blocks of transactions. It is expected that the difficulty of proof-of-work imposed on nodes in the network should be only sufficient to require around ten minutes to complete the creation of a valid block. This difficulty value is called the target and it is readjusted every two weeks (approximately every 2160 blocks - there are 2160 ten-minute intervals in two weeks) in order to keep the difficulty in achieving the proof-of-work near ten minutes. The target is set higher to make proof-of-work more difficult (if the network is validating blocks too quickly) or lower to make proof-of-work easier (if the network is not validating blocks quickly enough).
In any transaction, the recipient may use the transferring user’s public key to verify its origin. This transaction is then sent to a pool of unvalidated transactions the node network may draw from in order to validate. The nodes that create blocks of valid transactions are called miners, which are nodes that have valid blockchains and work to add more blocks to the blockchain.
The miner’s goal is to seek to create a block which will represent some number of validated transactions, and have this block added to the blockchain. To do so, the miner must satisfy the proof-of-work to show their interest is legitimate.
The creation of a block is as follows:
- The miner selects a group of transactions it wishes to validate as a block from the network. Transactions that are not validated into a block should not be treated as a reliable result by users.
- A block is created on the miner. The miner must show proof-of-work in order to have this block added to the blockchain.
- The block contains a value called a nonce which is just some value that can be incremented. It is random. If it was not, all miners would be starting from the same initial state.
- The nonce is hashed with the transactions, producing a result.
- This result must be less than the target. As a simplification, it is often said that the result must contain a prefix of a specific number of 0’s; the target will also have a prefix of 0’s and the candidate result must be less.
- If this occurs, the block is considered valid and may be added to the blockchain if no other nodes have achieved this already.
- If not, the nonce can be incremented and a new hash can be compared to the target.
- If the nonce cannot be incremented, the miner may get new transactions and try the entire process all over again.
- If successful, the miner will receive a coin of their own as a reward for their work, which provides incentive to those running node hosts.
- Miners may also collect a transaction fee that is distinct from the block reward, in order to encourage participation among nodes that are not fortunate enough to regularly produce accepted blocks.
There are other mechanisms in the blockchain protocol that ensure that blocks that are invalid cannot be added to the chain.
The chain that is the longest is considered authoritative; it has the most work involved in its creation and there is the most challenging obstacle to an attacker.
There are a variety of ways Bitcoin might be attacked:
- A magic technology could allow an attacker to create a longer blockchain than the one that is currently honest and accepted.
- A “51%” attack in which case it becomes feasible for a majority of processing power in the network to apply power to lengthening a malicious fork of the blockchain.
- A potential race or timing flaw in the network.
- An unknown failure in the cryptographic primitives used.
- Further unknowns...
- Bitcoin's fundamental advantage is the blockchain, which creates consensus among parties who do not know or trust each other.
- Bitcoin has a diverse network of participants that protects against any particular party taking control and poisoning the blockchain.
- Bitcoin is the only "e-coin" style currency that has had any meaningful success.
- Bitcoin is hard to integrate into the real economy; it has a reputation for enabling black-markets.
- The transaction rate of the network is too slow to be used in everyday economic activity.
- Bitcoin is hard to use and understand.
- Proof-of-work is wasteful.
It should be noted that those parties pursuing "private" or closed blockchain alternatives to Bitcoin get none of the advantages, but must suffer many of the disadvantages.
last update 2017-03-07