# Understanding the concept of “rollup” for blockchain scalability

##### María Teresa Nieto Galán8 March, 2022

In previous articles we have already discussed how important scalability is in Blockchain technology and how this ecosystem is starting to create solutions to achieve faster and more computationally and energy efficient public networks.

(If you have come this far without reading the previous article, I suggest you take five minutes and read it.:) )

Of all the solutions analysed, one of the most promising is what are known as “rollups”. This new paradigm is expected to be the cornerstone of scalability in Ethereum and is classified as a layer 2 solution.

However, before we get down to the nitty-gritty of what this idea is all about, let’s take a look at the mathematical trickery behind the blockchain technology, also known as cryptography.

The most basic concept we will start with is the so-called hash or summary function. This mathematical algorithm allows us to transform any data (words, phrases, documents, etc.) into a new series of characters with a fixed length. For example, if we hash “Hello world!” we would obtain the following: “239bdfaad79afdf9220349ddccd67b1e801aa275d757ac90c3977ac2f0a1f9e4”.

One of the characteristics of hashes is that if we modify any character of the content we transform, the hash changes completely. For example, if we remove an exclamation mark from the previous sentence and hash “Hello world” the result would be: “48666287270d81108ea41339aa48316f92c52995690b6da6b4f86242b408f779”. Therefore, one of the many use cases of this type of cryptographic functions is to be able to guarantee the integrity of documents.

Finally, it should be noted that the hash, unlike the encryption, once it has been generated, it is not possible to go backwards. In other words, if we have a hash, we cannot decrypt what was there prior to the execution of the algorithm.

## Let’s complicate the theory and add a bit of botany: Merkle Trees

On the other hand, another concept to review is what is known as Merkle trees. This is a data structure in the form of a binary tree, binary because each node has only two children.

If we look at the figure below, the tree is built from the bottom up, so that at level 0 we would have the raw data, at level 1 the hashed data, at level two we would hash the two child nodes and so on until we get to the last level or the root node of the tree.

This type of data structure provides a secure and efficient method of verifying information, since, if we were to change a piece of data in one of the leaves at level 0, when performing the hashes towards the higher levels, the result would change drastically at the root node.

The biggest use case for Merkle trees today is the secure storage of transactions in a blockchain network.

Now, you may ask, why so much of a cryptographic concept if it is already applied in this technology? The answer is simple, rollups are also based on the concept of Merkle trees to be able to group transactions.

## We already have all the components ready… what do the rollups consist of?

A rollup is a set of protocols that combines Merkle trees, plus cryptography which we will not go into in depth in this article, and a smart contract deployed on a blockchain network.

This smart contract maintains the root of the rollup state, or, in other words, it stores the contents of the root node of the Merkle tree that contains the information that has been compressed. This compressed information is a set of transactions, so, instead of performing all transactions on the network, these can be done outside and only a summary of all transactions would be uploaded to perform only one transaction instead.

This mechanism is not restricted, but anyone can publish a batch of transactions, as long as they take into account the root of the previous state in the calculation (very similar to the way blocks are chained in blockchain).

At the time of recording the result of a new batch of transactions, the smart contract checks that the state root of the previous batch of transactions matches the root of its current state, because it has not yet been updated. If it matches, it would be updated by changing the state to the new root as shown in the following image:

What would happen, however, if someone batches transactions that have not actually occurred? In the end we are relying on the state of the previous root being the same, but at no point do we check that the transactions being batched are valid.

There are two types of rollups for this necessary validation:

• Optimistic Rollup: Transactions that are batched are assumed to be valid by default. The smart contract keeps a record of the entire history of the roots and hash of each batch. If someone discovers that the batch had an erroneous state root, a proof of fraud is published on the chain. The contract then verifies this proof by reconstructing the tree and in case of fraud, the batch and subsequent batches are reverted. If there is no evidence of fraud, this method is very efficient. However, if there is a lot of evidence, all the information has to be processed to analyse its validity and, therefore, efficiency is lost.
• ZK-Rollup: a proof of validity is stored in the contract following the Zero Knowledge Proof protocol using ZKSnarks proofs, based on it. This would prove that the result of the root of the new state is correct without having to process all transactions in the batch. To this end, the contract would perform a validity check of the root before storing it.

It is also worth noting that rollups are sometimes closely related to the use of sidechains or alternative chains. In this way, transactions would be carried out on an alternative chain and from time-to-time rollups of sets of transactions that have taken place would be generated with the aim of being dumped on another network.

In other words, if we wanted to make transactions on Ethereum, but this network did not give us the necessary performance, they could be made on an alternative network and every so often rollups could be dumped onto the main network.

## Rollup solutions in the market

There are currently companies that are already starting to use this mechanism to benefit from this improved scalability in public blockchain networks.

Among them is Polygon with Hermez, which has created an open-source zk-rollups solution, with the aim of being able to transfer tokens securely and at a lower cost.

There is also zkSync, a scaling and privacy engine for Ethereum. This implementation allows low-cost transfers of ETH and ERC20 tokens on the Ethereum network or even atomic swaps.

And finally, Consensys’ zk-rollups solution, which will be validated through a consensus test together with one of the world’ payment giants, Mastercard.