Skip to content

Commit 1f912f0

Browse files
entropidelicjotabulaciosNicolasRampolditaturosatiMauroToscano
authored
feat(batcher client): add verify function in service manager to check proof merkle path (#367)
Co-authored-by: jotabulacios <[email protected]> Co-authored-by: NicolasRampoldi <[email protected]> Co-authored-by: Santos Rosati <[email protected]> Co-authored-by: Mauro Toscano <[email protected]> Co-authored-by: Uriel Mihura <[email protected]>
1 parent 39733ac commit 1f912f0

File tree

23 files changed

+2384
-584
lines changed

23 files changed

+2384
-584
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ cache
66
**/build
77
**/target
88
task_sender/test_examples/gnark_groth16_bn254_infinite_script/infinite_proofs/**
9+
batcher/aligned/batch_inclusion_responses/*
10+
**/aligned_verification_data

Makefile

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,15 @@ batcher/target/release/aligned:
185185

186186
batcher_send_sp1_task:
187187
@echo "Sending SP1 fibonacci task to Batcher..."
188-
@cd batcher/aligned/ && cargo run --release -- \
188+
@cd batcher/aligned/ && cargo run --release -- submit \
189189
--proving_system SP1 \
190190
--proof test_files/sp1/sp1_fibonacci.proof \
191191
--vm_program test_files/sp1/sp1_fibonacci-elf \
192192
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657
193193

194194
batcher_send_sp1_burst:
195195
@echo "Sending SP1 fibonacci task to Batcher..."
196-
@cd batcher/aligned/ && cargo run --release -- \
196+
@cd batcher/aligned/ && cargo run --release -- submit \
197197
--proving_system SP1 \
198198
--proof test_files/sp1/sp1_fibonacci.proof \
199199
--vm_program test_files/sp1/sp1_fibonacci-elf \
@@ -206,7 +206,7 @@ batcher_send_infinite_sp1:
206206

207207
batcher_send_plonk_bn254_task: batcher/target/release/aligned
208208
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
209-
@cd batcher/aligned/ && cargo run --release -- \
209+
@cd batcher/aligned/ && cargo run --release -- submit \
210210
--proving_system GnarkPlonkBn254 \
211211
--proof test_files/plonk_bn254/plonk.proof \
212212
--public_input test_files/plonk_bn254/plonk_pub_input.pub \
@@ -215,7 +215,7 @@ batcher_send_plonk_bn254_task: batcher/target/release/aligned
215215

216216
batcher_send_plonk_bn254_burst: batcher/target/release/aligned
217217
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
218-
@cd batcher/aligned/ && cargo run --release -- \
218+
@cd batcher/aligned/ && cargo run --release -- submit \
219219
--proving_system GnarkPlonkBn254 \
220220
--proof test_files/plonk_bn254/plonk.proof \
221221
--public_input test_files/plonk_bn254/plonk_pub_input.pub \
@@ -225,7 +225,7 @@ batcher_send_plonk_bn254_burst: batcher/target/release/aligned
225225

226226
batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
227227
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
228-
@cd batcher/aligned/ && cargo run --release -- \
228+
@cd batcher/aligned/ && cargo run --release -- submit \
229229
--proving_system GnarkPlonkBls12_381 \
230230
--proof test_files/plonk_bls12_381/plonk.proof \
231231
--public_input test_files/plonk_bls12_381/plonk_pub_input.pub \
@@ -234,7 +234,7 @@ batcher_send_plonk_bls12_381_task: batcher/target/release/aligned
234234

235235
batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
236236
@echo "Sending Groth16 BLS12-381 1!=0 task to Batcher..."
237-
@cd batcher/aligned/ && cargo run --release -- \
237+
@cd batcher/aligned/ && cargo run --release -- submit \
238238
--proving_system GnarkPlonkBls12_381 \
239239
--proof test_files/plonk_bls12_381/plonk.proof \
240240
--public_input test_files/plonk_bls12_381/plonk_pub_input.pub \
@@ -245,7 +245,7 @@ batcher_send_plonk_bls12_381_burst: batcher/target/release/aligned
245245

246246
batcher_send_groth16_bn254_task: batcher/target/release/aligned
247247
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
248-
@cd batcher/aligned/ && cargo run --release -- \
248+
@cd batcher/aligned/ && cargo run --release -- submit \
249249
--proving_system Groth16Bn254 \
250250
--proof test_files/groth16/ineq_1_groth16.proof \
251251
--public_input test_files/groth16/ineq_1_groth16.pub \
@@ -254,7 +254,7 @@ batcher_send_groth16_bn254_task: batcher/target/release/aligned
254254

255255
batcher_send_groth16_burst: batcher/target/release/aligned
256256
@echo "Sending Groth16Bn254 1!=0 task to Batcher..."
257-
@cd batcher/aligned/ && cargo run --release -- \
257+
@cd batcher/aligned/ && cargo run --release -- submit \
258258
--proving_system Groth16Bn254 \
259259
--proof test_files/groth16/ineq_1_groth16.proof \
260260
--public_input test_files/groth16/ineq_1_groth16.pub \
@@ -274,15 +274,15 @@ batcher_send_burst_groth16: batcher/target/release/aligned
274274

275275
batcher_send_halo2_ipa_task: batcher/target/release/aligned
276276
@echo "Sending Halo2 IPA 1!=0 task to Batcher..."
277-
@cd batcher/aligned/ && cargo run --release -- \
277+
@cd batcher/aligned/ && cargo run --release -- submit \
278278
--proving_system Halo2IPA \
279279
--proof test_files/halo2_ipa/proof.bin \
280280
--public_input test_files/halo2_ipa/pub_input.bin \
281281
--vk test_files/halo2_ipa/params.bin \
282282

283283
batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
284284
@echo "Sending Halo2 IPA 1!=0 task to Batcher..."
285-
@cd batcher/aligned/ && cargo run --release -- \
285+
@cd batcher/aligned/ && cargo run --release -- submit \
286286
--proving_system Halo2IPA \
287287
--proof test_files/halo2_ipa/proof.bin \
288288
--public_input test_files/halo2_ipa/pub_input.bin \
@@ -291,7 +291,7 @@ batcher_send_halo2_ipa_task_burst_5: batcher/target/release/aligned
291291

292292
batcher_send_halo2_kzg_task: batcher/target/release/aligned
293293
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
294-
@cd batcher/aligned/ && cargo run --release -- \
294+
@cd batcher/aligned/ && cargo run --release -- submit \
295295
--proving_system Halo2KZG \
296296
--proof test_files/halo2_kzg/proof.bin \
297297
--public_input test_files/halo2_kzg/pub_input.bin \
@@ -300,7 +300,7 @@ batcher_send_halo2_kzg_task: batcher/target/release/aligned
300300

301301
batcher_send_halo2_kzg_task_burst_5: batcher/target/release/aligned
302302
@echo "Sending Halo2 KZG 1!=0 task to Batcher..."
303-
@cd batcher/aligned/ && cargo run --release -- \
303+
@cd batcher/aligned/ && cargo run --release -- submit \
304304
--proving_system Halo2KZG \
305305
--proof test_files/halo2_kzg/proof.bin \
306306
--public_input test_files/halo2_kzg/pub_input.bin \

README.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ curl -L https://raw.githubusercontent.com/yetanotherco/aligned_layer/main/batche
4444
Send the proof with:
4545

4646
```bash
47-
aligned \
47+
aligned submit \
4848
--proving_system SP1 \
4949
--proof ~/.aligned/test_files/sp1_fibonacci.proof \
5050
--vm_program ~/.aligned/test_files/sp1_fibonacci-elf \
@@ -58,18 +58,19 @@ aligned \
5858
The SP1 proof needs the proof file and the vm program file.
5959

6060
```bash
61-
aligned \
61+
aligned submit \
6262
--proving_system <SP1|GnarkPlonkBn254|GnarkPlonkBls12_381|Groth16Bn254> \
6363
--proof <proof_file> \
6464
--vm_program <vm_program_file> \
6565
--conn wss://batcher.alignedlayer.com \
66-
--proof_generator_addr [proof_generator_addr]
66+
--proof_generator_addr [proof_generator_addr] \
67+
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path]
6768
```
6869

6970
**Example**
7071

7172
```bash
72-
aligned \
73+
aligned submit \
7374
--proving_system SP1 \
7475
--proof ./batcher/aligned/test_files/sp1/sp1_fibonacci.proof \
7576
--vm_program ./batcher/aligned/test_files/sp1/sp1_fibonacci-elf \
@@ -81,19 +82,20 @@ aligned \
8182
The GnarkPlonkBn254, GnarkPlonkBls12_381 and Groth16Bn254 proofs need the proof file, the public input file and the verification key file.
8283

