March 29, 2024

How does Bitcoin work? Dive into technical aspects

In this article, we will look at the fundamental technologies and mechanisms that make Bitcoin work.

Topics such as difficulty adjustment, bitcoin supply curve, transaction engine, UTXOs, Merkle trees, hard and soft forks, and block explorer will be covered.

</p>

How are new bitcoins created?

Bitcoins are created through a process known as mining. Miners must solve a complex math problem(called Proof-of-Work, or PoW - proof of work)before they can add new transactions to the blockchain. In return, they are rewarded with new bitcoins.

Anyone who has a computer can become a miner. By becoming a miner, you can participate in confirming and recording transactions along with other miners.

Block creation times and difficulty adjustments

It is difficult to predict how many minerswill join the network. If there are too few of them, the system will be too slow, resulting in a poor user experience. If there are too many of them, the system will be too fast, which will lead to security problems(for example, it will be easier to double-spend). It is therefore important that the system maintains a relatively constant tempo regardless of how many miners there are(in other words, processing power).

Bitcoin uses a mechanism known as“difficulty adjustment” to maintain a constant mining speed of approximately 10 minutes per block. "Difficulty" is adjusted every two weeks, taking into account the processing power during this time. If computing power is insufficient(i.e. the average block creation time is more than 10 minutes), the difficulty decreases. And vice versa, if the computing power is too high(i.e. blocks are generated more often than every 10 minutes on average), the difficulty increases.

How is difficulty corrected?

The Bitcoin protocol requires miners to compete with each other to see who can solve a cryptographic problem the fastest.(known as proof of work)so that the winner can propose a new block and add it to the blockchain.

The cryptographic problem is solved by selecting the so-called nonce so that the block hash does not exceed the target value(less than 256 bits in size).

</p>

Interesting read: To understand blockchain, you need to understand what a hash is

Miners have to find such a random 32-bita number, known as a nonce, so that the hash of the block is less than or equal to the target value given by the network. If your hash is less than the goal, then you win and receive a mining reward. If not, then you change the nonce and try again, etc.

The more computing power on the network, theless target hash. The smaller the target hash, the more difficult it is for miners to find a suitable nonce to create a block hash that is smaller than that target hash.(Imagine that a computer randomly selects a number between 1 and 100. The probability of getting a number less than 10 is 0.1, while the probability of getting a number less than 50 is 0.5.)

Therefore, this is how the Bitcoin network doesdifficulty adjustment.

What are hash rates, mining rewards and transaction fees?

In the previous section, we saw why compute power is important and how it relates to block creation times and difficulty adjustments. Computing power can be measured by hashrate.

Hashrate

Hashrate is the number of hashing operationsperformed per unit of time. This figure varies depending on the equipment used. For example, if a miner's device is capable of generating a hashrate of 30 MHz, then this is equivalent to 30 million hashes per second(a hash is one transformation from one state to another, or, to simplify even more, one calculation).

Thus, a GPU with a hash rate of 30 MHz makes 30 million calculations per second.

The higher the hash rate, the higher the likelihood that the miner will solve the problem and receive a block reward. The probability of a miner solving a problem can be roughly estimated using the following formula:

P = X / Y,

Where:

  • P is the probability of solving the problem;
  • X - hashrate of the miner;
  • Y is the total hashrate of the network, that is, of all miners currently working.

You've probably heard about mining farms -huge industrial-scale complexes equipped with equipment whose sole purpose is to mine cryptocurrency. There could be thousands of connected GPUs(graphics processors)or ASIC(integrated circuits for special purposes), which significantly increases the overallcomputing power versus a single piece of equipment. The purpose of all this is to increase the likelihood of solving the problem and receiving mining rewards.

Mining reward

illustrations: BitNews

Mining reward is compensation(in the form of newly created coins), paid by the system to miners who have solved the cryptographic problem and obtained the right to create a new block.

