verify_fibair/
verify_fibair.rs

1use clap::Parser;
2use eyre::Result;
3use openvm_benchmarks_prove::util::BenchmarkCli;
4use openvm_circuit::arch::instructions::program::DEFAULT_MAX_NUM_PUBLIC_VALUES;
5use openvm_native_circuit::NativeConfig;
6use openvm_native_compiler::conversion::CompilerOptions;
7use openvm_native_recursion::testing_utils::inner::build_verification_program;
8use openvm_sdk::{
9    config::{AppConfig, DEFAULT_APP_LOG_BLOWUP, DEFAULT_LEAF_LOG_BLOWUP},
10    prover::AppProver,
11    Sdk,
12};
13use openvm_stark_sdk::{
14    bench::run_with_metric_collection,
15    collect_airs_and_inputs,
16    config::{baby_bear_poseidon2::BabyBearPoseidon2Engine, FriParameters},
17    dummy_airs::fib_air::chip::FibonacciChip,
18    engine::StarkFriEngine,
19    openvm_stark_backend::Chip,
20};
21
22/// Benchmark of aggregation VM performance.
23/// Proofs:
24/// 1. Prove Fibonacci AIR.
25/// 2. Verify the proof of 1. by execution VM program in STARK VM.
26fn main() -> Result<()> {
27    let args = BenchmarkCli::parse();
28    let app_log_blowup = args.app_log_blowup.unwrap_or(DEFAULT_APP_LOG_BLOWUP);
29    let leaf_log_blowup = args.leaf_log_blowup.unwrap_or(DEFAULT_LEAF_LOG_BLOWUP);
30
31    let n = 1 << 15; // STARK to calculate (2 ** 15)th Fibonacci number.
32    let fib_chip = FibonacciChip::new(0, 1, n);
33    let engine = BabyBearPoseidon2Engine::new(
34        FriParameters::standard_with_100_bits_conjectured_security(app_log_blowup),
35    );
36
37    run_with_metric_collection("OUTPUT_PATH", || -> Result<()> {
38        // run_test tries to setup tracing, but it will be ignored since run_with_metric_collection already sets it.
39        let (fib_air, fib_input) = collect_airs_and_inputs!(fib_chip);
40        let vdata = engine.run_test(fib_air, fib_input).unwrap();
41        // Unlike other apps, this "app" does not have continuations enabled.
42        let app_fri_params =
43            FriParameters::standard_with_100_bits_conjectured_security(leaf_log_blowup);
44        let mut app_vm_config = NativeConfig::aggregation(
45            DEFAULT_MAX_NUM_PUBLIC_VALUES,
46            app_fri_params.max_constraint_degree().min(7),
47        );
48        app_vm_config.system.profiling = args.profiling;
49
50        let compiler_options = CompilerOptions::default();
51        let app_config = AppConfig {
52            app_fri_params: app_fri_params.into(),
53            app_vm_config,
54            leaf_fri_params: app_fri_params.into(),
55            compiler_options,
56        };
57        let (program, input_stream) = build_verification_program(vdata, compiler_options);
58        let sdk = Sdk::new();
59        let app_pk = sdk.app_keygen(app_config)?;
60        let app_vk = app_pk.get_app_vk();
61        let committed_exe = sdk.commit_app_exe(app_fri_params, program.into())?;
62        let prover = AppProver::<_, BabyBearPoseidon2Engine>::new(app_pk.app_vm_pk, committed_exe)
63            .with_program_name("verify_fibair");
64        let proof = prover.generate_app_proof_without_continuations(input_stream.into());
65        sdk.verify_app_proof_without_continuations(&app_vk, &proof)?;
66        Ok(())
67    })?;
68    Ok(())
69}