Skip to content

Commit

Permalink
feat(): v0 shared bridge (#29)
Browse files Browse the repository at this point in the history
Co-authored-by: Bence Haromi <[email protected]>
Co-authored-by: vladbochok <[email protected]>
Co-authored-by: Vlad Bochok <[email protected]>
Co-authored-by: ilitteri <[email protected]>
Co-authored-by: Santiago Pittella <[email protected]>
Co-authored-by: Ivan Litteri <[email protected]>
Co-authored-by: Igor Aleksanov <[email protected]>
Co-authored-by: Dima Zhornyk <[email protected]>
Co-authored-by: Raid Ateir <[email protected]>
Co-authored-by: Raid Ateir <[email protected]>
Co-authored-by: dimazhornyk <[email protected]>
Co-authored-by: Raid5594 <[email protected]>
Co-authored-by: Rahul Saxena <[email protected]>
Co-authored-by: Stanislav Breadless <[email protected]>
  • Loading branch information
15 people authored Mar 7, 2024
1 parent f29f2b7 commit 1328226
Show file tree
Hide file tree
Showing 362 changed files with 17,125 additions and 5,769 deletions.
11 changes: 10 additions & 1 deletion .github/workflows/l1-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ jobs:
- name: Build artifacts
run: yarn l1 build

- name: Build L2 artifacts
run: yarn l2 build

- name: Create cache
uses: actions/cache/save@v3
with:
Expand All @@ -31,6 +34,9 @@ jobs:
l1-contracts/artifacts
l1-contracts/cache
l1-contracts/typechain
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -112,6 +118,9 @@ jobs:
l1-contracts/artifacts
l1-contracts/cache
l1-contracts/typechain
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
- name: Run tests
run: yarn l1 test --no-compile
Expand All @@ -135,4 +144,4 @@ jobs:
run: cargo run

- name: Compare
run: diff tools/data/Verifier.sol l1-contracts/contracts/zksync/Verifier.sol
run: diff tools/data/Verifier.sol l1-contracts/contracts/state-transition/Verifier.sol
18 changes: 9 additions & 9 deletions .github/workflows/l2-contracts-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ jobs:
- name: Install dependencies
run: yarn

- name: Build L2 artifacts
run: yarn l2 build

- name: Build L1 artifacts
run: yarn l1 build

- name: Build L2 artifacts
run: yarn l2 build

- name: Create cache
uses: actions/cache/save@v3
with:
key: artifacts-l2-${{ github.sha }}
path: |
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
l1-contracts/artifacts
l1-contracts/cache
l1-contracts/typechain
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
lint:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -82,12 +82,12 @@ jobs:
fail-on-cache-miss: true
key: artifacts-l2-${{ github.sha }}
path: |
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
l1-contracts/artifacts
l1-contracts/cache
l1-contracts/typechain
l2-contracts/artifacts-zk
l2-contracts/cache-zk
l2-contracts/typechain
- name: Run Era test node
uses: dutterbutter/[email protected]
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ tools/data/Verifier.sol
typechain/
yarn-debug.log*
yarn-error.log*
l1-contracts/yarn-error.log*
l1-contracts/lcov.info
l1-contracts/report/*
l1-contracts/coverage/*
69 changes: 37 additions & 32 deletions docs/Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ See the [documentation](https://era.zksync.io/docs/dev/fundamentals/rollups.html
addresses.
- **Security council** - an address of the Gnosis multisig with the trusted owners that can decrease upgrade timelock.
- **Validator/Operator** - a privileged address that can commit/verify/execute L2 batches.
- **L2 batch (or just batch)** - An aggregation of multiple L2 blocks. Note, that while the API operates on L2 blocks, the prove system operates on batches, which represent a single proved VM execution, which typically contains multiple L2 blocks.
- **L2 batch (or just batch)** - An aggregation of multiple L2 blocks. Note, that while the API operates on L2 blocks,
the prove system operates on batches, which represent a single proved VM execution, which typically contains multiple
L2 blocks.
- **Facet** - implementation contract. The word comes from the EIP-2535.
- **Gas** - a unit that measures the amount of computational effort required to execute specific operations on the
zkSync Era network.
Expand All @@ -44,9 +46,8 @@ even an upgrade system is a separate facet that can be replaced.

One of the differences from the reference implementation is access freezability. Each of the facets has an associated
parameter that indicates if it is possible to freeze access to the facet. Privileged actors can freeze the **diamond**
(not a specific facet!) and all facets with the marker `isFreezable` should be inaccessible until the governor or its owner
unfreezes the diamond. Note that it is a very dangerous thing since the diamond proxy can freeze the upgrade system and then
the diamond will be frozen forever.
(not a specific facet!) and all facets with the marker `isFreezable` should be inaccessible until the admin or the state transition manager unfreezes the diamond. Note that it is a very dangerous thing since the diamond proxy can freeze the upgrade
system and then the diamond will be frozen forever.

#### DiamondInit

Expand All @@ -59,20 +60,20 @@ Implementation detail - function returns a magic value just like it is designed
#### GettersFacet

Separate facet, whose only function is providing `view` and `pure` methods. It also implements
[diamond loupe](https://eips.ethereum.org/EIPS/eip-2535#diamond-loupe) which makes managing facets easier.
This contract must never be frozen.
[diamond loupe](https://eips.ethereum.org/EIPS/eip-2535#diamond-loupe) which makes managing facets easier. This contract
must never be frozen.

#### AdminFacet

Controls changing the privileged addresses such as governor and validators or one of the system parameters (L2
bootloader bytecode hash, verifier address, verifier parameters, etc), and it also manages the freezing/unfreezing and execution of
upgrades in the diamond proxy.
Controls changing the privileged addresses such as admin and validators or one of the system parameters (L2
bootloader bytecode hash, verifier address, verifier parameters, etc), and it also manages the freezing/unfreezing and
execution of upgrades in the diamond proxy.

#### Governance

This contract manages operations (calls with preconditions) for governance tasks. The contract allows for operations to be scheduled,
executed, and canceled with appropriate permissions and delays. It is used for managing and coordinating upgrades and changes in all
zkSync Era governed contracts.
This contract manages operations (calls with preconditions) for governance tasks. The contract allows for operations to
be scheduled, executed, and canceled with appropriate permissions and delays. It is used for managing and coordinating
upgrades and changes in all zkSync Era governed contracts.

Each upgrade consists of two steps:

Expand Down Expand Up @@ -206,23 +207,23 @@ L1 <-> L2 communication.

##### L1ERC20Bridge

The "standard" implementation of the ERC20 token bridge. Works only with regular ERC20 tokens, i.e. not with
fee-on-transfer tokens or other custom logic for handling user balances.
The legacy implementation of the ERC20 token bridge. Works only with regular ERC20 tokens, i.e. not with
fee-on-transfer tokens or other custom logic for handling user balances. Only works for Era.

- `deposit` - lock funds inside the contract and send a request to mint bridged assets on L2.
- `claimFailedDeposit` - unlock funds if the deposit was initiated but then failed on L2.
- `finalizeWithdrawal` - unlock funds for the valid withdrawal request from L2.

##### L2ERC20Bridge

The L2 counterpart of the L1 ERC20 bridge.
##### L1SharedBridge

- `withdraw` - initiate a withdrawal by burning funds on the contract and sending a corresponding message to L1.
- `finalizeDeposit` - finalize the deposit and mint funds on L2.
The "standard" implementation of the ERC20 and WETH token bridge. Works only with regular ERC20 tokens, i.e. not with
fee-on-transfer tokens or other custom logic for handling user balances.

##### L1WethBridge
- `deposit` - lock funds inside the contract and send a request to mint bridged assets on L2.
- `claimFailedDeposit` - unlock funds if the deposit was initiated but then failed on L2.
- `finalizeWithdrawal` - unlock funds for the valid withdrawal request from L2.

The custom bridge exclusively handles transfers of WETH tokens between the two domains. It is designed to streamline and
The bridge also handles WETH token deposits between the two domains. It is designed to streamline and
enhance the user experience for bridging WETH tokens by minimizing the number of transactions required and reducing
liquidity fragmentation thus improving efficiency and user experience.

Expand All @@ -231,11 +232,14 @@ it is wrapped back into WETH and delivered to the L2 recipient.

Thus, the deposit is made in one transaction, and the user receives L2 WETH that can be unwrapped to ETH.

##### L2WethBridge
##### L2SharedBridge

The L2 counterpart of the L1 Shared bridge.

The L2 counterpart of the L1 WETH bridge.
- `withdraw` - initiate a withdrawal by burning funds on the contract and sending a corresponding message to L1.
- `finalizeDeposit` - finalize the deposit and mint funds on L2.

For withdrawals, the contract receives ETH from the L2 WETH bridge contract, wraps it into WETH, and sends the WETH to
For WETH withdrawals, the contract receives ETH from the L2 WETH bridge contract, wraps it into WETH, and sends the WETH to
the L1 recipient.

#### ValidatorTimelock
Expand All @@ -248,15 +252,16 @@ investigation and mitigation before resuming normal operations.
It is a temporary solution to prevent any significant impact of the validator hot key leakage, while the network is in
the Alpha stage.

This contract consists of four main functions `commitBatches`, `proveBatches`, `executeBatches`, and `revertBatches`, that
can be called only by the validator.
This contract consists of four main functions `commitBatches`, `proveBatches`, `executeBatches`, and `revertBatches`,
that can be called only by the validator.

When the validator calls `commitBatches`, the same calldata will be propogated to the zkSync contract (`DiamondProxy` through
`call` where it invokes the `ExecutorFacet` through `delegatecall`), and also a timestamp is assigned to these batches to track
the time these batches are commited by the validator to enforce a delay between committing and execution of batches. Then, the
validator can prove the already commited batches regardless of the mentioned timestamp, and again the same calldata (related
to the `proveBatches` function) will be propogated to the zkSync contract. After, the `delay` is elapsed, the validator
is allowed to call `executeBatches` to propogate the same calldata to zkSync contract.
When the validator calls `commitBatches`, the same calldata will be propogated to the zkSync contract (`DiamondProxy`
through `call` where it invokes the `ExecutorFacet` through `delegatecall`), and also a timestamp is assigned to these
batches to track the time these batches are commited by the validator to enforce a delay between committing and
execution of batches. Then, the validator can prove the already commited batches regardless of the mentioned timestamp,
and again the same calldata (related to the `proveBatches` function) will be propogated to the zkSync contract. After,
the `delay` is elapsed, the validator is allowed to call `executeBatches` to propogate the same calldata to zkSync
contract.

### L2 specifics

Expand Down
23 changes: 19 additions & 4 deletions l1-contracts/.env
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
CHAIN_ETH_NETWORK=localhost
CHAIN_ETH_NETWORK=hardhat
CONTRACTS_PRIORITY_TX_MAX_GAS_LIMIT=72000000
CONTRACTS_DEPLOY_L2_BRIDGE_COUNTERPART_GAS_LIMIT=10000000
ETH_CLIENT_WEB3_URL=http://127.0.0.1:8545
CONTRACTS_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_GOVERNANCE_FACET_ADDR=0x0000000000000000000000000000000000000000
CHAIN_ETH_ZKSYNC_NETWORK_ID=270
CONTRACTS_BRIDGEHUB_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BRIDGEHUB_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_STATE_TRANSITION_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_STATE_TRANSITION_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_VERIFIER_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BLOB_VERSIONED_HASH_RETRIEVER_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_ADMIN_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_DIAMOND_CUT_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_EXECUTOR_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_MAILBOX_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_GETTERS_FACET_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_DIAMOND_INIT_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_DIAMOND_UPGRADE_INIT_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_DIAMOND_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_VERIFIER_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_BASE_TOKEN_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_DEFAULT_UPGRADE_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_GENESIS_UPGRADE_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_TRANSPARENT_PROXY_ADMIN_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_GOVERNANCE_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_L1_ERC20_BRIDGE_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_L1_ERC20_BRIDGE_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_L1_SHARED_BRIDGE_IMPL_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_L1_SHARED_BRIDGE_PROXY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_L1_ALLOW_LIST_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_CREATE2_FACTORY_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_VALIDATOR_TIMELOCK_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_VALIDATOR_TIMELOCK_EXECUTION_DELAY=0
ETH_SENDER_SENDER_OPERATOR_COMMIT_ETH_ADDR=0x0000000000000000000000000000000000000000
CONTRACTS_SHARED_BRIDGE_UPGRADE_STORAGE_SWITCH=0
Loading

0 comments on commit 1328226

Please sign in to comment.