2024-11-08 12:23:55 +01:00
|
|
|
use plonky2::plonk::circuit_data::CircuitConfig;
|
|
|
|
|
use plonky2::plonk::config::GenericConfig;
|
|
|
|
|
use plonky2::iop::witness::PartialWitness;
|
|
|
|
|
use plonky2::plonk::circuit_builder::CircuitBuilder;
|
|
|
|
|
use anyhow::Result;
|
|
|
|
|
use std::time::Instant;
|
|
|
|
|
|
2024-11-12 13:06:28 +01:00
|
|
|
use proof_input::json::import_circ_input_from_json;
|
2024-11-08 12:23:55 +01:00
|
|
|
use codex_plonky2_circuits::circuits::sample_cells::{SampleCircuit, SampleCircuitInput};
|
|
|
|
|
use codex_plonky2_circuits::circuits::params::CircuitParams;
|
|
|
|
|
use proof_input::params::{D, C, F};
|
|
|
|
|
|
|
|
|
|
fn main() -> Result<()> {
|
|
|
|
|
// Load the parameters from environment variables
|
2024-11-14 10:31:32 +01:00
|
|
|
let circuit_params = CircuitParams::from_env()?;
|
2024-11-08 12:23:55 +01:00
|
|
|
|
|
|
|
|
// Read the witness from input.json
|
2024-11-14 10:31:32 +01:00
|
|
|
let circ_input: SampleCircuitInput<F, D> = import_circ_input_from_json("input.json")?;
|
2024-11-08 12:23:55 +01:00
|
|
|
println!("Witness imported from input.json");
|
|
|
|
|
|
|
|
|
|
// Create the circuit
|
|
|
|
|
let config = CircuitConfig::standard_recursion_config();
|
|
|
|
|
let mut builder = CircuitBuilder::<F, D>::new(config);
|
|
|
|
|
let circ = SampleCircuit::new(circuit_params);
|
|
|
|
|
let mut targets = circ.sample_slot_circuit(&mut builder);
|
|
|
|
|
|
|
|
|
|
// Create a PartialWitness and assign
|
|
|
|
|
let mut pw = PartialWitness::new();
|
2024-11-14 10:31:32 +01:00
|
|
|
circ.sample_slot_assign_witness(&mut pw, &mut targets, circ_input);
|
2024-11-08 12:23:55 +01:00
|
|
|
|
|
|
|
|
// Build the circuit
|
|
|
|
|
let build_time = Instant::now();
|
|
|
|
|
let data = builder.build::<C>();
|
|
|
|
|
println!("Build time: {:?}", build_time.elapsed());
|
|
|
|
|
println!("Circuit size (degree bits): {:?}", data.common.degree_bits());
|
|
|
|
|
|
|
|
|
|
// Prove the circuit with the assigned witness
|
|
|
|
|
let start_time = Instant::now();
|
|
|
|
|
let proof_with_pis = data.prove(pw)?;
|
|
|
|
|
println!("Proving time: {:?}", start_time.elapsed());
|
|
|
|
|
|
2024-11-14 10:31:32 +01:00
|
|
|
//TODO: write proof to json file
|
2024-11-08 12:23:55 +01:00
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|