Skip to content

Commit 16d2e2d

Browse files
authored
Merge pull request 0xPolygon#517 from 0xPolygon/sc/verification-flow
zkEVM: High level architecture - smart contract verification flow
2 parents 67c3c78 + 112857d commit 16d2e2d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed
240 KB
Loading
Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,33 @@
1-
!!! warning
2-
Coming soon.
1+
---
2+
comments: true
3+
---
4+
5+
Transactions flowing through the system reach the smart contract environment after one of two contract call use-cases:
6+
7+
- Sequence batches requests coming from the sequencer component in the node.
8+
- Verifying batches requests coming from the aggregator component in the node.
9+
10+
This section focuses on the verification workflow.
11+
12+
The sequence diagram below shows the verification workflow for rollup stacks and/or the AggLayer calling the `verifyBatchesTrustedAggregator(...)` function on the rollup manager.
13+
14+
![Polygon Solidity consensus verification flow](../../../../img/cdk/high-level-architecture/verification-flow.png)
15+
16+
## `verifyBatchesTrustedAggregator(rollupID, pendingStateNum, initNumBatch, finalNewBatch, newLocalExitRoot, newStateRoot, beneficiary, proof)`
17+
18+
This function is called on the `PolygonRollupManager` contract.
19+
20+
The zkEVM node aggregator, or the AggLayer, calls the [`verifyBatchesTrustedAggregator`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/b2a62e6af5738366e7494e8312184b1d6fdf287c/contracts/v2/PolygonRollupManager.sol#L921) function on the [`PolygonRollupManager.sol`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/feature/etrog/contracts/v2/PolygonRollupManager.sol) contract.
21+
22+
The function creates a rollup data storage object with the data provided by the caller, which it first verifies by sending it to the helper function [`_verifyAndRewardBatches`](https://github.com/0xPolygonHermez/zkevm-contracts/blob/b2a62e6af5738366e7494e8312184b1d6fdf287c/contracts/v2/PolygonRollupManager.sol#L977).
23+
24+
This internal function calculates the inputSnark bytes value, which is a `(SHA256 % "RFIELD")` calculation on the input data, and uses this value to verify the proof by calling `rollup.verifier.verifyProof(proof, [inputSnark])` on an `IVerifierRollup` interface implementation.
25+
26+
!!! note
27+
Using a `verifier` variable on the rollup object means the verifier implementation can be customized in the future.
28+
29+
Next, in the `_verifyAndRewardBatches` helper function, the code reverts if the proof does not verify successfully. Otherwise, the code pays POL rewards to the beneficiary.
30+
31+
The function then updates the state and calls `rollup.rollupContract.onVerifyBatches(...)`, which is a callback into the rollup consensus contract, allowing for customizable behavior. `onVerifyBatches(...)` takes the new state root and final batch, and emits a `VerifyBatches(...)` event.
32+
33+
The command flow returns to the `verifyBatchesTrustedAggregator` function which consolidates and updates the state with the `newStateRoot` and the new `localExitRoot` and calls the `updateExitRoot(...)` function on the `GlobalExitRootManager` contract passing the rollup's updated exit root.

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ nav:
9595
- Consensus contracts - sequencing: zkEVM/architecture/high-level/smart-contracts/sequencing.md
9696
- Bridging: zkEVM/architecture/high-level/smart-contracts/bridging.md
9797
- Exit roots: zkEVM/architecture/high-level/smart-contracts/exit-roots.md
98-
#- Consensus contracts - verification: zkEVM/architecture/high-level/smart-contracts/verification.md
98+
- Consensus contracts - verification: zkEVM/architecture/high-level/smart-contracts/verification.md
9999
- API:
100100
- PolygonRollupManager.sol: zkEVM/architecture/high-level/smart-contracts/api/PolygonRollupManager.md
101101
- PolygonZkEVMBridgeV2.sol: zkEVM/architecture/high-level/smart-contracts/api/PolygonZkEVMBridgeV2.md

0 commit comments

Comments
 (0)