Skip to content

Commit 860127e

Browse files
exit root and docs mgmt
1 parent f66241c commit 860127e

File tree

8 files changed

+103
-117
lines changed

8 files changed

+103
-117
lines changed
-220 KB
Binary file not shown.
-174 KB
Binary file not shown.

docs/img/zkEVM/bridge-l1-l2.png

1.35 MB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
Abstract contract required to preserve the storage slots from previous versions. Inherits from `IPolygonZkEVMGlobalExitRootV2.sol`
2+
3+
## Functions
4+
5+
### `lastRollupExitRoo`
6+
7+
Rollup root, contains all exit roots of all rollups.
8+
9+
Returns `bytes32` object.
10+
11+
### `lastMainnetExitRoot`
12+
13+
Mainnet exit root; updated every time a deposit is made in mainnet.
14+
15+
Returns `bytes32` object.
16+
17+
### `globalExitRootMap`
18+
19+
Stores every global exit root: where root == `blockhash`.
20+
21+
Note that global exit roots in previous versions recorded `timestamp` instead of `blockhash`.
22+
23+
Returns `mapping(bytes32 => uint256)` object.

docs/zkEVM/architecture/high-level/smart-contracts/bridging.md

Lines changed: 49 additions & 62 deletions
Large diffs are not rendered by default.

docs/zkEVM/architecture/high-level/smart-contracts/exit-roots.md

Lines changed: 17 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@ The Merkle root of an exit tree is known as the exit tree root, and it is the fi
66

77
The global exit tree root of the L1 info tree is, therefore, the source of truth for the whole network.
88

9-
## Local exit trees
9+
## Rollup local exit trees
1010

11-
The L2 bridge has a special Merkle tree called a local exit tree for each network that participates in bridging and claiming.
11+
The L2 bridge contract manages a special Merkle tree called a local exit tree for each network that participates in bridging and claiming which is managed and updated by the [PolygonZkEVMGlobalExitRootL2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/feature/etrog/contracts/PolygonZkEVMGlobalExitRootL2.sol) contract.
1212

1313
<center>
1414
![Local exit tree for network participant](../../../../img/cdk/high-level-architecture/local-exit-tree.png)
1515
</center>
1616

1717
Data from `bridgeAsset()` and `bridgeMessage()` calls on the bridge is stored in leaf nodes on the local exit trees.
1818

19+
!!! important
20+
The following exit tree structures are managed by the [PolygonRollupManager.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonRollupManager.sol), the L1 [PolygonZkEVMBridgeV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMBridgeV2.sol) contract, and the[PolygonZkEVMGlobalExitRootV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol).
21+
1922
## Exit tree for rollups
2023

2124
The roots of the local exit trees feed into a single exit tree that manages state from all participating L2 rollups.
@@ -28,15 +31,17 @@ The L2 local exit root is accessible on the rollup manager by calling the `getRo
2831

2932
## L1 local exit tree
3033

31-
Data from `bridgeAsset()` and `bridgeMessage()` calls on the bridge at the L1 Ethereum level is stored in leaf nodes on the L1 local exit tree.
34+
Every time there is a call to `bridgeAsset()` and `bridgeMessage()` on the bridge at the L1 Ethereum level, the data is stored in a leaf node on the L1 local exit tree.
3235

3336
<center>
34-
![Exit tree for rollups](../../../../img/cdk/high-level-architecture/l1-ethereum-exit-tree.png)
37+
![L1 local exit tree](../../../../img/cdk/high-level-architecture/l1-ethereum-exit-tree.png)
3538
</center>
3639

3740
## L1 info tree
3841

39-
All subtrees feed into the L1 info tree, which contains the global exit root (GER).
42+
The L1 info tree is stored in the [PolygonZkEVMGlobalExitRootV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol) contract also known as the global exit root manager.
43+
44+
All subtrees exit roots feed into the leaves of the L1 info tree, which contains the global exit root (GER).
4045

4146
The GER is the fingerprint of the information stored in all trees, and thus represents the true state of the system.
4247

@@ -56,7 +61,7 @@ uint8 private constant _LEAF_TYPE_ASSET = 0;
5661
uint8 private constant _LEAF_TYPE_MESSAGE = 1;
5762
```
5863

