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

Port docs to kl/sync-layer-reorg #997

Merged
merged 67 commits into from
Oct 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f3c8bb6
starting porting docs
StanislavBreadless Oct 25, 2024
9dea7bb
describe rollup da
StanislavBreadless Oct 25, 2024
8b553c9
a rename
StanislavBreadless Oct 25, 2024
c3eaf32
new diagrams
kelemeno Oct 26, 2024
e5054d0
add in new diagram
kelemeno Oct 26, 2024
9e437bf
fix old docs
StanislavBreadless Oct 26, 2024
2e9fd92
rollup da pic
kelemeno Oct 26, 2024
eabacb5
port notion
kelemeno Oct 26, 2024
8b37216
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 26, 2024
9e4d256
Merge pull request #1010 from matter-labs/kl/upgrade-diagrams
kelemeno Oct 26, 2024
a1b1106
restructure docs
kelemeno Oct 26, 2024
98c2ca6
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 26, 2024
9717e0a
renaming
kelemeno Oct 26, 2024
abbfdaf
Merge pull request #1011 from matter-labs/kl/port-notion
kelemeno Oct 26, 2024
d94284f
imgae folders
kelemeno Oct 26, 2024
30a442a
Merge pull request #1013 from matter-labs/kl/img-folders
kelemeno Oct 26, 2024
3a35c9f
deleted some old docs
StanislavBreadless Oct 26, 2024
bd2afab
new structure
kelemeno Oct 26, 2024
f176dee
move more around
kelemeno Oct 26, 2024
c6017b2
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 26, 2024
6ad22d6
Merge pull request #1016 from matter-labs/kl/split_docs
kelemeno Oct 26, 2024
7919510
port upgrade docs
StanislavBreadless Oct 26, 2024
678b5ab
merge with base
StanislavBreadless Oct 26, 2024
f15cef3
comment out file
StanislavBreadless Oct 26, 2024
2c308cb
replace a file
StanislavBreadless Oct 26, 2024
aaf3793
another reorg
kelemeno Oct 26, 2024
1faa17b
remove old issues and move more about chain admin
StanislavBreadless Oct 26, 2024
676ef25
remove unused text
StanislavBreadless Oct 26, 2024
479fbbd
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 26, 2024
47e8223
some more changes
kelemeno Oct 26, 2024
37f5da8
typos
kelemeno Oct 26, 2024
9bd2583
Merge pull request #1017 from matter-labs/kl/really_split_docs
kelemeno Oct 26, 2024
1e592d8
some small image and typo fixes
kelemeno Oct 26, 2024
5a15fbd
more changes etc
kelemeno Oct 26, 2024
633e7f3
Merge pull request #1020 from matter-labs/kl/doc-reorg-2
kelemeno Oct 27, 2024
67a78bb
some reording
StanislavBreadless Oct 27, 2024
8f7425a
update history
StanislavBreadless Oct 27, 2024
18f6e55
some fixme/cleanup
StanislavBreadless Oct 27, 2024
39adc69
links and reading order
kelemeno Oct 27, 2024
cb577e2
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 27, 2024
e16768a
add an issue fix
StanislavBreadless Oct 27, 2024
77703e3
fix some fixmes
StanislavBreadless Oct 27, 2024
b8b3df5
more link fixes
StanislavBreadless Oct 27, 2024
6e93fa9
fix constants and more links
StanislavBreadless Oct 27, 2024
bfb0c07
fix links
StanislavBreadless Oct 27, 2024
6f188d3
more todos fixed
StanislavBreadless Oct 27, 2024
a6af5bc
remove todos from contracts
StanislavBreadless Oct 27, 2024
473bffa
comment on general ugprade process
StanislavBreadless Oct 27, 2024
5ea8a06
sync with base
StanislavBreadless Oct 27, 2024
d1b1e45
fmt
StanislavBreadless Oct 27, 2024
1100a4d
more lints
StanislavBreadless Oct 27, 2024
6d87d5a
more lints
StanislavBreadless Oct 27, 2024
6c1d24e
fmt
StanislavBreadless Oct 27, 2024
dfc7595
raid's comment
kelemeno Oct 27, 2024
620285a
Merge branch 'sb-port-docs-to-reorg' of ssh://github.com/matter-labs/…
kelemeno Oct 27, 2024
bfda290
spellcheck
StanislavBreadless Oct 27, 2024
ec36f3c
fix more lint
StanislavBreadless Oct 27, 2024
9571efa
Merge remote-tracking branch 'origin/sb-port-docs-to-reorg' into sb-p…
StanislavBreadless Oct 27, 2024
d179768
(feat): add dead-links jobs
Oct 27, 2024
33d84ef
(fix): installation
Oct 27, 2024
1505139
(fix): yaml flow
Oct 27, 2024
2c80631
(fix): lint & flow
Oct 27, 2024
30e04a8
(fix): dead links && make CI fail with a dead link
Oct 27, 2024
57ec871
(fix): linting
Oct 27, 2024
6f06427
(fix): remove saving to file
Oct 27, 2024
81f9f9a
(fix): renaming
Oct 27, 2024
209cd09
(fix): Overview.md to lowercase
Oct 27, 2024
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
2 changes: 1 addition & 1 deletion .github/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We truly appreciate efforts to discover and disclose security issues responsibly
## Vulnerabilities

