Skip to content

Commit 1947388

Browse files
itsacoyoterazzorsecMexicanAce
authored
docs: update developer reference docs (#126)
# Description Update developer reference docs from https://github.com/code-423n4/2024-03-zksync/tree/main/docs --------- Co-authored-by: Razzor <[email protected]> Co-authored-by: Nicolas Villanueva <[email protected]>
1 parent a7ce7d6 commit 1947388

File tree

63 files changed

+4663
-659
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+4663
-659
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,6 @@ yarn.lock
9999
.nitro
100100
.cache
101101
dist
102-
.firebase
102+
.firebase
103+
104+
.vscode/

.lintstagedrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
- eslint
44
'*.md':
55
- markdownlint-cli2
6-
- cspell lint --file
6+
- cspell lint --no-must-find-files --files
77
'*.{json,yml}':
88
- prettier --list-different

content/00.build/65.developer-reference/00.index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ overview to help you effectively build on ZKsync Era.
1212
---
1313
title: Introduction to Rollups
1414
icon: i-heroicons-scale-16-solid
15-
to: /build/developer-reference/intro-rollups
15+
to: /build/developer-reference/protocol
1616
---
1717
Explore the fundamentals of rollups for enhanced scalability and lower gas costs.
1818
::

content/00.build/65.developer-reference/10.intro-rollups.md

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: ZKsync Era Protocol
3+
description: Learn about ZKsync Era and the differences from Ethereum
4+
---
5+
6+
ZKsync Era is a Layer 2 scaling solution designed to enhance Ethereum's scalability without compromises.
7+
This document provides an overview of ZKsync Era's rollup mechanism, explaining the main idea and how it contributes to a more scalable,
8+
secure, and user-friendly blockchain ecosystem.
9+
10+
## What is a Rollup?
11+
12+
A rollup is a blockchain scalability solution that processes and stores transaction data off-chain
13+
while ensuring the data's integrity and availability on the main chain.
14+
By doing so, rollups significantly increase transaction throughput without compromising security.
15+
There are primarily two types of rollups: Optimistic Rollups and Zero-Knowledge (zk) Rollups.
16+
ZKsync Era utilizes the latter, leveraging cryptographic proofs for security and efficiency.
17+
18+
## How and why it works?
19+
20+
Ethereum's decentralized network has limited transaction throughput because its capacity doesn't scale with the number of validators.
21+
In essence, each validator performs the same job of validating each processed transaction, creating a bottleneck.
22+
In contrast, in Web2 scalability improves with the addition of more servers,
23+
as the network's capacity to handle requests increases linearly with each new server.
24+
25+
The concept of a rollup addresses the blockchain scalability issue by moving computation off-chain
26+
and only sending the result of these computations back to Ethereum.
27+
ZK rollups, in particular, submit a validity proof alongside the execution result,
28+
making the validation of a zk proof significantly cheaper than re-executing each transaction.
29+
30+
### The Data Availability (DA) Problem
31+
32+
A crucial aspect of ensuring the integrity and security of rollups is addressing the Data Availability (DA) problem.
33+
If the state of the rollup is unknown to observers of Ethereum,
34+
then in scenarios where the validators (centralized or decentralized) stop processing,
35+
it becomes impossible to make state transitions without relying on a trusted validator.
36+
However, if the data is always available to observers, it's feasible to restore the state and continue processing the network
37+
even if the trusted validator ceases its operation.
38+
This link provides further details on the Data Availability problem: [Ethereum Data Availability](https://ethereum.org/en/developers/docs/data-availability/).
39+
40+
### ZK proof
41+
42+
Zero-Knowledge Proofs (ZKPs) offer a method to execute verifiable programs, wherein it's cheap to verify a zk proof on-chain.
43+
In the context of ZKsync, ZKPs allow for the confirmation of the correctness of transaction execution without re-executing them.
44+
45+
ZK circuits are out of the contest's scope.
46+
However, there is an ongoing [live bug bounty program on Immunefi](https://immunefi.com/bounty/zksyncera/)
47+
open to anyone interested in identifying vulnerabilities within this domain.
48+
49+
## ZKsync Era components
50+
51+
ZKsync Era protocol consists of the following critical components:
52+
53+
- **Node Implementation**: This component is responsible for receiving transactions from users and processing them.
54+
It maintains the off-chain state and handles the aggregation of transactions into batches as well as sends sealed batches onchain.
55+
- **ZK Circuits**: These circuits are intricate mathematical constructs that represent verifiable computation logic.
56+
They are responsible for determining what can be verified as a valid proof.
57+
Specifically for ZKsync, these circuits define the computation rules for EraVM execution, thats also defines how transactions are executed.
58+
- **Prover**: The prover constructs the cryptographic proofs that attest to the correctness of the transactions processed off-chain.
59+
These proofs can be verified later on Ethereum, ensuring that only valid transactions are accepted.
60+
- **Smart Contracts**: These contracts are the on-chain component of the zkRollup.
61+
They are responsible for verifying the proofs submitted by the prover and updating the Ethereum blockchain's state accordingly.
62+
Additionally, they facilitate interactions between Ethereum and ZKsync, such as deposits, withdrawals, and cross-layer messaging.
63+
64+
![ZKsync components.png](/images/developer-reference/zksync-components.png)
65+
66+
While this contest primarily focuses on the smart contracts side of ZKsync Era,
67+
understanding the interaction between different components can be beneficial.
68+
For additional context or insights, consider exploring these resources:
69+
70+
- **Node Implementation**: https://github.com/matter-labs/zksync-era
71+
- **ZK Circuits**: https://github.com/matter-labs/era-zkevm_circuits
72+
73+
## The ZK Chain
74+
75+
The ZK Chain is the continuation of Ethereum's rollup centric roadmap.
76+
Ethereum provides security via DA and verification of proofs, but the question of execution is left to the rollups.
77+
In order to have the best UX, it is necessary to solve interoperability and the free flow of assets between chains.
78+
We do this via the Shared Bridge Contract on L1 which stores Ether and ERC20 tokens for all ZK Chains (implementing custom bridges is still possible).
79+
This upgrade will allow hyperbridging between ZK Chains in the next major upgrade.
80+
The chains will be able to trust each other due to the fact that they are managed by the same STM contract, using the same VM and proof system.
81+
In the future more upgrades will follow, as this is still a topic under heavy research.
82+
83+
- For more details watch this video on [How the ZK Stack will power the Internet of Value](https://www.youtube.com/watch?v=BxpKa-S2m34).
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Migrating ZKsync Era into the ZK Chain
3+
description: Guide on how to migrate a single chain ZKsync Era into the ZK Chain
4+
---
5+
6+
This document describes the process of migrating the currently deployed single chain ZKsync Era into the ZK Chain,
7+
including the process of moving funds from Diamond Proxy and L1 ERC20 Bridge into the brand new Shared bridge while ensuring security guarantees.
8+
9+
**Note: The migration to the new system of ZK Chains has already happened.**
10+
11+
## Migration process
12+
13+
We will migrate the old system of Era's `Diamond Proxy`, `L1ERC20Bridge`
14+
to a system that is capable of hosting multiple interoperable ZK Chains with the
15+
`L1SharedBridge`, `Bridgehub`, `StateTransitionManager` and other contracts.
16+
17+
This upgrade process has the following steps:
18+
19+
### I. Upgrade the system
20+
21+
1. Deploy the new contracts
22+
23+
We first deploy the new contracts.
24+
These include the `Bridgehub`, `StateTransitionManager`, `L1SharedBridge`, the new facets and the `ValidatorTimelock`.
25+
At this point, if we wanted to we could register new ZK Chains.
26+
27+
2. Integrate Era into new contracts, and upgrade L2 system contracts
28+
29+
We upgrade Era (we do this via a standard diamond cut upgrade, set the L2 system contract upgrade tx hash,
30+
and a call to the new DiamondInit function to initialize the `DiamondProxy` with the new protocol version and variables).
31+
We integrate Era into the the contracts via `registerAlreadyDeployedStateTransition` on STM and `createNewChain` on Bridgehub.
32+
We transfer all Ether to the `L1SharedBridge`. We do this via the the `transferFundsFromLegacy` function on the `L1SharedBridge`.
33+
34+
At this point deposits to the `L1SharedBridge` and to the legacy functions on `Mailbox` facet of the `DiamondProxy` should work.
35+
The legacy `L1ERC20Bridge` will also work, as it will communicate with the backwards compatible `Mailbox`.
36+
37+
### II. Upgrade L1ERC20Bridge contract
38+
39+
1. Upgrade L2 bridge
40+
41+
The new `L2ERC20Bridge` will upgraded to become the `L2SharedBridge`,
42+
and it will be backwards compatible with all messages from the old `L1ERC20Bridge`,
43+
so we upgrade that first as L1->L2 messages are much faster, and in the meantime we can upgrade the `L1ERC20Bridge`.
44+
The new `L2SharedBridge` can receive deposits from both the old `L1ERC20Bridge` and the new `L1SharedBridge`.
45+
46+
2. Upgrade L1ERC20Bridge
47+
48+
We upgrade the `L1ERC20Bridge`, and move all ERC20 tokens to the `L1SharedBridge`.
49+
50+
Note migrating Era and its `L1ERC20Bridge` are possible to do for other separately deployed ZK Chains as well, in case we need to do it multiple times.

content/00.build/65.developer-reference/20.zksync-overview.md

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)