59-
Data in a leaf is a Keccak256 hash of the metadata (ABI encoded metadata if any) with the following parameters:
64+
Data in a leaf contains a Keccak256 hash of the metadata (ABI encoded metadata if any) and the following parameters (matched by publicly available transaction data as seen in the [bridge L1 to L2](bridging.md#l1-to-l2) documentation):
6065

6166
```solidity
6267
_addLeaf(
@@ -73,51 +78,9 @@ _addLeaf(
7378
```
7479

7580
!!! info "Leaf parameters"
76-
- int32 originNetwork: Origin network ID, where the original asset belongs.
77-
- address originTokenAddress: If `leafType = 0`, Origin network token address (`0x0000...0000`) is reserved for ether. If `leafType = 1`, `msg.sender` of the message.
78-
- uint32 destinationNetwork: Bridging destination network ID.
79-
- address destinationAddress: Address that receives the bridged asset in the destination network.
80-
- uint256 leafAmount: Amount of tokens/ether to bridge.
81-
- bytes32 keccak256(metadata): Hash of the metadata. This metadata contains information about asset transferred or the message payload.
82-
83-
## Asset transfer scenarios
84-
85-
In this subsection, we present two scenarios to illustrate the role of exit trees and the global exit tree in the asset transfer process.
86-
87-
### Transfer from L1 to rollup L2
88-
89-
Consider a scenario where a user wants to transfer assets from the L1 Mainnet to the L2 Rollup.
90-
91-
Once the user commits to a transfer, a new exit leaf with the information of the assets being bridged is appended to the L1 exit tree. The transfer data typically looks like this:
92-
93-
```
94-
Origin network: 0 (L1)
95-
Origin address: 0x56566...
96-
Dest Network: 1 (L2)
97-
Dest Address: 0x12345...
98-
Amount: 145
99-
Metadata: 0x0...
100-
```
101-
102-
With the newly added exit leaf, the L1 exit tree now has a new root. Updating the global exit tree with this new L1 exit tree root means changing the root of the global exit tree.
103-
104-
To claim the bridged assets on the destination L2 network, the global exit root is verified using a Merkle proof. This proof allows one to confirm whether an exit leaf, containing information about assets being bridged to L2, is represented in the global exit tree by the corresponding L1 exit tree root.
105-
106-
![Updating L1 exit tree and the global exit root](../../../../img/zkEVM/03pzb-exit-leaf-add-L1-L2.png)
107-
108-
### Transfer from rollup L2 to L1
109-
110-
Transfers can also occur from an L2 Rollup to the L1 mainnet. In this scenario, the same procedure outlined in the previous example is followed, but in the reverse direction.
111-
112-
That is, once a user commits to a transfer, an exit leaf is added to the L2 exit tree with corresponding transfer information. The transfer data in this case looks as follows:
113-
114-
```
115-
Origin network: 3 (L2)
116-
Origin address: 0x34655...
117-
Dest Network: 0 (L1)
118-
Dest Address: 0x27564...
119-
Amount: 92
120-
Metadata: 0x116...
121-
```
122-
123-
The newly added L2 exit leaf means the L2 exit tree has a new root. The new L2 exit tree Root is then appended to the global exit tree, and thus the root of the global exit tree is updated.
81+
- `int32 originNetwork`: Origin network ID, where the original asset belongs.
82+
- `address originTokenAddress`: If `leafType = 0`, Origin network token address (`0x0000...0000`) is reserved for ether. If `leafType = 1`, `msg.sender` of the message.
83+
- `uint32 destinationNetwor`k: Bridging destination network ID.
84+
- `address destinationAddress`: Address that receives the bridged asset in the destination network.
85+
- `uint256 leafAmount`: Amount of tokens/ether to bridge.
86+
- `bytes32 keccak256(metadata)`: Hash of the metadata. This metadata contains information about assets transferred or the message payload.

docs/zkEVM/architecture/high-level/smart-contracts/main-contracts.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,16 @@ The [PolygonZkEVMGlobalExitRootV2.sol](https://github.com/0xPolygonHermez/zkevm-
6868
- Updating the L1 info tree by emitting the `UpdateL1InfoTree(...)` event.
6969
- Updating exit roots.
7070
- Retrieving latest exit roots and leaf values.
71+
72+
### `PolygonZkEVMGlobalExitRootL2.sol`
73+
74+
The [PolygonZkEVMGlobalExitRootL2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/feature/etrog/contracts/PolygonZkEVMGlobalExitRootL2.sol) contract manages the L2 rollup info trees.
75+
76+
It is a lighter-weight version of the global exit root contract mentioned previously.
77+
78+
#### Key functionality
79+
80+
- Stores every global exit root in the `globalExitRootMap`. The root of this map is the timestamp.
81+
- Updates the `lastRollupExitRoot` on any bridge call.
82+
- Updates the L2 network and global exit root with the `updateExitRoot(...)` function.
83+

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ nav:
101101
- Consensus contracts - sequencing: zkEVM/architecture/high-level/smart-contracts/sequencing.md
102102
- Bridging: zkEVM/architecture/high-level/smart-contracts/bridging.md
103103
- Exit roots: zkEVM/architecture/high-level/smart-contracts/exit-roots.md
104-
- Consensus contracts - verification: zkEVM/architecture/high-level/smart-contracts/verification.md
104+
#- Consensus contracts - verification: zkEVM/architecture/high-level/smart-contracts/verification.md
105105
- API:
106106
- PolygonRollupManager.sol: zkEVM/architecture/high-level/smart-contracts/api/PolygonRollupManager.md
107107
- PolygonZkEVMBridgeV2.sol: zkEVM/architecture/high-level/smart-contracts/api/PolygonZkEVMBridgeV2.md

0 commit comments

Comments
 (0)