Reading time: 2 min
On the immutability of information: what do "hash" and "nonce" mean?
One of the main advantages of blockchain is the impossibility of modifying data and information shared between the nodes of such a network. This article aims to investigate the factors that make this possible and to clarify, in detail, their functioning. In particular, we will deal with the key concepts of hash and nonce. How many times have we lent money to a friend and then forgotten about it? Let's assume that there is a close-knit group of friends who, in order to overcome this problem, decide to keep track of all the transactions that have taken place between their members by writing them down in a ledger. The ledger’s management is then entrusted to Andrew, a friend that everybody finds honest and reliable.
Let's assume now that another one of them, Katy, has a big debt to pay off and decides to steal part of the money by modifying the entries on the ledger. Andrew notices the wrongdoing and, to prevent the act from being repeated in the future, uses a particular algorithm called "hash function". This is a mathematical algorithm capable of converting (or encrypting) a string consisting of a variable number of characters (the transaction) into another consisting of a fixed amount of alphanumeric characters, usually 256 bits, called "digest".  Its peculiarity consists in the fact that the modification of even one character of the starting string corresponds to a completely different digest, and that it is not possible to go back from the latter to the original string (unidirectionality). By doing so, each transaction corresponds to a certain sequence of characters.
To make the register even more secure, Andrew decides to modify the algorithm, so that subsequent digests will depend not only on the current transaction but also on the digest of the previous one. Now, in order to tamper with the ledger, it will be necessary to alter all transactions prior to the one targeted. Let us assume for a moment that Katy, by committing a considerable amount of time and energy, succeeds in the enterprise. Andrew will then be forced to insert a new layer of security, adding at the end of each entry the so-called "nonce". This is the abbreviation of "number only used once", and indicates a random string of secret numbers, specific for each transaction. Katy can now consider herself defeated because she would have to perform an impractical number of calculations to find the correct nonce for each transaction. To date, only quantum computers can perform such extremely long and complex operations.
If you are a developer, a blockchain enthusiast or simply interested in technology, we invite you to discover AstraKode Blockchain, an innovative low-code platform through which you can create and develop networks blockchain and smart contract quickly and easily.