Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
rudramani
Participant

Content:



  • Introduction

  • Blockchain

  • A Block

    • Genesis Block

    • Hashing

    • Transaction Data

    • Merkle tree

    • Timestamp

    • Nonce




Introduction


Blockchain and cryptocurrency concepts can be easily understood if we divide the concepts in two parts: A Block and transaction flow. In this article we will learn how a block is created in a Bitcoin and what are the components of A Block.

Blockchain


A Blockchain is a decentralized database, or simply a decentralized linked list, where list of records (called blocks) are linked via cryptography. By decentralized, we mean that there is no single database where all records are saved rather the same set of data is saved in multiple databases. A block in a Blockchain contains list of records (called transaction data), a timestamp (UNIX time) and cryptographic hash of previous block (hash converts the previous block data into a fixed length of random data). This process of saving blocks can be seen below (You can make your own blocks here😞

 

Figure 1:  An example of Blockchain



A Block


In the introduction part, we have seen how blocks are linked to each other and what a block contains. Now let us explore technical information of a block (a block header) part by part.


Figure 2 A Block




  • Genesis Block


It is the first block of any Blockchain and its value is always hard coded. Since no previous block existed before it, hence the previous hash remains ‘0’ in this case. All the data are maintained in the later blocks and the very next block will have the Hash value of Genesis block in the “previous hash” section as shown in figure 1 above.

  • Hashing
    Hashing is a process in which an algorithm is used to convert a string of any length to a string of fixed length. It is very important in case of Blockchain as it helps to keep track of huge data without saving them and rather saving hash of that data. Bitcoin uses SHA 256 while Ethereum uses Keccak-256 algorithms respectively. The only important thing to take away is that this generated hash key is the one that stores data of current block and address of the next block, hence linking both the blocks and keeping track of the previous block. In given diagram below, I have generated hash of a string using SHA 256 algorithm, you too can generate hash values from here.



Figure 3 SHA-256 Conversion




  • Transaction Data


All the transaction records are saved as Transaction Data. Each block of a Blockchain can contain thousands of transaction data and it will be inefficient to store all the data inside each block as a series. This will decrease the search efficiency of a data. To solve this issue, data inside a block is stored in the form of a Merkle tree.

 

  • Merkle tree


A Merkle tree is a representation of data (in this case hash key of our transaction data) in a form of leaf and child node. These nodes are connected to a single root. This root is the representation of all the transaction data into a single hash key. To make it simple, just assume a tree with multiple branches and each branch has their own branches. Now the last level of branches will have our data. These data will have their own hash keys as discussed earlier. These hashed keys will be put into pairs and will be hashed again. This process is repeated till we get only one hash. This hash is stored in the Blockchain as Data and using it only other data can be retrieved. This high level of hashing makes it tamper proof.


Figure 4 A Merkle Tree




  • Timestamp


As the name suggests a timestamp is a Date-time value that is stored in a block.  Any transaction in this world is incomplete without date and time data. It tells at which time that block was created. In Blockchain this value is in the form of Unix Timestamp. Unix Timestamp is the number of seconds that have elapsed since 01.01.1970 which means 0000000000 in UNIX time is equal to January 1, 1970 12:00:00 AM. A timestamp is converted value of GMT. Thus, if a block is created, it will take current time of GMT and convert it into Unix Time, validate it if it is greater than the saved time of previous block and then save it. You can convert any time to UNIX time here.

  • Nonce
    The literal meaning of nonce is “unique for particular occasion”. A nonce is not a general Blockchain term but is a cryptographic term mainly discussed in terms of Bitcoin. A nonce is a number which has to be guessed in such a way that when added before the hashed value of current block should produce a value whose hashed value is less than the difficulty (it is also a part of block and is regenerated for every block), its length is equal to the hashed block length i.e. 64 character which is equal to SHA-256 length in case of Bitcoin.

    Process of finding nonce:


    • The person(miner) must guess a value of nonce (it can start with 000…0001)

    • Get the hash value of block header of previous block (000dceb75a135c…)

    • Append that nonce before the hash of block header (000…0001000dceb75a135c...)

    • Rehash the above appended value (xyz)

    • Get the difficulty value from the block header (abc)

    • Check if the above rehashed value is less than the difficulty value or not (xyz < abc)

    • If yes, then a new block is added in the current Blockchain of the Bitcoin and this person is rewarded some bitcoins for his work




References:

https://blockchaindemo.io/

https://www.epochconverter.com/

https://www.researchgate.net/publication/330367578_A_Tryst_Of_ERP_With_Blockchain

https://bitcoin.org/bitcoin.pdf

 

 
2 Comments