If you'd like to report a security issue in the repositories of matter-labs organization, please proceed to our
[Bug Bounty Program on Immunefi](https://era.zksync.io/docs/reference/troubleshooting/audit-bug-bounty.html#bug-bounty-program).
[Bug Bounty Program on Immunefi](https://immunefi.com/bug-bounty/zksyncera/information/).

## Other Security Issues

Expand Down
22 changes: 22 additions & 0 deletions .github/workflows/dead-links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Check Dead Links in Markdown Files

on: pull_request

jobs:
check-dead-links:
name: Check Dead Links in Markdown Files
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Rust and Lychee
run: |
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
~/.cargo/bin/cargo install lychee

- name: Find and check markdown files
run: |
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
find . -type f -name "*.md" ! -path "*/node_modules/*" ! -path "*/openzeppelin*" ! -path "*/murky/*" -exec lychee --github-token $GITHUB_TOKEN {} +
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There are many ways to contribute to the ZK Stack:
issues.
3. Resolve issues: either by showing an issue isn't a problem and the current state is ok as is or by fixing the problem
and opening a PR.
4. Report security issues, see [our security policy](./github/SECURITY.md).
4. Report security issues, see [our security policy](./.github/SECURITY.md).
5. [Join the team!](https://matterlabs.notion.site/Shape-the-future-of-Ethereum-at-Matter-Labs-dfb3b5a037044bb3a8006af2eb0575e0)

## Fixing issues
Expand All @@ -34,7 +34,7 @@ We aim to make it as easy as possible to contribute to the mission. This is stil
and suggestions here too. Some resources to help:

1. [In-repo docs aimed at developers](docs)
2. [ZKsync Era docs!](https://era.zksync.io/docs/)
2. [ZKsync Era docs!](https://docs.zksync.io/zk-stack)
3. Company links can be found in the [repo's readme](README.md)

## Code of Conduct
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ or re-auditing a single line of code. ZKsync Era also uses an LLVM-based compile
write smart contracts in C++, Rust and other popular languages.

This repository contains both L1 and L2 ZKsync smart contracts. For their description see the
[system overview](docs/Overview.md).
[system overview](docs/overview.md).

## Disclaimer

Expand Down
2 changes: 1 addition & 1 deletion SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ We truly appreciate efforts to discover and disclose security issues responsibly
## Vulnerabilities

If you'd like to report a security issue in the repositories of matter-labs organization, please proceed to our
[Bug Bounty Program on Immunefi](https://era.zksync.io/docs/reference/troubleshooting/audit-bug-bounty.html#bug-bounty-program).
[Bug Bounty Program on Immunefi](https://immunefi.com/bug-bounty/zksyncera/information/).

## Other Security Issues

Expand Down
304 changes: 0 additions & 304 deletions docs/Overview.md

This file was deleted.

52 changes: 52 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# ZK Stack contracts specs

The order of the files here only roughly represents the order of reading. A lot of topics are intertwined, so it is recommended to read everything first to have a complete picture and then refer to specific documents for more details.

- [Glossary](./glossary.md)
- [Overview](./overview.md)
- Contracts of an individual chain
- [ZK Chain basics](./settlement_contracts/zkchain_basics.md)
- Data availability
- [Custom DA support](./settlement_contracts/data_availability/custom_da.md)
- [Rollup DA support](./settlement_contracts/data_availability/rollup_da.md)
- [Standard pubdata format](./settlement_contracts/data_availability/standard_pubdata_format.md)
- [State diff compression v1 spec](./settlement_contracts/data_availability/state_diff_compression_v1_spec.md)
- L1->L2 transaction handling
- [Processing of L1->L2 transactions](./settlement_contracts/priority_queue/processing_of_l1->l2_txs.md)
- [Priority queue](./settlement_contracts/priority_queue/priority-queue.md)
- Chain Management
- [Chain type manager](./chain_management/chain_type_manager.md)
- [Admin role](./chain_management/admin_role.md)
- [Chain genesis](./chain_management/chain_genesis.md)
- [Standard Upgrade process](./chain_management/upgrade_process.md)
- Bridging
- Bridgehub
- [Overview of the bridgehub functionality](./bridging/bridgehub/overview.md)
- [Asset Router](./bridging/asset_router/overview.md)
- L2 System Contracts
- [System contracts bootloader description](./l2_system_contracts/system_contracts_bootloader_description.md)
- [Batches and blocks on ZKsync](./l2_system_contracts/batches_and_blocks_on_zksync.md)
- [Elliptic curve precompiles](./l2_system_contracts/elliptic_curve_precompiles.md)
- [ZKsync fee model](./l2_system_contracts/zksync_fee_model.md)
- Gateway
- [General overview](./gateway/overview.md)
- [Chain migration](./gateway/chain_migration.md)
- [L1->L3 messaging via gateway](./gateway/messaging_via_gateway.md)
- [L3->L1 messaging via gateway](./gateway/nested_l3_l1_messaging.md)
- [Gateway protocol versioning](./gateway/gateway_protocol_upgrades.md)
- [DA handling on Gateway](./gateway/gateway_da.md)
- Upgrade history
- [Gateway upgrade diff](./upgrade_history/gateway_upgrade/gateway_diff_review.md)
- [Gateway upgrade process](./upgrade_history/gateway_upgrade/upgrade_process.md)

![Reading order](./img/reading_order.png)

## For auditors: Invariants/tricky places to look out for

This section is for auditors of the codebase. It includes some of the important invariants that the system relies on and which if broken could have bad consequences.

- Assuming that the accepting CTM is correct & efficient, the L1→GW part of the L1→GW→L3 transaction never fails. It is assumed that the provided max amount for gas is always enough for any transaction that can realistically come from L1.
- GW → L1 migration never fails. If it is possible to get into a state where the migration is not possible to finish, then the chain is basically lost. There are some exceptions where for now it is the expected behavior. (check out the “Migration invariants & protocol upgradability” section)
- The general consistency of chains when migration between different settlement layers is done. Including the feasibility of emergency upgrades, etc. I.e. whether the whole system is thought-through.
- Preimage attacks in the L3→L1 tree, we apply special prefixes to ensure that the tree structure is fixed, i.e. all logs are 88 bytes long (this is for backwards compatibility reasons). For batch leaves and chain id leaves we use special prefixes.
- Data availability guarantees. Whether rollup users can always restore all their storage slots, etc. An example of a potential tricky issue can be found in “Security notes for Gateway-based rollups” [in this document](./gateway/gateway_da.md).
47 changes: 47 additions & 0 deletions docs/bridging/asset_router/asset_router.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# AssetRouters (L1/L2) and NativeTokenVault

[back to readme](../../README.md)

The main job of the asset router is to be the central point of coordination for bridging. All crosschain token bridging is done between asset routers only and once the message reaches asset router, it then routes it to the corresponding asset handler.

In order to make this easier, all L2 chains have the asset router located on the same address on every chain. It is `0x10003` and it is pre-deployed contract. More on how it is deployed can be seen in the [Chain Genesis](../../chain_management/chain_genesis.md) section.

The endgame is to have L1 asset router have the same functionality as the L2 one. This is not the case yet, but some progress has been made: L2AssetRouter can now bridge L2-native assets to L1, from which it could be bridged to other chains in the ecosystem.

The specifics of the L2AssetRouter is the need to interact with the previously deployed L2SharedBridgeLegacy if it was already present. It has less “rights” than the L1AssetRouter: at the moment it is assumed that all asset deployment trackers are from L1, the only way to register an asset handler on L2 is to make an L1→L2 transaction.

> Note, that today registering new asset deployment trackers will be permissioned, but the plan is to make it permissionless in the future

The specifics of the L1AssetRouter come from the need to be backwards compatible with the old L1SharedBridge. Yes, it will not share the same storage, but it will inherit the need to be backwards compatible with the current SDK. Also, L1AssetRouter needs to facilitate L1-only operations, such as recovering from failed deposits.

Also, L1AssetRouter is the only base token bridge contract that can participate in initiation of cross chain transactions via the bridgehub. This will change in the future with the support of interop.

### L1Nullifier

While the endgoal is to unify L1 and L2 asset routers, in reality, it may not be that easy: while L2 asset routers get called by L1→L2 transactions, L1 ones don't and require manual finalization of transactions, which involves proof verification, etc. To move this logic outside of the L1AssetRouter, it was moved into a separate L1Nullifier contract.

_This is the contract the previous L1SharedBridge will be upgraded to, so it should have the backwards compatible storage._

### NativeTokenVault (L1/L2)

NativeTokenVault is an asset handler that is available on all chains and is also predeployed. It is provides the functionality of the most basic bridging: locking funds on one chain and minting the bridged equivalent on the other one. On L2 chains NTV is predeployed at the `0x10004` address.

The L1 and L2 versions of the NTV are almost identical in functionality, the main differences come from the differences of the deployment functionality in L1 and L2 envs, where the former uses standard CREATE2 and the latter uses low level calls to `CONTRACT_DEPLOYER`system contract.

Also, the L1NTV has the following specifics:

- It operates the `chainBalance` mapping, ensuring that the chains do not go beyond their balances.
- It allows recovering from failed L1→L2 transfers.
- It needs to both be able to retrieve funds from the former L1SharedBridge (now this contract has L1Nullifier in its place), but also needs to support the old SDK that gives out allowance to the “l1 shared bridge” value returned from the API, i.e. in our case this is will the L1AssetRouter.

### L2SharedBridgeLegacy

L2AssetRouter has to be pre-deployed onto a specific address. The old L2SharedBridge will be upgraded to L2SharedBridgeLegacy contract. The main purpose of this contract is to ensure compatibility with the incoming deposits and re-route them to the shared bridge.

This contract is never deployed for new chains.

### Summary

![image.png](./img/bridge_contracts.png)

> New bridge contracts
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading