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

CCS implementation #52

Merged
merged 26 commits into from
Mar 4, 2024
Merged

CCS implementation #52

merged 26 commits into from
Mar 4, 2024

Conversation

sjudson
Copy link
Contributor

@sjudson sjudson commented Jan 31, 2024

This PR implements the Customizable Constraint System (CCS) independently of the R1CS implementation, up to extracting the sparse matrix implementation so both can use it, and support for an R1CS -> CCS conversion:

let ccs_shape = CCSShape::from(r1cs_shape);

Todo:

  • Implement CCS
  • Implement Linearized CCS

@sjudson sjudson added the enhancement New feature or request label Jan 31, 2024
@sjudson sjudson changed the title Initial CCS implementation CCS implementation Jan 31, 2024
@sjudson sjudson marked this pull request as draft January 31, 2024 17:00
@slumber slumber requested a review from tess-eract February 2, 2024 10:54
@slumber
Copy link
Contributor

slumber commented Feb 2, 2024

@sjudson do you want to push lccs implementation to this branch? Alternatively, we can merge it in this state.

What's the 2nd step in PR description about implementing CCCS? I believe it's already there

pub struct CCSInstance<G: CurveGroup, C: CommitmentScheme<G>> {
/// Commitment to witness.
pub commitment_W: C::Commitment,
/// X is assumed to start with a `ScalarField::ONE`.
pub X: Vec<G::ScalarField>,
}

(Regarding additional C in the type name: similar to R1CSInstance which is in fact committed and we just imply this without naming it CR1CSInstance. Note that spartan code on the other hand calls it CR1CS, but we could try to be consistent at least within the supernova crate)

@sjudson sjudson marked this pull request as ready for review February 8, 2024 19:58
@sjudson sjudson requested a review from slumber February 9, 2024 18:13
Copy link
Contributor

@tess-eract tess-eract left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good work! my only comments that affect correctness/performance are a) swapping i and j in the matrix_to_mle function, and b) avoiding using mle_to_mvp, working with eval vectors rather than coefficient vectors everywhere. the rest are suggestions, and more or less a matter of taste.

@sjudson sjudson force-pushed the ccs branch 3 times, most recently from e54242f to 64ba2cd Compare February 16, 2024 17:50
@sjudson sjudson mentioned this pull request Feb 17, 2024
5 tasks
Copy link

vercel bot commented Feb 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nexus-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 28, 2024 9:19pm