Currently, the reward for each blockBitcoin is 6.25 coins. To receive this reward, miners compete to see who will be the first to solve the problem. Therefore, the higher the hashrate, the more likely it is to receive a reward. In order to improve the return on investment and increase the likelihood of successful mining, mining companies and individuals often have to spend a significant amount of money on hardware and electricity first.

However, due to a sharp increase in the overall network hash rateit becomes almost impossible for individual miners to mine bitcoins, as their resources are limited. Therefore, individuals can provide their resources to the general pool, which will perform mining for them. This way pools can get more resources to compete with each other, and individuals can be rewarded proportional to the hashrate they provide to mitigate the volatility they might encounter when mining on their own.

Mining reward every 210,000 blocksdecreases by half. Bitcoin started with a block reward of 50 BTC, then decreased to 25 BTC in 2012, and 12.5 BTC in 2016. In 2020, the block reward was halved again to 6.25 BTC, and this will continue until all 21 million BTC are mined.

Different cryptocurrencies have different mining rewards and a different emission schedule. You can find them out in the whitepaper of the corresponding cryptocurrency.

Block rewards are paid through a coinbase transaction - the first transaction in a block. In addition to the reward, it pays transaction fees to miners.

Transaction fees

</p>

Since Bitcoin and other cryptocurrencies,using a PoW mechanism, mining rewards are gradually decreasing, miners also have another incentive to confirm transactions: network fees. Users of cryptocurrencies using PoW consensus must also pay network fees to miners for each transaction. This fee may vary depending on the network load and the specific cryptocurrency. Transaction fees are the remainder of a transaction's input that remains unspent. They are usually computed in satoshi per byte.

Commissions motivate miners to confirm your transactions. You can pay low fees or not pay at all, but this significantly reduces the likelihood of a transaction being included in the next block.

There are also coins with low or zerocommissions, but they usually use a different type of consensus (eg DPoS, PBFT) or another technology (eg DAG). The most famous examples of such coins are XRP, EOS and IOTA.

Bitcoin offer

The final supply of bitcoins is 21,000,000.At the moment, almost 19,000,000 coins have already been mined. Initially, the block reward was 50 BTC, but it is halved every 210,000 blocks, which is called halving and happens approximately every 4 years. Consequently, the inflation rate drops noticeably. Current block reward is 6.25 BTC(after three halvings)... The next Bitcoin halving is expected on June 3, 2024. All Bitcoins are predicted to be mined shortly after 2100.

Bitcoin supply and block reward (in million). : Crypto.com

Loss of private keys or damageequipment, some bitcoins are lost forever, so the actual supply is significantly less than the theoretical value. Bitcoin's inventor Satoshi Nakamoto also left his significant amount of coins intact after being mined many years ago.

How do Bitcoin transactions work?

Let's imagine the Bitcoin transaction procedures using the following scenario as an example:

Online merchant Bob decides to accept Bitcoin payments. Alice has bitcoins and wants to buy something from Bob.

Wallets and addresses

Both Bob and Alice have Bitcoin wallets on their computers. : Crypto.com

Walletsare files that provide access to multiple Bitcoin addresses.

Addressis a string of letters and numbers, for example1HULMwZEPkjEPech43BeKJL1ybLCWrfDpN... Each address has its own bitcoin balance.

Addresses can be thought of as bank accounts, but they work a little differently. Bitcoin users can create as many addresses as they want.

Create a new address

Bob creates a new address to which Alice will send him a payment. : Crypto.com

The addresses for users are generated by the Bitcoin client software.

When Bob creates a new address, he is actuallygenerates a pair of cryptographic keys, consisting of a private or private key (known only to you) and a public or public (known to everyone). If you sign a message with a private key, it can be verified using the public key. Bob's new address is a unique public key, and the corresponding private key is stored in his wallet. The public key allows anyone to verify the authenticity of a message signed with a private key.

</p>

Sending payment

Alice informs her Bitcoin client that she wants to send coins to Bob's address. : Crypto.com

