You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/l2/README.md
+35-20Lines changed: 35 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,19 +11,27 @@ Notice a lot of checks that a real L2 should have are missing, since the focus a
11
11
12
12
## How it works: Step by Step
13
13
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.
15
+
16
+
### Step 1
17
+
14
18
1. Load or initialize the state.
15
19
2. Load user transfers.
16
20
3. Run the zkvm + transfers to perform.
17
21
4. Generate and submit the proof to Aligned.
18
-
5. Wait for the proof to be aggregated.
19
-
6. Call the smart contract function `updateStateTransition`, which:
22
+
5. Store proof binary on disk to be later retrieved by the on chain verifier.
23
+
24
+
### Step 2
25
+
26
+
6. Load the proof binary.
27
+
7. Call the smart contract function `updateStateTransition`, which:
20
28
1. Calls `verifyProofInclusion` in the `AlignedProofAggregationService`, which:
21
29
- Computes the proof commitment with the provided `public_inputs` and `program_id`
22
30
- Computes the Merkle Root, using the provided Merkle Proof.
23
31
- Checks the root exists in the aggregation root.
24
32
2. Verifies that the initial_state_root public input matches the on-chain state.
25
33
3. If successful, updates the state root with the post_state_root public input.
26
-
7. If the contract call succeeds, updates the local database.
34
+
8. If the contract call succeeds, updates the local database.
27
35
28
36
### Usage
29
37
@@ -54,24 +62,25 @@ This same wallet is used to send the proof via aligned, so you'll also need to f
54
62
55
63
#### 2. Deploy the contract
56
64
57
-
- Generate the base `.env`. For `Holesky` you can run:
65
+
-Generate the base `.env`. For `Holesky` you can run:
58
66
59
67
```shell
60
68
make gen_env_contract_holesky
61
69
```
62
70
63
-
- Get the program ID of the l2 program you are proving:
71
+
-Get the program ID of the l2 program you are proving:
64
72
65
73
```shell
66
74
make generate_program_id
67
75
```
68
76
69
-
- Complete the following fields `contracts/.env` file:
70
-
-```PROGRAM_ID=``` (use the previously generated ID, you can re check with a ```sh cat ./crates/l2/programs_ids.json``` )
71
-
-`PRIVATE_KEY`: the private key used for the deployment, it needs to have some funds to pay for the deployment.
72
-
-`OWNER_ADDRESS`: you have to provide the address of the wallet created in step `1.`.
77
+
- Complete the following fields `contracts/.env` file:
78
+
79
+
-`PROGRAM_ID=` (use the previously generated ID, you can re check with a `sh cat ./crates/l2/programs_ids.json` )
80
+
-`PRIVATE_KEY`: the private key used for the deployment, it needs to have some funds to pay for the deployment.
81
+
-`OWNER_ADDRESS`: you have to provide the address of the wallet created in step `1.`.
73
82
74
-
- Deploy the contracts with:
83
+
-Deploy the contracts with:
75
84
76
85
```shell
77
86
make deploy_contract
@@ -81,27 +90,33 @@ Save the output contract address.
81
90
82
91
#### 3. Run L2 program
83
92
84
-
- Generate the base `.env`. For `Holesky` you can run:
93
+
-Generate the base `.env`. For `Holesky` you can run:
85
94
86
95
```shell
87
96
make gen_env_l2_holesky
88
97
```
89
98
90
-
- Complete the missing fields on the ```sh .env```:
99
+
-Complete the missing fields on the `sh .env`:
91
100
92
-
-`BEACON_CLIENT_URL`: A beacon client url, public node usually don't work as they don't support the endpoints to retrieve blob data
93
-
-`PRIVATE_KEY_STORE_PATH`: The path to the keystore created in `1.`.
94
-
-`PRIVATE_KEY_STORE_PASSWORD`: The password of the keystore crated in step `1.`.
95
-
-`STATE_TRANSITION_CONTRACT_ADDRESS`: The address of the contract deployed in step `2.`
101
+
-`BEACON_CLIENT_URL`: A beacon client url, public node usually don't work as they don't support the endpoints to retrieve blob data
102
+
-`PRIVATE_KEY_STORE_PATH`: The path to the keystore created in `1.`.
103
+
-`PRIVATE_KEY_STORE_PASSWORD`: The password of the keystore crated in step `1.`.
104
+
-`STATE_TRANSITION_CONTRACT_ADDRESS`: The address of the contract deployed in step `2.`
96
105
97
-
- If you have run the program before, and want to start from scratch, run:
106
+
-If you have run the program before, and want to start from scratch, run:
98
107
99
-
```make clean_db```
108
+
`make clean_db`
100
109
101
-
-Run the L2:
110
+
- Perform the L2 account updates and prove them in the zkvm:
102
111
103
112
```shell
104
-
make run_l2
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
105
120
```
106
121
107
122
You should see a transaction receipt in the console and after the stateRoot updated on-chain.
0 commit comments