|
| 1 | +use zkaleido::{ProofType, ZkVmInputResult, ZkVmProgram, ZkVmProgramPerf}; |
| 2 | + |
| 3 | +use crate::input::Risc0Groth16VerifyInput; |
| 4 | + |
| 5 | +pub struct Risc0Groth16VerifyProgram; |
| 6 | + |
| 7 | +impl ZkVmProgram for Risc0Groth16VerifyProgram { |
| 8 | + type Input = Risc0Groth16VerifyInput; |
| 9 | + type Output = bool; |
| 10 | + |
| 11 | + fn name() -> String { |
| 12 | + "risc0_groth16_verify".to_string() |
| 13 | + } |
| 14 | + |
| 15 | + fn proof_type() -> zkaleido::ProofType { |
| 16 | + ProofType::Core |
| 17 | + } |
| 18 | + |
| 19 | + fn prepare_input<'a, B>(input: &'a Self::Input) -> ZkVmInputResult<B::Input> |
| 20 | + where |
| 21 | + B: zkaleido::ZkVmInputBuilder<'a>, |
| 22 | + { |
| 23 | + B::new().write_serde(input)?.build() |
| 24 | + } |
| 25 | + |
| 26 | + fn process_output<H>( |
| 27 | + public_values: &zkaleido::PublicValues, |
| 28 | + ) -> zkaleido::ZkVmResult<Self::Output> |
| 29 | + where |
| 30 | + H: zkaleido::ZkVmHost, |
| 31 | + { |
| 32 | + H::extract_serde_public_output(public_values) |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +impl ZkVmProgramPerf for Risc0Groth16VerifyProgram {} |
| 37 | + |
| 38 | +#[cfg(test)] |
| 39 | +mod tests { |
| 40 | + use std::sync::Arc; |
| 41 | + |
| 42 | + use zkaleido::ZkVmProgram; |
| 43 | + use zkaleido_native_adapter::{NativeHost, NativeMachine}; |
| 44 | + |
| 45 | + use crate::{ |
| 46 | + input::Risc0Groth16VerifyInput, process_groth16_verify_risc0, |
| 47 | + program::Risc0Groth16VerifyProgram, |
| 48 | + }; |
| 49 | + |
| 50 | + fn get_native_host() -> NativeHost { |
| 51 | + NativeHost { |
| 52 | + process_proof: Arc::new(Box::new(move |zkvm: &NativeMachine| { |
| 53 | + process_groth16_verify_risc0(zkvm); |
| 54 | + Ok(()) |
| 55 | + })), |
| 56 | + } |
| 57 | + } |
| 58 | + |
| 59 | + #[test] |
| 60 | + fn test_native() { |
| 61 | + let input = Risc0Groth16VerifyInput::load(); |
| 62 | + let host = get_native_host(); |
| 63 | + let receipt = Risc0Groth16VerifyProgram::prove(&input, &host).unwrap(); |
| 64 | + let risc0_verified = |
| 65 | + Risc0Groth16VerifyProgram::process_output::<NativeHost>(receipt.public_values()) |
| 66 | + .unwrap(); |
| 67 | + |
| 68 | + assert!(risc0_verified); |
| 69 | + } |
| 70 | +} |
0 commit comments