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

Feat/Switch Spartan Backend to Use Goldilocks Field #17

Open
wants to merge 50 commits into
base: main
Choose a base branch
from

Conversation

darth-cy
Copy link
Collaborator

@darth-cy darth-cy commented Nov 4, 2024

Completed in this PR:

  • Removed ristretto255 scalar field definition. Use new goldilocks Scalar impl.
  • Remove elliptic group definition.
  • All curve pairing-based PCS code sections removed.
  • Add degree 2 extension field to Goldilocks using the ceno-goldilocks repo.
  • Convert all structs with hard-coded Scalar field struct to a generic.
  • All Scalar operations and checks will be preserved.

Scalar Checks Debugging progress:
[Done] ProductCircuitEvalProofBatched -> fn verify: 1 check
[Done] HashLayerProof -> fn verify_helper: 4 checks
[Done] HashLayerProof -> fn verify: 1 check

@matthiasgoergens
Copy link
Collaborator

Temporarily mark and disable all curve pairing-based PCS code sections (commented out and marked with TODO: Alternative PCS)

Just delete unused code. We can get it back from the git history. At most you want to leave a comment that tells people what used to be there, and to check in the git history for details.

matthiasgoergens added a commit that referenced this pull request Nov 5, 2024
We are cleaning up a lot in #17

Here we extract some of that cleanup, to make that other PR easier to
review.
@darth-cy darth-cy self-assigned this Nov 5, 2024
spartan_parallel/src/scalar/goldilocks.rs Outdated Show resolved Hide resolved
spartan_parallel/src/scalar/goldilocks.rs Outdated Show resolved Hide resolved
spartan_parallel/src/scalar/goldilocks.rs Outdated Show resolved Hide resolved
@yczhangsjtu
Copy link
Collaborator

Currently, there are some compilation failures in cargo test because README.md is included in doc and the compiler seems to be trying to compile the codes in README, and these codes are outdated.

spartan_parallel/src/scalar/goldilocks.rs Outdated Show resolved Hide resolved
matthiasgoergens added a commit that referenced this pull request Nov 18, 2024
* Delete all the things

We are cleaning up a lot in #17

Here we extract some of that cleanup, to make that other PR easier to
review.

* Delete more
Comment on lines +74 to 76
pub struct ZKSumcheckInstanceProof<S: SpartanExtensionField> {
proofs: Vec<DotProductProof<S>>,
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

In our usage of spartan, we don't care about zero knowledge property. Moreover, it's also difficult to build zero knowledge sumcheck protocol based on hash function. Therefore, we can get rid of (i.e. remove) types like ZKSumcheckInstanceProof and only keep SumcheckInstanceProof.

@yczhangsjtu
Copy link
Collaborator

yczhangsjtu commented Nov 27, 2024

I'm a bit concerned about eliminating all the function parameters and struct fields related to commitments because, well, we'll have to add them back in later when we connect it to our own PCS. I see the codebase provides a trait for commitment scheme, and a mock implementation for this trait. Isn't it simpler to just switching to the mock implementation, and only deleting the ECC-based implementations?

@darth-cy
Copy link
Collaborator Author

darth-cy commented Nov 27, 2024

I'm a bit concerned about eliminating all the function parameters and struct fields related to commitments because, well, we'll have to add them back in later when we connect it to our own PCS. I see the codebase provides a trait for commitment scheme, and a mock implementation for this trait. Isn't it simpler to just switching to the mock implementation, and only deleting the ECC-based implementations?

The mock commitment seems to still be based on pairing. Notably there's a trait bound JoltField on mock commitment's internal DensePolynomial<F>. Is this trait bound compatible with Goldilocks? As a side note, it seems sub-directory commitment is not included and doesn't compile as of now. The spec for JoltField is oddly not found. I'm suspecting this folder is copied from some other repo and not originally from Spartan?

@yczhangsjtu
Copy link
Collaborator

yczhangsjtu commented Nov 27, 2024

I'm a bit concerned about eliminating all the function parameters and struct fields related to commitments because, well, we'll have to add them back in later when we connect it to our own PCS. I see the codebase provides a trait for commitment scheme, and a mock implementation for this trait. Isn't it simpler to just switching to the mock implementation, and only deleting the ECC-based implementations?

The mock commitment seems to still be based on pairing. Notably there's a trait bound JoltField on mock commitment's internal DensePolynomial<F>. Is this trait bound compatible with Goldilocks? As a side note, it seems sub-directory commitment is not included and doesn't compile as of now. The spec for JoltField is oddly not found. I'm suspecting this folder is copied from some other repo and not originally from Spartan?

I see. The commitment scheme trait, and the implementations, aren't actually used at all.

spartan_parallel/Cargo.toml Outdated Show resolved Hide resolved
spartan_parallel/examples/interface.rs Outdated Show resolved Hide resolved
circ_blocks/examples/zxc.rs Outdated Show resolved Hide resolved
Comment on lines +46 to +47
/// Inner Goldilocks extension field
type InnerType: ExtensionField + Field;
Copy link
Collaborator

Choose a reason for hiding this comment

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

It's pretty cumbersome to access its base field via <S::InnerType as ExtensionField>::BaseField, right?

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to use BaseField in a lot of places for performance. For example, the type of each cell's value in the R1CS matrices must belong to the base field.

row: usize,
col: usize,
val: Scalar,
val: S,
Copy link
Collaborator

Choose a reason for hiding this comment

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

If S itself extends the ExtensionField trait, then val's type should be S::BaseField. Otherwise, we need to use this cumbersome expression <S::InnerType as ExtensionField>::BaseField.

let gens = DotProductProofGens::new(right.pow2(), label);
PolyCommitmentGens { gens }
}
Z: Vec<S>, // evaluations of the polynomial in all the 2^num_vars Boolean inputs
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need be more flexible to allow DensePolynomial to store either base elements or extension elements like https://github.com/scroll-tech/ceno/blob/master/multilinear_extensions/src/mle.rs#L163 did in ceno repo.

ts * r_hash_sqr + val * r_hash + addr
};
let r_hash_sqr = *r_hash * *r_hash;
let hash_func = |addr: &S, val: &S, ts: &S| -> S { *ts * r_hash_sqr + *val * *r_hash + *addr };
Copy link
Collaborator

Choose a reason for hiding this comment

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

This closure can be boosted by by changing the type of addr, ts from S to S::BaseField as extension field element multiply by base field element e*b (https://github.com/scroll-tech/ceno-Goldilocks/blob/master/src/extfield.rs#L24) is much faster than e * e

@kunxian-xia
Copy link
Collaborator

@kunxian-xia kunxian-xia linked an issue Dec 3, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement Goldilocks for Spartan_Parallel
4 participants