mirror of
https://github.com/arnaucube/sonobe-playground.git
synced 2026-01-14 01:51:29 +01:00
Common inputs
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use ark_bn254::{Bn254, constraints::GVar, Fr, G1Projective as G1};
|
||||
use ark_bn254::{constraints::GVar, Bn254, Fr, G1Projective as G1};
|
||||
use ark_crypto_primitives::sponge::poseidon::PoseidonConfig;
|
||||
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
|
||||
use sonobe::{
|
||||
commitment::{kzg::KZG, pedersen::Pedersen},
|
||||
folding::{hypernova::HyperNova, nova::Nova},
|
||||
FoldingScheme,
|
||||
frontend::circom::CircomFCircuit,
|
||||
transcript::poseidon::poseidon_canonical_config,
|
||||
FoldingScheme,
|
||||
};
|
||||
|
||||
pub type NovaFolding =
|
||||
@@ -24,11 +24,20 @@ pub type HyperNovaFolding = HyperNova<
|
||||
false,
|
||||
>;
|
||||
|
||||
pub struct StepInput<OtherInstances> {
|
||||
pub external_inputs: Vec<Fr>,
|
||||
pub other_instances: Option<OtherInstances>,
|
||||
}
|
||||
|
||||
pub trait FoldingSchemeExt: FoldingScheme<G1, G2, CircomFCircuit<Fr>> {
|
||||
fn prepreprocess(
|
||||
poseidon_config: PoseidonConfig<Fr>,
|
||||
circuit: CircomFCircuit<Fr>,
|
||||
) -> Self::PreprocessorParam;
|
||||
|
||||
fn transform_inputs(
|
||||
full_input: Vec<Vec<Fr>>,
|
||||
) -> impl Iterator<Item = StepInput<Self::MultiCommittedInstanceWithWitness>>;
|
||||
}
|
||||
|
||||
impl FoldingSchemeExt for NovaFolding {
|
||||
@@ -38,6 +47,15 @@ impl FoldingSchemeExt for NovaFolding {
|
||||
) -> Self::PreprocessorParam {
|
||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
||||
}
|
||||
|
||||
fn transform_inputs(
|
||||
full_input: Vec<Vec<Fr>>,
|
||||
) -> impl Iterator<Item = StepInput<Self::MultiCommittedInstanceWithWitness>> {
|
||||
full_input.into_iter().map(|input| StepInput {
|
||||
external_inputs: input,
|
||||
other_instances: None,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl FoldingSchemeExt for HyperNovaFolding {
|
||||
@@ -47,6 +65,15 @@ impl FoldingSchemeExt for HyperNovaFolding {
|
||||
) -> Self::PreprocessorParam {
|
||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
||||
}
|
||||
|
||||
fn transform_inputs(
|
||||
full_input: Vec<Vec<Fr>>,
|
||||
) -> impl Iterator<Item = StepInput<Self::MultiCommittedInstanceWithWitness>> {
|
||||
full_input.into_iter().map(|input| StepInput {
|
||||
external_inputs: input,
|
||||
other_instances: Some((vec![], vec![])),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_folding<FS: FoldingSchemeExt>(
|
||||
|
||||
24
src/main.rs
24
src/main.rs
@@ -3,9 +3,15 @@ use std::time::Instant;
|
||||
use scenario_config::ScenarioConfig;
|
||||
|
||||
use crate::folding::{
|
||||
prepare_folding, verify_folding, FoldingSchemeExt, HyperNovaFolding, NovaFolding,
|
||||
FoldingSchemeExt, HyperNovaFolding, NovaFolding, prepare_folding, verify_folding,
|
||||
};
|
||||
|
||||
mod circuit;
|
||||
|
||||
mod folding;
|
||||
mod input;
|
||||
mod scenario_config;
|
||||
|
||||
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||
let start = Instant::now();
|
||||
let result = action();
|
||||
@@ -13,13 +19,7 @@ fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||
result
|
||||
}
|
||||
|
||||
mod circuit;
|
||||
mod folding;
|
||||
mod input;
|
||||
mod scenario_config;
|
||||
|
||||
fn scenario<FS: FoldingSchemeExt>(config: ScenarioConfig, rng: &mut impl rand::RngCore) {
|
||||
|
||||
// ============== FOLDING PREPARATION ==========================================================
|
||||
|
||||
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
||||
@@ -28,10 +28,15 @@ fn scenario<FS: FoldingSchemeExt>(config: ScenarioConfig, rng: &mut impl rand::R
|
||||
|
||||
// ============== FOLDING ======================================================================
|
||||
|
||||
for (i, external_inputs_at_step) in config.input().iter().enumerate() {
|
||||
let input = config.input().to_vec();
|
||||
for (i, step_input) in FS::transform_inputs(input).enumerate() {
|
||||
measure(&format!("Prove_step {i}"), || {
|
||||
folding
|
||||
.prove_step(&mut *rng, external_inputs_at_step.clone(), None)
|
||||
.prove_step(
|
||||
&mut *rng,
|
||||
step_input.external_inputs,
|
||||
step_input.other_instances,
|
||||
)
|
||||
.expect("Failed to prove step")
|
||||
});
|
||||
}
|
||||
@@ -54,6 +59,7 @@ fn main() {
|
||||
|
||||
println!("========== Nova folding scheme ==========");
|
||||
scenario::<NovaFolding>(config.clone(), &mut rng);
|
||||
|
||||
println!("========== HyperNova folding scheme ==========");
|
||||
scenario::<HyperNovaFolding>(config, &mut rng);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user