Skip to content

Commit 55bc806

Browse files
add sequencing info
1 parent a1c3aea commit 55bc806

File tree

7 files changed

+106
-38
lines changed

7 files changed

+106
-38
lines changed
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
!!! warning
2-
Coming soon.
2+
Coming soon.
3+
4+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
How bridging works: Bridge contracts -> keeping things in sync between chains L1 L2, sequencer, state db, local/global exit roots
2+
3+
https://www.notion.so/polygontechnology/Lx-Ly-Unified-Bridge-API-and-Auto-claim-Service-943590d404da4827af62fe207e1ee2a4

docs/zkEVM/architecture/high-level/smart-contracts/consensus-sequencing.md

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

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

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,44 @@
1-
## `PolygonRollupManager.sol`
1+
## L1 consensus contracts
22

3-
The [PolygonRollupManager.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonRollupManager.sol) contract is responsible for managing rollups and verifying batches. It creates and updates rollup stacks by storing hash-sequenced data as newly sequenced batches arrive.
3+
The group of consensus contracts deal with sequencing and verifying transaction batches.
4+
5+
### `PolygonRollupBaseEtrog.sol`
6+
7+
[PolygonRollupBaseEtrog.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/lib/PolygonRollupBaseEtrog.sol) is the base contract for rollups and validiums.
8+
9+
### `PolygonZkEVMEtrog.sol`
10+
11+
[https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/consensus/zkEVM/PolygonZkEVMEtrog.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/consensus/zkEVM/PolygonZkEVMEtrog.sol) is the rollup contract that inherits from the base contract that calls the `onSequenceBatches(...)` function on the `PolygonRollupManager.sol` contract.
12+
13+
### `PolygonValidiumEtrog.sol`
14+
15+
[PolygonValidiumEtrog.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol) is the validium contract that inherits from the base contract that calls the `onSequenceBatches(...)` function on the `PolygonRollupManager.sol` contract.
16+
17+
### `PolygonRollupBaseEtrogNoGap.sol`
18+
19+
### `PolygonValidiumStorageMigration.sol`
20+
21+
## L1 main contracts
22+
23+
### `PolygonRollupManager.sol`
24+
25+
The [PolygonRollupManager.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonRollupManager.sol) contract is responsible for keeping track of and managing rollups. It also verifies batches. It creates and updates rollup stacks by storing hash-sequenced data as newly sequenced batches arrive.
426

