Skip to content

Commit 9cee781

Browse files
committed
docs: clearer readme
1 parent 4574762 commit 9cee781

2 files changed

Lines changed: 52 additions & 39 deletions

File tree

examples/l2/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
crates/l2/programs_ids.json
32
contract-owner.keystore.json
43
cmd/db

examples/l2/README.md

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,37 @@ After processing the transfers, the vm computes the commitment of the post state
99

1010
Notice a lot of checks that a real L2 should have are missing, since the focus are on the integration of Aligned.
1111

12-
## How it works: Step by Step
12+
## L2 workflow overview
1313

14-
This L2 works in two steps. First we need perform the user transfers and prove that state transition inside the zkvm and send it to aligned verification layer (a.k.a fast mode). Then, once our proof has been aggregated by aligned (this happens every 24hs) we need to run the on chain verifier to update the state transition on chain for which we need to retrieve the merkle path for the proof.
14+
This Layer 2 (L2) system operates in two main steps:
1515

16-
### Step 1
16+
- Off-chain execution and proof generation + verification with Aligned Verification Layer (a.k.a Fast Mode).
17+
- On-chain state update via proof verification with Aligned aggregation mode.
1718

18-
1. Load or initialize the state.
19-
2. Load user transfers.
20-
3. Run the zkvm + transfers to perform.
21-
4. Generate and submit the proof to Aligned.
22-
5. Store proof binary on disk to be later retrieved by the on chain verifier.
19+
In Step 1, we execute user transfers and generate a zkVM-based proof of the state transition, which is submitted to Aligned’s verification layer.
2320

24-
### Step 2
21+
In Step 2, once the proof is aggregated (every 24 hours), it is verified on-chain to update the global state.
2522

26-
6. Load the proof binary.
27-
7. Call the smart contract function `updateStateTransition`, which:
28-
1. Calls `verifyProofInclusion` in the `AlignedProofAggregationService`, which:
29-
- Computes the proof commitment with the provided `public_inputs` and `program_id`
30-
- Computes the Merkle Root, using the provided Merkle Proof.
31-
- Checks the root exists in the aggregation root.
32-
2. Verifies that the initial_state_root public input matches the on-chain state.
33-
3. If successful, updates the state root with the post_state_root public input.
34-
8. If the contract call succeeds, updates the local database.
23+
### Step 1: Off-Chain Execution & Proof Generation
24+
25+
1. Initialize State: Load or initialize the current system state.
26+
2. Load Transfers: Retrieve or receive the user transfer data for this batch.
27+
3. Execute in zkVM: Run the zkVM with the loaded transfers to compute the new state.
28+
4. Generate Proof: Produce a zk-proof for the executed state transition committing the commitment of the received + the commitment of the new state.
29+
5. Submit Proof to Aligned: Send the proof to Aligned Verification Layer
30+
6. Save the binary proof locally for later on-chain verification.
31+
32+
### Step 2: On-Chain State Update
33+
34+
7. Load the proof binary: Retrieve the saved proof binary from disk.
35+
8. Update On-Chain State: Call the smart contract method `updateStateTransition`, which:
36+
37+
- Internally calls `verifyProofInclusion` on AlignedProofAggregationService which:
38+
1. Computes the proof commitment from the proof `public_inputs` and `program_id`.
39+
2. Uses the Merkle proof to reconstruct and validate the Merkle root.
40+
3. Confirms whether there exists and aggregated proof with that root.
41+
- Validates that the `initial_state_root` proof public input matches the on-chain state.
42+
- If valid, updates the on-chain state root to the `post_state_root`.
3543

3644
### Usage
3745

@@ -41,6 +49,8 @@ This L2 works in two steps. First we need perform the user transfers and prove t
4149
2. [Foundry](https://book.getfoundry.sh/getting-started/installation)
4250
3. [Docker](https://docs.docker.com/engine/): for SP1 prover
4351

52+
## Setup Holeksy
53+
4454
#### 1. Create keystore
4555

4656
You can use cast to create a local keystore. If you already have one you can skip this step.
@@ -88,7 +98,7 @@ make deploy_contract
8898

8999
Save the output contract address.
90100

91-
#### 3. Run L2 program
101+
### 3. Setup the L2
92102

93103
- Generate the base `.env`. For `Holesky` you can run:
94104

@@ -107,21 +117,9 @@ make gen_env_l2_holesky
107117

108118
`make clean_db`
109119

110-
- Perform the L2 account updates and prove them in the zkvm:
120+
Finally [run the l2](#run-the-l2).
111121

112-
```shell
113-
make update_state_transition
114-
```
115-
116-
- Update state transition on chain, you should run this after your proof has been aggregated by aligned (this process happens every 24hs):
117-
118-
```shell
119-
make verify_state_transition_on_chain
120-
```
121-
122-
You should see a transaction receipt in the console and after the stateRoot updated on-chain.
123-
124-
### Running it on a local network
122+
## Setup Localnet
125123

126124
You can also run this example on a local devnet. To get started, navigate to the root of the Aligned repository and run:
127125

@@ -130,8 +128,6 @@ You can also run this example on a local devnet. To get started, navigate to the
130128
make ethereum_package_start
131129
# Start the batcher
132130
make batcher_start_ethereum_package
133-
# Send proofs to be able to build batches
134-
make batcher_send_burst_groth16
135131
```
136132

137133
The remaining steps are the same as for other networks, except you'll be using the `devnet` environment. Specifically, generate the `.env` files for `devnet` using:
@@ -148,14 +144,32 @@ By default and to make things simpler, the `.env` will be generated using a dev
148144
make gen_devnet_owner_wallet
149145
```
150146

151-
Finally, generate the program id with: `make generate_program_id`, copy the address to the generated `.env` and deploy the contract:
147+
Finally, generate the program id with:
148+
149+
````shell
150+
make generate_program_id
151+
```
152+
153+
Copy the address to the generated `.env` and deploy the contract:
152154

153155
```shell
154156
make deploy_contract
157+
````
158+
159+
Pass the output address in the `.env` and [run the l2](#run-the-l2).
160+
161+
## Running the L2
162+
163+
- Perform the L2 account updates and prove them in the zkvm:
164+
165+
```shell
166+
make update_state_transition
155167
```
156168
157-
Pass the output address in the `.env` and run the l2:
169+
- Update state transition on chain, you should run this after your proof has been aggregated by aligned (this process happens every 24hs):
158170
159171
```shell
160-
make run_l2
172+
make verify_state_transition_on_chain
161173
```
174+
175+
You should see a transaction receipt in the console and after the stateRoot updated on-chain.

0 commit comments

Comments
 (0)