Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add dev reference for build section #41

Merged
merged 9 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions content/00.build/65.developer-reference/00.index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
title: Getting Started
description: Kickstart your development journey with ZKsync Era, covering everything from rollups to system contracts and fee structures.
---

Welcome to the ZKsync Era Developer reference documentation! This guide is your starting point for
understanding the core components and advanced features of ZKsync. It provides an essential
overview to help you effectively build on ZKsync Era.

::card-group
::card
---
title: Introduction to Rollups
icon: i-heroicons-scale-16-solid
to: /build/developer-reference/intro-rollups
---
Explore the fundamentals of rollups for enhanced scalability and lower gas costs.
::
::card
---
title: Ethereum Differences
icon: i-heroicons-adjustments-horizontal-16-solid
to: /build/developer-reference/ethereum-differences/evm-instructions
---
Learn about the key distinctions between Ethereum Layer 1 and ZKsync Era.
::
::card
---
title: Native Account Abstraction
icon: i-heroicons-user-circle-16-solid
to: /build/developer-reference/account-abstraction/introduction
---
Utilize account abstraction to streamline user experiences and contract interactions.
::
::card
---
title: ZKsync Era Contracts
icon: i-heroicons-document-duplicate-16-solid
to: /build/developer-reference/era-contracts/l1-contracts
---
Discover the ZKsync Era L1 and system contracts.
::
::card
---
title: ZKsync Era Fee Model
icon: i-heroicons-currency-dollar-16-solid
to: /build/developer-reference/fee-model
---
Understand the fee structure in ZKsync to optimize transaction costs.
::
::card
---
title: Bridging Assets
icon: i-heroicons-arrow-path-16-solid
to: /build/developer-reference/bridging-assets
---
Facilitate asset transfers between Ethereum Layer 1 and ZKsync Layer 2 efficiently
::
::
63 changes: 63 additions & 0 deletions content/00.build/65.developer-reference/10.intro-rollups.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
title: Introduction to Rollups
description: Gain a comprehensive understanding of rollups.
---

## Introduction

To better understand rollups we need to dive briefly into Ethereum and Layer 2 solutions.

The Ethereum network is frequently congested, which results in slow transactions and increased gas prices.
While this has remained so for a long time, an improved solution is needed: one that will not put limits on the throughput, but instead,
achieve a high transaction rate without having to trade off security. That is where Layer 2 solutions shine.

Layer 2 solutions are designed as an extension to Ethereum, and offer various solutions poised to be the critical scalability component to
the inherent network congestion on Ethereum. Covering all Layer 2 solutions is beyond the scope of this doc.
We will go through a brief explainer on rollups in this section.

## What are rollups?

Rollups are a recent development intended to increase the scalability of Ethereum by performing calculations off-chain, rolling many
transactions up into a single batch, and sending it to the main Ethereum chain in a single action.
Instead of submitting each transaction separately, rollup operators submit a summary of the required changes to represent all transactions
in a batch.

To be able to work on a rollup, funds need to be locked on a smart contract on the Layer 1 blockchain.
This allows transactions to be processed without the overhead of all the data associated with performing a transaction on the main chain.
**Rollups significantly decrease associated transaction processing times and gas fees.**

## Optimistic vs ZK rollups

Currently, there are 2 types of rollups used to scale Ethereum.

1. ZK Rollups (Zero-Knowledge Rollups) - eg: ZKsync, Loopring, Starknet, Scroll etc
2. Optimistic Rollups - eg: Optimism, Arbitrum etc

The main difference between ZK and Optimistic rollups is in the way this batch of transactions becomes <em>final</em>.

### What are ZK rollups?

In ZK rollups ('ZK' standing for zero-knowledge) the batch of transactions is verified for correctness on the Ethereum network. After the
verification passes, the batch of transactions is considered final like any other Ethereum transaction. This is achieved through the power
of cryptographic <em>validity proofs</em> (commonly called zero-knowledge proofs). With any batch of off-chain transactions, the ZK rollup
operator generates a proof of validity for this batch. Once the proof is generated, it is submitted to Ethereum to make the roll-up batch final.
In ZKsync, this is done via a **SNARK**, succinct non-interactive argument of knowledge.

### What are Optimistic rollups?

Optimistic rollups, on the other hand, have no mechanism to prove the validity of the off-chain transactions. Instead, they are considered
“optimistic” because they assume off-chain transactions are valid unless proven otherwise. Hence, they rely on <em>fraud proof systems</em>, a
challenge to the submitted state to Ethereum. If such a challenge is submitted, the Optimistic rollup operator needs to show that the
state and transactions in questions are actually valid. This is a cumbersome process, and requires watchers to make sure that the Optimistic
rollup operator is honest at all times.

