How does a bitcoin transaction occupy a space in a block?

Tharaka Wijesundara
6 min readMar 22, 2023

--

Have you been exhausted searching for a complete but simple guide to understanding how a bitcoin transaction takes place? 😰 This is a series of articles that explain bitcoin from its history of evolution to the complete journey of a bitcoin transaction with its underlying mathematics. The series consists of six articles and now you are in the fourth article.4️⃣ To kick off from the very beginning, click here. Happy reading.👨‍💻👩‍💻

Bitcoin transaction journey

If you are coming from the previous article, then you may know what we have missed right?😇We were in the stage of initiating a transaction. However for that to happen successfully, somehow you need to digitally sign the transaction to prove that you have permission(you are authorized) to initiate the transaction. Once you signed, it’s not possible to modify it again and reverse it. It’s more like signing an agreement with your signature but digital signatures give you much more security. Here is Bob’s case, he doesn’t need to worry about signing because the wallet will do the rest on his behalf once he entered the amount with the recipient’s address.

Wallets use their own algorithms to create private keys. In the process of creating a Metamask account, you were asked to keep a set of word phrases secret. Metamask uses that word phrases for private key generation. A private key is just a 256-bit number. It should be computationally impossible to guess it. Therefore the private key generation algorithm should be smart enough to generate a number that is impossible to guess, which means it should have high randomness. Once the private key is ready, the public key is derived using Elliptic Curve Multiplication.

Key Generation — Image Source

Once you have the pair of keys in your hand, you can sign the message(the transaction) with your private key. The verification process is pretty simple. The participants (nodes) in the network use the signature, public key, and plain message. It gets verified only by the respective public key and, for every other public key, verification should be failed.

Signing and Verification

Until we get into the mathematical part of key generation, signing, and verification, this would be enough to deepen further into the transaction journey. 🥳

Once Bob specifies the amount, 1 BTC, with Alice’s address and confirms to proceed, the wallet with take care of broadcasting the transaction details (signature, message, public key) through the connected node. You can see where your node is connected through the settings under the RPC URL.

RPC URL for Etherium mainnet in Metamask

Note: Here, Metamask supports only EVM-based tokens and native cryptocurrencies, and not possible to exchange Bitcoin. Click here for bitcoin-specific wallet applications.

First, the connected node will validate it and notify its peers. Then each receiving node will do the same and notify its peers. Here the validation refers to the process of verifying the signature and the transaction using the available UTXO set. (We have discussed this before.🔙)

As depicted in the following figure, within a few seconds the transaction will be propagated across the network and nodes will add it to their own Mempool. Here, you encounter another new term. Mempool is a temporary location for the transactions to wait until they are selected for the mining block based on the transaction fee included.

Transaction propagation

Eventually, the miner or the mining pool will pick the Bobs transaction from the Mempool and add it to the candidate block.

Let’s say we have two miners named M1 and M2. It’s not mandatory for them to take the same transaction set for the current block. Each node will select its own set based on its own criteria. Bob’s transaction will be there in M1’s block while M2 is mining with a different set of transactions. However, in bitcoin, there is an algorithm called the transaction selection algorithm. Based on that we can observe whether the miners have selected the transactions that are intended to be included. This site gives you a visual representation of the current snapshot of mining and the Bitcoin network.

Snapshot of block mining — mempool.space

Once miners select their own transaction set, to add their own block into the blockchain, they need to solve a computationally complex mathematical problem to secure the block reward. Each miner needs to find its own value based on the selected block data. The process of finding that unique value is called mining. Before getting into the mining algorithm, let’s look at what a block is.

Block in Bitcoin

Sample bitcoin block — Image Source

Blockchain consists of linearly connected blocks. As we discussed throughout the series, it’s computationally impossible to tamper with blockchain because each blockchain contains the hash of the previous block. No need to explain it by myself, since I found a gentleman who explained how the blockchain is architected and why it is much more secure. Watch this video and get a hands-on experience through the site he mentioned in the video description.

As you could understand, this is the simple structure of a block and the actual bitcoin block consists of more information than this. Please refer to this link to see the complete structure of a block. You may have noticed a lot but please note that some of them are not stored in an actual block and they are generated from the block explorer.

If you read the very first blog of the series about blockchain history. There you could find someone called Hal Finney. If you head over to the above link, you could find the block that he mined.😎 Simply change the above link to /0 and you will be directed to the very first block of the blockchain history where Satoshi Nakamoto mined.😎 We named it the Genesis block.

Merkle tree

Image Source

Have you noticed something called merkleRootHash in the block header? It referred to the root hash of a hash-based data structure called Merke Tree. Since it is a tree structure (binary tree), we encounter some tree-specific terms like leaf nodes, children, branching factor and root, etc. It is a bottom-up architecture where, it is merged from bottom to up by hashing based on its branching factor, which means each leaf node has up to two children.

Why do we need to use Merkle trees in bitcoin? What do you think? It is not actually limited to the blockchain. It is used in well-known version controlling software, Git, and many other peer-to-peer networks. Even though you may feel like it is a simple tree structure, it has way more benefits in data validation over a simple hash list when it comes to validation time and network performance like payload size.

please refer to these articles to dive more deeply into Merkle trees. Article 1, Article 2.

References:

  1. https://blog.goodaudience.com/how-a-miner-adds-transactions-to-the-blockchain-in-seven-steps-856053271476
  2. https://learn.saylor.org/mod/book/view.php?id=36350&chapterid=18931
  3. https://www.gemini.com/cryptopedia/what-is-block-in-blockchain-bitcoin-block-size#section-transaction-data-within-a-bitcoin-block
  4. https://towardsdatascience.com/a-shallow-dive-into-bitcoins-blockchain-part-2-transactions-d4ee83067bae

--

--