Unboxing Bitcoin

Anjaneya Mishra
9 min readOct 3, 2022

--

This paper intends to understand bitcoin deeply and bring out aspects of the bitcoin architecture that lend various properties essential to create a secure, non-inflationary, digital currency for online commerce.

This article picks up each feature of bitcoin and attempts to explain the underlying technology to better understand how bitcoin does what it does.

Since bitcoin is a digital currency or the currency for the internet, it would be helpful to first define a currency. Currency is a medium of exchange that stores value. For a currency to have any practical application, the value of the currency should remain unchanged. For example, one dollar must always be equal to a dollar. This should be contrasted with the effect of inflation — a situation where the same dollar can procure fewer goods with time.

A transaction is the exchange of this value held within a unit of currency; paying a banknote to a cashier to buy a product is an example of a transaction. Trust is an essential underlying assumption of each transaction. In the cashier example, both counterparts trust that the value of the note is the same as that represented by it. Currently, large organizations such as Visa or MasterCard help facilitate transactions and maintain trust in the ecosystem by creating pathways to share information and maintaining the integrity of these channels.

Bitcoin’s innovation maintains the integrity of transactions through cryptographically secured logic and code. Since bitcoin is a secure online currency, you can transact freely on the internet without the need of an organization like Visa to move transaction requests around. If you want to send money to your friend in Nigeria (reference) you can simply send this money without having to interact with any third party.

To understand why bitcoin has the features that it does, we need to look no further than physical currency. Currency is a representation of value. To secure value, mechanisms need to be there to prevent users from spending the same unit twice, i.e., prevent double-spending. One doesn’t face this challenge with a physical currency like bank notes since the change in physical possession of the note represents a transaction, and initial physical possession is essential to spend. However, in the case of a digital currency, double spending is a major risk, since replication over the internet is very simple.

The bitcoin architecture is designed to maintain a history of authentic transactions and prevent double-spend transactions. Let’s see how. The only way to reliably confirm that a double-spend transaction doesn’t exist is to be aware of all transactions. Bitcoin solves this double-spend issue by publishing each transaction on each computer on the network. The transactions are bundled up in a file of a fixed size, known as a block — the block size is 1 MB in the case of bitcoin.

The bitcoin transaction contains two identifying elements — the signature of the private key of the previous owner and the public key of the current owner. The private key represents ownership of your coin. The key can be stored on a dedicated thumb drive, written on a piece of paper (called cold storage), or in your head — a colder storage! 😃 If you own a billion dollars worth of bitcoin and you memorize the key, then every time you travel, you do so with a billion dollars with you, without needing a bank account or a credit card.

To transact in bitcoin, you first declare ownership of your coin by signing your private key and then entering the recipient’s public key — their bitcoin account. Hence, bitcoin is defined as a series of digital signatures. Each signature assigns the coin to a new owner. This record goes back to when the coin was first minted. Each Bitcoin is minted as a reward to “nodes”. Nodes are Central Processing Units (CPUs) or computers that help support the blockchain. Let’s see how.

When you sign a bitcoin or spend it, the transaction is published to nodes in the network. Nodes inspect each transaction as they receive them. There is a prescribed criterion for transactions to be accepted, and only those that adhere to this criterion are permitted. Permitted transactions are then included in a memory pool for all nodes to include in blocks that they will compile.

Not all transactions reach all nodes in the network because of message loss. Each node selects transactions from the memory pool and compiles them into blocks. The nodes then work to validate these blocks through a mechanism called Proof of Work (PoW). Miners select transactions from the memory pool based on age — how long ago the coin was spent — and the quantum of the transaction. Larger and older transactions are prioritized over smaller and younger ones. The first node to complete the PoW process then broadcasts the validated block to all the other nodes for them to verify that the block has been validated and include it in the blockchain.

Miners operate nodes. They verify that the transactions contained in the block are genuine. Once they are satisfied that the block is genuine, they verify it and signify this by working on compiling transactions for the next block. Through this mechanism, we see that as long as all transactions reach a significant number of nodes, they will eventually be included in a block and so transaction message loss is not a concern.

The validation process involves the previously mentioned PoW. The application of this PoW algorithm is the core of how bitcoin secures trust over the internet. Proof of Work is a process that leverages cryptography to secure bitcoin transactions.

Proof of Work traces its history back to 1992. It was created as a way to address email spam. PoW works by making it difficult to complete a certain task — like sending an email for example. In the real world, it most closely resembles a postage stamp. If there were no postage stamps, then anyone would be able to send a letter for free, leading to spam that could overload the postal network.

