How does the Bitcoin network verify a transaction?

A transaction does not exist until it is recorded in a block. To keep the network safe and secure, miners have to reach a consensus before implementing a transaction.

The process can be broken up into three steps:

  • Sign: Alice wants to send Bitcoin to Bob’s public address
  • Generate: Miners gather data and create their own block.
  • Compete: Miners compete to get their block issued on the blockchain.

After issuance of a transaction, miners gather data, create their own block and compete amongst each other to get their block approved on the main blockchain. A transaction cannot occur until it is mined and verified by the network

The transaction issuer signs a transaction with its private key

  1. Alice issues a transaction from her wallet. She sets the recipient's public address (Bob's) and the amount to disburse.
  2. The public address requires a signature from the corresponding private key in order to be accepted. Therefore, Alice signs the transaction with her private key, stored in a wallet that can be protected by a password.
  3. The transaction is then sent online to the bitcoin network to be recorded on the blockchain.

Miners generate a block with the transaction and verify it is valid

  1. Miners then create a new block from signed transactions and verify that they are valid.
  2. The block's data is then converted into a hash by miners.
  3. Miners offers their solution to the mathematical problem by creating a block.

A hash is a fixed-length string that holds large amounts of data via encryption. Each block has a unique hash because it has a unique set of data. Changing one variable in the data will change the hash. This way, the network knows if a fake transaction has been inserted in a previous block because each block's hash is part of the formula that generates a new block.

Miners compete amongst each other to produce the next block

  1. Once miners have a valid block and hash, they compete amongst each other to get their block added to the blockchain by solving a mathematical formula that involves hashing.
  2. Under the hood, miners need to gather different unconfirmed transactions (input) compute them into a hashing function set by an algorithm and create a new hash (output) with pre-determined conditions (starts with a certain amount of zeros).

As more miners compete for rewards, the hash problem gets tougher and tougher. This way, the difficulty to mine a block adjusts itself with the number of miners working.

The network sets every two weeks a new hash target value: miners need to solve the problem by providing a valid hash inferior to the target.

Retargeting makes hashing difficulty evolve with the number of miners connected to the network.