Skip to content

Commit 47f77eb

Browse files
1201 make risc0 public input optional (#1204)
Co-authored-by: Mariano Nicolini <[email protected]>
1 parent fbecccb commit 47f77eb

File tree

18 files changed

+3835
-17
lines changed

18 files changed

+3835
-17
lines changed

Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,16 @@ batcher_send_risc0_task:
307307
--rpc_url $(RPC_URL) \
308308
--network $(NETWORK)
309309

310+
batcher_send_risc0_task_no_pub_input:
311+
@echo "Sending Risc0 fibonacci task to Batcher..."
312+
@cd batcher/aligned/ && cargo run --release -- submit \
313+
--proving_system Risc0 \
314+
--proof ../../scripts/test_files/risc_zero/no_public_inputs/risc_zero_no_pub_input.proof \
315+
--vm_program ../../scripts/test_files/risc_zero/no_public_inputs/no_pub_input_id.bin \
316+
--proof_generator_addr 0x66f9664f97F2b50F62D13eA064982f936dE76657 \
317+
--rpc_url $(RPC_URL) \
318+
--payment_service_addr $(BATCHER_PAYMENTS_CONTRACT_ADDRESS)
319+
310320
batcher_send_risc0_burst:
311321
@echo "Sending Risc0 fibonacci task to Batcher..."
312322
@cd batcher/aligned/ && cargo run --release -- submit \
@@ -502,6 +512,11 @@ generate_sp1_fibonacci_proof:
502512
@mv scripts/test_files/sp1/fibonacci_proof_generator/script/sp1_fibonacci.proof scripts/test_files/sp1/
503513
@echo "Fibonacci proof and ELF generated in scripts/test_files/sp1 folder"
504514

515+
generate_risc_zero_empty_journal_proof:
516+
@cd scripts/test_files/risc_zero/no_public_inputs && RUST_LOG=info cargo run --release
517+
@echo "Fibonacci proof and ELF with empty journal generated in scripts/test_files/risc_zero/no_public_inputs folder"
518+
519+
505520
__RISC_ZERO_FFI__: ##
506521
build_risc_zero_macos:
507522
@cd operator/risc_zero/lib && cargo build $(RELEASE_FLAG)

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,23 @@ fn verify_internal(verification_data: &VerificationData) -> bool {
2121
false
2222
}
2323
ProvingSystemId::Risc0 => {
24-
if let (Some(image_id_slice), Some(pub_input)) = (
25-
&verification_data.vm_program_code,
26-
&verification_data.pub_input,
27-
) {
28-
let mut image_id = [0u8; 32];
29-
image_id.copy_from_slice(image_id_slice.as_slice());
30-
return verify_risc_zero_proof(
31-
verification_data.proof.as_slice(),
32-
&image_id,
33-
pub_input,
24+
let Some(image_id_slice) = &verification_data.vm_program_code else {
25+
warn!(
26+
"Trying to verify Risc0 proof but image id was not provided. Returning false"
3427
);
35-
}
28+
return false;
29+
};
3630

37-
warn!("Trying to verify Risc0 proof but image id or public input was not provided. Returning false");
38-
false
31+
// Risc0 can have 0 public input. In which case we supply an empty Vec<u8>.
32+
let pub_input = verification_data.pub_input.clone().unwrap_or_default();
33+
34+
let mut image_id = [0u8; 32];
35+
image_id.copy_from_slice(image_id_slice.as_slice());
36+
return verify_risc_zero_proof(
37+
verification_data.proof.as_slice(),
38+
&image_id,
39+
&pub_input,
40+
);
3941
}
4042
ProvingSystemId::GnarkPlonkBls12_381
4143
| ProvingSystemId::GnarkPlonkBn254

batcher/aligned/src/main.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,10 +506,13 @@ fn verification_data_from_args(args: &SubmitArgs) -> Result<VerificationData, Su
506506
"--vm_program",
507507
args.vm_program_code_file_name.clone(),
508508
)?);
509-
pub_input = Some(read_file_option(
510-
"--public_input",
511-
args.pub_input_file_name.clone(),
512-
)?);
509+
510+
// Risc0 and have zero or none public inputs
511+
pub_input = args
512+
.pub_input_file_name
513+
.clone()
514+
.map(read_file)
515+
.transpose()?;
513516
}
514517
ProvingSystemId::GnarkPlonkBls12_381
515518
| ProvingSystemId::GnarkPlonkBn254

docs/3_guides/0_submitting_proofs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ risc0-zkvm = { git = "https://github.com/risc0/risc0", tag = "v1.0.1", default-f
177177
"prove",
178178
] }
179179
```
180+
- Note: In Risc0 verification `--pub_input` contains the bytes of the `receipt.journal.bytes` which contains both the public input (`env::read()`) and public output (`env::commit()`) values of a program executed in the Risc0 VM. If your Risc0 program contains public outputs, but no public inputs you still need to submit the serialized `receipt.journal.bytes` with your proof using the Aligned CLI for your proof to be verified.
180181
181182
**Example**
182183
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Cargo build
2+
**/target
3+
4+
# Cargo config
5+
.cargo
6+
7+
# MacOS nuisances
8+
.DS_Store

0 commit comments

Comments
 (0)