Skip to content

Commit ba3d4e3

Browse files
Merge branch 'main' of https://github.com/0xPolygon/polygon-docs into cdk/erigon-setup
2 parents d311534 + 4a2eaad commit ba3d4e3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+702
-93
lines changed

docs/cdk/agglayer/agglayer-go.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
## Overview
2+
3+
The AggLayer-go is a service designed to receive zero-knowledge (ZK) proofs from various CDK chains and verify their validity before sending them to the L1 for final settlement.
4+
5+
!!! warning
6+
This service is being deprecated in favor of the more robust and efficient [Rust implementation](agglayer-rs.md).
7+
8+
## Architecture
9+
10+
The AggLayer Golang architecture supports interactions with multiple CDK chains for proof-verification. It uses a PostgreSQL database for storage and interacts with both L1 and L2 chains through configured RPC nodes.
11+
12+
The diagram below shows the full start-up, running, and shutdown sequence for the application and its components.
13+
14+
<center>
15+
![CDK architecture](../../img/cdk/agglayer/agglayer-go.png)
16+
</center>
17+
18+
## Get started
19+
20+
### Run locally with Docker
21+
22+
1. Clone the repository:
23+
24+
```bash
25+
git clone https://github.com/AggLayer/agglayer-go
26+
```
27+
28+
2. Execute the following command:
29+
30+
```bash
31+
make run-docker
32+
```
33+
34+
## Production set up
35+
36+
1. Ensure only one instance of the AggLayer is running at a time.
37+
2. Use a containerized setup, or OS level service manager/monitoring system, for automatic restarts in the case of failures.
38+
39+
### Prerequisites
40+
41+
#### Hardware
42+
43+
- For each CDK chain it's necessary to configure its corresponding RPC node, synced with the target CDK.
44+
- This node is for checking the state root after executions of L2 batches.
45+
- We recommend a durable HA PostgresDB for storage, preferably AWS Aurora PostgreSQL or Cloud SQL for PostgreSQL in GCP.
46+
47+
#### Software
48+
49+
- Docker
50+
- Docker Compose
51+
52+
### Installation
53+
54+
1. Clone the repository:
55+
56+
```bash
57+
git clone https://github.com/AggLayer/agglayer-go
58+
```
59+
60+
2. Install Golang dependencies:
61+
62+
```bash
63+
go install .
64+
```
65+
66+
### Configure key signing
67+
68+
1. Install `polygon-cli`:
69+
70+
```bash
71+
go install github.com/maticnetwork/polygon-cli@latest
72+
```
73+
74+
2. Create a new signature:
75+
76+
```bash
77+
polygon-cli signer create --kms GCP --gcp-project-id gcp-project --key-id mykey-tmp
78+
```
79+
80+
3. Install `gcloud` CLI and set up ADC:
81+
82+
```bash
83+
gcloud auth application-default login
84+
```
85+
86+
4. Configure `KMSKeyName` in `agglayer.toml`.
87+
88+
### Configure `agglayer.toml`
89+
90+
* `[FullNodeRPCs]` to point to the corresponding L2 full node.
91+
* `[L1]` to point to the corresponding L1 chain.
92+
* `[DB]` section with the managed database details.
93+
94+
## API
95+
96+
Refer to the `cmd` and `client` directories for API implementation details. Documentation and specific API routes can be generated from these sources.
97+
98+
---
99+
100+
For more information, visit the [AggLayer-go repository](https://github.com/AggLayer/agglayer-go).

docs/cdk/agglayer/agglayer-rs.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
## Overview
2+
3+
AggLayer-rs is a Rust-based service designed to receive ZK proofs from various CDK chains and verify their validity before sending them to the L1 for final settlement. It replaces the previous [Golang implementation](agglayer-go.md).
4+
5+
## Architecture
6+
7+
The AggLayer Rust architecture supports interactions with multiple CDK chains for proof-verification. Its architecture is the same as `agglayer-go`, but without the PostgreSQL database for storage.
8+
9+
## Getting started
10+
11+
### Prerequisites
12+
13+
#### Hardware
14+
15+
- RPC nodes: Configure RPC nodes for each CDK chain, and synced with the target CDK, to check the state roots post L2 batch executions.
16+
17+
#### Software
18+
19+
- Rust
20+
21+
### Installation
22+
23+
1. Clone the repository:
24+
25+
```sh
26+
git clone https://github.com/AggLayer/agglayer-rs.git
27+
cd agglayer-rs
28+
```
29+
30+
2. Build and run:
31+
32+
```sh
33+
cargo build
34+
cargo run
35+
```
36+
37+
## How to
38+
39+
### Configure the service
40+
41+
Edit configuration by modifying the `agglayer.toml` file for service settings like RPC endpoints and network parameters. For example:
42+
43+
```toml
44+
[network]
45+
rpc_url = "https://your_rpc_url"
46+
chain_id = "your_chain_id"
47+
```
48+
49+
### Run tests
50+
51+
1. Run unit tests:
52+
53+
```sh
54+
cargo test
55+
```
56+
57+
2. Run integration tests by first ensuring all necessary services are running, then execute:
58+
59+
```sh
60+
cargo test -- --ignored
61+
```
62+
63+
## API reference
64+
65+
### Endpoints
66+
67+
#### Submit proof
68+
69+
- **Endpoint**: `/submit_zkp`
70+
- **Method**: POST
71+
- **Payload**:
72+
73+
```json
74+
{
75+
"zkp": "base64_encoded_zkp",
76+
"chain_id": "cdk_chain_id"
77+
}
78+
```
79+
80+
- **Response**:
81+
82+
```json
83+
{
84+
"status": "success",
85+
"message": "ZKP submitted successfully"
86+
}
87+
```
88+
89+
---
90+
91+
For more information, visit the [AggLayer Rust repository](https://github.com/AggLayer/agglayer-rs).

docs/cdk/agglayer/overview.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
!!! info "Disclaimer"
2+
- Some of the content in this section discusses technology in development and not ready for release.
3+
- Please check against the main documentation site for any live releases.
4+
- Feel free to experiment with any code in public repos.
5+
6+
The AggLayer is an in-development interoperability protocol that allows for trustless, cross-chain token transfers and message-passing, as well as more complex operations. The safety of the AggLayer is provided by ZK proofs.
7+
8+
The AggLayer currently connects chains built with Polygon CDK, a developer toolkit for designing ZK-powered Layer 2s. The long term goal for the protocol is to be flexible enough to provide interoperability among a growing range of blockchain architectures, including L2s, appchains, and non-EVM chains.
9+
10+
## AggLayer components
11+
12+
### Polygon CDK
13+
14+
The AggLayer connects chains built with Polygon CDK, which use ZK proofs to generate state transitions that are cryptographically secure.
15+
16+
### Unified bridge
17+
18+
The unified bridge is a single bridge contract for all AggLayer-connected chains, allowing for the cross-chain transfer of fungible (non-wrapped) tokens. It is the source of unified liquidity for the AggLayer.
19+
20+
!!! tip "More information"
21+
See the [unified bridge documentation](unified-bridge.md) for details.
22+
23+
### AggLayer service
24+
25+
The AggLayer service is a service designed to receive ZK proofs from various CDK chains and verify their validity before sending them to the L1 for final settlement. Currently, the AggLayer service has two implementations: [agglayer-go](agglayer-go.md) and [agglayer-rs](agglayer-rs.md).

docs/cdk/agglayer/token-flows.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
The following describes how token transfers and message passing are implemented by the unified bridge across various L1 and L2 permutations. While the examples provided describe only token transfers, the sequence is the same for arbitrary messages in this current implementation of the AggLayer.
2+
3+
## L1 to L2
4+
5+
1. If a call to `bridgeAsset` or `bridgeMessage` on L1 passes validation, the unified bridge contract appends an exit leaf to the L1 exit tree and computes the new L1 exit tree root.
6+
7+
2. The global exit root manager appends the new L1 exit tree root to the global exit tree and computes the global exit root.
8+
9+
3. The sequencer fetches the latest global exit root from the global exit root manager.
10+
11+
4. At the start of the transaction batch, the sequencer stores the global exit root in special storage slots of the L2 global exit root manager smart contract, allowing L2 users to access it.
12+
13+
5. A call to `claimAsset` or `claimMessage` provides a Merkle proof that validates the correct exit leaf in the global exit root.
14+
15+
6. The unified bridge contract validates the caller's Merkle proof against the global exit root. If the proof is valid, the bridging process succeeds; otherwise, the transaction fails.
16+
17+
## L2 to L1
18+
19+
1. If a call to `bridgeAsset` or `bridgeMessage` on L2 passes validation, the unified bridge contract appends an exit leaf to the L2 exit tree and computes the new L2 exit tree root.
20+
21+
2. The L2 global exit root manager appends the new L2 exit tree root to the global exit tree and computes the global exit root. At that point, the caller's bridge transaction is included in one of the batches selected and sequenced by the sequencer.
22+
23+
3. The aggregator generates a zk-proof attesting to the computational integrity in the execution of sequenced batches which include the transaction.
24+
25+
4. For verification purposes, the aggregator sends the zk-proof together with all relevant batch information that led to the new L2 exit tree root (computed in step 2), to the verifier contract.
26+
27+
5. The verifier contract utilizes the `verifyBatches` function to verify validity of the received zk-proof. If valid, the contract sends the new L2 exit tree root to the global exit root manager in order to update the global exit tree.
28+
29+
6. `claimMessage` or `claimAsset` is then called on the unified bridge contract with Merkle proofs for correct validation of exit leaves.
30+
31+
7. The unified bridge contract retrieves the global exit root from the L1 global exit root manager and verifies validity of the Merkle proof. If the Merkle proof is valid, the settlement completes, otherwise, the transaction is reverted.
32+
33+
## L2 to L2
34+
35+
1. When a batch of transactions is processed, the bridge contract appends the L2 exit tree with a new leaf containing the batch information. This updates the L2 exit tree root.
36+
37+
2. The bridge contracts communicates the L2 exit tree root to the L2 global exit root manager. The L2 global exit root manager, however, does not update the global exit tree at this stage.
38+
39+
3. For proving and verification, the zk-proof-generating circuit obtains the L2 exit tree root from the L2 global exit root manager.
40+
41+
4. Only after the batch has been successfully proved and verified does the L2 global exit root manager append the L2 exit tree root to the global exit tree. As a result, the global exit root is updated.
42+
43+
5. The zk-proof-generating circuit also writes the L2 exit tree root to the mainnet. The L1 bridge contract can then finalize the transfer by using the `claim` function.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Overview
2+
3+
The unified bridge is a single bridge contract on Ethereum, providing a safe, common access point for the transfer of all native, never-wrapped tokens. Each chain has a local copy of the unified bridge root, enabling cross-chain interoperability that doesn’t require the security risks of third-party bridges.
4+
5+
6+
!!! important "AggLayer smart contracts"
7+
- The current version of the unified bridge uses the contracts in the [PolygonzkEVM smart contract repo](https://github.com/0xPolygonHermez/zkevm-contracts).
8+
9+
## Bridging mechanism
10+
11+
The bridging mechanism enables token transfers and message-passing between Ethereum (L1) and CDK chains via smart contracts. Detailed in the [zkEVM bridging documentation](../../zkEVM/architecture/high-level/smart-contracts/bridging.md), core components include the bridge and exit root Solidity smart contracts.
12+
13+
## Data structures
14+
15+
Each chain holds a single data structure which stores a record of all token withdrawals and messages that originated from that chain. This “exit tree” is an append-only Merkle trie, similar in structure to the Ethereum deposit trie. The latest state of each chain and the unified bridge is represented by the root of this Merkle tree, referred to as the “exit root.”
16+
17+
As cryptographic commitments, exit roots ensure the integrity of the network as a whole. Refer to the [exit root documentation](../../zkEVM/architecture/high-level/smart-contracts/exit-roots.md) for greater detail about the role of exit roots in the system.
259 KB
Loading
-686 KB
Binary file not shown.
-652 KB
Binary file not shown.
-17.1 MB
Binary file not shown.
750 KB
Loading

0 commit comments

Comments
 (0)