Alice's wallet contains private keys for each of her addresses. The Bitcoin client signs the transaction request with a private key corresponding to the address from which the coins are sent.

Anyone in the network can now use the public key to verify that the transaction request came from the legitimate account owner.

A public key is used to receive bitcoins.

The private key is used to sign a transaction and also to spend bitcoins.

To spend bitcoins, their current owner provides their public key and digital signature in the corresponding transaction.

The digital signature of a transaction is created using a private key, which means authorization of spending the funds referred to by the transaction.

Using a public key and digital signatureany member of the Bitcoin network can verify the transaction and accept it as valid, confirming that the person sending the coins owned them at the time of the transfer.

Transaction confirmation

Let's say Gary, Garth, and Glenn are Bitcoin miners. Their computers combine transactions from the last 10 minutes into a new block. : Crypto.com

Cryptographic hashes

Cryptographic hash functions transform a setdata into a fixed-length alphanumeric string called a hash sum. Even the smallest change in the original data will significantly change the resulting hash sum. And it is almost impossible to predict which input data will give a specific hash sum.

entrance SHA256 output
BitNovosti 491fd0ac791d6ef2229de5cab423ca6eb21dfe16e129e3a89a6893682a80e219
Bitnovosti 950822b5e38e6c48e20add70a4593d7f4b66917c457d06ff929fe4e7e86d440a
bitnovosti 8b4cd5c3d8be54f7a19cae929f0e15b6de0bdda08ce929c327c90fa82611e2aa

Nons

To get different hash sums from the samedata, Bitcoin uses nonce. Nons is just a random number that is added to the data before hashing. Changing the nonce leads to a completely different hash sum.

: Crypto.com

The miner's computers calculate hash sums based on a combination of the previous hash sum, the new block of transactions, and the nonce.

Hashing itself is not difficult computationallytask, but the Bitcoin system requires that the new hash-sum has a certain form - in particular, it must start with a certain number of zeros.

Miners cannot predict which nonce will givea hash sum with the required number of leading zeros. Therefore, they are forced to generate many hashes with different nonces until they get a suitable value.

Each block includes a coinbase transaction,which pays the winning miner - in our example Gary - a reward. A new address is created in Gary's wallet with the balance of the newly mined bitcoins.

Initially reward for each blockwas 50 BTC. After every 210,000 blocks, or approximately every four years, the reward is halved. As of May 2020, the block reward is 6.25 BTC. In addition, the miner receives the fees paid by the senders of the transactions. The fee motivates the miner to include the transaction in his block.

Transaction confirmed

Over time, on top of Alice's translation to Bob inother, newer transactions accumulate on the blockchain. For someone to change the details, they have to redo the work of Gary - because the change requires a completely different winning nonce - and then the work of all subsequent miners. Such a task is practically impossible. : Crypto.com

  • The transaction is broadcast to the Bitcoin network, where each participant verifies it and passes on until it reaches almost all the nodes of the network.
  • The mining node verifies the transaction and includes it in the block, which is written to the blockchain.
  • After writing to the blockchain and confirmingwith a sufficient number of subsequent blocks, the transaction becomes an integral part of the open distributed ledger of Bitcoin and is recognized by all participants as valid.
  • The new owner of bitcoins can spend them in a new transaction.

Utxo

Before introducing a UTXO, you need to know what the entry and exit of a Bitcoin transaction is.

entrance

An input is a link to the output of a previous transaction. All new transaction input values(i.e. the total sum of previous outputs referenced by the inputs of the new transaction)add up, and the sum(less commission)is completely used in the output of the new transaction.

Often, a transaction involves multiple inputs.

Output

The output contains instructions for sending bitcoins. The transaction output includes the amount that output will cost when requested.

UTXO (Unspent Transaction Output)

Since the output of each specific transactioncan be spent only once, the outputs of all transactions included in the blockchain can be divided into unspent (UTXO) and spent. For a transaction to be valid, its inputs must only be UTXOs.

</p>

