From b038d04c43bb1c1eec850303a32a7b0fd1cd0c47 Mon Sep 17 00:00:00 2001 From: flyq Date: Fri, 17 Nov 2023 12:45:03 +0800 Subject: [PATCH] refactor --- Cargo.toml | 12 +++--- src/circuit.rs | 3 +- src/lib.rs | 5 ++- src/nifs.rs | 3 +- src/plonk.rs | 88 ++++++++++++++++++++++---------------------- src/relaxed_plonk.rs | 5 --- 6 files changed, 58 insertions(+), 58 deletions(-) delete mode 100644 src/relaxed_plonk.rs diff --git a/Cargo.toml b/Cargo.toml index fa8f77d..625330a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,10 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -ark-ec = "0.4.0" -ark-poly = "0.4.0" -jf_plonk = { git = "https://github.com/EspressoSystems/jellyfish", package = "jf-plonk" } -jf_primitives = { git = "https://github.com/EspressoSystems/jellyfish", package = "jf-primitives"} -jf_utils = { git = "https://github.com/EspressoSystems/jellyfish", package = "jf-utils"} +ark-ec = "0.4" +ark-poly = "0.4" +jf_plonk = { git = "https://github.com/ZKMod-Lab/jellyfish", package = "jf-plonk", branch = "relaxed-stage-1" } +jf_primitives = { git = "https://github.com/ZKMod-Lab/jellyfish", package = "jf-primitives", branch = "relaxed-stage-1" } +jf_utils = { git = "https://github.com/ZKMod-Lab/jellyfish", package = "jf-utils", branch = "relaxed-stage-1" } +serde = "1.0" +thiserror = "1.0" diff --git a/src/circuit.rs b/src/circuit.rs index eb58ee9..b56758c 100644 --- a/src/circuit.rs +++ b/src/circuit.rs @@ -1 +1,2 @@ -/// Folding circuit with cycle curves \ No newline at end of file +/// Folding circuit with cycle curves +use crate::errors::NovaError; diff --git a/src/lib.rs b/src/lib.rs index 39bc96f..eab2d2c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,7 @@ -pub mod relaxed_plonk; +pub mod circuit; +pub mod errors; +pub mod nifs; +pub mod plonk; #[cfg(test)] mod tests { diff --git a/src/nifs.rs b/src/nifs.rs index 8ddc8bd..b30843e 100644 --- a/src/nifs.rs +++ b/src/nifs.rs @@ -1 +1,2 @@ -/// Non-interactive Folding Scheme \ No newline at end of file +/// Non-interactive Folding Scheme +use crate::errors::NovaError; diff --git a/src/plonk.rs b/src/plonk.rs index a66fabb..ef9b004 100644 --- a/src/plonk.rs +++ b/src/plonk.rs @@ -10,7 +10,9 @@ use ark_poly::{ }; use jf_primitives::pcs::prelude::{Commitment, UnivariateKzgPCS}; use jf_utils::par_utils::parallelizable_slice_iter; +use serde::{Deserialize, Serialize}; +use std::marker::PhantomData; /// Public parameters for a given PLONK #[derive(Clone, Serialize, Deserialize)] #[serde(bound = "")] @@ -29,22 +31,22 @@ pub struct PLONKShape { pub(crate) num_public_input: usize, // PLONK selectors - pub(crate) q_c: Vec, + pub(crate) q_c: Vec, // with length 5 or 6 - pub(crate) q_lc: Vec>, + pub(crate) q_lc: Vec>, // with length 2 - pub(crate) q_mul: Vec>, - pub(crate) q_ecc: Vec, - pub(crate) q_hash: Vec, - pub(crate) q_o: Vec, - pub(crate) q_e: Vec, + pub(crate) q_mul: Vec>, + pub(crate) q_ecc: Vec, + pub(crate) q_hash: Vec, + pub(crate) q_o: Vec, + pub(crate) q_e: Vec, } /// A type that holds witness vectors for a given PLONK instance /// The size of wire list is 5 for TurboPlonk, and 6 for UltraPlonk #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct PLONKWitness { - W: Vec>, + W: Vec>, } /// A type that holds an PLONK instance @@ -52,14 +54,14 @@ pub struct PLONKWitness { #[serde(bound = "")] pub struct PLONKInstance { pub(crate) comm_W: Vec>, - pub(crate) X: Vec, + pub(crate) X: Vec, } /// A type that holds a witness for a given Relaxed PLONK instance #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct RelaxedPLONKWitness { - pub(crate) W: Vec>, - pub(crate) E: Vec, + pub(crate) W: Vec>, + pub(crate) E: Vec, } /// A type that holds a Relaxed PLONK instance @@ -68,8 +70,8 @@ pub struct RelaxedPLONKWitness { pub struct RelaxedPLONKInstance { pub(crate) comm_W: Vec>, pub(crate) comm_E: Commitment, - pub(crate) X: Vec, - pub(crate) u: E::ScalarFieldField, + pub(crate) X: Vec, + pub(crate) u: E::ScalarField, } // impl PLONK { @@ -85,20 +87,20 @@ pub struct RelaxedPLONKInstance { impl PLONKShape { fn new( num_cons: usize, - num_vars: usize, + num_wire_types: usize, num_public_input: usize, - q_c: Vec, - q_lc: Vec>, - q_mul: Vec>, - q_ecc: Vec, - q_hash: Vec, - q_o: Vec, - q_e: Vec, + q_c: Vec, + q_lc: Vec>, + q_mul: Vec>, + q_ecc: Vec, + q_hash: Vec, + q_o: Vec, + q_e: Vec, ) -> Result, NovaError> { // .... Ok(PLONKShape { num_cons, - num_vars, + num_wire_types, num_public_input, q_c: q_c.to_owned(), q_lc: q_lc.to_owned(), @@ -113,7 +115,7 @@ impl PLONKShape { /// Checks if the Relaxed PLONK instance is satisfiable given a witness and its shape pub fn is_sat_relaxed( &self, - ck: &CommitmentKey, + ck: E::ScalarField, // &CommitmentKey, U: &RelaxedPLONKInstance, W: &RelaxedPLONKWitness, ) -> Result<(), NovaError> { @@ -123,7 +125,7 @@ impl PLONKShape { /// Checks if the PLONK instance is satisfiable given a witness and its shape pub fn is_sat( &self, - ck: &CommitmentKey, + ck: E::ScalarField, // &CommitmentKey, U: &PLONKInstance, W: &PLONKWitness, ) -> Result<(), NovaError> { @@ -134,22 +136,19 @@ impl PLONKShape { /// Relaxed PLONK instance-witness pair and an PLONK instance-witness pair pub fn commit_T( &self, - ck: &CommitmentKey, + ck: E::ScalarField, // &CommitmentKey, U1: &RelaxedPLONKInstance, W1: &RelaxedPLONKWitness, U2: &PLONKInstance, W2: &PLONKWitness, - ) -> Result<(Vec, Commitment), NovaError> { + ) -> Result<(Vec, Commitment), NovaError> { // } } impl PLONKWitness { /// A method to create a witness object using a vector of scalars - pub fn new( - S: &PLONKShape, - W: &[[E::ScalarFieldField]], - ) -> Result, NovaError> { + pub fn new(S: &PLONKShape, W: &[[E::ScalarField]]) -> Result, NovaError> { if S.num_wire_types != W.len() { Err(NovaError::InvalidWireTypes) } else { @@ -158,8 +157,8 @@ impl PLONKWitness { } /// Commits to the witness using the supplied generators - pub fn commit(&self, ck: &CommitmentKey) -> Commitment { - CE::::commit(ck, &self.W) + pub fn commit(&self, ck: E::ScalarField) -> Commitment { + // CE::::commit(ck, &self.W) } } @@ -168,7 +167,7 @@ impl PLONKInstance { pub fn new( S: &PLONKShape, comm_W: &[Commitment], - X: &[E::ScalarFieldField], + X: &[E::ScalarField], ) -> Result, NovaError> { if S.num_public_input != X.len() { Err(NovaError::InvalidPublicInput) @@ -182,14 +181,14 @@ impl PLONKInstance { } //////////////////////////////////////////// -impl AbsorbInROTrait for PLONKInstance { - // fn absorb_in_ro(&self, ro: &mut E::RO) { - // self.comm_W.absorb_in_ro(ro); - // for x in &self.X { - // ro.absorb(scalar_as_base::(*x)); - // } - // } -} +// impl AbsorbInROTrait for PLONKInstance { +// // fn absorb_in_ro(&self, ro: &mut E::RO) { +// // self.comm_W.absorb_in_ro(ro); +// // for x in &self.X { +// // ro.absorb(scalar_as_base::(*x)); +// // } +// // } +// } impl RelaxedPLONKWitness { /// Produces a default RelaxedPLONKWitness given an PLONKShape @@ -360,12 +359,11 @@ impl AbsorbInROTrait for RelaxedPLONKInstance { #[cfg(test)] pub(crate) mod test { + use jf_primitives::pcs::errors::PCSError; use jf_utils::test_rng; - fn end_to_end_test_template() -> Result<(), PCSError> - where - E: Pairing, - { + #[test] + fn end_to_end_test_template() -> Result<(), PCSError> { let rng = &mut test_rng(); for _ in 0..100 { let mut degree = 0; diff --git a/src/relaxed_plonk.rs b/src/relaxed_plonk.rs deleted file mode 100644 index 6dbfc75..0000000 --- a/src/relaxed_plonk.rs +++ /dev/null @@ -1,5 +0,0 @@ -pub use jf_plonk::{ - errors::PlonkError, - proof_system::{PlonkKzgSnark, UniversalSNARK}, - transcript::StandardTranscript, -};