8384
```bash
84-
aligned \
85+
aligned submit \
8586
--proving_system <SP1|GnarkPlonkBn254|GnarkPlonkBls12_381|Groth16Bn254> \
8687
--proof <proof_file> \
8788
--public_input <public_input_file> \
8889
--vk <verification_key_file> \
8990
--conn wss://batcher.alignedlayer.com \
90-
--proof_generator_addr [proof_generator_addr]
91+
--proof_generator_addr [proof_generator_addr] \
92+
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path]
9193
```
9294

9395
**Examples**:
9496

9597
```bash
96-
aligned \
98+
aligned submit \
9799
--proving_system GnarkPlonkBn254 \
98100
--proof ./batcher/aligned/test_files/plonk_bn254/plonk.proof \
99101
--public_input ./batcher/aligned/test_files/plonk_bn254/plonk_pub_input.pub \
@@ -102,7 +104,7 @@ aligned \
102104
```
103105

104106
```bash
105-
aligned \
107+
aligned submit \
106108
--proving_system GnarkPlonkBls12_381 \
107109
--proof ./batcher/aligned/test_files/plonk_bls12_381/plonk.proof \
108110
--public_input ./batcher/aligned/test_files/plonk_bls12_381/plonk_pub_input.pub \
@@ -111,14 +113,35 @@ aligned \
111113
```
112114