527
It is responsible for the verification workflow by supplying updated exit root data to the [[PolygonZkEVMGlobalExitRootV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol)](#polygonzkevmglobalexitrootv2sol) contract.
628

7-
### Key functionality
29+
#### Key functionality
830

931
- Defining and adding rollup types which contains consensus implementation details and compatibility checks.
1032
- Defining the [`RollupData`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonRollupManager.sol#L70s) struct.
1133
- Initializes the trusted aggregator process for verifying multiple batches.
12-
- Gets exit root data by computing all local exit roots of all rollups.
13-
- Calculates batch rewards.
34+
- Getting exit root data by computing all local exit roots of all rollups.
35+
- Calculating batch rewards.
1436

15-
## `PolygonZkEVMBridgeV2.sol`
37+
### `PolygonZkEVMBridgeV2.sol`
1638

1739
The [PolygonZkEVMBridgeV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMBridgeV2.sol) is the main communication mechanism between the L1 and L2 realms. It manages bridging and claiming of assets and messages across environments.
1840

19-
### Key functionality
41+
#### Key functionality
2042

2143
- Bridging assets with the `bridgeAsset(...)` function.
2244
- Bridging messages with a choice of `bridgeMessage(...)` functions for various scenarios.
@@ -26,11 +48,11 @@ The [PolygonZkEVMBridgeV2.sol](https://github.com/0xPolygonHermez/zkevm-contract
2648
- Providing access to the global exit root manager via the `IBasePolygonZkEVMGlobalExitRoot`.
2749
- Interacting with the `PolygonZkEVMGlobalExitRootL2.sol` contract which exists in the L2 space as part of the bridge functionality.
2850

29-
## `PolygonZkEVMGlobalExitRootV2.sol`
51+
### `PolygonZkEVMGlobalExitRootV2.sol`
3052

3153
The [PolygonZkEVMGlobalExitRootV2.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/main/contracts/v2/PolygonZkEVMGlobalExitRootV2.sol) contract manages the L1 info tree that represents the current state of the system by updating global exit roots on state changes. It does this task across multiple networks and layers.
3254

33-
### Key functionality
55+
#### Key functionality
3456

3557
- Updating the L1 info tree by emitting the `UpdateL1InfoTree(...)` event.
3658
- Updating exit roots.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Transactions flowing through the system reach the smart contract environment after one of two contract call use cases; sequencing coming from the sequencer component, or verifying batches coming from the aggregator component.
2+
3+
This section looks at the sequencing workflow.
4+
5+
## `sequenceBatches(batches, maxSequenceTs, initSequenceBatch, l2Coinbase)`
6+
7+
This function is called on the `PolygonZkEVMEtrog.sol` contract.
8+
9+
The rollup sequencer component calls the [`sequenceBatches`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/1ad7089d04910c319a257ff4f3674ffd6fc6e64e/contracts/v2/lib/PolygonRollupBaseEtrog.sol#L425) function on the [`PolygonZkEVMEtrog.sol`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/1ad7089d04910c319a257ff4f3674ffd6fc6e64e/contracts/v2/consensus/zkEVM/PolygonZkEVMEtrog.sol) contract which inherits the function from [PolygonRollupBaseEtrog.sol](https://github.com/0xPolygonHermez/zkevm-contracts/blob/1ad7089d04910c319a257ff4f3674ffd6fc6e64e/contracts/v2/lib/PolygonRollupBaseEtrog.sol).
10+
11+
The function takes an array of `BatchData` structs from one of the consensus contracts. Each struct contains L2 Ethereum transactions data, and some forced state information.
12+
13+
```solidity
14+
struct BatchData {
15+
bytes transactions;
16+
bytes32 forcedGlobalExitRoot;
17+
uint64 forcedTimestamp;
18+
bytes32 forcedBlockHashL1;
19+
}
20+
```
21+
22+
The function validates arguments, checks and organizes the batches, and appends them in the correct sequence while computing an accumulated hash and eventually emits a `SequenceBatch` event which sends a newly sequenced batch of transactions to the `PolygonRollupManager.sol` contract via the [`onSequenceBatches(...)`](#onsequencebatchesnewsequencedbatches-newaccinputhash) function.
23+
24+
Stepwise, the function does the following:
25+
26+
1. Validates arguments.
27+
1. Tells the bridge to update the global exit root by calling `globalExitRootManager.updateExitRoot(L1LocalExitRoot)` which creates a new global exit root with the newest L1 local exit root.
28+
1. Gets L1 info root and other variables needed for computation.
29+
1. Goes through the batches to compute the accumulated hash with `keccak(batch.transaction)` and `keccak(accInputHash, txHash, l1InfoRoot, maxSequenceTs, l2Coinbase, bytes32(0))`.
30+
1. Stores the accumulated hash.
31+
1. Caller pays the rollup manager in POL.
32+
1. Calls the `PolygonRollupManager.onSequenceBatches(...)` function which waits for an `OnSequenceBatches(...)` event callback.
33+
1. Emits `SequenceBatches(...)` event.
34+
35+
## `onSequenceBatches(newSequencedBatches, newAccInputHash)`
36+
37+
This function is called on the `PolygonRollupManager.sol` contract.
38+
39+
It takes the sequenced batches and the accumulated hash from the caller, adds the batches to the correct stack, and updates the batch count.
40+
41+
Stepwise, the function does the following:
42+
43+
1. Validates the arguments and the caller contract.
44+
1. Updates the `totalSequencedBatches` storage variable.
45+
1. Updates the `lastBatchSequenced` and adds a new `SequencedBatchData` struct for the rollup that called `sequenceBatches`.
46+
1. Attempts to consolidate pending state for the rollup by updating `lastVerifiedBatch`, `batchNumToStateRoot[]`, and `lastLocalExitRoot` state variables, and also by updating `globalExitRootManager.updateExitRoot(L2sLocalExitRoot)`, after which it emits a `ConsolidatePendingState(...)` event.
47+
1. Emits an `OnSequenceBatches(...)` event back to the original `sequenceBatches(...)` call.
48+
49+
## `sequenceBatchesValidium(...)`
50+
51+
This function is called on the `PolygonValidiumEtrog.sol` contract.
52+
53+
The sequencing logic is nearly the same as for the rollup `sequenceBatches(...)` function except the function takes a `ValidiumBatchData[]` array instead of `BatchData[]` which means instead of passing the actual batch data, the struct passes the hashes of the transactions.
54+
55+
```solidity
56+
struct ValidiumBatchData {
57+
bytes32 transactionsHash;
58+
bytes32 forcedGlobalExitRoot;
59+
uint64 forcedTimestamp;
60+
bytes32 forcedBlockHashL1;
61+
}
62+
```
63+
64+
Stepwise, the function has identical logic to the `PolygonRollupBaseEtrog.sequenceBatches(...)` function except for:
65+
66+
1. `ValdiumBatchData` instead of `BatchData`.
67+
1. Accumulates the txHash into `accumulatedNonForcedTransactionHash`.
68+
1. Adds a validity check with `dataAvailabilityProtocol.verifyMessage(accumulatedNonForcedTransactionHash, dataAvailabilityMessage)`.

docs/zkEVM/architecture/high-level/smart-contracts/consensus-verification.md renamed to docs/zkEVM/architecture/high-level/smart-contracts/verification.md

File renamed without changes.

mkdocs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ nav:
9898
- Smart contracts:
9999
- Overview: zkEVM/architecture/high-level/smart-contracts/overview.md
100100
- Main contracts: zkEVM/architecture/high-level/smart-contracts/main-contracts.md
101-
- Consensus contracts - sequencing: zkEVM/architecture/high-level/smart-contracts/consensus-sequencing.md
101+
- 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/consensus-verification.md
104+
- Consensus contracts - verification: zkEVM/architecture/high-level/smart-contracts/verification.md
105105
- API: zkEVM/architecture/high-level/smart-contracts/api.md
106106
- Addresses: zkEVM/architecture/high-level/smart-contracts/addresses.md
107107
#- AggLayer: https://potential-couscous-4gw6qyo.pages.github.io/index.html

0 commit comments

Comments
 (0)