verity_dp_zk_host/
generate_groth16_proof.rs

1use alloy_sol_types::SolValue;
2use anyhow::Context;
3use risc0_ethereum_contracts::groth16;
4use risc0_zkvm::{default_prover, ExecutorEnv, ProverOpts, VerifierContext};
5
6/// Generates a Groth16 proof given the input data for the zk circuit.
7/// Returns a tuple (seal, journal_output) where:
8/// - `seal` is the encoded proof representation
9/// - `journal_output` is the output of the zk proving process
10pub fn generate_groth16_proof(input: &[u8], guest_elf: &[u8]) -> (Vec<u8>, Vec<u8>) {
11    // Begin the proving process
12    let env = ExecutorEnv::builder().write_slice(&input).build().unwrap();
13    let receipt = default_prover()
14        .prove_with_ctx(
15            env,
16            &VerifierContext::default(),
17            guest_elf,
18            &ProverOpts::groth16(),
19        )
20        .unwrap()
21        .receipt;
22
23    // Encode the seal using the Groth16 encoding
24    let seal = groth16::encode(receipt.inner.groth16().unwrap().seal.clone()).unwrap();
25
26    // Extract and decode the journal from the receipt
27    let journal = receipt.journal.bytes.clone();
28    let journal_output = <Vec<u8>>::abi_decode(&journal, true)
29        .context("decoding journal data")
30        .unwrap();
31
32    (seal, journal_output)
33}