error_outlineWEBSITE HACKED ? sos@getsecureworld.com

What is a transaction’s step-by-step life cycle?

Blockchain Security + blog Z. Oualid today

Background
share close

Blockchain networks are built upon the concept of the transaction, either for transferring money or to even setting up a smart contract. However, each transaction performed in the Blockchain has a specific life cycle that all of them follow to reach their goal. This life cycle could be simple or complex depending on the goal of the transaction. Therefore, what is a transaction’s step-by-step life cycle?

The Bitcoin transactions life cycle could be resumed in the following steps:

  1. Transaction is forged by the sender
  2. The transaction is broadcasted to the Blockchain network.
  3. Miners verify this transaction and it in a block
  4. The miner solve the PoW and broadcasts the new block.
  5. Sender receive confirmations after each new block validation

The previously mentioned transaction steps are generic ones that basically happen in any kind of Blockchain. Therefore, in the following sections of this blog post, we are going to explain in detail what happens in each step in either the Bitcoin or Ethereum context. In addition, you are going to see the main differences between the Bitcoin transaction steps and Ethereum steps.

Those details are very important and will help security auditors to better understand how things work especially when dealing with smart contracts. Knowing that information is crucial for better smart contract auditing. So if you are interested just keep reading.

1.      Transaction is forged by the sender

You can think of the transactions at this stage as objects that you manipulate and add data to them. It could be JSON data or bits of data. For example in Ethereum Blockchain a transaction could be created as follows:

tx = {
    ‘nonce’: nonce,
    ‘to’: account_2,
    ‘value’: web3.toWei(1, ‘ether’),
    ‘gas’: 2000000,
    ‘gasPrice’: web3.toWei(’50’, ‘gwei’)
}

Where nonce is the number of transactions you have sent from your address. This parameter is used and incremented each time a new transaction is sent to the Blockchain. This value also helps you avoid sending the same transaction multiple times.

Once the transaction object is created it is then signed with your private key and converted to raw data to be then sent to the Blockchain in the next step.

2.      The transaction is broadcasted to the Blockchain network

Once the transaction is signed with the user’s private key, its wallet sends the transaction to a node in the Blockchain. That node is then responsible for broadcasting the transaction to the different nodes in the Blockchain to begin the validation process.

Bitcoin for example uses a flood fill algorithm to distribute transactions and blocks to all the nodes, pretty quickly. When a Bitcoin node starts up, it establishes a set of TCP/IP connections with other nodes, which it maintains during its operation.

When the wallet sends the transaction data to a Bitcoin node, this one sends copies of that data to all of the other Bitcoin nodes with whom it is linked. The information is then relayed to all of the nodes to which they are linked, and so on.

Most wallets, keep a list of the available nodes to whom the wallet can communicate the transaction data. This list is updated each time a transaction is sent to the network to avoid relying on only one machine that can stop at any moment.

3.      Miners verify this transaction

Once the transaction is received by the different miners of the Blockchain, it is first verified against the whole Blockchain older transactions to avoid any double-spending. Then that transaction is put in a pool and waited to get included in a block to get validated.

4.      The miner solve the PoW and broadcasts the new block.

At this level, things might be quite different from one Blockchain to another. In the Bitcoin Blockchain, for example, validating a new block requires solving a digital puzzle that requires a lot of computation energy. The more the number of nodes or the power of computation gets higher, the more the digital puzzle gets difficult to solve.

A digital puzzle simply means finding a hash that starts with a certain number of zeros and that is lower than a specific value. This whole process is called Proof of Work (PoW), if you want more details about it you can take a look at the blog post.

However, in the Ethereum Blockchain, the validation of the new blocks is based on a concept called Proof of Stack (PoS). In this concept, the nodes that have stacked more coins on the network get better chances to become a leader and validate a block. The idea here is that if you have invested more money in the Blockchain, it means there is a bigger chance you would not damage it.

Both concepts have pros and cons. However, the most popular ones are the fact that Proof of Work is both time-consuming with 10min for each new block to be added in the block and energy consumption. In contrast to Ethereum with 1min for new blocks and low energy consumption.

If you want a more detailed comparison of those consensus concepts (PoW and PoS) I invite you to take a look at the following blog post. Or if you are building your own Blockchain and want to know which consensus algorithm will work better for you take a look at how you can choose the best consensus algorithm blog post.

Once the leader is chosen or the digital puzzle is solved the block is included in the Blockchain and the result is broadcasted to the whole network.

5.      Sender receive confirmations after each new block validation

Even if the digital puzzle is solved and the transaction is added to the Blockchain, the transaction does is not yet confirmed and could be rejected at any moment. This could happen if the Blockchain nodes do not confirm the newly generated block. Therefore, the user should wait for at least 6 confirmations message from the Blockchain to ensure that the transaction is validated and saved in the Blockchain forever.

The confirmation message is a simple notification message sent by the Blockchain whenever a new block is validated. This means that for a bitcoin transaction to become definitive, the user should wait for at least 1h (6 blocks = 6 x 10min = 60min)

Written by: Z. Oualid

Rate it

About the author
Avatar

Z. Oualid

I am a Cyber Security Expert, I have worked with many companies around the globe to secure their applications and their networks. I am certified OSCP and OSCE which are the most recognized and hard technical certifications in the industry of cybersecurity. I am also a Certifed Ethical hacker (CEH). I hope you enjoy my articles :).


Previous post

Post comments (0)

Leave a reply

Your email address will not be published. Required fields are marked *