113115
```bash
114-
aligned \
116+
aligned submit \
115117
--proving_system Groth16Bn254 \
116118
--proof ./batcher/aligned/test_files/groth16/ineq_1_groth16.proof \
117119
--public_input ./batcher/aligned/test_files/groth16/ineq_1_groth16.pub \
118120
--vk ./batcher/aligned/test_files/groth16/ineq_1_groth16.vk \
119121
--conn wss://batcher.alignedlayer.com
120122
```
121123

124+
### Creating a transaction from the CLI to verify proof in Ethereum
125+
After running the commands of the previous section to submit proofs to the batcher, you will receive responses that will be written to disk in a JSON format inside the `<batch_inclusion_data_directory_path>`, for example `19f04bbb143af72105e2287935c320cc2aa9eeda0fe1f3ffabbe4e59cdbab691_0.json`. By default, the `batch_inclusion_data` directory will be created where the submit command is being executed, but you can specify it with the `<batch_inclusion_data_directory_path>` argument. To verify their inclusion in a batch, run the following command, replacing the `<path_to_batch_inclusion_data>` placeholder with the path to your response file, and `<private_key_store>` with the path to your ECDSA key store:
126+
127+
```bash
128+
aligned verify-proof-onchain \
129+
--aligned-verification-data <path_to_verification_data> \
130+
--private-key-store <path_to_private_key_store> \
131+
--eth_rpc_url <holesky_rpc_url> \
132+
--chain holesky
133+
```
134+
135+
As an example,
136+
137+
```bash
138+
aligned verify-proof-onchain \
139+
--aligned-verification-data 19f04bbb143af72105e2287935c320cc2aa9eeda0fe1f3ffabbe4e59cdbab691_0.json --private-key-store config-files/anvil.ecdsa.key.json \
140+
--eth_rpc_url https://ethereum-holesky-rpc.publicnode.com \
141+
--chain holesky
142+
143+
```
144+
122145
## Register as an Aligned operator in testnet
123146

