ZKsync 백서

ZKsync

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 12쪽 중 8쪽

Server : Server implementation for ZKsync OS. ZKsync OS Scripts : Scripts for ZKsync OS protocol upgrades. Smart Contracts era-contracts : Submodule containing the smart contracts for ZKsync. Prover & Protocol Airbender : RISC-V prover system for ZKsync OS. zksync-protocol : Houses the ZKsync Era protocol implementation, including VM and circuits. Development tools Airbender Platform : Rust toolkit for writing RISC-V zk-provable programs. anvil-zksync : An in-memory node designed for integration testing and debugging. Explorer block-explorer : The official block explorer for navigating the ZKsync network. Feel free to explore these repositories, and don't hesitate to contribute! Participate in ZKsync Developer discussions Join the discourse on GitHub discussions or other community forums to provide answers, ask questions, or share insights. Contributing to Documentation Learn how to propose, write, and validate documentation changes for ZKsync Docs. ZK Stack Overview This section provides an overview of the ZK Stack as a key tool to launch and operate ZKsync chains ## /zk-stack/components ZK Stack ZK Stack Components Overview Overview of components in the ZK Stack This section provides a high-level overview of the components that make up a ZKsync Chain. The main components of each ZKsync chain are: ZKsync OS : A new “operating system” for ZKsync Chains. ZKsync OS Server : The new high-performance sequencer for ZKsync OS. ZKsync Airbender : A horizontally scalable implementation of the ZK proof generator. Block Explorer : An API and user interface for exploring transactions and verifying contracts. Fee Withdrawer : A tool to automate the transfer of collected fees from a ZKsync chain to a base layer address. ZKsync Chains Delve into the concept of ZKsync chains and rollup clusters. ZKsync OS Introduction to ZKsync OS. ## /zk-stack/components/zksync-os ZK Stack ZKsync OS Introduction to ZKsync OS. ZKsync OS is a system-level implementation for ZKsync's state transition function. Under ZKsync's new architecture, execution is decoupled from proving. ZKsync OS acts as the operation layer in this new architecture. It takes block data and an initial state as input and computes the new state after the application of the block. ZKsync OS is implemented as a Rust program that will be compiled to two targets. This first one, x86, is used for running in the sequencer. The second, RISC-V, is fed as an input to the ZKsync Airbender prover to produce the validity proof of the state transition. Components of ZKsync OS ZKsync OS is designed to support multiple VMs. The main components of ZKsync OS are: Bootloader : The entry point program. It initializes the system and then runs transactions using two components: the system and the execution environment interpreters. Execution Environments : Regular interpreters that take bytecode, calldata, resources (similar to gas) and some other call context values as its input. Interpreters are instantiated with some local state to execute a frame. When an interpreter sees a call to another contract, return/revert from current frame, or contract creation it triggers special functionality to process it, as a potentially different interpreter should be run. System : Common for all environments and the bootloader. Provides an abstract interface for low-level handling of IO (storage, events, L1 messages, oracles) and memory management. The system communicates with the external oracle (non-determinism source), which is needed to read block data , and also for some IO operations, e.g. to perform the initial read for a storage slot. This modular design enables us to isolate a minimal interface required to implement an Execution Environment. In addition, the system abstraction makes the storage model customizable and allows for different instances of the entire system. You can read more about how ZKsync OS works in the protocol documentation . The code for ZKsync OS can be found in the ZKsync OS GitHub repository . ZK Stack Components Overview Overview of components in the ZK Stack ZKsync OS Server Overview of the ZKsync OS sequencer. ## /zk-stack/components/server ZK Stack ZKsync OS Server Overview of the ZKsync OS sequencer. The ZKsync OS Sever is a complex system composed of several services and modules that work together to monitor Ethereum Layer 1 (L1), maintain Layer 2 (L2) state, and manage the order of incoming transactions. The new sequencer can process over 10,000 transactions per second through a single-binary architecture that dramatically reduces operational overhead. The system scales horizontally through Elastic Nodes, delivering enterprise performance without enterprise complexity or costs. With the ZKsync OS Sequencer, transaction costs drop to $0.0001 per transaction , a 99% reduction from Layer 1 solutions. This enables microtransactions, high-frequency applications, and business models that weren't economically viable before. Components The server implementation consists of three main subsystems: Sequencer : Executes transactions and sends the results downstream to other components. RPC API : Implementation of the Web3 JSON-RPC API. Batcher : Turns a stream of blocks into a stream of batches (1 batch = 1 proof = 1 L1 commit), exposes prover APIs, and submits batches and proofs to L1. For a more detailed overview, please refer to the ZKsync OS Server GitHub repository . Design Principles The three main design principles that were used for the server are: Minimal, async persistence to meet throughput and latency requirements. Synchronous persistence is avoided at the critical path. Additionally, the sequencer aims at storing only the data that is strictly needed, minimizing the potential for state inconsistency. Easy to replay arbitrary blocks . The sequencer components are idempotent. The batcher component skips all blocks until the first uncommitted batch. Thus, downstream components only receive batches that they need need to act upon. Strong separation between states . The actual state only includes data needed to execute the VM: key-value storage and a preimages map. The receipts repositories includes data only needed in the API. The data related to proofs and L1, which is not needed by the sequencer or JSON RPC, is only introduced downstream from batcher. ZKsync OS Introduction to ZKsync OS. Airbender Overview Introduction to ZKsync Airbender ## /zk-stack/components/zksync-airbender ZK Stack Airbender Overview Introduction to ZKsync Airbender Airbender is ZKsync's next-generation RISC-V proof system, purpose-built to enable efficient ZK proofs of RISC-V bytecode execution. Built on the foundation of highly optimized STARK/FRI implementations, Airbender is designed to support ZKsync's long-term scaling strategy by being fast, cheap, and flexible to a wide range of use cases (without compromising security). Airbender runs on consumer GPUs and standard hardware, eliminating the dependency on large datacenters. How It Fits with ZKsync OS ZKsync OS and Airbender have been developed in parallel to support modular and scalable architecture for ZKsync Chains. ZKsync OS acts as a modular execution layer, allowing chains to run various virtual machines like EVM, EraVM, or WASM. Airbender serves as the proving system that validates the execution of these VMs, encoded in RISC-V bytecode. Key Features RISC-V 32I+M instruction set AIR constraints Optimized DEEP STARK/FRI proofs Mersenne31 prime field Blake2s + Blake3 hash function The name “Airbender” is a reference to AIR constraints (Arithmetic Intermediate Representation). Proving Pipeline The proving process follows a structured six-stage pipeline designed for optimal performance and resource utilization: Stage 1 - Witness Generation : Computes Low-Degree Extensions (LDEs) of witness data and generates trace commitments. This stage establishes the foundational data structures for the proof. Stage 2 - Lookup and Memory Argument : Configures lookup tables and memory arguments, establishing the infrastructure for efficient verification of memory operations and table lookups. Stage 3 - STARK Quotient Polynomial : Computes the primary STARK quotient polynomial, which encodes the constraint satisfaction proof for the main circuit. Stage 4 - DEEP Polynomial : Implements FRI batching optimizations to reduce the overall proof size and verification complexity. Stage 5 - FRI IOPP Generation : Produces the final Interactive Oracle Proof of Proximity (FRI proof) that enables efficient verification. Stage 6 - SNARK Wrapper: Wrap the final FRI proof into a final FFLONK proof which gets posted and verified onchain. The code for ZKsync Airbender can be found in the ZKsync Airbender GitHub repository . ZKsync OS Server Overview of the ZKsync OS sequencer. Airbender Deep Dive Dive into the ZKsync Airbender Architecture ## /zk-stack/components/zksync-airbender/deepdive ZK Stack Airbender Deep Dive Dive into the ZKsync Airbender Architecture Architecture Overview ZKSync Airbender's architecture is built around several key components that work together to provide efficient and secure ZK proving of RISC-V execution. RISC-V 32I+M Architecture : Airbender implements a complete RISC-V 32-bit integer instruction set with multiplication extensions, providing a familiar and well-specified execution environment for developers. Modular Circuit Design : The system employs configurable "machine variants" that can selectively enable or disable features based on use case requirements. This flexibility allows for optimized circuits tailored to specific execution contexts, from general-purpose kernel execution to highly specialized recursive proving scenarios. Advanced Cryptographic Primitives : The proof system integrates optimized implementations of Blake2s, Blake3, and 256-bit big integer operations as precompiled circuits, enabling efficient cryptographic operations within the proven execution environment. Scalable Proof Generation : Airbender can handle up to 2³⁰ CPU cycles in a single proving run, with intelligent batching that processes approximately 2²² cycles per chunk. Hybrid CPU/GPU Implementation : The system provides both CPU and GPU implementations of the prover, with preliminary witness generation performed on CPU before transitioning to GPU-accelerated circuit-specific proving for optimal performance. Circuit Design Philosophy Mersenne31 Field Arithmetic : All arithmetic operations are performed over Mersenne31 field elements (2³¹ - 1), chosen for its efficiency in both software and hardware implementations. When additional security is required, the system switches to extension fields, particularly for lookup finalization operations. Register and Memory Model : The system implements an approach where all 32-bit RISC-V registers are stored in RAM rather than as dedicated circuit elements. This design choice relegates register access to the RAM argument system while maintaining only minimal shared state (such as the Program Counter) across execution cycles. Degree-2 Constraint Optimization : All AIR (Algebraic Intermediate Representation) constraints are limited to degree-2 polynomials, which streamlines STARK/FRI optimizations and simplifies circuit performance analysis by focusing on witness trace column counts. Execution Model Fetch-Decode-Execute Loop : Airbender follows the traditional CPU execution model with a standardized fetch-decode-execute loop that operates in machine privilege mode. This loop is identically enforced at each cycle and row of the witness trace, providing predictable and verifiable execution semantics. ROM-Based Instruction Storage : Program bytecode is stored in a read-only memory (ROM) region that is accessed through preprocessed lookup tables. This ROM virtually inhabits a reserved portion of the RAM address space, simplifying the memory model while maintaining clear separation between code and data. Custom Instruction Extensions : The system supports custom instructions through the CSRRW opcode, which is converted to delegation argument calls for accessing precompiled circuits and non-deterministic storage. This extension mechanism allows for efficient implementation of complex operations while maintaining the core RISC-V compatibility. Batch Processing : The system processes execution in batches of approximately 4 million cycles (2²²), with individual chunks proven separately and connected through global RAM and delegation arguments. Configuration Variants Airbender supports multiple machine configurations to optimize for different use cases: Full Kernel Mode : Complete RISC-V 32I+M support for running ZKsync OS kernel code, with standard compiler assumptions about memory alignment and instruction usage. Application Mode : Removes signed multiplication and division operations to reduce circuit complexity for applications that don't require these operations. Recursion Mode : Highly optimized configuration for recursive proof verification, supporting custom field arithmetic operations while eliminating unnecessary instruction support. Limitations Airbender makes several standard assumptions about the code that needs to be proven: Static Bytecode Model : The current implementation assumes bytecode is placed in ROM and does not support runtime-loaded or dynamically generated code. This design choice simplifies the proving model but limits certain programming patterns. Initialization Constraints : The system does not support non-trivially initialized static variables, requiring manual initialization patterns for programs that need persistent state. Trap Handling : Rather than implementing complex trap handling within the CPU state, the system converts traps to unprovable constraints, causing the prover to fail when bugs are encountered. This approach ensures correctness but requires careful program design. Memory Alignment : The system disallows inefficient unaligned memory accesses to maintain proving efficiency, relying on compiler guarantees for proper memory layout. For more low-level details about ZKsync Airbender, you can refer to the ZKsync Airbender GitHub repository . Airbender Overview Introduction to ZKsync Airbender Block explorer Explore the functionality of Block Explorer, a comprehensive tool for monitoring activities on your ZKsync chain. ## /zk-stack/components/block-explorer ZK Stack Block explorer Explore the functionality of Block Explorer, a comprehensive tool for monitoring activities on your ZKsync chain. The Block Explorer is a tool designed to provide comprehensive insights into all activities occurring on a ZKsync chain. This tool is especially useful for users and developers who need to monitor or interact with the blockchain. Block Explorer consists of three main components: Block Explorer Worker: This indexer service manages ZKsync chain data. Its main role is to collect data from the blockchain in real time, process this data, and populate a database that supports the API. Block Explorer API: This component offers an HTTP API to access structured data from the ZKsync chain. It retrieves data from the database maintained by the Block Explorer Worker. Block Explorer App: This is the user interface that enables users and developers to navigate and examine transactions, blocks, batches, contracts, tokens, and other elements within the ZKsync chain. Airbender Deep Dive Dive into the ZKsync Airbender Architecture Fee withdrawer Learn about the Fee Withdrawer, a tool that automates the transfer of collected fees from a ZKsync chain to a base layer address. ## /zk-stack/components/fee-withdrawer ZK Stack Fee withdrawer Learn about the Fee Withdrawer, a tool that automates the transfer of collected fees from a ZKsync chain to a base layer address. The Fee Withdrawer is a specialized tool that automates the process of transferring collected fees from a ZKsync chain to a specified address on the base layer. This functionality is crucial for maintaining the continuous operation of the ETH operator on the base layer, ensuring there is always a sufficient supply of the gas token available for transactions. Block explorer Explore the functionality of Block Explorer, a comprehensive tool for monitoring activities on your ZKsync chain. Launch a ZKsync chain Launch a ZKsync chain locally using the ZKsync OS Server. ## /zk-stack/running/ownership-model ZK Stack Ownership Model An overview of the most important contracts and roles in the ZK Stack ecosystem. This section covers L1 and L2 contracts, their relationships, and the roles that manage them. Contracts overview Contract Description Owned by Shared within ecosystem Source code CTM (ChainTypeManager) Trust zone that ensures unified state transition process across chains ProtocolUpgradeHandler Yes, but might have multiple instances with different ownership Source Bridgehub Primary ecosystem entry point for L1↔L2 messaging, CTM management, chain registration ProtocolUpgradeHandler Yes Source L1 SharedBridge (legacy) Bridges assets between L1 and all ZKsync chains ProtocolUpgradeHandler Yes Source DiamondProxy Main contract of a specific chain, responsible for state transition CTM (Admin can control some processes) No Facets ValidatorTimelock Trustlessly sets a batch execution delay ProtocolUpgradeHandler Yes, enforced within CTM Source Verifier Verifies ZK proofs - Yes, within CTM Source L1/L2 NativeTokenVault Holds L1 native ETH and ERC20 tokens bridged into ZKsync chains ProtocolUpgradeHandler Yes NTV L1/L2 AssetRouter Bridges assets between L1 and ZKsync chains, supporting both ETH and ERC20 tokens ProtocolUpgradeHandler Yes Asset Router L1/L2 DA Validators Ensure that pubdata is committed properly - L1: optionally shared, L2: no Default L1 3rd Party L1 L2 Roles overview Name Purpose Owned by Shared Source code DecentralizedGovernance (set of contracts) Owns ProtocolUpgradeHandler, controls all ecosystem contracts, accepts/vetoes proposals. - Yes Repository ChainAdmin - Change fee parameters - Set validator for a chain - Set transaction filterer - Set base token multiplier - Set pubdata pricing mode - Set the timestamp when the protocol upgrade will be applied Chain operator’s Multisig No Source ProtocolUpgradeHandler Ownership of CTM, Bridgehub, L1 and L2 bridges, AssetRouters, NTVs DecentralizedGovernance Yes Source BlobOperator EOA that sends CommitBatches transactions Chain operator No EOA Operator EOA that sends ProveBatches and ExecuteBatches transactions Chain operator No EOA FeeCollector An address that receives the funds from fees paid by user transactions on L2 Chain operator No Not enforced TokenMultiplierSetter An address nominated by the ChainAdmin that can set the ETH↔BaseToken price ratio Chain operator No EOA FAQ What powers does the governance have? What powers does the chain admin have? Why do these limitations exist? What are the benefits of being on the shared CTM? Are there other limitations to being on the shared CTM? What are the other options and what are their tradeoffs? If I start on the shared CTM, can I permissionlessly opt out? How do upgrades work in the shared CTMs and in external CTMs? Can the chain be started on a different CTM and join the shared CTM? Launch a ZKsync chain Launch a ZKsync chain locally using the ZKsync OS Server. Rollup as a Service ## /zk-stack/running/raas ZK Stack Rollup as a Service Deploying and running using a Rollup as a Service provider Launching a ZKsync-based chain involves a number of infrastructure and operational considerations — from sequencer management and data availability to monitoring, scaling, and security. To streamline this process, you can work with Rollup-as-a-Service (RaaS) providers. RaaS partners offer the infrastructure and tooling needed to deploy, operate, and customize your ZK Stack chain. These providers handle much of the heavy lifting around setup and maintenance, allowing your team to focus on your protocol, product, and community. We collaborate w
프로젝트로 돌아가기