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: add dory commitment scheme #586

Closed
wants to merge 10 commits into from
Closed

feat: add dory commitment scheme #586

wants to merge 10 commits into from

Conversation

g1684774
Copy link

@g1684774 g1684774 commented Feb 7, 2025

I have a rewrite from DualDory (go) and I'm currently porting it to jolt.

Concerns

It looks like DualDory didn't implement commitments for polynomials opening. Also Justin's book doesn't have a section on how to implement for Multilinear polynomials.

Questions

I'd like some help to understand:

  • How should I populate the Transcript? Is it needed for Dory? Used for Fiat-Shamir
  • How to deal with other types of MultilinearPolynomial;
  • Does Dory support a better type of batching other than just looping over; Looping is ok
  • Multiple operations might fail, how to handle them? Is it ok to panic? Yes
    • Inverting a Scalar Zero
    • Getting the inner product of G1xG2
  • Go implementation used Sha2 for digest, is it ok to use Sha3? Use Transcript
  • How does the reduce part fits jolt?. Reduce is used for commitments with more than 1 element

I'm new to jolt and I don't understand if the API is already defined or it needs to change to fit Dory.

I'm also currently learning about ZK and Snarks cryptography, so please let me know if there's something wrong.

@g1684774 g1684774 force-pushed the dory branch 3 times, most recently from 8f76867 to f887d89 Compare February 7, 2025 14:15
@moodlezoup
Copy link
Collaborator

moodlezoup commented Feb 7, 2025

Hi @g1684774 ! Thanks for taking this on! I haven't had a chance to thoroughly review your PR yet, but let me try to answer some of your questions first:

  • How should I populate the Transcript? Is it needed for Dory?

Our Transcript struct should be used for the "reduce" steps in the Dory code. Both are used to implement the Fiat-Shamir transform –– we have some running "digest" or "state", and whenever the prover makes a commitment of some sort, the commitment has to be "absorbed" into the digest (aka appended to the transcript) by making (in broad strokes) the following update:
state := hash(state, commitment)

  • How to deal with other types of MultilinearPolynomial;

See inline comment

  • Does Dory support a better type of batching other than just looping over;

What you have is fine for now!

  • Multiple operations might fail, how to handle them? Is it ok to panic?

Yes, panic is ok

  • Go implementation used Sha2 for digest, is it ok to use Sha3?

See above answer about the Transcript; note that we have a KeccakTranscript struct that implements the Transcript trait

  • How does the reduce part fits jolt?

See above answer about the Transcript

Btw, if you haven't already you might want to check out Section 15.4 of Justin's book, which covers Dory. There may be some discrepancies between the description there and the Go implementation, but it should provide some high-level context for why things work the way they do.

Comment on lines 22 to 34
let v1 = params
.g1v
.iter()
.zip(poly.iter())
.map(|(a, b)| *a * *b)
.collect::<Vec<G1<P>>>();

let v2 = params
.g2v
.iter()
.zip(poly.iter())
.map(|(a, b)| *a * *b)
.collect::<Vec<G2<P>>>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

These are multi-scalar multiplications (MSMs), which we have our own optimized implementation for: https://github.com/a16z/jolt/blob/main/jolt-core/src/msm/mod.rs#L176-L220

Note that it supports all types of MultilinearPolynomials

Copy link
Author

Choose a reason for hiding this comment

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

I took a deeper look and it seems that this is not MSM since I'm not taking the .sum(). This is a conversion of [ScalarField] -> [G1] to be used in the next steps. Does that make sense or am I missing anything?

Signed-off-by: Ray <g1684774@gmail.com>
@g1684774
Copy link
Author

Thanks for the response. I have a few more questions:

  • Does that mean that the Go implementation already does the Fiat-Shamir transform by calling ro() whereas jolt wants to provide the points by calculating the points by itself sending digest produced by the transcript?

  • And if the previous question is true, does it mean that I need to unwind the recursive part and let jolt call it for me? Will Jolt call it log(n) times before calling verify? Does jolt provide a state telling me if is step1 or step2?

  • Something that I couldn't quite get it for Dory is about the Public Params. Are the Public Params actually a Vec?

@moodlezoup
Copy link
Collaborator

Thanks for the response. I have a few more questions:

  • Does that mean that the Go implementation already does the Fiat-Shamir transform by calling ro() whereas jolt wants to provide the points by calculating the points by itself sending digest produced by the transcript?

Where you see β := step1Elements.RO() in the Go code, for example, we'd instead want to append the ReduceProverStep1Elements struct to the transcript, then do let beta = transcript.challenge_scalar()
Hopefully that answers your question?

  • Something that I couldn't quite get it for Dory is about the Public Params. Are the Public Params actually a Vec?

The public params are the "preprocessing" required for Dory. They consist mainly of two vectors of group elements (from G1 and G2 respectively). This stuff should be output by CommitmentScheme::setup.

Comment on lines +52 to +60
fn append_gt<P: Pairing, ProofTranscript: Transcript>(transcript: &mut ProofTranscript, gt: Gt<P>) {
let mut buf = vec![];
gt.serialize_uncompressed(&mut buf).unwrap();
// Serialize uncompressed gives the scalar in LE byte order which is not
// a natural representation in the EVM for scalar math so we reverse
// to get an EVM compatible version.
buf = buf.into_iter().rev().collect();
transcript.append_bytes(&buf);
}
Copy link
Author

Choose a reason for hiding this comment

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

There's no append_gt in transcript, should I add it there?

@g1684774 g1684774 closed this Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants