Polygon’s Zero Knowledge Odyssey: Part 2
Polygon zkEVM: The next Big Adventure in Blockchain
Note: The following article is a part of a 5-part series. Highly recommend reading the previous article before proceeding.
Rollout: (As of January 2023)
- Closed Testnet 1: October 2022 (Deprecated)
- Public Testnet 2: December 2022
- Public Mainnet: Q1 2023 (Expected)
Polygon’s zkEVM (Zero-Knowledge Ethereum Virtual Machine), previously known as Hermez 2.0, is a unique implementation of the Ethereum Virtual Machine that allows for private and secure smart contract execution on the Polygon network. It is the upgraded version of Hermez 1.0.
Note: A detailed comparison between Hermez 2.0 and 1.0 can be found here.
The zkEVM utilizes ZKPs (Zero Knowledge Proofs) to enable this functionality, making it particularly useful for use cases that require increased privacy and security. Polygon’s internal teams, including Hermez, Zero and Miden are together working on this solution.
One of the key benefits of using the zkEVM is the ability to create “zero-knowledge smart contracts”. These are smart contracts that can be executed privately and securely, without revealing the full details of the contract and the data it processes to anyone, but the parties involved. This makes the zkEVM particularly useful for use cases such as confidential financial transactions, identity verification, and other applications where privacy is a key concern.
The use of ZKPs in the zkEVM is achieved through a rollup technology called “recursive SNARKs” that allows proving that a computation was correctly executed on the state of a smart contract. This maintains the security and integrity of the network, as the proof guarantees that the smart contract is correctly executed. Plonky2, another proving technology which improves upon recursive SNARKs, is being currently implemented in the zkEVM as of this date.
The zkEVM is built on top of the existing EVM, which means that it is fully compatible with existing Ethereum smart contracts, i.e., it is EVM equivalent. This makes it relatively easy for developers to migrate their existing smart contracts to the zkEVM and take advantage of its increased privacy and security features.
In addition, the zkEVM is built on the Polygon network which is an Ethereum scaling solution using zk-Rollups. This gives an added layer of scalability to the zkEVM enabling high throughput use cases such as decentralized exchanges, where many transactions need to be processed quickly and efficiently.
Architecture
Polygon zkEVM handles state transitions caused by Ethereum Layer 2 transaction executions (transactions that users send to the network). Following that, it creates validity proofs that attest to the accuracy of these off-chain state change calculations by utilizing zero-knowledge features.
The major components of zkEVM are:
- Proof of Efficiency (PoE) Consensus Mechanism
- zkNode
- Sequencers & Aggregators
- Synchronizer
- RPC - zkProver
- LX-to-LY Bridge
The skeletal architecture of Polygon zkEVM is shown below:
zkEVM supports creation of general-purpose smart contracts by compiling L2 transactions, executing state changes, and generating validity proofs to verify the accuracy of off-chain state change calculations.
This process involves two essential steps: batching L2 transactions and validating them.
Sequencers, a limited number of nodes, collect transactions, compute them, and compile them into a batch. These nodes usually run specialized hardware and are not highly transparent or auditable, but cryptographic measures make it mathematically impossible to create an invalid zk-proof.
Aggregators, on the other hand, confirm the validity of the transactions and provide the validity proof. This group acts as a check and balance system for the sequencers and ensures censorship resistance.
Proof-of-Efficiency (PoE)
As opposed to Proof of Donation (PoD) implemented in Hermez 1.0, Polygon zkEVM has adopted the Proof-of-Efficiency (PoE) consensus algorithm to tackle the centralization problems in current rollups. The algorithm aims to meet the following criteria:
- Permissionless Sequencing for Batch Transaction Creation
- Efficiency as the Crucial Factor for Network Performance
- Prevention of Control Evasion by Any Single Party through Sufficient Decentralization
- Robust Security Measures against Harmful Attacks
Note: Comparison between PoE and PoD can be found here.
Features:
- Privacy: It allows for the creation of smart contracts that can be executed privately and securely, without revealing the full details of the contract and the data it processes to anyone, but the parties involved. This makes it particularly useful for use cases such as confidential financial transactions, identity verification, and other applications where privacy is a key concern.
- Security: Zero-knowledge proofs (ZKPs) and recursive SNARKs used to validate the correctness of transactions, ensuring the security of the network. Provides same level of security of the Ethereum mainnet due to EVM equivalence.
- Scalability: By allowing for off-chain computation of transactions, the zkEVM increases the number of transactions significantly, that can be processed per second and reduces transaction fees, enabling more efficient and cheaper execution of smart contracts.
- Compatibility: It is built on top of the existing EVM, which means that it is fully compatible with existing Ethereum smart contracts on opcode level. This makes it relatively easy for developers to migrate their existing smart contracts to the zkEVM and take advantage of its increased privacy and security features.
Performance Benchmarks:
Use Cases of Polygon zkEVM
- Decentralized Finance (DeFi): Because of Polygon zkEVM’s high security and censorship resistance nature of it, it is a good fit for Defi applications. Unlike Optimistic Roll-ups where users have to wait for upto 7 days for deposits and withdrawals, zk-Rollups doesn’t have to wait for long periods for deposits and withdrawals i.e Polygon zkEVM offers better capital efficiency for dApps/users.
- Supply Chain: It can be used to record and verify the provenance of goods and products, without revealing sensitive information about the supply chain.
- Gaming: Low gas cost, high transactions and greater level of security coupled with Ethereum composability attracts blue chip NFTs, Gamefi and Enterprise applications.
- Identity Verification: it can be used for secure and private identity verification, allowing for the storage, and sharing of sensitive personal information without risking data breaches.
Setup
Building dApps on zkEVM is similar to Ethereum. Simply switch to the zkEVM RPC to start building on a network with much higher throughput and lower fees. Polygon zkEVM provides a complete EVM-like experience for Developers and Users alike. So, you do not need special tools or new wallets for building or interacting with zkEVM.
Connecting to zkEVM
In order to add the Polygon zkEVM network to your wallet, you will need to enter the following details:
- Network Name: Polygon zkEVM Testnet
- RPC URL: https://rpc.public.zkevm-test.net
- Chain ID: 1422
- Currency Symbol: ETH
- Block Explorer URL: https://explorer.public.zkevm-test.net
Also, for moving assets across chains, you will need to use the zkEVM Bridge. The bridge interface is available on https://public.zkevm-test.net/. The Bridge API (for developers) is available at https://bridge-api.public.zkevm-test.net/
Setup Local zkNode
The tutorial for current version of the environment requires go, docker and docker-compose to be previously installed on your machine. If you don’t have these installed, check out the links provided below:
- https://go.dev/doc/install
- https://www.docker.com/get-started
- https://docs.docker.com/compose/install/
Before starting the zkEVM node setup, we need to clone the official zkNode repository from Polygon zkEVM GitHub.
git clone https://github.com/0xPolygonHermez/zkevm-node.git
The zkEVM-node docker image must be built at least once and whenever the code is changed. If you haven’t already built the zkEVM-node image, you must run:
make build-docker
Certain commands on the zkEVM-node can interact with smart contracts, run specific components, create encryption files, and print debug information. To interact with the binary program, we provide docker-compose
files and a Makefile
to spin up/down the various services and components, ensuring smooth local deployment and a better command line interface for developers.
The test/
directory contains scripts and files for developing and debugging. Change the working directory to test/
on your local machine.
cd test/
Now, run the zkNode environment:
make run
To stop the zkNode:
make stop
To restart the whole zkNode environment:
make restart
Sample Data
It’s important to populate your local zkEVM node with some data before you start testing out the network. The make run command will execute the containers required to run the environment, but it will not execute anything else. Your local L2 network will be essentially empty.
The following scripts are available if you require sample data that has already been deployed to the network.
# To add some examples of transactions and smart contracts:
make deploy-sc
# To deploy a full Uniswap environment:
make deploy-uniswap
# To grant the MATIC smart contract a set amount of tokens:
make run-approve-matic
Conclusion
This article provided a glimpse into Polygon zkEVM’s remarkable potential. Polygon has raced ahead of its competitors in trying to achieve a completely zero knowledge based smart contract which would be EVM equivalent on the Consensus level.
But there is much more to discover about this promising technology of Zero Knowledge. In the next article, we dive deeper into sea of Polygon Miden and uncover the potential it holds for the future of decentralized systems.
Part 3: Polygon’s Zero Knowledge Odyssey: Part 3 | by Sanil Shah | Feb, 2023 | Medium
References:
Polygon zkEVM: Polygon | Ethereum’s Internet of Blockchains — Polygon
Evolution of zkEVM: The Evolution of Polygon’s zkEVM Pursuit | CryptoEQ