All About ZkEVM - Complete Guide

Introduction

zkEVM refers to the zero–knowledge Virtual Machine that executes smart contract transactions in such a way that it is compatible with existing Ethereum infrastructure and zero –knowledge-proof computations. Thus, it allows transactions to be a part of layer 2 solutions, and zero-knowledge rollups while making it cost-efficient. The layer 2 blockchain ecosystem is already EVM compatible and runs programs that are created by Ethereum environments. Thus, being EVM compatible is essential for smart contract logic to ensure their widespread adoption.

How Does An zkEVM Work?

A zkEVM follows the Ethereum environment as the zero-knowledge rollup and brings great experience for developers while tooling it to the highly scalable and secure layer 2. Moreover, it also makes it possible for developers to provide a new environment to the existing dApps and smart contracts. Thus, zkEVM takes the initial state, process transactions, and output everything into consideration along with zero-knowledge proof. Let's understand how a zkEVM environment works.

Execution Environment of zkEVM

The EVM is responsible for executing smart contracts and computing the state of the Ethereum network after the block is added to the chain. It parses Solidity code and translated them into a computer-legible bytecode that was originally human–written. Thus, zkEVM governs through specific rules and defines the smart contract that developers can write. Since the zkEVM is an advanced EVM it allows developers to easily port Ethereum dApps and tokens to the zkEVM environment.

Proving Circuit in zkEVM

The zero-knowledge-proofs which are the way for parties to prove the knowledge they possess cryptographically without revealing the underlying information. The proving circuit of zkEVM produces zero-knowledge proofs to verify and validate the transactions and ensure the user transactions are computed correctly.

Verifier Contract in zkEVM

Every transaction on the Ethereum network is verified by nodes. On the other hand, Zero-knowledge rollups which are the layer-2 scaling solutions “roll up” the large batch of transactions and verify them ZKP published on layer -1 blockchain. As a result, it increases the throughput, lowers costs, and maintains security. The zero-knowledge rollups in Layer-2 submit validity proofs to the smart contracts deployed on underlying layer 1.

Different Types of zkEVM

According to Vitalik Buterin, the Ethereum founder the following categories have been defined for zkEVM.

Type 1: Fully Ethereum- equivalent

It is a type of zkEVM that does not change any part of the existing Ethereum system, therefore making it easier to generate zero–knowledge proofs. Moreover, it makes them fully compatible with all the Ethereum–based native applications while facilitating the reuse of tools block explorers and execution clients.  However, certain parts of the Ethereum protocol may require huge computation for generating zero-knowledge proofs.

Type 2: Fully EVM-equivalent

Although this type of zkEVM is fully compatible with existing Ethereum applications but also makes minor modifications for making proof generation and development easier. Even though proving time is faster in this case, the current implementation is still slower. Scroll and Polygon Hermez are planning to create Type-2 zkEVM.

Type 2.5: EVM – equivalent except for gas costs

The increasing gas costs for specific operations may improve the proving time for some of the most difficult proof generation scenarios. However, some applications get broken and may require developers to make certain modifications.

Type 3: Almost EVM-equivalent

This type of zkEVM sacrifices some features of EVM and facilitates easy application development and proof generation. It also facilitates changes to precompiles, VM memory stack, and working of the smart contract. Even though most Ethereum applications can work in this environment some may require to be rewritten. Polygon Hermez and Scroll are seen as popular Type 3 zkEVM projects.

Type 4: High-Level-Language Equivalent

A type-4 system considers codes written in a high-level language such as Solidity or Vyper and further compiles them to the ZKPs–friendly language. As a result, enable faster proof generation and cost reduction even if the contracts do not have the same addresses. The zkSync 2.0, and Nethermind’s Wrap are the popular Type-4 zkEVM projects.

Advantages of zkEVM

There are several advantages that zkEVM has over layer 1 and other layers 2 rollups which are as follows – 

  • Provides secure scalability by optimizing speed and transaction throughput 
  • zkEVM lowers the gas cost as it only needs to publish final state changes on the chain.
  • This advanced EVM provides faster finality for assets to move around the DeFi ecosystem.
  • EVM compatibility of zkEVM allows leveraging Ethereum's existing developer ecosystem with extensive tools, documents, code libraries, and tested infrastructure. 

Challenges for zkEVM

The zero-knowledge proofs and the Ethereum Virtual Machine were created independently and have recently been combined to form zkEVMs.  However, several obstacles need to be removed for it works effectively.

Architecture based on stacks

The last data added to the stack is the first to be removed in the stack-based design which is used by the EVM. This approach is straightforward to understand and apply. However, to facilitate high-performance processing and zero-knowledge calculations zkEVM requires a register-based approach.

Storage and Proving Costs

The EVM organizes data using a Merkle Patricia Trie and a Keccak hashing algorithm to help trace that data by converting it to hashes. This has a high proof cost because it requires a significant amount of processing to validate the hashes. Moreover, the process of generating zero-knowledge proofs is resource-intensive and requires specialized hardware.

Complexity of Opcode

When executing a smart contract, the EVM, unlike traditional virtual computers, employs special opcodes such as CALL, DELEGATECALL, REVERT, and INVALID to tell the EVM what to do. This increases intricacy, making it more difficult to comprehend what the EVM is doing.

Final Words

zkEVM leverages  Ethereum expertise and current infrastructure to create highly scalable and low-cost layer-2 rollups while preserving fundamental security through on-chain proof generation. Finally, zkEVM surpasses prior constraints by merging zero-knowledge proofs and an Ethereum Virtual Machine to provide the scalable and safe infrastructure required for broad Web3 usage.