Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Feat plonk snark #554

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/snark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ log = { version = "0.4", features = ["std"] }
pasta_curves = "0.5"

# for load r1cs
bellman_ce = { git = "https://github.com/matter-labs/bellman", version = "0.3.2" }
bellman_ce = { version = "0.3.2", features = ["plonk"], git = "https://github.com/matter-labs/bellman.git", rev = "5520aa2" }
rand = "0.4.6"
bellpepper-core = "0.4.0"
byteorder = "1.4.3"
crypto-bigint = { version = "0.5.2", features = ["serde"] }
Expand Down
11 changes: 11 additions & 0 deletions crates/snark/src/circuit/bellman.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! implement bellman proof system for circuit, this is useful for plonk and growth16

use super::Circuit;
use super::TrivialCircuit;
use crate::prelude::bellman;
use crate::prelude::bellman::pairing::Engine;
use crate::prelude::bellman::ConstraintSystem;
Expand Down Expand Up @@ -54,3 +55,13 @@ where E::Fr: ff::PrimeField
Ok(())
}
}


impl<E: Engine> bellman::Circuit<E> for TrivialCircuit<E::Fr>
where E::Fr: ff::PrimeField
{
//noinspection RsBorrowChecker
fn synthesize<CS: ConstraintSystem<E>>(self, _cs: &mut CS) -> Result<(), SynthesisError> {
Ok(())
}
}
7 changes: 7 additions & 0 deletions crates/snark/src/circuit/bellpepper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! implement bellpepper proof system for circuit

use super::Circuit;
use super::TrivialCircuit;
use crate::prelude::bellpepper;
use crate::prelude::bellpepper::num::AllocatedNum;
use crate::prelude::bellpepper::ConstraintSystem;
Expand Down Expand Up @@ -53,3 +54,9 @@ impl<F: PrimeField> bellpepper::Circuit<F> for Circuit<F> {
Ok(())
}
}

impl<F: PrimeField> bellpepper::Circuit<F> for TrivialCircuit<F> {
fn synthesize<CS: ConstraintSystem<F>>(self, _cs: &mut CS) -> Result<(), SynthesisError> {
Ok(())
}
}
24 changes: 23 additions & 1 deletion crates/snark/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub mod bellpepper;

/// Input of witness
#[derive(Serialize, Deserialize, Clone)]
pub struct Input<F: PrimeField> {
pub struct Input<F: ff::PrimeField> {
/// inner input
pub input: Vec<(String, Vec<F>)>,
}
Expand Down Expand Up @@ -291,3 +291,25 @@ impl<F: PrimeField> StepCircuit<F> for Circuit<F> {
Ok(z_out)
}
}


/// A trivial step circuit that simply returns the input
/// from <https://github.com/microsoft/Nova/blob/master/src/traits/circuit.rs#L25>
#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct TrivialCircuit<F: PrimeField> {
_p: core::marker::PhantomData<F>,
}

impl<F: PrimeField> StepCircuit<F> for TrivialCircuit<F> {
fn arity(&self) -> usize {
1
}

fn synthesize<CS: ConstraintSystem<F>>(
&self,
_cs: &mut CS,
z: &[AllocatedNum<F>],
) -> core::result::Result<Vec<AllocatedNum<F>>, SynthesisError> {
Ok(z.to_vec())
}
}
Loading
Loading