-
Notifications
You must be signed in to change notification settings - Fork 189
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
feat: Make commitment key generation configurable with an optional parameter #203
feat: Make commitment key generation configurable with an optional parameter #203
Conversation
32f11cd
to
d3c7bb6
Compare
What's the purpose of the optional parameters passed to |
@CPerezz thanks for the question, I have added a summary to the PR, please let me know if it addresses your concerns fully |
kk so I see why you need this. But unsure why you can't do it differently:
I'm just saying this as it looks a bit odd in the API to have this hinting fn when it's only used for this particular Spartan setup. But maybe there's no better way to actually fit this in.. |
I would love to use a trait constant. But as the current implementation of the computation-committing Spartan should make clear (in this PR, that’s in the Note that this Spartan variant differs from (and improves on) the literature’s SPARK-based Spartan, but since this was previously implemented in this repo, we can see that even then, the commitment key floor depended on the R1CS matrices, and could not be conveyed by a constant: I concur with your thinking that depending on unstable nightly features is unwise. Note: the |
131c1c1
to
15d05fa
Compare
15d05fa
to
470164a
Compare
470164a
to
ae999ec
Compare
@huitseeker I wonder if the following might be a better solution. Eventually, there will be a trait (e.g., CycleEngineTrait) that specifies G1, G2, etc., which will eliminate unneeded complexity with many type parameters. The same trait could also specify a CompressedSNARK that will be later used to compress the produced IVC proofs. In that case, the setup could just ask the compressedSNARK type to tell its size requirements. Would we still need the modifications in this PR in that world? |
ae999ec
to
a75a7c3
Compare
@srinathsetty The question is a bit theoretical, since |
8891ce7
to
474da9c
Compare
…ommitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing #53. - This PR puts Arecibo in line with microsoft/Nova#203
…ommitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing microsoft#53. - This PR puts Arecibo in line with microsoft#203
…ommitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing #53. - This PR puts Arecibo in line with microsoft/Nova#203
e479375
to
402afba
Compare
…rameter - Implemented the `Len` trait within `CommitmentKey` to allow length quantification in terms of group generators. Made ppSnark fail setup if given commitment key with insufficient length, as measured by its own commitment_key_floor() (see below) - Made RelaxedR1CSTrait include a fn commitment_key_floor() -> Box<dyn for<'a> Fn(&'a R1CSShape<G>) -> usize> with default implementation to quantify the Snark's commitment key size requirements in the shape of a closure, - Made PublicParameters accept optional Box<dyn for<'a> Fn(&'a R1CSShape<G>) -> usize> parameters for each circuit's group, to parametrize the CommitmentKey creation. Implementation details: - defined type alias CommitmentKeyHint<G> = Box<dyn Fn(&R1CSShape<G>) -> usize>; (only used internally) - Modified numerous function calls and parameter setups to include optional parameter `CommitmentKeyHint` that gives a more flexible commitment key generation. - Added the `CommitmentKeyHint` to the `r1cs` import list and expanded `NovaShape` trait to optionally accept it.
…ommitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules.
- Introduced a new function `default_commitment_key_hint` in `nova_snark` package to provide a clearer default sizing hint for the commitment key, - Replaced hard-coded zero values throughout the codebase with calls to `default_commitment_key_hint` function,
e62132f
to
a3fdbe6
Compare
…ommitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing #53. - This PR puts Arecibo in line with microsoft/Nova#203
…ommitment key size hint (#95) * refactor: Refactor public parameters setup to remove optionality of commitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing #53. - This PR puts Arecibo in line with microsoft/Nova#203 * doc: document Supernova Public Parameters - Enhanced the `PublicParams` struct within `./src/supernova/mod.rs` with detailed comments * feat: Refactor to use `default_commitment_key_hint` across codebase - Introduced a new function `default_commitment_key_hint` in `nova_snark` package to provide a clearer default sizing hint for the commitment key, - Replaced hard-coded zero values throughout the codebase with calls to `default_commitment_key_hint` function,
…ommitment key size hint (#95) * refactor: Refactor public parameters setup to remove optionality of commitment key size hint - Converted `CommitmentKeyHint<G>` from a boxed dynamic trait object to a direct dynamic trait object in `r1cs/mod.rs`. - Changed the `commitment_key` function to always require a commitment key floor, eliminating the need for default behavior when a floor function isn't provided. - Updated the `r1cs_shape` function across various files to take in a `CommitmentKeyHint` instead of it being optional and introduce a closure as an argument. - Relevant modifications and updates were made in the `r1cs_shape` and `commitment_key` function calls within the test functions for various modules. - Ported use of commitment key hint to Supernova, closing #53. - This PR puts Arecibo in line with microsoft/Nova#203 * doc: document Supernova Public Parameters - Enhanced the `PublicParams` struct within `./src/supernova/mod.rs` with detailed comments * feat: Refactor to use `default_commitment_key_hint` across codebase - Introduced a new function `default_commitment_key_hint` in `nova_snark` package to provide a clearer default sizing hint for the commitment key, - Replaced hard-coded zero values throughout the codebase with calls to `default_commitment_key_hint` function,
- Implement marking of `NovaError` enum as non-exhaustive in `errors.rs`. - Introduce a new error case `InvalidCommitmentKeyLength` in `NovaError` enum that checks the length of the provided commitment key. - Improve code readability by renaming `generators_hint` variable to `ck_hint` in the `commitment_key` function.
Summary
The size of the public parameters can vary depending on the method used to process them in a later SNARK. In particular, the memory checking techniques used for computational commitments (Spartan paper section 6) requires larger commitment keys.
However, because public parameters are created before any SNARK that might use them, their creation as a Rust object is harder to parametrize. So the size of the commitment key is currently set, for all public parameters, to the more conservative (larger) size required in
spartan/ppsnark.rs
.The current PR allows parametrizing public parameter creation with an optional function of the R1CS shape of the circuits: the size of the parameters will be the min of the usual considerations (min of wire /constraint count) and its output. This function can then be provided by SNARKs as an associated function. It allows the mere type definition of the SNARK to convey its special needs in terms of public parameters.
The Spartan instance that does have those special needs now implements this function to convey its extra requirements, letting all other SNARKs enjoy smaller parameters.
In detail
Len
trait forCommitmentKey
to allow length quantification in terms of group generators. Madeppsnark::RelaxedR1CSSNARK
fail setup if given commitment key with insufficient length, as measured by its owncommitment_key_floor()
(see below)RelaxedR1CSTrait
include afn commitment_key_floor() -> Box<dyn for<'a> Fn(&'a R1CSShape<G>) -> usize>
with default implementation to quantify the Snark's additional commitment key size requirements, in the shape of a closure,PublicParams
take a&dyn for<'a> Fn(&'a R1CSShape<G>) -> usize
parameter for each circuit's group, to parametrize theCommitmentKey
creation.Other implementation details:
CommitmentKeyHint<G> = dyn Fn(&R1CSShape<G>) -> usize
CommitmentKeyHint
that gives a more flexible commitment key generation.CommitmentKeyHint
to ther1cs
import list and expandedNovaShape
trait to optionally accept it.