ZK Stack components

What is ZK Stack?

ZK Stack is a modular framework for building sovereign ZK-powered Ethereum rollups (called ZK Chains); it is a modular, open-source framework that is both free and designed to build custom ZK Chains (ZK-powered L2s and L3s), based on the code of zkSync Era, the first ZK Chain.

At its core, the ZK Stack offers two key features: sovereignty and seamless connectivity. The creator (you) possesses full rights to the code and enjoys unrestricted autonomy to customize and shape many aspects of your chain. ZK Chains operate independently but are interconnected by a network of hyperbridges, enabling trustless, fast (within minutes), and cheap (cost of a single transaction) interoperability.

What are the ZK Stack modules today?

zkEVM

Our execution machine: EVM compatible, tailored for ZK, and including enhancements like Native Account Abstraction.

  • Virtual machine

    Repo:

    era-zk_evm

    The rust-based virtual machine is responsible for transaction validation and execution (including logic for rollbacks, history, etc).

Smart Contracts and System Contracts

Repo:

era-contracts

All the smart contracts needed for the rollup, both on L1 and L2.

System contracts are important contracts with admin powers (could be compared to kernel modules), which define the behaviour of the system. The bytecodes of these contracts are set upon genesis and can be changed only by conducting upgrades. You can read more about system contracts here.

While the zkEVM does not know about the bytecodes of system contracts per se, it does rely on some of these for behaving correctly (for instance, it uses AccountCodeStorage system contract's storage to retrieve bytecodes of deployed zkEVM contracts, etc).

Server/Node (and its sub-components)

Repo:

zksync-era

All the backend services needed to run a ZK Chain, including:

  • RPC services

    The main interface for users to interact with the server.

    • HttpApi - Public Web3 API running on HTTP.

    • WsApi - Public Web3 API (including PubSub) running on WebSocket server

  • ETH Operator

    This module is responsible for interacting with the base layer, both as an observer, as well as executing transactions.

    • EthWatcher - Monitor the base layer for specific events, such as Deposits or System Upgrades.

    • EthTxAggregator - Aggregates L1 batches and prepare a base layer tx, such as
      commit_blocks , prove_blocks , execute_blocks.

    • EthTxManager - Signs and sends base layer txs, prepared by EthTxAggregator also responsible for resending txs if they are stuck for any reason (example, low gas price).

  • Sequencer

    Component that takes a list of incoming transactions, and packs them into blocks and batches - so that each one fits within the multiple constraints that our proving system has. It takes these batches and executes them on the zkEVM.

    • Tree and TreeBackup - maintains a local RocksDB with the complete storage tree, computing the hash of the latest

    • StateKeeper - the component that executes the transactions and saves sealed blocks to the DB

  • Contract verification API

    The service that receives smart contract verification requests, validates them and provides the code/ABIs for verified contracts.

Prover

The set of components that allows zkEVM instructions (and the state changes they cause) to be proven with zero knowledge cryptography.

  • Circuits

    Repo:

    era-zkevm_circuits

    Based on the virtual machine zkEVM, but with added functionality that re-executes transactions generating special traces that are used to recreate a given computation as a set of arithmetic circuits, which are then used for zero-knowledge proofs. Currently we have 13 different circuits types, that are responsible for proving different elements of the execution.

  • Witness generator

    Repo:

    zksync-era (Witness Generator)

    Based on the virtual machine zkEVM, but with added functionality that re-executes transactions generating special traces that are used to recreate a given computation as a set of arithmetic circuits, which are then used for zero-knowledge proofs.

  • Boojum

    Repo:

    era-boojum

    Our STARK approach to proving zkEVM instructions. This module contains:

    • GPU implementation - Can be run on consumer-grade GPUs with as little as only 16GB of RAM.

    • CPU implementation - Mostly for testing purposes, but an alternative to enable anyone to generate proofs in case GPUs are not available.

  • Fri compressor

    Repo:

    zksync-era (FRI compressor)

    Final stage of proof generation, wrapping the STARK proof generated by Boojum into a SNARK for cheaper verification on Ethereum.

  • Verifier

    Repo:

    zksync-era (Verifier)

    Solidity smart contract that is responsible for verifying that the state changes that were committed are valid given some proof.

Fee withdrawer

Repo:

era-fee-withdrawer

A component that automates the withdrawal of the ZK Chain collected fees to an address on the base layer. This helps ensure the ETH operator on the base layer side has a constant influx of the gas token to keep working properly.

Portal - Wallet + Bridge

Repo:

dapp-portal

A dApp that allows you (and your users) to easily interact with your ZK Chain, including bridging assets from and to the base layer, sending them within your ZK Chain, checking historical transactions, and managing contacts. You can also enhance its capabilities by running the Block Explorer Indexer/API.

Block explorer

Repo:

block-explorer

A module to allow exposing everything that is happening on your ZK Chain to your users/developers. It comes with 4 components:

  • Block Explorer Worker: an indexer service for ZK Chain data. The purpose of the service is to read the data from the blockchain in real-time, transform it and fill in its database to be used by the API.

  • Block Explorer API: a service that provides an HTTP API for retrieving structured ZK Chain data. It must be connected to the block explorer worker database.

  • Block Explorer App: The UI that allows user/devs to explore transactions, blocks, batches, contracts, tokens, and much more, on your ZK Chain.

© 2023 Matter Labs | All rights reserved.