Each transaction has at least one input andone exit. Each input consumes the satoshis paid in the previous output. Each output then waits as a UTXO until a subsequent input consumes it. When your wallet tells you that you have 10,000 satoshis, those satoshis represent one or more UTXOs.

Imagine that you have previously used an address1HULMwZEPkjEPech43BeKJL1ybLCWrfDpNto get Bitcoins twice.The transaction dated 05/02/2019 contains 4000 satoshi, and the transaction dated 09/03/2019 contains 6000 satoshi. The Bitcoin blockchain will not help you add up your balance so that there is a record like1HULMwZEPkjEPech43BeKJL1ybLCWrfDpN: 10,000.Instead, every time you want to spend your bitcoins, you must unlock every transaction you own (with bitcoins sent using your public key) separately.

If you want to spend 3000 Satoshi, then youyou need to unblock either the transaction from 02/05/2019, or the transaction from 03/09/2019, since each of them contains more than 3000 satoshi. But if you want to send 8000 satoshi, you need to unblock both transactions and send all coins in a new transaction.

Partial spending is not allowed, so youmust use all unlocked bitcoins. If you only intended to send 8,000 satoshis, then you still need to spend 10,000 satoshis in a new transaction, and then spend 2,000 satoshis back to your address.

</p>

Merkle tree

There are many transactions in a Bitcoin block. Sometimes we need to check if a particular transaction is included in a block or not.

The Merkle tree summarizes all transactions in a block, creating a digital fingerprint of the entire set of transactions, allowing the user to check if the transaction is included in the block.

Technically, a Merkle tree is a tree-like structure,which is constructed by hashing the paired data (leaves) and then pairing and hashing the results until one hash remains - the Merkle root. The tree is built from bottom to top, starting with the hashes of individual transactions(known as Transaction ID, or TXID)... In Bitcoin, the Merkle tree uses double SHA-256 - the SHA-256 hash of the SHA-256 hash of some value. The hash function for transaction A can be thought of as hash (hash (A)).

Each leaf node is a hash of transaction data,and the non-leaf one is the hash of the previous hashes. Merkle trees are binary and therefore require an even number of leaf nodes. If the number of transactions is odd, the last hash will be duplicated once to create an even number of leaf nodes.

For example, imagine a block of four transactions A, B, C and D. The Merkle tree will look like this:

Merkle tree. : Crypto.com

An easy way to create a unique printof all TXIDs is to concatenate and hash them. But if we want to check if some TXID is part of the hash, we will need to know all the other TXIDs as well.

Simple hash

: Crypto.com

However, with a Merkle tree, if we want to check,whether TXID is part of a Merkle root, we only need to know some of the hashes along the tree path. As a consequence, if we use the Merkle tree as our unique fingerprint in the block header, we can later figure out if a transaction is present in the block, without having to know all the other TXIDs of the block.

: Crypto.com

Hard and soft forks

Fork in programming is called modification of open source code. As a rule, the fork code is similar to the original, but with significant changes, and the two versions can easily coexist.

Since cryptocurrencies are decentralized, everyonethe participants in their networks - known as nodes - must adhere to the same rules in order to work properly together. This set of rules is known as a protocol. Typical protocol rules include block size on the blockchain, rewards miners receive for mining a new block, and more. The decentralized nature of the blockchain means that the nodes of the network must be able to agree on the overall state of the blockchain. A uniform protocol for all network nodes leads to a single blockchain containing verified data (transactions) that the network considers correct. However, if there are nodes in the network that cannot agree on the state of the blockchain, then this leads to a split into two branches. In the world of cryptocurrencies, a fork is more often used to implement fundamental changes or create a new asset with similar (but not identical) characteristics to the original.

There are two types of forks in cryptocurrencies:soft forksAndhard forks... But both types of forks fundamentally change how the cryptocurrency protocol works.

Hard fork