## L1 and L2: what's the difference?

The term **Layer 1** (or **L1**) is used to refer to the underlying primary chain, such as the Ethereum network or Bitcoin. Layer 1
blockchains determine protocol rules and transaction finality, and perform the base-level functions of applications built upon them.

The term **Layer 2** (or **L2**) is used to describe an overlaying application or network that operates on top of the Layer 1 chain. These
are most often built to provide further scalability solutions by taking on a portion of transaction-based tasks to lighten the impact on the
layer 1 chain, quickening transaction times and lowering gas fees.

**ZKsync Era is an L2, where L1 is the main Ethereum blockchain.**
80 changes: 80 additions & 0 deletions content/00.build/65.developer-reference/20.zksync-overview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
title: ZKsync Era Overview
description:
---

## ZKsync Era overview

The general rollup workflow is as follows:

- Users can receive, deposit, and transfer assets to each other.
- Users can withdraw assets under their control to an L1 address.

Rollup operation requires the assistance of an operator, who rolls transactions together, computes a zero-knowledge proof of the correct
state transition, and affects the state transition by interacting with the rollup
contract. To understand the design, we need to look into how ZKsync rollup transactions work.

ZKsync operations are divided into rollup transactions (initiated inside rollup by a
rollup account) and priority operations (initiated on the mainchain by an Ethereum account).

The ZKsync rollup operation lifecycles are as follows:

- A user creates a transaction or a priority operation.
- After processing this request, the operator creates a rollup operation and adds it to the block.
- Once the block is complete, the operator submits it to the ZKsync smart contract
as a block commitment. Part of the logic of some rollup operations is checked by the smart contract.
- The proof for the block is submitted to the ZKsync smart contract as block verification. If the verification succeeds, the new state is considered final.

Furthermore, on ZKsync, each L2 block will progress through the following four stages until it is final.

- `Pending`: The transaction was received by the operator, but it has not been processed yet.
- `Processed`: The transaction is processed by the operator and is confirmed to be included in the next block.
- `Committed`: This indicates that the transaction data of this block has been
posted on Ethereum. It does not prove that it has been executed in a valid way, but it ensures the
availability of the block data.
- `Finalized`: This indicates that the SNARK validity proof for the transaction has
been submitted and verified by the smart contract. After this step, the transaction is considered to be final.

The typical time for a transaction to go from `Processed` to `Finalized` is a couple of hours at the current stage.

Please note that for developer convenience, we usually treat the `Processed` and
`Committed` states as a single stage called `Committed` since they have no difference from the UX/DevEx standpoints.

### The State of ZKsync

The current version of ZKsync Era solves the needs of most applications on Ethereum,
and with more features planned for release soon, ZKsync Era will provide developers
with a design space to experiment with applications not possible on Ethereum today.
With this release, we are supporting the following features:

- Native support of ECDSA signatures: Unlike the first version of ZKsync and other
ZK rollups, no special operation is required to register the user’s private key.
Any account can be managed in L2 with the same private key that is used for L1.
- Solidity 0.8.x support: Deploy your existing codebase with little to no changes required.
- With small exceptions, our Web3 API is fully compatible with Ethereum. This allows seamless integration with existing indexers, explorers, etc.
- Support for Ethereum cryptographic primitives: ZKsync natively supports `keccak256`, `sha256`, and `ecrecover` via precompiles.
- Hardhat plugin: Enables easy testing and development of smart contracts on ZKsync.
- L1 → L2 smart contract messaging: Allows developers to pass data from Ethereum to
smart contracts on ZKsync, providing the required information to run various smart contracts.
- Native account abstraction: ZKsync Era implements [account abstraction natively]
(../developer-reference/account-abstraction.md), which brings multiple UX improvements for all accounts.

## Highlights of ZKsync Era

- Mainnet-like security with zero reliance on 3rd parties.
- Permissionless EVM-compatible smart contracts.
- Standard Web3 API.
- Preserving key EVM features, such as smart contract composability.
- Introducing new features, such as native account abstraction.

## ZKsync in comparison

ZKsync [stands out remarkably](https://blog.matter-labs.io/evaluating-ethereum-l2-scaling-solutions-a-comparison-framework-b6b2f410f955)
in security and usability among existing L2 scaling solutions.
Thanks to the combination of cutting-edge cryptography and on-chain data
availability, ZK rollups (the core network of ZKsync) are the only L2 scaling
solution that doesn't require any operational activity to keep the funds safe.

For example, users can go offline and still be able to withdraw their assets safely
when they come back, even if the ZK rollup validators are no longer around.
For a comprehensive distinction between ZKsync Era and Ethereum, read this [guide](./30.ethereum-differences/10.evm-instructions.md).
Loading
Loading