124147
### Requirements
@@ -609,7 +632,8 @@ aligned \
609632
--proof <proof_file> \
610633
--public-input <public_input_file> \
611634
--vm_program <vm_program_file> \
612-
--proof_generator_addr [proof_generator_addr]
635+
--proof_generator_addr [proof_generator_addr] \
636+
--aligned_verification_data_path [aligned_verification_data_path]
613637
```
614638

615639
### Task Sender
@@ -1069,7 +1093,8 @@ cargo run --release -- \
10691093
--proof <proof_path> \
10701094
--vm_program <vm_program_path> \
10711095
--conn wss://batcher.alignedlayer.com \
1072-
--proof_generator_addr [proof_generator_addr]
1096+
--proof_generator_addr [proof_generator_addr] \
1097+
--aligned_verification_data_path [aligned_verification_data_path]
10731098
```
10741099

10751100
## FAQ

batcher/Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/aligned-batcher-lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2021"
55

66
[dependencies]
7-
alloy-primitives = { version = "0.7.4", features = ["serde"] }
7+
ethers = { version = "2.0", features = ["ws", "rustls"] }
88
anyhow = "1.0.83"
99
log = { version = "0.4.21"}
1010
serde = { version = "1.0.201", features = ["derive"] }

batcher/aligned-batcher-lib/src/types/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use std::fmt;
22

3-
use alloy_primitives::Address;
43
use anyhow::anyhow;
5-
use lambdaworks_crypto::merkle_tree::{merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend};
4+
use ethers::types::Address;
5+
use lambdaworks_crypto::merkle_tree::{
6+
merkle::MerkleTree, proof::Proof, traits::IsMerkleTreeBackend,
7+
};
68
use serde::{Deserialize, Serialize};
79
use sha3::{Digest, Keccak256};
810

@@ -90,7 +92,6 @@ impl IsMerkleTreeBackend for VerificationCommitmentBatch {
9092
hasher.update(leaf.proof_commitment);
9193
hasher.update(leaf.pub_input_commitment);
9294
hasher.update(leaf.proving_system_aux_data_commitment);
93-
hasher.update(leaf.pub_input_commitment);
9495
hasher.update(leaf.proof_generator_addr);
9596

9697
hasher.finalize().into()
@@ -111,6 +112,7 @@ pub struct BatchInclusionData {
111112
pub verification_data_commitment: VerificationDataCommitment,
112113
pub batch_merkle_root: [u8; 32],
113114
pub batch_inclusion_proof: Proof<[u8; 32]>,
115+
pub verification_data_batch_index: usize,
114116
}
115117

116118
impl BatchInclusionData {
@@ -127,6 +129,7 @@ impl BatchInclusionData {
127129
verification_data_commitment: verification_data_commitment.clone(),
128130
batch_merkle_root: batch_merkle_tree.root.clone(),
129131
batch_inclusion_proof,
132+
verification_data_batch_index,
130133
}
131134
}
132135
}

batcher/aligned-batcher/src/eth/abi/AlignedLayerServiceManager.json

Lines changed: 2019 additions & 1 deletion
Large diffs are not rendered by default.

batcher/aligned-batcher/src/eth/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct BatchVerified {
1818
}
1919

2020
pub type AlignedLayerServiceManager =
21-
AlignedLayerServiceManagerContract<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>;
21+
AlignedLayerServiceManagerContract<SignerMiddleware<Provider<Http>, Wallet<SigningKey>>>;
2222

2323
pub type BatchVerifiedEventStream<'s> = EventStream<
2424
's,
@@ -43,7 +43,7 @@ pub async fn get_contract(
4343
&ecdsa_config.private_key_store_path,
4444
&ecdsa_config.private_key_store_password,
4545
)?
46-
.with_chain_id(chain_id.as_u64());
46+
.with_chain_id(chain_id.as_u64());
4747

4848
let signer = Arc::new(SignerMiddleware::new(provider, wallet));
4949

batcher/aligned-batcher/src/gnark/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl From<&[u8]> for ListRef {
2323
fn from(v: &[u8]) -> Self {
2424
let len = v.len();
2525
let data = v.as_ptr().cast();
26-
ListRef{data, len}
26+
ListRef { data, len }
2727
}
2828
}
2929

batcher/aligned-batcher/src/halo2/ipa/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub fn verify_halo2_ipa(proof: &[u8], public_input: &[u8], verification_key: &[u
7171
>(
7272
&params, &vk, strategy, &[&[instances]], &mut transcript
7373
)
74-
.is_ok();
74+
.is_ok();
7575
}
7676
}
7777
}

0 commit comments

Comments
 (0)