impl<G: CurveGroup> CCSShape<G> {
/// Checks if the CCS instance together with the witness `W` satisfies the CCS constraints determined by `shape`.
pub fn is_satisfied<C: PolyCommitmentScheme<G>>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we implement CycleFold, we'll also need to consider CCS instances over the secondary field. The commitments for these will just be Pedersen commitments, not coming from a polynomial commitment scheme. (KZG-style commitments won't exist for the secondary curve, because it doesn't support pairings). On the other hand, it is indeed important - for compression - that the commitment scheme for the primary curve does come from a PCS. In the nova repo, we define everything in terms of vector commitment schemes, and then to create the "compressible" version, we coerce the PCS for the primary field into a vector commitment scheme. Another approach would be to just define separate types, e.g. CCSInstanceSecondary<G: CurveGroup, C: CommitmentScheme<G>> - it's a bit redundant, but maybe cleaner.

/// Multisets of selector indices, each paired with a constant multiplier.
pub cSs: Vec<(G::ScalarField, Vec<usize>)>,
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Putting the other type definitions (CCSInstance etc.) above the impls might improve readability.

tess-eract

This comment was marked as duplicate.

Copy link
Contributor

@tess-eract tess-eract left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i and j should be swapped here: later, we will call fix_variables to get
the combination of the rows of M, it will bind the log_m lowest-order
bits.

I don't think this function is needed anymore. spartan uses a different method of turning sparse matrices into polynomials that's specialized for its "computational commitments". ;


let z = [U.X.as_slice(), W.W.as_slice()].concat();
let Mzs: Vec<G::ScalarField> = ark_std::cfg_iter!(&self.Ms)
.map(|M| vec_to_mle(M.multiply_vec(&z).as_slice()).evaluate::<G>(U.rs.as_slice()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To ensure endianness compatibility with sumcheck, we need to ensure that the polynomial P(v): DenseMultilinearExtension that we pass to ark-ml-sumcheck later on satisfies P(v).evaluate(r) == vec_to_mle(v).evaluate(r). The evaluate() function for DenseMultilinearExtension is little-endian, i.e. the first variable is encoded by the least significant bit of the index. That's the opposite of how evaluate() works on spartan's DensePolynomial, so we either need P(v) = DenseMultilinearExtension::from_coefficients_vec(v.rev_bits()) xor we need vec_to_mle(v) = DensePolynomial::new(v.rev_bits()). Since both of these maps use clones anyway, it shouldn't be more expensive to reverse the bits.

@sjudson sjudson merged commit 8610505 into main Mar 4, 2024
6 checks passed
@sjudson sjudson deleted the ccs branch March 4, 2024 18:48
tess-eract added a commit that referenced this pull request Mar 8, 2024
* Initial CCS implementation.

* Remove direct construction interfaces so that everything goes through R1CS.

* Trim more, Fold multipliers together, and inline satisfaction checking.

* Fix formatting.

* Precompute products.

* Remove direct CCS construction.

* Add mle helpers.

* Start to integrate polynomial commitments.

* Shading closer to polynomial commitments.

* Initial stab at relating various polynomial types and traits.

* Finish utility functions.

* Fix endianness and ranges and get tests passing.

* Fix formatting.

* Realized there's a better way to invoke the partially fixed polynomial.

* Update interfaces and some additional reworking.

* Resolve clippy.

* Unify shapes.

* Product renaming

Co-authored-by: Dan Dore <dorebell@gmail.com>

* Revert "Unify shapes."

This reverts commit 3463e43.

* Move to polynomial/poly commitment implementations from Spartan repo.

* Move to unified matrix-based model.

* Fix tests.

* Fix fmt.

* Remove files accidently restored during rebase.

* Move to using polynomial commitment exlcusively.

* Fix formatting.

---------

Co-authored-by: Dan Dore <dorebell@gmail.com>
tess-eract added a commit that referenced this pull request Mar 14, 2024
* add basic setup flow using SRS

* merge with main

* some small fixes to bugs in the compression module from recent PRs

* spartan integration fixes

* tests for srs generation

* sets default srs size to 19

* use `deserialize_compressed_unchecked`

* remove unnecessary blinding factor from SRS generation

* fix

* adds SRS to git lfs

* add git lfs to CI workflow

* sample test srs in CI

* install nexus-tools in CI

* ignore tests related to large SRS

* remove SRS generation from CI

* merge fixes

* fmt

* fixes from review

* small fix

* remove file-manipulating tests

* Adds a cli option to the prover crate for compression (#55)

* testing proof deserialization

* proofs save and verify

* removed cargo.lock

* todo: merge dorebell onto this

* fixed merge mistakes

* reads proof and compresses. key not yet saved to file

* added back cargo.lock

* moved the compression cli into prover crate

* formatting

* remove whitespace

* added com option to prove

* updated local prove

* todo:save key and proof to file

* derive CanonicalSerialize+CanonicalDeserialize for Spartan types

* add options to save and load spartan key from file

* save compressed proof to file, implement arkworks serialization

* clippy

* remove SRS generation from CI

* ignore spartan_encode_test

* integrate compression cli with recent version of nexus-tools

* add cli function to sample test SRS

* forgot to add new files

* small compression UI fixes

* add spartan setup command to main 'cargo nexus'

* bump number of SRS vars to 27

* minor fix

* review fixes

* another round of review fixes

* read pp and srs from default cache locations if unspecified during compression

* add helper function to get minimum srs size for a given k

---------

Co-authored-by: Dan Dore <dorebell@gmail.com>

* fix broken edit links in docs (#99)

* CCS implementation (#52)

* Initial CCS implementation.

* Remove direct construction interfaces so that everything goes through R1CS.

* Trim more, Fold multipliers together, and inline satisfaction checking.

* Fix formatting.

* Precompute products.

* Remove direct CCS construction.

* Add mle helpers.

* Start to integrate polynomial commitments.

* Shading closer to polynomial commitments.

* Initial stab at relating various polynomial types and traits.

* Finish utility functions.

* Fix endianness and ranges and get tests passing.

* Fix formatting.

* Realized there's a better way to invoke the partially fixed polynomial.

* Update interfaces and some additional reworking.

* Resolve clippy.

* Unify shapes.

* Product renaming

Co-authored-by: Dan Dore <dorebell@gmail.com>

* Revert "Unify shapes."

This reverts commit 3463e43.

* Move to polynomial/poly commitment implementations from Spartan repo.

* Move to unified matrix-based model.

* Fix tests.

* Fix fmt.

* Remove files accidently restored during rebase.

* Move to using polynomial commitment exlcusively.

* Fix formatting.

---------

Co-authored-by: Dan Dore <dorebell@gmail.com>

* All Contributors Setup (#120)

* Update README.md

* Update README.md

* Create .all-contributorsrc

* docs: add nexus-xyz as a contributor for code (#121)

* docs: update README.md

* docs: update .all-contributorsrc

---------

Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>

* Switch Contributors (#122)

* Delete .all-contributorsrc

* Update README.md

* fix merge conflicts

---------

Co-authored-by: Guru Vamsi Policharla <guruvamsi.policharla@gmail.com>
Co-authored-by: Daniel Marin <60114322+danielmarinq@users.noreply.github.com>
Co-authored-by: Samuel Judson <sam@sjudson.com>
Co-authored-by: allcontributors[bot] <46447321+allcontributors[bot]@users.noreply.github.com>
sjudson pushed a commit that referenced this pull request Feb 5, 2025
* Add Design Doc

* Add Initial Type Specification

* Sam Comments

* Updates for Final Sam Comments
sjudson pushed a commit that referenced this pull request Feb 12, 2025
* Add Design Doc

* Add Initial Type Specification

* Sam Comments

* Updates for Final Sam Comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants