Mathematics gives structure to blockchain. The most important mathematical concept in all blockchain applications is the hash function (see Video 2 above). The hashed message cannot be interpreted correctly without the original input. But once you have the original input, it is easy for anyone to verify the hash. Thus, cryptographic hashing becomes a good way to implement immutability of a blockchain ledger, e.g., Bitcoin’s "proof-of-work". However, in mathematics, the concepts are first defined and then they are further elaborated. Let us begin with the formal definition of a hash function.

Hash functions can be defined as functions that are capable of transforming any block of binary data into another fixed-size binary block. The result of such a transformation is called hash (Martínez et al. 2020).

What does this definition mean? Well, for first, it talks about blocks of binary data, which are data that are comprised of ones and zeros. Therefore, hash function transforms data into another form, effectively making it shorter and unintelligible with normal tools.

Why to use hash functions to secure the data in the blockchain? It is for the reason of keeping the data safe and making sure frauds are harder to make. The blockchain is a peer-to-peer distributed system, so its functions have to take into account that some peer might want to take advantage of the system. The method of safeguarding the data with hash functions is therefore very important. Consider the Bitcoin example. What would happen if somebody would be able to edit the bitcoin ledger for their own advantage? At least it would decrease the trust peers place on bitcoin. In the worst case, the whole Bitcoin would cease. Therefore, the Bitcoin ledger has unique hash value for all the transactions.

It is interesting to note that when hashing the data, the size of the data decreases. Mathematically this can be expressed as by saying that a hash function is a unidirectional function that is applied to a message m of variable size, where the message belongs to a certain set of messages, M, and provides a digest of the message with a fixed, predetermined bit size, n (Martínez et al. 2020). This effectively means that all the hash codes given to transactions are of similar size, impossible to discern from one another by non-mathematical means. Therefore, it is important to understand some mathematics behind hashing the data. First thing to note that as the hash is of smaller size than the original data, it lends more efficiency to the functions of any blockchain as network does not become encumbered with as heavy traffic as by using the original data.

Mathematical properties of a hash function (according to Martínez et al. 2020)

The compliance with the above properties guarantees, at least initially, that the functions that fulfill them are not vulnerable and prevent that, taking as input the hash of a message, the content of the message can be retrieved and that no one will be able to find another message with the same hash.

In addition to hash functions, the elliptic curve digital signature algorithm (ECDSA) is used to safeguard blockchain against identity thefts and double spending. Here it only shown as an example of the mathematics involved in blockchains, to give a taste of how definitions communicate the necessary exact properties of the blockchain. These definitions are used in all blockchain applications.

The ECDSA works because of the properties of a specific type of elliptic curves. The mathematical formulation of an elliptic curve in question is as follows:

~y^2 = (x^3 + ax + b)~ mod p, where a and b are integers and p is a prime number.

The properties of this type of elliptic curve are such that a cryptographic scheme can be developed using it as a base (see Figure 3.1 for an example of this type of curve). More accurately, the ECDSA depends on the fact that given type of curve has intersections that can be used to make a simple computation for the properties of these intersections, which is hard to reverse, that is, from the result it is hard to find out the premises of the computation. When we have discussed more about cryptography in Chapters 3 and 4, you might want to find out more about elliptic curve online. The Instructables website has a good, detailed introduction.

**Figure 3.1** An example of elliptic curve with a line from P to Q to R (Martínez et al. 2020).

The blocks of any blockchain can be hashed using hash functions. However, to make these blocks a blockchain, blocks need to be connected to one another. As it turns out, a special tool called hash pointers can be used. These are placed into the hash value of the block, so that the data in any block also contains its hash pointer to the previous block it is connected to. We will discuss the hash pointer’s implementation more closely in the coming chapters.

Mathematically it is not enough to know that there is a chain of blocks defined by hash pointers, but it is also necessary to find a method that allows identifying if a block is already a part of a chain, and if so, where it is located. As decrypting hash functions is time-consuming, their use in defining the location of each block in a chain is not effective. Consequently, a method that stores and manages hash pointers efficiently is needed. Therefore, the use of e.g., Merkle trees is needed (see Martínez et al. 2020).

**Figure 3.2** An example of Merkle tree with different currencies in the tree (Martínez et al. 2020).

Figure 3.2 depicts a simple Merkle tree. The hash pointers are organised into a Merkle tree and all the blockchain information is collected into Merkle trees. The information in Merkle trees in blockchains are hashes of transaction data.

About mathematics behind Bitcoin:

More involved article about mathematics of Bitcoin:

Link to the article by Martínez et al. (2020):