Polygon's zkEVMs: A Comprehensive Approach to Web3 Scalability

Polygon's zkEVMs: A Comprehensive Approach to Web3 Scalability

As the Web3 ecosystem expands, addressing scalability remains a significant challenge. Layer 2 solutions and Zero Knowledge Proofs (ZKPs) have emerged as potential remedies, with Polygon standing out as a popular Layer 2 provider. Polygon's zkEVMs offer increased throughput, reduced gas costs, and faster finality times compared to traditional EVMs. In this blog post, we explore Polygon zkEVMs, including their nature, functionality, and use cases, and provide a step-by-step tutorial on setting up smart contracts on Polygon's zkEVM.

I. Introduction

The phrase "Web3" is used to refer to the upcoming internet technology. It is based on blockchain technology and decentralized protocols, making it more open, safe, and transparent than the conventional web. Scalability is one of the greatest problems that Web3 is experiencing. Traditional blockchains, like those used by Bitcoin and Ethereum, have a limited amount of processing capacity, which limits the number of transactions they can execute each second. This has led to outrageous charges, lengthy confirmation times, and a poor customer experience.

Different Layer 2 solutions have been developed to address this issue. By processing transactions off-chain and periodically settling them on-chain, these technologies aid in scaling the blockchain. Zero Knowledge Proofs (ZKPs), a cryptographic system that enables two parties to verify something to each other without disclosing any extra information, are one of the most promising Layer 2 solutions.

II. What are Layer 2 solutions?

Layer 2 solutions are technologies built atop a blockchain to enhance its scalability and performance. These solutions enable faster, more cost-effective transactions and greater blockchain capacity. Layer 2 technologies fall into two categories: state channels and sidechains.

State channels are off-chain networks that facilitate transactions between users outside the blockchain, resulting in quicker and cheaper transactions. Sidechains connect to the main blockchain, allowing transactions to occur on one network before settling on the main chain.

Layer 2 solutions offer numerous benefits, including improved transaction speeds, reduced fees, and increased capacity, while preserving the security and decentralization of the blockchain.

III. What are Zero Knowledge Proofs (ZKPs)?

Zero-knowledge proofs are cryptographic techniques that allow a prover to demonstrate to a verifier their knowledge of a particular secret or solution without revealing the secret or solution itself. The verifier can be confident in the validity of the proof without gaining any additional information about the secret or solution.

Various types of ZKPs exist, including zk-SNARKs, zk-STARKs, and Bulletproofs, with zk-SNARKs being the most widely used in blockchain applications like Zcash and Ethereum.

ZKPs have numerous applications, such as privacy, authentication, and identity verification. They allow users to prove their identity without disclosing extra information, enhancing security and privacy.

IV. What is Polygon?

Polygon is a Layer 2 scaling solution for Ethereum that seeks to provide quicker and more affordable transactions. As a sidechain connected to the Ethereum main chain, Polygon enables off-chain transactions before settling them on the main chain.

Polygon's Layer 2 solution allows for rapid and cost-effective transactions while increasing the Ethereum blockchain's capacity. Moreover, Polygon offers interoperability with other blockchains, making it a versatile solution for various Web3 applications.

V. What is Polygon Hermez?

Polygon Hermez is a ZK-rollup on Polygon that incorporates a zero-knowledge virtual machine designed for EVM compatibility. It achieves this by executing "micro opcodes" derived from EVM bytecode in the uVM, a virtual machine that employs SNARK and STARK proofs to verify the correctness of the code.

The strategic combination of both proof types provides unique benefits. SNARK proofs are smaller and less expensive to verify on Ethereum, while STARK proofs are quicker to generate.

The Polygon Hermez zkEVM generates proof of validity for state transitions using a STARK proving circuit. A STARK proof is submitted to Ethereum for validation, verifying the correctness of STARK proofs, essentially creating a "proof of a proof."

VI. zkEVM vs EVM

