Skip to content

Commit 4574762

Browse files
committed
chore: update .env files and readme
1 parent c59deef commit 4574762

5 files changed

Lines changed: 41 additions & 42 deletions

File tree

examples/l2/.env.devnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ ETH_RPC_URL=http://localhost:8545
44
WS_ETH_RPC_URL=ws://localhost:8546
55
BEACON_CLIENT_URL=http://localhost:58801
66
# Generate it with make gen_devnet_owner_wallet
7-
PRIVATE_KEY_STORE_PATH="../../contract-owner.keystore.json" # This is read from crates/l2.
7+
PRIVATE_KEY_STORE_PATH="../contract-owner.keystore.json" # This is read from cmd/.
88
PRIVATE_KEY_STORE_PASSWORD="<!w5Y%In94Vw"
99
STATE_TRANSITION_CONTRACT_ADDRESS=<STATE_TRANSITION_CONTRACT_ADDRESS>

examples/l2/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11

22
crates/l2/programs_ids.json
33
contract-owner.keystore.json
4+
cmd/db
5+
cmd/proof.bin
6+
crates/db

examples/l2/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ clean_db:
3939

4040
__L2_PROGRAM__:
4141
update_state_transition:
42-
@cd cmd && cargo run --release --bin update_state_transition
42+
@. ./.env && cd cmd && cargo run --release --bin update_state_transition
4343

4444
verify_state_transition_on_chain:
45-
@cd cmd && cargo run --release --bin verify_state_transition_on_chain
45+
@. ./.env && cd cmd && cargo run --release --bin verify_state_transition_on_chain

examples/l2/README.md

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,27 @@ Notice a lot of checks that a real L2 should have are missing, since the focus a
1111

1212
## How it works: Step by Step
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.
15+
16+
### Step 1
17+
1418
1. Load or initialize the state.
1519
2. Load user transfers.
1620
3. Run the zkvm + transfers to perform.
1721
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:
2028
1. Calls `verifyProofInclusion` in the `AlignedProofAggregationService`, which:
2129
- Computes the proof commitment with the provided `public_inputs` and `program_id`
2230
- Computes the Merkle Root, using the provided Merkle Proof.
2331
- Checks the root exists in the aggregation root.
2432
2. Verifies that the initial_state_root public input matches the on-chain state.
2533
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.
2735

2836
### Usage
2937

@@ -54,24 +62,25 @@ This same wallet is used to send the proof via aligned, so you'll also need to f
5462

5563
#### 2. Deploy the contract
5664

57-
- Generate the base `.env`. For `Holesky` you can run:
65+
- Generate the base `.env`. For `Holesky` you can run:
5866

5967
```shell
6068
make gen_env_contract_holesky
6169
```
6270

63-
- Get the program ID of the l2 program you are proving:
71+
- Get the program ID of the l2 program you are proving:
6472

6573
```shell
6674
make generate_program_id
6775
```
6876

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.`.
7382

74-
- Deploy the contracts with:
83+
- Deploy the contracts with:
7584

7685
```shell
7786
make deploy_contract
@@ -81,27 +90,33 @@ Save the output contract address.
8190

8291
#### 3. Run L2 program
8392

84-
- Generate the base `.env`. For `Holesky` you can run:
93+
- Generate the base `.env`. For `Holesky` you can run:
8594

8695
```shell
8796
make gen_env_l2_holesky
8897
```
8998

90-
- Complete the missing fields on the ```sh .env```:
99+
- Complete the missing fields on the `sh .env`:
91100

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.`
96105

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:
98107

99-
```make clean_db```
108+
`make clean_db`
100109

101-
- Run the L2:
110+
- Perform the L2 account updates and prove them in the zkvm:
102111

103112
```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
105120
```
106121

107122
You should see a transaction receipt in the console and after the stateRoot updated on-chain.

examples/l2/crates/l2/src/aligned.rs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,4 @@ pub async fn check_proof_proof_aggregation_status(
7979
.expect("Get merkle path for proof");
8080

8181
proof_status
82-
83-
// match proof_status {
84-
// aligned_sdk::aggregation_layer::ProofStatus::Verified {
85-
// merkle_root,
86-
// merkle_path,
87-
// } => {
88-
// info!(
89-
// "Proof aggregated in aggregation with merkle root {:?}",
90-
// hex::encode(merkle_root)
91-
// );
92-
// merkle_path
93-
// }
94-
// aligned_sdk::aggregation_layer::ProofStatus::Invalid => {
95-
// panic!("Proof did pass merkle root verification");
96-
// }
97-
// aligned_sdk::aggregation_layer::ProofStatus::NotFound => {
98-
// panic!("Proof not found in the last 24 hours logs");
99-
// }
100-
// }
10182
}

0 commit comments

Comments
 (0)