mirror of
https://github.com/arnaucube/sonobe-playground.git
synced 2026-01-13 17:41:28 +01:00
Prepare for Hypernova
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -3325,6 +3325,9 @@ name = "playground"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ark-bn254 0.4.0",
|
||||
"ark-crypto-primitives",
|
||||
"ark-ec 0.4.1",
|
||||
"ark-ff 0.4.1",
|
||||
"ark-groth16",
|
||||
"ark-grumpkin",
|
||||
"ark-serialize 0.4.1",
|
||||
|
||||
@@ -6,12 +6,15 @@ authors = ["Piotr Mikołajczyk <piomiko41@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
ark-bn254 = { version = "^0.4.0", features = ["r1cs"] }
|
||||
ark-crypto-primitives = { version = "0.4.0" }
|
||||
ark-ec = { version = "0.4.0" }
|
||||
ark-ff = { version = "0.4.0" }
|
||||
ark-grumpkin = { version = "0.4.0", features = ["r1cs"] }
|
||||
ark-groth16 = { version = "0.4.0", features = ["parallel"] }
|
||||
ark-serialize = { version = "0.4.0" }
|
||||
rand = { version = "0.8.5" }
|
||||
sonobe = { git = "https://github.com/privacy-scaling-explorations/sonobe", rev = "f1d82418ba047cf90805f2d0505370246df24d68", package = "folding-schemes" }
|
||||
num-traits = "0.2.15"
|
||||
num-traits = { version = "0.2.15" }
|
||||
|
||||
[patch.crates-io]
|
||||
ark-r1cs-std = { git = "https://github.com/winderica/r1cs-std", branch = "cherry-pick" }
|
||||
|
||||
@@ -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