The advantages of Polygon zkEVM over traditional EVM include:

  • Increased throughput: By bundling transactions, zkEVM achieves approximately 2000 TPS, significantly improving transaction processing speed.

  • Reduced gas fees: Batching transactions lowers gas costs due to simultaneous processing.

  • Enhanced security: By emulating all EVM opcodes, zkEVM inherits the security of Layer 1.

  • Cost efficiency: zk-rollups minimize call data sent back to Layer 1, reducing overall transaction expenses.

  • Quicker finality: zkEVM transactions achieve faster finality times compared to Layer 1 blockchains.

VII. Deploying Smart Contracts on Polygon's zkEVM

After creating and testing a smart contract on the Polygon network, deploy it on the zkEVM for better scalability and lower gas fees. In this section, we outline the steps to deploy smart contracts on Polygon's zkEVM and provide examples of popular applications using it.

A. Developer and User Process Overview

Before deploying smart contracts on Polygon's zkEVM, complete several steps, including installing the Polygon SDK, crafting and testing your smart contracts, compiling the code, and deploying them on the testnet or mainnet using the Polygon SDK. Follow these steps:

  1. Install the Polygon SDK and configure a development environment.

     npm install -g polygon-sdk
     polygon init my-project
     cd my-project
    
  2. Develop and test your smart contract in Solidity.

     // SPDX-License-Identifier: MIT
     pragma solidity ^0.8.12;
    
     contract MyContract {
         uint256 public myNumber;
    
         function setNumber(uint256 _number) public {
             myNumber = _number;
         }
     }
    
  3. Compile the smart contract, generating the ABI and bytecode.

     npx hardhat compile
    
  4. Use the Polygon SDK to deploy your smart contract on Polygon's testnet or mainnet.

     polygon deploy --network mumbai --filepath artifacts/contracts/MyContract.sol/MyContract.json
    

B. Deploying Smart Contracts on Polygon's zkEVM

To deploy your smart contract on Polygon's zkEVM, complete these additional steps:

  1. Install the ZKSwap SDK.

     npm install zkswap-sdk
    
  2. Use the ZKSwap SDK to generate proof for your smart contract.

     const { provider } = require('@zkswap/providers');
     const { Contract } = require('@zkswap/contracts');
     const { generateProof } = require('@zkswap/identity');
    
     const myContract = new Contract({ abi: myContractABI, bytecode: myContractBytecode, provider, });
    
     const inputs = [123];
    
     const proof = await generateProof(myContract, 'setNumber', inputs);
    
  3. Submit the proof to Polygon's zkEVM with the Polygon SDK.

     const { submitProof } = require('@polygon/sdk');
    
     await submitProof(proof);
    

C. Popular Applications Using Polygon's zkEVM

Popular applications using Polygon's zkEVM include Immutable, an Ethereum-centric gaming ecosystem, and QuickSwap, a decentralized exchange built on Polygon with zkEVM support.

VIII. Use cases of Polygon zkEVM

  1. DeFi applications: zkEVM enhances DeFi platforms like lending, borrowing, and yield farming by reducing transaction costs and increasing throughput, enabling more efficient and accessible financial services in the decentralized ecosystem.

  2. Gaming platforms: zkEVM improves the gaming experience by enabling faster transactions and reducing costs for in-game purchases and asset transfers, fostering a more seamless gaming environment and supporting the growth of blockchain-based gaming.

  3. Decentralized Exchanges (DEXs): zkEVM boosts DEX performance by increasing transaction capacity and reducing trade settlement times, allowing users to trade assets more efficiently and at lower costs, making DEXs more competitive with centralized exchanges.

  4. NFT marketplaces: zkEVM enhances NFT marketplaces by reducing gas fees associated with minting, trading, and transferring NFTs, making NFTs more accessible and affordable for users, and promoting the growth of the NFT ecosystem.

IX. Conclusion

Polygon's zkEVMs tackle Web3 scalability issues by integrating Layer 2 solutions and Zero-Knowledge Proofs. These zkEVMs offer enhanced throughput, reduced gas costs, and faster finality times compared to traditional EVMs, making them an optimal choice for Web3 applications. By deploying smart contracts on Polygon's zkEVM, developers can leverage these benefits to foster a more efficient and accessible decentralized ecosystem.

Did you find this article valuable?

Support Anmol Sirola by becoming a sponsor. Any amount is appreciated!