First they ignore you, then they laugh at you, then they fight you, then you win. - Mahatma Gandhi.



The network

A Bitcoin implementation is code that individuals can run on their computers to turn them into Bitcoin nodes.
The reference implementation is the open-source code known as Bitcoin Core, which can be downloaded from https://bitcoincore.org/en/download/

Interconnected Bitcoin nodes constitute the Bitcoin network:

Bitcoin Network representation

The function of a node is to independently verify the validity of transactions, rejecting those that do not follow the Bitcoin rules.


Transactions

A Bitcoin transaction consists of a digitally signed message instructing the transfer of a certain amount of monetary units.

Digital signatures are generated from a Private Key and its corresponding Public Key.
A Private Key is a random number between 0 and 2^256 (roughly the number of atoms in the known universe), so its entropy is 256 bits.
The Public Key is derived from the Private Key through a one-way function, which means that is impossible to obtain a Private Key from a Public Key.

A Private Key can encrypt data that only its corresponding Public Key can decrypt, and vice versa.

A digital signature for a message involves encrypting the message with the Private Key and adding a text that includes the original (non-encrypted) message along with the Public Key.

Verification that the owner of the Private Key has authorized the message is achieved by decrypting the message with the Public Key and confirming that the resulting message matches the original one.


Bitcoin Addresses are encoded Public Keys, designed to be more human-readable and resistant to typos.

The generation and storage of Private Keys, along with their corresponding Public Keys and Addresses, are straightforward processes that can be facilitated by programs called Wallets.

Nodes maintain a mempool, which is a list of transaction requests, and store a copy of the distributed ledger known as the Blockchain, containing confirmed transactions.

Each node obtains the current balances, referred to as the UTXO set, from its own copy of the Blockchain.


Proof of Work

In the case of conflicting transactions, validity should be determined by chronological order.
But nodes cannot mathematically prove the order of solicitation, and as transaction requests are propagated like gossip between nodes and can be published from any node, different nodes receive these commands at different times and in varying chronological order.
Therefore, if the nodes differ in which version of the trasaction should be recognized as valid, a double-spend occurs, resulting in the coexistence of different monetary systems.

Bitcoin's key innovation to address this problem is the mechanism known as Proof of Work.
This mechanism makes it possible to dispense with the need for a central authority by probabilistically rotating the power to execute transaction requests. Different mining nodes earn that power based on their relative computational strength.

It works akin to a continuous decentralized lottery where participants acquire "tickets" using an impossible-to-falsify resource: energy.

Alternative systems to Proof of Work rely on resources within their own system, which makes them insecure. These systems are verified through data that can be cheaply falsified and they are vulnerable to attacks where a single entity clandestinely controls the majority of nodes.
Consequently, these systems require an authority to expend human resources, leading to bureaucracy and privileges.

Consensus mechanisms that don't involve work, instead involve governance.


Blocks

Once a transaction request is included in a block of data that is independently verified, copied, and propagated by each node, it is considered executed.

However, the coexistence of two competing blocks for some minutes is possible. This issue is resolved when a new block is created, as each new block must be linked to the last previous block, and nodes follow the chain with the most cumulative work, typically the longest chain.
Consequently, the probability of a block being discarded diminishes with its depth in the chain, and each subsequent block increases the probability of immutability, referred to as confirmation.

Transactions in discarded blocks return to the list of transaction requests if not included in the new blocks.

The creator of each block receives a reward, consisting of transaction fees and a subsidy through a transaction called coinbase.
Each transaction request indicates the fee to be paid to prioritize its execution.
The subsidy comprises new bitcoin units, with issuance halved every 210,000 blocks (around 4 years). This results in a decreasing monetary inflation to reach a maximum of 21 million bitcoins.

The integrity of the information within the block record is easily verifiable due to the use of cryptographic hash functions. These one-way functions transform any digital data input into fixed-size data called a hash.
Hashes are entirely different from one another, even with only slight differences in the input data.
In Bitcoin, the most commonly used hash function is SHA256, which produces a 256-bit hash. For instance, the transaction ID is the double SHA256 hash of the transaction data, and the block ID is the double SHA256 hash of the data in the block header.


Data contained in the the block header:

1. #The hash of the previous block ID.
2. # The combined hash of all transactions' hashes, known as the Root of a Merkle Tree.
3. N # Nonce and hash target.
4. T Timestamp.

Each block consists of its header and the transactions along with their respective hashes:

A block that includes its header and a set of transactions

1. The hash of the previous block ID:

It forms a chain where each new block's hash includes the entire transaction history.
Any alteration to a block invalidates it and all subsequent blocks.
Similar to a mosquito in amber, the deeper a block is in the chain, the more immovable it becomes.


2. The root of a Merkle Tree:

It provides an easy way to verify transaction integrity.


3. Nonce and hash target:

Nonce:

To mine a block, one must find a nonce that, when combined with the rest of the block header data, results in a hash (Block ID) lower than a specified threshold, known as the hash target.

