Ethereum Scaling Solution: zk-rollups inside zk-Sync

Published by Nomana Majeed on

This article covers the implementation of zk-rollups using zk-Sync library accessed from github for testing purposes. We have also summarised some issues encountered during the implementation while using the zk-Sync library.

The zk-Sync protocol provides scalable, low-cost payments on Ethereum using zk-rollups technology. Please note that the zk-Sync library is still in the development phase. Therefore, if you plan to use the library, be prepared to the new updates and modifications. An access to our test application [3] is available here.

An important consideration about the upgrades in the zk-Sync library is that if you are interested to utilize this library then you need to make sure that you are using the latest version and your code is also updated according to the version, otherwise an error may occur. We were previously working on version 0.11.1 and the current application supports latest version 0.10.9 that has released recently.

To update the version, you can use:

npm install zk-Sync


yarn add zk-Sync

To run the application, first download the file from GitHub on your system and then perform the following commands in the terminal:

Rollups, an off-chain aggregation of transactions performed within the Ethereum smart contract is a L2 scaling solution that runs on top of the Ethereum blockchain and this feature not only reduces the transaction fee but also allows more than 1000 transactions per second. It guarantees security and publishes highly compressed data on-chain such that any user can reconstruct the state.

If you are interested in learning more about rollups and how they work, we refer you to our article on rollups available here. You will get a deep insight into zk-rollups and optimistic rollups. It is highly recommended that you familiarize yourself with how rollups work before reading this article. We also recommend reading the original article by Vitalik Buterin.

Step by step demonstration of test application

1. Used Rinkeby Test Network

Figure 1

2. Create an Ethereum account via MetaMask

Your respective wallet should have enough funds to play with the application, also do not forget to save your seed phrase.

All right! Now we have our wallet and a certain amount of Test-Ether in it… perfect! We can use the application now.

Let us take a look at what happens in the testing application. We have created two accounts in our application, one serves as a sender and other as a receiver of transactions. We use one wallet to perform the transaction, and for this purpose we also need its seed phrase. No problem! I know my seed phrase (secret key) so I can perform the transaction.

Let us create a transaction as follows:

Figure 2

3. In the diagram above, we insert the seed phrase and the amount we want to send in our transaction (by default it’s 0.1, you can change it). Then, press the initialize button.

4. When we press the initialize button, it will initialize the zk-Sync and create the zk-Sync wallet. Then, the desired balance will be deposited from the Ethereum wallet to the zk-Sync wallet.

Figure 3

For this purpose, derive zk-Sync.Signer from the Ethereum wallet to sign the native zk-Sync transactions. Wait for the confirmation from the zk-Sync operator, unlock the zk-Sync account after verification, check the account balance and retrieve the account state. This is how it looks like in the output:

Figure 4

Okay, now the funds have been transferred to the zk-Sync wallet. As mentioned in the beginning, we need another account (which we have already created) for the transfer, you can add the second wallet in front of “to” inside the code available at GitHub:

Figure 5

5. Now, recall the methodology of zk-rollups.

It takes a bunch of transactions, right? Then we also need a bundle of transactions. For convenience, instead of creating multiple accounts to send the multiple transaction in one bunch, we have split the one main transaction into multiple transactions depending on how many transactions we want to send in a batch.  Zk-Sync currently supports up to 50 transactions and we have set the value to 3, but you can change it according to your choice.

Figure 6
Figure 7

Once we click on the execute and submit batch button, the batch transaction will be executed according to the filled number of transactions and the amount entered. Now, submit the batch on the Ethereum mainchain. At this point, we would like to address a small issue we encountered while working. Originally, we tried to execute the two stages “Execute” and “Submit” separately but unfortunately, we encounter an error. The reason was “when we submit the batch transaction to the mainchain via “batchbuilder”, a signature is also required, but executing the two steps separately did not send the signature.

Figure 8

6. After submitting the batch to the Ethereum mainchain, we obtained the following outputs consisting of from, to, amount, public key, signature, etc (we choose 3 transactions in a bundle):

Figure 9

Here the public key of all the transactions in a bundle is the same as we used one wallet for all the transactions but the signature is different for each transaction (user has to sign his transaction before submitting it to the validator). Note that if the validity proof fails, you just have to redo everything (unlike optimistic rollups, where you lose your funds if fraud-proof fails!). Thought, zk-SNARKs proof generation time in Zk-Sync is round about 10 minutes after the submission but it does not influence the usability of the system since the transactions are confirmed instantly and receiver can see the transaction immediately (as we can see it after the submission in our test application).

7. Finally, we can see the hash of the transactions after batch submission. It serves as a verification of the corresponding transaction; the hash value can be used to verify that your transaction is included in the bundle of transactions. Anyone can reconstruct the state using this (also known as call data).

Figure 10

Currently, it is not possible to analyse the number of bytes involved in the batch transaction since a batch can have multiple recipients. This is one of the good features of zk-Sync as it involves multiple provers. Funds withdrawal time is approximately 10 minutes, and the total time (minutes) for the entire process depicted above is:

Figure 11






Categories: Blog