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

Merged
merged 53 commits into from
Jan 7, 2025

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 matthiasgoergens self-requested a review November 5, 2024 00:45
@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
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 commented Dec 3, 2024

@kunxian-xia kunxian-xia linked an issue Dec 3, 2024 that may be closed by this pull request
@darth-cy darth-cy force-pushed the feat/goldilocks-spartan branch from 88029e3 to 5f86ada Compare December 5, 2024 07:10
@kunxian-xia kunxian-xia mentioned this pull request Dec 13, 2024
@kunxian-xia kunxian-xia added this pull request to the merge queue Jan 7, 2025
Copy link
Collaborator

@matthiasgoergens matthiasgoergens left a comment

Choose a reason for hiding this comment

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

Just looking through this briefly and got some questions. Not a full review. (And you can merge without addressing my questions / comments. I'm just curious.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we re-implement the field arithmetic here? What's the reason we can't re-use ceno-goldilocks or Plonky2 or so?

.chain(col.read_ts.iter())
.chain(val_vec.iter()),
.into_iter()
.chain(row.read_ts.into_iter())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Itertool's chain macro is a bit easier to read, IHMO. But that doesn't have to be in this PR.

@@ -436,25 +369,21 @@ impl SparseMatPolynomial {
let row = self.M[i].row;
let col = self.M[i].col;
let val = &self.M[i].val;
eval_table_rx[row] * eval_table_ry[col] * val
eval_table_rx[row] * eval_table_ry[col] * *val
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are implementing our own field element arithmetic anyway, we can add instances for arithmetic with references, too. See how we do that in Ceno.

(We don't need to do that in this PR.)

.fold(vec![Scalar::zero(); num_rows], |mut Mz, (r, v)| {
Mz[r] += v;
.fold(vec![S::field_zero(); num_rows], |mut Mz, (r, v)| {
Mz[r] = Mz[r] + v;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We can implement AddAssign?


for i in 0..self.M.len() {
let entry = &self.M[i];
M_evals[entry.col] += rx[entry.row] * entry.val;
M_evals[entry.col] = M_evals[entry.col] + rx[entry.row] * entry.val;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why don't we implement AddAssign?

let derefs = {
// combine all polynomials into a single polynomial (used below to produce a single commitment)
let comb = DensePolynomial::merge(row_ops_val.iter().chain(col_ops_val.iter()));
let comb = DensePolynomial::merge(row_ops_val.into_iter().chain(col_ops_val.into_iter()));
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could just clone here, then you don't need to change all the other lines. Makes the diff easier to review.

Merged via the queue into main with commit b7a4e64 Jan 7, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Implement Goldilocks for Spartan_Parallel
4 participants