mirror of
https://github.com/arnaucube/sonobe-playground.git
synced 2026-01-14 01:51:29 +01:00
Prepare for Hypernova
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
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 rand::rngs::OsRng;
|
||||
use sonobe::{
|
||||
commitment::{kzg::KZG, pedersen::Pedersen},
|
||||
folding::nova::{Nova, PreprocessorParam},
|
||||
folding::{hypernova::HyperNova, nova::Nova},
|
||||
frontend::circom::CircomFCircuit,
|
||||
transcript::poseidon::poseidon_canonical_config,
|
||||
FoldingScheme,
|
||||
@@ -11,27 +12,63 @@ use sonobe::{
|
||||
|
||||
pub type NovaFolding =
|
||||
Nova<G1, GVar, G2, GVar2, CircomFCircuit<Fr>, KZG<'static, Bn254>, Pedersen<G2>, false>;
|
||||
pub type NovaVerifierParam =
|
||||
<NovaFolding as FoldingScheme<G1, G2, CircomFCircuit<Fr>>>::VerifierParam;
|
||||
pub type HyperNovaFolding = HyperNova<
|
||||
G1,
|
||||
GVar,
|
||||
G2,
|
||||
GVar2,
|
||||
CircomFCircuit<Fr>,
|
||||
KZG<'static, Bn254>,
|
||||
Pedersen<G2>,
|
||||
1,
|
||||
1,
|
||||
false,
|
||||
>;
|
||||
|
||||
pub fn prepare_folding(
|
||||
pub type VerifierParam<FS> = <FS as FoldingScheme<G1, G2, CircomFCircuit<Fr>>>::VerifierParam;
|
||||
|
||||
pub trait FoldingSchemeExt: FoldingScheme<G1, G2, CircomFCircuit<Fr>> {
|
||||
fn prepreprocess(
|
||||
poseidon_config: PoseidonConfig<Fr>,
|
||||
circuit: CircomFCircuit<Fr>,
|
||||
) -> Self::PreprocessorParam;
|
||||
}
|
||||
|
||||
impl FoldingSchemeExt for NovaFolding {
|
||||
fn prepreprocess(
|
||||
poseidon_config: PoseidonConfig<Fr>,
|
||||
circuit: CircomFCircuit<Fr>,
|
||||
) -> Self::PreprocessorParam {
|
||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
||||
}
|
||||
}
|
||||
|
||||
impl FoldingSchemeExt for HyperNovaFolding {
|
||||
fn prepreprocess(
|
||||
poseidon_config: PoseidonConfig<Fr>,
|
||||
circuit: CircomFCircuit<Fr>,
|
||||
) -> Self::PreprocessorParam {
|
||||
Self::PreprocessorParam::new(poseidon_config, circuit)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_folding<FS: FoldingSchemeExt>(
|
||||
circuit: &CircomFCircuit<Fr>,
|
||||
start_ivc_state: Vec<Fr>,
|
||||
rng: &mut OsRng,
|
||||
) -> (NovaFolding, NovaVerifierParam) {
|
||||
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");
|
||||
let folding = NovaFolding::init(&nova_params, circuit.clone(), start_ivc_state)
|
||||
.expect("Failed to init Nova");
|
||||
) -> (FS, FS::VerifierParam) {
|
||||
let preprocess_params = FS::prepreprocess(poseidon_canonical_config::<Fr>(), circuit.clone());
|
||||
let params =
|
||||
FS::preprocess(&mut *rng, &preprocess_params).expect("Failed to preprocess folding scheme");
|
||||
let folding =
|
||||
FS::init(¶ms, circuit.clone(), start_ivc_state).expect("Failed to init folding scheme");
|
||||
|
||||
(folding, nova_params.1)
|
||||
(folding, params.1)
|
||||
}
|
||||
|
||||
pub fn verify_folding(
|
||||
folding: &NovaFolding,
|
||||
folding_vp: NovaVerifierParam,
|
||||
folding_vp: VerifierParam<NovaFolding>,
|
||||
start_ivc_state: Vec<Fr>,
|
||||
num_steps: u32,
|
||||
) {
|
||||
|
||||
33
src/main.rs
33
src/main.rs
@@ -3,7 +3,9 @@ use std::time::Instant;
|
||||
use scenario_config::ScenarioConfig;
|
||||
use sonobe::FoldingScheme;
|
||||
|
||||
use crate::folding::{prepare_folding, verify_folding};
|
||||
use crate::folding::{
|
||||
prepare_folding, verify_folding, FoldingSchemeExt, HyperNovaFolding, NovaFolding,
|
||||
};
|
||||
|
||||
fn measure<T, Action: FnOnce() -> T>(action_name: &str, action: Action) -> T {
|
||||
let start = Instant::now();
|
||||
@@ -17,28 +19,35 @@ mod folding;
|
||||
mod input;
|
||||
mod scenario_config;
|
||||
|
||||
fn main() {
|
||||
fn scenario<FS: FoldingSchemeExt>() {
|
||||
let mut rng = rand::rngs::OsRng;
|
||||
let config = ScenarioConfig::new();
|
||||
|
||||
let (mut folding, folding_vp) = measure("Prepare folding", || {
|
||||
prepare_folding(&config.circuit, config.start_ivc_state.clone(), &mut rng)
|
||||
prepare_folding::<FS>(&config.circuit, config.start_ivc_state.clone(), &mut rng)
|
||||
});
|
||||
|
||||
for (i, external_inputs_at_step) in config.input().iter().enumerate() {
|
||||
measure(&format!("Nova::prove_step {i}"), || {
|
||||
measure(&format!("Prove_step {i}"), || {
|
||||
folding
|
||||
.prove_step(rng, external_inputs_at_step.clone(), None)
|
||||
.expect("Failed to prove step")
|
||||
});
|
||||
}
|
||||
|
||||
measure("Folding verification", || {
|
||||
verify_folding(
|
||||
&folding,
|
||||
folding_vp,
|
||||
config.start_ivc_state,
|
||||
config.num_steps as u32,
|
||||
)
|
||||
});
|
||||
// measure("Folding verification", || {
|
||||
// verify_folding(
|
||||
// &folding,
|
||||
// folding_vp,
|
||||
// config.start_ivc_state,
|
||||
// config.num_steps as u32,
|
||||
// )
|
||||
// });
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("========== Nova folding scheme ==========");
|
||||
scenario::<NovaFolding>();
|
||||
println!("========== HyperNova folding scheme ==========");
|
||||
scenario::<HyperNovaFolding>();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user