Proof of Work involves doing a certain piece of quantified and definite “work” that unlocks a reward for doing the work. In the context of bitcoin, this “work” is rewarded in bitcoin.

This reward process is designed around a secure hash algorithm (SHA). SHA is an irreversible and deterministic algorithm. Deterministic means that each input has a specific output. Additionally, given an output, it is virtually impossible to reach the input it was computed from. The way this algorithm is designed, it also prevents collision events — when two inputs have the same output.

Bitcoin uses SHA-256, which converts any input into a random 256-bit output. I found a fun calculator that you can use to “hash” out any input here. Miners hash inputs through the SHA-256 algorithm to meet a certain target. Targets have been defined for a set of blocks. This target is defined in terms of the number of zeros at the beginning of a hash. This means that the miner would have to try multiple inputs to get an output that is below a certain number — the target.

Having a hash target is a way to scale the difficulty of mining blocks. Difficulty increases exponentially with the increase in the number of 0-bits at the beginning of the target hash. This is done to ensure that the rate at which blocks are validated remains at approximately 10 mins. This target hash is changed every 2016 blocks in order to maintain the block-validation rate with the increase in the network computing power.

The various input values used by miners to validate the block are not random. This information is found in the block header. The block header is the equivalent of a standard receipt for a package you order online. It contains information about the transactions and sets the base for the input value. The block header contains a property called root hash that contains within it all the transactions of the block. Along with this, it contains the ‘nonce*’*, the hash of the previous block, and the target value for that block. Nonce stands for ‘number used once’.

Miners start working towards the SHA-256 input value when they select a list of transactions to include in their block. Each selected transaction is then hashed. The output hashes of transactions are paired and then re-hashed. This process is repeated till we arrive at a single root hash which is the output of the hash of each transaction. This data structure is referred to as the merkle tree.

Picturing a Merkle Tree — Link

Since SHA-256 is deterministic, all the transactions in the block are reduced to a single hash, unique to the transactions in that block. This saves on memory requirements and reduces the time required to verify a block after validation.

When miners arrive at the root hash, they now have the most essential ingredient to the SHA-256 input. This root hash is concatenated with the previous block’s hash, the timestamp, and the nonce. The nonce starts with 0 for the first input and increases with each successive attempt by the miner to meet the block target. The nonce works as a counter for the number of attempts taken to meet target requirements. Since more attempts point to a higher difficulty level, the nonce is an indicator of the difficulty in mining that block.

When miners start selecting transactions to form their block, the first transaction is to issue themselves the block reward in bitcoin. This is known as the ‘coinbase transaction’ — the inspiration for the name of the crypto exchange. Since each transaction has to go through other nodes, a miner cannot arbitrarily issue any amount of bitcoin to themselves. Doing so would make the transaction a failed one and the miner would lose all the work they have done to run the PoW process, thus incentivizing miners to remain honest.

Once a block is validated, bitcoin can be said to be minted and rewarded to the successful miner. When bitcoin first started, the block reward was 50 bitcoin — worth nearly USD 1 Mn as on 24th Sept 2022 — in a period, many would call a “crypto winter”. Crypto winter is a phrase used to refer to a prolonged bear market. This reward halves at a regular cadence of 210,000 blocks, an event that occurs every 4 years on average. This schedule of reducing rewards gives bitcoin its anti-inflationary characteristic.

When a successful miner has been rewarded, other miners start work on compiling a new block. As an input to their block, they will use the successful output that validated the previous block — the previous block’s hash. Each block thus refers to the block before it, right up until the first or genesis block, thus, forming a chain of blocks called a blockchain.

Hence, there are three layers of transaction security in the process of bitcoin mining. The first is when transactions are checked before being included in the memory pool, the second is when nodes work to verify a validated block, and the last layer is when miners choose their previous block hash.

The miner’s decision to choose which parent block to link to is the core of how bitcoin operates as a consensus system. A miner can link their new block to any block existing on the blockchain. The miner can choose to add his block to the main chain — the one with the most proof of work associated with it (or the longest), or a secondary chain. This is how he chooses to “vote”. This voting mechanism has implications during a fork — an event where a group of nodes decides to create an independent chain. Examples of forks are here.

The longest chain is also the most secure. If a malicious actor were desirous of changing a transaction in any block, not only would they have to do the work to validate the block, but also the work of all the blocks after it. This actor would also have to add blocks at a rate such that it surpasses the main chain in block size. The larger the main chain, the harder this is to accomplish. This renders a block immune to change and the record contained within it secure. The main chain represents the most significant proof of work effort and ensures that all parties to the bitcoin community agree on a single version of history.

--

--