@ -0,0 +1,21 @@ |
|||||
|
use std::env::current_dir;
|
||||
|
use ark_bn254::Fr;
|
||||
|
use sonobe::frontend::circom::CircomFCircuit;
|
||||
|
use sonobe::frontend::FCircuit;
|
||||
|
|
||||
|
const IVC_STEP_WIDTH: usize = 2;
|
||||
|
const STEP_INPUT_WIDTH: usize = 256;
|
||||
|
|
||||
|
pub fn create_circuit() -> CircomFCircuit<Fr> {
|
||||
|
let root = current_dir().expect("Failed to get current directory");
|
||||
|
let circuit_file = root.join("circuit/grayscale_step.r1cs");
|
||||
|
let witness_generator_file = root.join("circuit/grayscale_step_js/grayscale_step.wasm");
|
||||
|
|
||||
|
let f_circuit_params = (
|
||||
|
circuit_file.into(),
|
||||
|
witness_generator_file.into(),
|
||||
|
IVC_STEP_WIDTH,
|
||||
|
STEP_INPUT_WIDTH,
|
||||
|
);
|
||||
|
CircomFCircuit::<Fr>::new(f_circuit_params).expect("Failed to create circuit")
|
||||
|
}
|
@ -0,0 +1,25 @@ |
|||||
|
use ark_bn254::{Bn254, constraints::GVar, Fr, G1Projective as G1};
|
||||
|
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
|
||||
|
use rand::rngs::OsRng;
|
||||
|
use sonobe::{
|
||||
|
commitment::{kzg::KZG, pedersen::Pedersen},
|
||||
|
folding::nova::{Nova, PreprocessorParam},
|
||||
|
FoldingScheme,
|
||||
|
frontend::circom::CircomFCircuit,
|
||||
|
transcript::poseidon::poseidon_canonical_config,
|
||||
|
};
|
||||
|
|
||||
|
pub type NovaFolding =
|
||||
|
Nova<G1, GVar, G2, GVar2, CircomFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
|
||||
|
|
||||
|
pub fn prepare_folding(
|
||||
|
circuit: &CircomFCircuit<Fr>,
|
||||
|
start_ivc_state: Vec<Fr>,
|
||||
|
rng: &mut OsRng,
|
||||
|
) -> NovaFolding {
|
||||
|
let nova_preprocess_params =
|
||||
|
PreprocessorParam::new(poseidon_canonical_config::<Fr>(), circuit.clone());
|
||||
|
let nova_params = NovaFolding::preprocess(&mut *rng, &nova_preprocess_params)
|
||||
|
.expect("Failed to preprocess Nova");
|
||||
|
NovaFolding::init(&nova_params, circuit.clone(), start_ivc_state).expect("Failed to init Nova")
|
||||
|
}
|
@ -0,0 +1,14 @@ |
|||||
|
use std::{fs::File, io::Read};
|
||||
|
|
||||
|
use ark_bn254::Fr;
|
||||
|
use ark_serialize::CanonicalDeserialize;
|
||||
|
|
||||
|
pub fn prepare_input() -> Vec<Vec<Fr>> {
|
||||
|
let mut file = File::open("circuit/input.bin").expect("Failed to open input file");
|
||||
|
let mut buffer = Vec::new();
|
||||
|
file.read_to_end(&mut buffer)
|
||||
|
.expect("Failed to read input file");
|
||||
|
|
||||
|
CanonicalDeserialize::deserialize_uncompressed(&mut buffer.as_slice())
|
||||
|
.expect("Failed to deserialize input")
|
||||
|
}
|
@ -1,3 +1,37 @@ |
|||||
|
use std::time::Instant;
|
||||
|
|
||||
|
use ark_bn254::Fr;
|
||||
|
use num_traits::identities::Zero;
|
||||
|
use sonobe::FoldingScheme;
|
||||
|
|
||||
|
use crate::{circuit::create_circuit, folding::prepare_folding, input::prepare_input};
|
||||
|
|
||||
|
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||
|
let start = Instant::now();
|
||||
|
let result = action();
|
||||
|
println!("{action_name}: {:?}", start.elapsed());
|
||||
|
result
|
||||
|
}
|
||||
|
|
||||
|
mod circuit;
|
||||
|
mod folding;
|
||||
|
mod input;
|
||||
|
|
||||
fn main() {
|
fn main() {
|
||||
println!("Hello, world!");
|
|
||||
|
let mut rng = rand::rngs::OsRng;
|
||||
|
|
||||
|
let circuit = measure("Prepare circuit", create_circuit);
|
||||
|
|
||||
|
let start_ivc_state = vec![Fr::zero(); 2];
|
||||
|
let mut folding = measure("Prepare folding", || {
|
||||
|
prepare_folding(&circuit, start_ivc_state, &mut rng)
|
||||
|
});
|
||||
|
|
||||
|
for (i, external_inputs_at_step) in prepare_input()[..5].iter().enumerate() {
|
||||
|
measure(&format!("Nova::prove_step {i}"), || {
|
||||
|
folding
|
||||
|
.prove_step(rng, external_inputs_at_step.clone(), None)
|
||||
|
.expect("Failed to prove step")
|
||||
|
});
|
||||
|
}
|
||||
}
|
}
|