A hard fork is a radical changecryptocurrency protocol incompatible with previous versions, which means that nodes with an older version of the protocol will not be able to process transactions and add new blocks to the blockchain. Forked (new) blockchain transactions will be invalidated on the old blockchain. All nodes and miners must update to the latest version of the protocol if they want to be on the new blockchain.

For example, the protocol increases the size limitblocks from 2 MB to 4 MB. If a refreshed node tries to add a 3MB block to the blockchain, the old, non-refreshed nodes will not consider this block valid and reject it. Thus, two versions of the once single blockchain will emerge. One will contain blocks of both the old and the new version, and the other will only contain the old one. Which blockchain grows faster depends on which nodes confirm the next blocks, and further splits are possible as well. It is possible that two blockchains (or more) can grow in parallel for any length of time.

Hard fork rules. : Crypto.com

Hard forks can be planned or contradictory depending on the situation.

In the event of a planned fork, the nodes voluntarilyupdate their software to follow the new rules, abandoning the old version. Those who do not upgrade will mine on the old blockchain that very few people will use.

But if the fork is inconsistent, it means that incommunity disagreements arose around the update. Typically, the protocol forks into two incompatible blockchains - and two different cryptocurrencies. Each blockchain will have its own community, and the developers will choose the one that they think is the best.

Since the new fork is based on the originalblockchain, all transactions of the original blockchain are copied to the new fork as well. For example, if you have 100 coins of cryptocurrency A and a hard fork based on that cryptocurrency creates a new cryptocurrency B, then you will also have 100 coins of cryptocurrency B.

Soft fork

A soft fork is a change in cryptocurrencyprotocol, leaving it backward compatible. This means that nodes that have not been updated can still process transactions and add new blocks to the blockchain, as long as they do not violate the rules of the new protocol. Such a fork only requires that most miners update according to the new rules, whereas a hard fork requires (almost) all nodes to update and agree with the new version.

Soft fork rules. : Crypto.com

For example, a new rule has been adopted that reducesblock size limit from 3 MB to 2 MB. The old nodes will still be able to process transactions and add new blocks not exceeding 2MB. But if the old node tries to add a block larger than 2 MB to the network, the updated nodes will reject it because it violates the new rules. This encourages the old nodes to upgrade because they are not as efficient as the upgraded ones.

Blockchain / Block Explorer

Explorer (explorer) blocksis an online tool for viewing the blockchainand transaction verification. It provides information such as the contents of an individual block, transaction history, and address balance. The block explorer is simply a search tool. Just like you use web browsers to navigate the Internet, a block explorer allows you to view the blockchain.

Block explorers exist for Bitcoin,and for altcoins. To find transactions in a specific cryptocurrency, you need to use the appropriate explorer. For Bitcoin, there are popular block explorers such as blockexplorer.com, blockchain.com, blockcypher.com, and btc.com. Let's present some of the most common block explorer functions using blockexplorer.com as an example.

Last blocks and last unconfirmed transactions

Almost all block explorers contain information about recent blocks and transactions. When the miner has solved the problem, he adds the block to the blockchain, and the explorers then update this information.

List of the last added blocks in the blockchain. : blockchain.com

Search for blocks and view all their transactions

Perhaps you want to know more detailed information on each block. You can either click the link in the block list, or enter the block number directly into the explorer's search bar.

: Crypto.com

You can also find information on each transactionthis or that block. When you click on a transaction, its ID and corresponding addresses will be displayed. You can easily find out how many bitcoins were transferred, which address sent them and which one received them.

: Crypto.com

Additional features

Data displayed in block explorerinterrelated. For example, you can click on any transaction to see more details about it. You will see the block number in which the transaction occurred, the total number of confirmations and some additional data. Then you can click on the wallet address and check its transaction history and balance.

: Crypto.com

The rest can be explored by the reader on their own by exploring blockchains with the help of block explorers.

</p>
You can always thank the translator for the work done:BTC:3ECjCH5tPoyDCqHGCXfiiiLZQ3tVGzCSxBETH:0xf45a9988c71363b717E48645A412D1eDa0342e7E