For instance, if the aim is to obtain a hash starting with 00 from data containing the text "bitcoin" attempts could be made with "bitcoin-1", "bitcoin-2", and so on until a successful nonce is found.
Try it here!.
In this example, the nonce would be 53.

The block ID is thus an easily verifiable proof of work.
Miners use energy spending to propose transactions, while the actual execution of transactions occurs in a decentralized manner through nodes.


Hash target:

Its function is to maintain an average block production rate of 10 minutes. This ensures a comparatively quick block propagation and validation, reducing orphan blocks and discouraging mining centralization incentives. The design prevents large miners from gaining significant advantages by building on their own blocks.
Moreover, a minimal data stream minimizes node operation costs and facilitates information replication.


4. Timestamp:

It is the approximate time each block was mined by its respective miner.
Every 2016 blocks, the network calculates the time difference between the first and last timestamps to adjust the hash target based on changes in total mining power.

The hash target can be multiplied or divided by a maximum of 4 to limit the impact of certain double spend attacks.

Timestamps aren't exact and do not necessarily increase in time from block to block. To be accepted by a node, a timestamp must be later than the median of the previous 11 timestamps and earlier than two hours in the future according to the node's current time.


Thanks to this mechanism, for the first time in history, the inflation of a monetary good is predictable.

Bitcoin inflation rate chart


The process of mining

Bitcoin technology uses electricity to avoid consuming human resources. It frees human time.

When we can secure a financial network by computer science rather than by accountants, regulators, investigators, police, and lawyers, we go from a system that is manual, local, and of inconsistent security to one that is automated, global, and much more secure. — Nick Szabo.

Bitcoin miners utilize energy much like firefighters use water when extinguishing a fire.

Bitcoin mining gravitates towards sources of power that unlock stranded energy, which would otherwise be wasted. Bitcoin miners provide a highly flexible and interruptible load, capable of operating anywhere.
In the long run, as competition increases and mining profitability decreases, only the use of surplus energy will remain economically viable.


The minimization of financial governance

Bitcoin technology enables to decentralize the control over a monetary system, minimizing financial governance. Bitcoin operates based on rules without rulers.
Questioning "who controls Bitcoin?" is akin to asking "who controls a language?".
Cypherpunks repulse governance, so the absence of it has always been the goal. This absence enhances the immutability of the network's security and the credibility of its monetary policy.

“Yes: stand back a little bit, you are taking away the sunlight from me”. - the philosopher Diogenes' reply to Alexander the Great's offer of granting him any wish.

In Bitcoin, consensus emerges when different computers simultaneously run the same protocol. By maximizing the role of the consensus protocol, social consensus is ruthlessly minimized.
The core design of Bitcoin is immutable, only those technological innovations that improve security are justified to be gradually included in its code. Advancing slowly is a dogma.

The nature of Bitcoin is such that once version 0.1 was released, the core design was set in stone for the rest of its lifetime. - Satoshi Nakamoto.

We must handle Bitcoin software with the respect we handle nuclear reactor software. - Hugo Nguyen.

This stuff is difficult. This stuff is subtle. If you are frustrated by how slow Bitcoin moves, let me tell you, Bitcoin moves too fast. Cryptography is hard and scary, and we need to make sure we move slowly. - Andrew Poelstra.


Updates

Bitcoin security updates follow a meticulous process:

1. Research: While deployment of new features in Bitcoin is incredibly slow (for good reason), the pace of research is overwhelming. - Andrew Poelstra.

2. Proposal: Updates are proposed for peer review, brain-storming, deployment on sidechains/test-nets, and iterative development.

3. Consensus: If the proposals generate interest, there is overwhelming consensus among network participants, and the most active software contributors unanimously accept them, the updates are implemented and tested.

4. Open Source Deployment: Updates are deployed as open-source code, allowing users to verify them independently.

5. Enforcement: The updates are enforced by nodes. Each node operator must manually install updates if they choose to embrace them.


The term "fork" refers to a change in consensus rules:

- Soft Fork: Tightens the consensus rules. Blocks considered valid by nodes running the old version may be considered invalid by those running the new version. It does not necessitate a simultaneous upgrade of the entire network.

- Hard Fork: Relaxes the consensus rules. Blocks considered invalid by nodes running the old version may be considered valid by those running the new version. It requires every node to upgrade, making it a last resort solution against an extreme security problem in the blockchain.

The greater the procedural risk and mental cost, the fewer incentives there are to upgrade.

In the event of a catastrophic and general failure in Bitcoin's technology, influential developers, hopefully sharing common principles, might contribute to deploying code that migrates the basic Bitcoin rules into a new technology. This scenario, often referred to as "the nuclear option," suggests that in such circumstances, the concept of Bitcoin would likely endure despite changes in technology.

If SHA-256 became completely broken, I think we could come to some agreement about what the honest block chain was before the trouble started, lock that in and continue from there with a new hash function. - Satoshi Nakamoto.


Bitcoin technology's great achievement is to automatically enforce property rights in a monetary system.