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

Unify the computation of digests and challenges in different folding schemes #94

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

Conversation

winderica
Copy link
Contributor

I observed that in Nova, we compute the challenges and digests by manually constructing the input vectors to CRH{Var}::evaluate, while in ProtoGalaxy, we have ProtoGalaxyTranscript for absorbing the inputs to a sponge.

It would be beneficial to unify the way we derive challenges and digests in different folding schemes, and thus I created this PR and made several changes in challenge generation and digest computation. Notably,

  1. PoseidonTranscript{Var}, the wrappers of PoseidonSponge{Var}, are removed. Instead, PoseidonSponge{Var} now implements the Transcript{Var} traits directly and supports both digest computation and challenge generation.
    • Yet, this does not mean we can use a single instance of PoseidonSponge{Var} for both purposes. One still needs to create two separate instances, e.g., sponge and transcript, for digest computation and challenge generation respectively.
  2. The Transcript{Var} traits now allow absorbing any non-native values (e.g., integers, points, CycleFold instances), as long as they implement AbsorbNonNative{Gadget}.
  3. The Transcript{Var}::absorb_point method now is solely for absorbing native points (i.e., those whose base field is also the sponge's field), so some absorb_point calls are replaced with absorb_nonnative.
  4. In Nova, CommittedInstance{Var}::hash and {CycleFold}ChallengeGadget::get_challenge_{native, gadget} now use the absorb methods provided by PoseidonSponge{Var} and Transcript{Var}.
  5. In ProtoGalaxy, ProtoGalaxyTranscript is removed in favor of implementing Absorb{Gadget} for CommittedInstance{Var}.

Yet, as this PR focuses on code quality and does not introduce bug fixes or new functionalities, we can lower the priority of merging it.

Copy link
Collaborator

@arnaucube arnaucube left a comment

Choose a reason for hiding this comment

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

This is great! Very nice!
Unifying the transcripts and hashes and polishing the absorbs of points and nonnative elements was a pending task!
Really like the approach of extending the arkworks Sponge trait.

Also, as with your previous PRs, thanks a lot for all the good comments/docs along the code, they are very insightful!

Just a couple of small questions.

pub trait AbsorbNonNative<F: PrimeField> {
/// Converts the object into field elements that can be absorbed by a `CryptographicSponge`.
/// Append the list to `dest`
fn to_native_sponge_field_elements(&self, dest: &mut Vec<F>);
Copy link
Collaborator

Choose a reason for hiding this comment

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

One question, I've tried to find where the to_native_sponge_field_elements is used and haven't succeed (other than structs implementing the method to implement the AbsorbNonNative trait). The usages of the AbsorbNonNative trait that I've found use the one that returns the Vec<F> instead of modifying a given dest input value.
Does the AbsorbNonNative have the method with the dest param in order to match the native Absorb trait, which internally uses a similar method from arkworks (also modifying the dest param)?

folding-schemes/src/folding/nova/circuits.rs Outdated Show resolved Hide resolved
@arnaucube arnaucube requested a review from dmpierre May 7, 2024 16:00
@winderica winderica marked this pull request as ready for review May 9, 2024 03:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants