-
Notifications
You must be signed in to change notification settings - Fork 248
Add support for tracing #489
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
aaab44b
8838837
1aca905
9fd5670
176cf93
0d9c59a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,7 @@ use ff::Field; | |
| use once_cell::sync::OnceCell; | ||
| use rand_core::OsRng; | ||
| use serde::{Deserialize, Serialize}; | ||
| use tracing::{debug, info, instrument}; | ||
|
|
||
| mod circuit; | ||
| pub mod nifs; | ||
|
|
@@ -107,6 +108,7 @@ where | |
| /// let pp = PublicParams::setup(&circuit, ck_hint1, ck_hint2)?; | ||
| /// Ok(()) | ||
| /// ``` | ||
| #[instrument(skip_all, name = "neutron::PublicParams::setup")] | ||
| pub fn setup( | ||
| c: &C, | ||
| ck_hint1: &CommitmentKeyHint<E1>, | ||
|
|
@@ -131,6 +133,7 @@ where | |
| // Generate the commitment key | ||
| let ck = R1CSShape::commitment_key(&[&r1cs_shape], &[ck_hint1])?; | ||
|
|
||
| let num_cons = r1cs_shape.num_cons; | ||
| let structure = Structure::new(&r1cs_shape); | ||
|
|
||
| let pp = PublicParams { | ||
|
|
@@ -148,6 +151,8 @@ where | |
| // call pp.digest() so the digest is computed here rather than in RecursiveSNARK methods | ||
| let _ = pp.digest(); | ||
|
|
||
| info!(num_cons = %num_cons, "setup complete"); | ||
|
|
||
| Ok(pp) | ||
| } | ||
|
|
||
|
|
@@ -166,6 +171,7 @@ where | |
| /// * `ck_hint2`: A `CommitmentKeyHint` for the secondary circuit (unused but kept for API consistency). | ||
| /// * `ptau_dir`: Path to the directory containing pruned ptau files. | ||
| #[cfg(feature = "io")] | ||
| #[instrument(skip_all, name = "neutron::PublicParams::setup_with_ptau_dir")] | ||
| pub fn setup_with_ptau_dir( | ||
| c: &C, | ||
| ck_hint1: &CommitmentKeyHint<E1>, | ||
|
|
@@ -194,6 +200,7 @@ where | |
| // Load the commitment key from ptau directory | ||
| let ck = R1CSShape::commitment_key_from_ptau_dir(&[&r1cs_shape], &[ck_hint1], ptau_dir)?; | ||
|
|
||
| let num_cons = r1cs_shape.num_cons; | ||
| let structure = Structure::new(&r1cs_shape); | ||
|
|
||
| let pp = PublicParams { | ||
|
|
@@ -211,6 +218,8 @@ where | |
| // call pp.digest() so the digest is computed here rather than in RecursiveSNARK methods | ||
| let _ = pp.digest(); | ||
|
|
||
| info!(num_cons = %num_cons, "setup complete"); | ||
|
|
||
| Ok(pp) | ||
| } | ||
|
|
||
|
|
@@ -256,6 +265,7 @@ where | |
| C: StepCircuit<E1::Scalar>, | ||
| { | ||
| /// Create new instance of recursive SNARK | ||
| #[instrument(skip_all, name = "neutron::RecursiveSNARK::new")] | ||
| pub fn new(pp: &PublicParams<E1, E2, C>, c: &C, z0: &[E1::Scalar]) -> Result<Self, NovaError> { | ||
| if z0.len() != pp.F_arity { | ||
| return Err(NovaError::InvalidInitialInputLength); | ||
|
|
@@ -291,6 +301,8 @@ where | |
| .map(|v| v.get_value().ok_or(SynthesisError::AssignmentMissing)) | ||
| .collect::<Result<Vec<<E1 as Engine>::Scalar>, _>>()?; | ||
|
|
||
| debug!("base case initialized"); | ||
|
|
||
| Ok(Self { | ||
| z0: z0.to_vec(), | ||
| r_W: FoldedWitness::default(&pp.structure), | ||
|
|
@@ -305,6 +317,7 @@ where | |
| } | ||
|
|
||
| /// Updates the provided `RecursiveSNARK` by executing a step of the incremental computation | ||
| #[instrument(skip_all, name = "neutron::RecursiveSNARK::prove_step", fields(step = self.i))] | ||
| pub fn prove_step(&mut self, pp: &PublicParams<E1, E2, C>, c: &C) -> Result<(), NovaError> { | ||
|
Comment on lines
319
to
321
|
||
| // first step was already done in the constructor | ||
| if self.i == 0 { | ||
|
|
@@ -363,10 +376,13 @@ where | |
| self.l_u = l_u; | ||
| self.l_w = l_w; | ||
|
|
||
| debug!(step = self.i, "step complete"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Verify the correctness of the `RecursiveSNARK` | ||
| #[instrument(skip_all, name = "neutron::RecursiveSNARK::verify", fields(num_steps))] | ||
| pub fn verify( | ||
| &self, | ||
| pp: &PublicParams<E1, E2, C>, | ||
|
|
@@ -428,6 +444,8 @@ where | |
| res_r?; | ||
| res_l?; | ||
|
|
||
| debug!("verification passed"); | ||
|
|
||
| Ok(self.zi.clone()) | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ use ff::Field; | |
| use once_cell::sync::OnceCell; | ||
| use rand_core::OsRng; | ||
| use serde::{Deserialize, Serialize}; | ||
| use tracing::{debug, info, instrument}; | ||
|
|
||
| mod circuit; | ||
| pub mod nifs; | ||
|
|
@@ -122,6 +123,7 @@ where | |
| /// Ok(()) | ||
| /// # } | ||
| /// ``` | ||
| #[instrument(skip_all, name = "nova::PublicParams::setup")] | ||
| pub fn setup( | ||
| c: &C, | ||
| ck_hint1: &CommitmentKeyHint<E1>, | ||
|
|
@@ -159,6 +161,8 @@ where | |
| return Err(NovaError::InvalidStepCircuitIO); | ||
| } | ||
|
|
||
| let num_cons = r1cs_shape_primary.num_cons; | ||
|
|
||
| let pp = PublicParams { | ||
| F_arity, | ||
|
|
||
|
|
@@ -181,6 +185,8 @@ where | |
| // call pp.digest() so the digest is computed here rather than in RecursiveSNARK methods | ||
| let _ = pp.digest(); | ||
|
|
||
| info!(num_cons = %num_cons, "setup complete"); | ||
|
|
||
| Ok(pp) | ||
| } | ||
|
|
||
|
|
@@ -219,6 +225,7 @@ where | |
| /// )?; | ||
| /// ``` | ||
| #[cfg(feature = "io")] | ||
| #[instrument(skip_all, name = "nova::PublicParams::setup_with_ptau_dir")] | ||
| pub fn setup_with_ptau_dir( | ||
| c: &C, | ||
| ck_hint1: &CommitmentKeyHint<E1>, | ||
|
|
@@ -264,6 +271,8 @@ where | |
| return Err(NovaError::InvalidStepCircuitIO); | ||
| } | ||
|
|
||
| let num_cons = r1cs_shape_primary.num_cons; | ||
|
|
||
| let pp = PublicParams { | ||
| F_arity, | ||
|
|
||
|
|
@@ -286,6 +295,8 @@ where | |
| // call pp.digest() so the digest is computed here rather than in RecursiveSNARK methods | ||
| let _ = pp.digest(); | ||
|
|
||
| info!(num_cons = %num_cons, "setup complete"); | ||
|
|
||
| Ok(pp) | ||
| } | ||
|
|
||
|
|
@@ -351,6 +362,7 @@ where | |
| C: StepCircuit<E1::Scalar>, | ||
| { | ||
| /// Create new instance of recursive SNARK | ||
| #[instrument(skip_all, name = "nova::RecursiveSNARK::new")] | ||
| pub fn new(pp: &PublicParams<E1, E2, C>, c: &C, z0: &[E1::Scalar]) -> Result<Self, NovaError> { | ||
| if z0.len() != pp.F_arity { | ||
| return Err(NovaError::InvalidInitialInputLength); | ||
|
|
@@ -430,6 +442,8 @@ where | |
| .map(|v| v.get_value().ok_or(SynthesisError::AssignmentMissing)) | ||
| .collect::<Result<Vec<<E1 as Engine>::Scalar>, _>>()?; | ||
|
|
||
| debug!("base case initialized"); | ||
|
|
||
| Ok(Self { | ||
| z0: z0.to_vec(), | ||
|
|
||
|
|
@@ -453,6 +467,7 @@ where | |
| } | ||
|
|
||
| /// Updates the provided `RecursiveSNARK` by executing a step of the incremental computation | ||
| #[instrument(skip_all, name = "nova::RecursiveSNARK::prove_step", fields(step = self.i))] | ||
| pub fn prove_step(&mut self, pp: &PublicParams<E1, E2, C>, c: &C) -> Result<(), NovaError> { | ||
|
Comment on lines
469
to
471
|
||
| // first step was already done in the constructor | ||
| if self.i == 0 { | ||
|
|
@@ -560,10 +575,13 @@ where | |
| self.ri_primary = r_next_primary; | ||
| self.ri_secondary = r_next_secondary; | ||
|
|
||
| debug!(step = self.i, "step complete"); | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
| /// Verify the correctness of the `RecursiveSNARK` | ||
| #[instrument(skip_all, name = "nova::RecursiveSNARK::verify", fields(num_steps))] | ||
| pub fn verify( | ||
| &self, | ||
| pp: &PublicParams<E1, E2, C>, | ||
|
|
@@ -661,6 +679,8 @@ where | |
| res_r_secondary?; | ||
| res_l_secondary?; | ||
|
|
||
| debug!("verification passed"); | ||
|
|
||
| Ok(self.zi.clone()) | ||
| } | ||
|
|
||
|
|
@@ -759,6 +779,7 @@ where | |
| S2: RelaxedR1CSSNARKTrait<E2>, | ||
| { | ||
| /// Creates prover and verifier keys for `CompressedSNARK` | ||
| #[instrument(skip_all, name = "nova::CompressedSNARK::setup")] | ||
| pub fn setup( | ||
| pp: &PublicParams<E1, E2, C>, | ||
| ) -> Result<(ProverKey<E1, E2, C, S1, S2>, VerifierKey<E1, E2, C, S1, S2>), NovaError> { | ||
|
|
@@ -783,10 +804,13 @@ where | |
| _p: Default::default(), | ||
| }; | ||
|
|
||
| info!("CompressedSNARK setup complete"); | ||
|
|
||
| Ok((pk, vk)) | ||
| } | ||
|
|
||
| /// Create a new `CompressedSNARK` (provides zero-knowledge) | ||
| #[instrument(skip_all, name = "nova::CompressedSNARK::prove")] | ||
| pub fn prove( | ||
| pp: &PublicParams<E1, E2, C>, | ||
| pk: &ProverKey<E1, E2, C, S1, S2>, | ||
|
|
@@ -877,6 +901,8 @@ where | |
| }, | ||
| ); | ||
|
|
||
| info!("CompressedSNARK proof generated"); | ||
|
|
||
| Ok(Self { | ||
| r_U_secondary: recursive_snark.r_U_secondary.clone(), | ||
| ri_secondary: recursive_snark.ri_secondary, | ||
|
|
@@ -906,6 +932,7 @@ where | |
| } | ||
|
|
||
| /// Verify the correctness of the `CompressedSNARK` (provides zero-knowledge) | ||
| #[instrument(skip_all, name = "nova::CompressedSNARK::verify", fields(num_steps))] | ||
| pub fn verify( | ||
| &self, | ||
| vk: &VerifierKey<E1, E2, C, S1, S2>, | ||
|
|
@@ -1021,6 +1048,8 @@ where | |
| res_primary?; | ||
| res_secondary?; | ||
|
|
||
| debug!("CompressedSNARK verification passed"); | ||
|
|
||
| Ok(self.zn.clone()) | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.