mirror of
https://github.com/arnaucube/sonobe-playground.git
synced 2026-01-13 17:41:28 +01:00
Small refactor
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
|
|
||||||
use ark_bn254::Fr;
|
use ark_bn254::Fr;
|
||||||
use sonobe::frontend::circom::CircomFCircuit;
|
use sonobe::frontend::{circom::CircomFCircuit, FCircuit};
|
||||||
use sonobe::frontend::FCircuit;
|
|
||||||
|
|
||||||
const IVC_STEP_WIDTH: usize = 2;
|
const IVC_STEP_WIDTH: usize = 2;
|
||||||
const STEP_INPUT_WIDTH: usize = 256;
|
const STEP_INPUT_WIDTH: usize = 256;
|
||||||
|
|||||||
27
src/main.rs
27
src/main.rs
@@ -1,13 +1,9 @@
|
|||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use ark_bn254::Fr;
|
use scenario_config::ScenarioConfig;
|
||||||
use num_traits::identities::Zero;
|
|
||||||
use sonobe::FoldingScheme;
|
use sonobe::FoldingScheme;
|
||||||
use crate::{
|
|
||||||
circuit::create_circuit,
|
use crate::folding::{prepare_folding, verify_folding};
|
||||||
folding::{prepare_folding, verify_folding},
|
|
||||||
input::prepare_input,
|
|
||||||
};
|
|
||||||
|
|
||||||
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
@@ -19,19 +15,17 @@ fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
|||||||
mod circuit;
|
mod circuit;
|
||||||
mod folding;
|
mod folding;
|
||||||
mod input;
|
mod input;
|
||||||
|
mod scenario_config;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut rng = rand::rngs::OsRng;
|
let mut rng = rand::rngs::OsRng;
|
||||||
|
let config = ScenarioConfig::new();
|
||||||
|
|
||||||
let circuit = measure("Prepare circuit", create_circuit);
|
|
||||||
|
|
||||||
let start_ivc_state = vec![Fr::zero(); 2];
|
|
||||||
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
||||||
prepare_folding(&circuit, start_ivc_state.clone(), &mut rng)
|
prepare_folding(&config.circuit, config.start_ivc_state.clone(), &mut rng)
|
||||||
});
|
});
|
||||||
|
|
||||||
let num_steps = 5;
|
for (i, external_inputs_at_step) in config.input().iter().enumerate() {
|
||||||
for (i, external_inputs_at_step) in prepare_input()[..num_steps].iter().enumerate() {
|
|
||||||
measure(&format!("Nova::prove_step {i}"), || {
|
measure(&format!("Nova::prove_step {i}"), || {
|
||||||
folding
|
folding
|
||||||
.prove_step(rng, external_inputs_at_step.clone(), None)
|
.prove_step(rng, external_inputs_at_step.clone(), None)
|
||||||
@@ -40,6 +34,11 @@ fn main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
measure("Folding verification", || {
|
measure("Folding verification", || {
|
||||||
verify_folding(&folding, folding_vp, start_ivc_state, num_steps as u32)
|
verify_folding(
|
||||||
|
&folding,
|
||||||
|
folding_vp,
|
||||||
|
config.start_ivc_state,
|
||||||
|
config.num_steps as u32,
|
||||||
|
)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
27
src/scenario_config.rs
Normal file
27
src/scenario_config.rs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
use ark_bn254::Fr;
|
||||||
|
use num_traits::Zero;
|
||||||
|
use sonobe::frontend::circom::CircomFCircuit;
|
||||||
|
|
||||||
|
use crate::{circuit::create_circuit, input::prepare_input, measure};
|
||||||
|
|
||||||
|
pub struct ScenarioConfig {
|
||||||
|
pub num_steps: usize,
|
||||||
|
pub start_ivc_state: Vec<Fr>,
|
||||||
|
pub circuit: CircomFCircuit<Fr>,
|
||||||
|
input: Vec<Vec<Fr>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ScenarioConfig {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
num_steps: 5,
|
||||||
|
start_ivc_state: vec![Fr::zero(); 2],
|
||||||
|
circuit: measure("Prepare circuit", create_circuit),
|
||||||
|
input: measure("Prepare input", prepare_input),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn input(&self) -> &[Vec<Fr>] {
|
||||||
|
&self.input[..self.num_steps]
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user