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

Bifolding IVC: Add Poseidon gadget for hashing commitments #2437

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fabrizio-m
Copy link
Contributor

No description provided.

Copy link
Member

@volhovm volhovm left a comment

Choose a reason for hiding this comment

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

Blockers:

  • Capability design/next row access is hacky and not future-proof, I'm happy to discuss it if you think this design is better
  • Cosmetics (easy to fix tho)

Essential but won't block if it's delivered next

  • No test (how can I check if this code works? why do you think it does?)

state
}

///constrains a round
Copy link
Member

Choose a reason for hiding this comment

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

The overwhelming standard is space after // or ///, and then capitalise the first word when it's a doc, as you'd do in a regular sentence.

Suggested change
///constrains a round
/// Constrains a round

Copy link
Member

Choose a reason for hiding this comment

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

(this comment applies to a lot of places in this file, and to other PRs generally too)

@@ -112,6 +112,8 @@
//! executed, `0` otherwise.

pub mod ivc;
/// poseidon implementation that hashes commitments to the columns containing values
pub mod poseidon;
Copy link
Member

Choose a reason for hiding this comment

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

This needs a more distinctive name. poseidon_hashed_com?..

@@ -36,6 +36,10 @@ pub trait ColAccessCap<F: PrimeField, CIx: ColumnIndexer> {
/// Turns a constant value into a variable.
fn constant(value: F) -> Self::Variable;
}
/// Environment capability for accessing the next row, constraint only.
pub trait NextCap<F: PrimeField, CIx: ColumnIndexer>: ColAccessCap<F, CIx> {
fn read_next(&self, col: CIx) -> Self::Variable;
Copy link
Member

Choose a reason for hiding this comment

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

I'd strongly suggest to put this into ColAccessCap as read_column_next: it's literally the same semantics (reading a column). Any reasons why you didn't go for this design?

@@ -36,6 +36,10 @@ pub trait ColAccessCap<F: PrimeField, CIx: ColumnIndexer> {
/// Turns a constant value into a variable.
fn constant(value: F) -> Self::Variable;
}
/// Environment capability for accessing the next row, constraint only.
pub trait NextCap<F: PrimeField, CIx: ColumnIndexer>: ColAccessCap<F, CIx> {
Copy link
Member

Choose a reason for hiding this comment

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

Another question on this framework: don't you also need write_column_next?

@@ -56,6 +55,16 @@ impl<F: PrimeField, CIx: ColumnIndexer, LT: LookupTableID> ColAccessCap<F, CIx>
Expr::Atom(ExprInner::Constant(cst_expr_inner))
}
}
impl<F: PrimeField, CIx: ColumnIndexer, LT: LookupTableID> NextCap<F, CIx>
Copy link
Member

Choose a reason for hiding this comment

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

You have to implement lenses for your new capability too (missing in this PR), otherwise it won't compose well in the future.

let check_out = env.read_column(PoseidonColumn::Check);
let res = round(env, state, absorb, check_out);
for i in 0..=2 {
let next = env.read_next(PoseidonColumn::State(i));
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the semantics of this. The idea behind constrain_X is that it can be used as a real assertion in the witness-building code.

  • When you execute constraint_round in the ConstraintBuilder mode, you'll get the constraint, alright.
  • But when you execute it in the WitnessBuilder mode, this will fail, because ... current WitnessBuilder does not allow you to write into the future cells.

I suggest this mechanic is added within this PR. You'll just need to:

  • Store cur_row explicitly in the WitnessBuilder, so that cur_row = witness.len() - 2 (e.g. witness is two rows, but current row is 0, and row 1 is "next").
  • Extend capabilities of read/write column to read/write next column.
  • Add write_column_next to compute_round.

@volhovm volhovm changed the title ivc poseidon Bifolding IVC: Add Poseidon gadget for hashing commitments Jul 25, 2024
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