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:
4
Makefile
4
Makefile
@@ -11,3 +11,7 @@ prepare-circuit: clear-circuit-artifacts # Build the circuit artifacts
|
|||||||
.PHONY: clear-circuit-artifacts
|
.PHONY: clear-circuit-artifacts
|
||||||
clear-circuit-artifacts: # Clear the circuit artifacts
|
clear-circuit-artifacts: # Clear the circuit artifacts
|
||||||
@rm -rf circuit/grayscale_step_js circuit/grayscale_step.r1cs
|
@rm -rf circuit/grayscale_step_js circuit/grayscale_step.r1cs
|
||||||
|
|
||||||
|
.PHONY: run
|
||||||
|
run: # Run the experiment
|
||||||
|
@cargo run --release
|
||||||
@@ -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_crypto_primitives::sponge::poseidon::PoseidonConfig;
|
||||||
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
|
use ark_grumpkin::{constraints::GVar as GVar2, Projective as G2};
|
||||||
use sonobe::{
|
use sonobe::{
|
||||||
commitment::{kzg::KZG, pedersen::Pedersen},
|
commitment::{kzg::KZG, pedersen::Pedersen},
|
||||||
folding::{hypernova::HyperNova, nova::Nova},
|
folding::{hypernova::HyperNova, nova::Nova},
|
||||||
FoldingScheme,
|
|
||||||
frontend::circom::CircomFCircuit,
|
frontend::circom::CircomFCircuit,
|
||||||
transcript::poseidon::poseidon_canonical_config,
|
transcript::poseidon::poseidon_canonical_config,
|
||||||
|
FoldingScheme,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type NovaFolding =
|
pub type NovaFolding =
|
||||||
@@ -24,11 +24,20 @@ pub type HyperNovaFolding = HyperNova<
|
|||||||
false,
|
false,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
pub struct StepInput<OtherInstances> {
|
||||||
|
pub external_inputs: Vec<Fr>,
|
||||||
|
pub other_instances: Option<OtherInstances>,
|
||||||
|
}
|
||||||
|
|
||||||
pub trait FoldingSchemeExt: FoldingScheme<G1, G2, CircomFCircuit<Fr>> {
|
pub trait FoldingSchemeExt: FoldingScheme<G1, G2, CircomFCircuit<Fr>> {
|
||||||
fn prepreprocess(
|
fn prepreprocess(
|
||||||
poseidon_config: PoseidonConfig<Fr>,
|
poseidon_config: PoseidonConfig<Fr>,
|
||||||
circuit: CircomFCircuit<Fr>,
|
circuit: CircomFCircuit<Fr>,
|
||||||
) -> Self::PreprocessorParam;
|
) -> Self::PreprocessorParam;
|
||||||
|
|
||||||
|
fn transform_inputs(
|
||||||
|
full_input: Vec<Vec<Fr>>,
|
||||||
|
) -> impl Iterator<Item = StepInput<Self::MultiCommittedInstanceWithWitness>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FoldingSchemeExt for NovaFolding {
|
impl FoldingSchemeExt for NovaFolding {
|
||||||
@@ -38,6 +47,15 @@ impl FoldingSchemeExt for NovaFolding {
|
|||||||
) -> Self::PreprocessorParam {
|
) -> Self::PreprocessorParam {
|
||||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
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 {
|
impl FoldingSchemeExt for HyperNovaFolding {
|
||||||
@@ -47,6 +65,15 @@ impl FoldingSchemeExt for HyperNovaFolding {
|
|||||||
) -> Self::PreprocessorParam {
|
) -> Self::PreprocessorParam {
|
||||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
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>(
|
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 scenario_config::ScenarioConfig;
|
||||||
|
|
||||||
use crate::folding::{
|
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 {
|
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
let result = action();
|
let result = action();
|
||||||
@@ -13,13 +19,7 @@ fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
|||||||
result
|
result
|
||||||
}
|
}
|
||||||
|
|
||||||
mod circuit;
|
|
||||||
mod folding;
|
|
||||||
mod input;
|
|
||||||
mod scenario_config;
|
|
||||||
|
|
||||||
fn scenario<FS: FoldingSchemeExt>(config: ScenarioConfig, rng: &mut impl rand::RngCore) {
|
fn scenario<FS: FoldingSchemeExt>(config: ScenarioConfig, rng: &mut impl rand::RngCore) {
|
||||||
|
|
||||||
// ============== FOLDING PREPARATION ==========================================================
|
// ============== FOLDING PREPARATION ==========================================================
|
||||||
|
|
||||||
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
||||||
@@ -28,10 +28,15 @@ fn scenario<FS: FoldingSchemeExt>(config: ScenarioConfig, rng: &mut impl rand::R
|
|||||||
|
|
||||||
// ============== FOLDING ======================================================================
|
// ============== 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}"), || {
|
measure(&format!("Prove_step {i}"), || {
|
||||||
folding
|
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")
|
.expect("Failed to prove step")
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -54,6 +59,7 @@ fn main() {
|
|||||||
|
|
||||||
println!("========== Nova folding scheme ==========");
|
println!("========== Nova folding scheme ==========");
|
||||||
scenario::<NovaFolding>(config.clone(), &mut rng);
|
scenario::<NovaFolding>(config.clone(), &mut rng);
|
||||||
|
|
||||||
println!("========== HyperNova folding scheme ==========");
|
println!("========== HyperNova folding scheme ==========");
|
||||||
scenario::<HyperNovaFolding>(config, &mut rng);
|
scenario::<HyperNovaFolding>(config, &mut rng);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user