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

Arrabbiata: coining alpha challenge + implement generic coin_challenge #3027

Merged
merged 6 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion arrabbiata/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! specify the number of iterations, and keep this file relatively simple.

use arrabbiata::{
challenge::ChallengeTerm,
curve::PlonkSpongeConstants,
interpreter::{self, InterpreterEnv},
witness::Env,
Expand Down Expand Up @@ -126,8 +127,8 @@ pub fn main() {
// Commit to the accumulator and absorb the commitment
// ----- Permutation argument -----

// FIXME:
// Coin challenge α for combining the constraints
env.coin_challenge(ChallengeTerm::ConstraintRandomiser);

// ----- Accumulation/folding argument -----
// FIXME:
Expand Down
49 changes: 48 additions & 1 deletion arrabbiata/src/witness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::time::Instant;

use crate::{
challenge::Challenges,
challenge::{ChallengeTerm, Challenges},
column::{Column, Gadget},
curve::{ArrabbiataCurve, PlonkSpongeConstants},
interpreter::{Instruction, InterpreterEnv, Side},
Expand Down Expand Up @@ -1236,4 +1236,51 @@ where
Instruction::NoOp => Instruction::NoOp,
}
}

/// Simulate an interaction with the verifier by requesting to coin a
/// challenge from the current prover sponge state.
///
/// This method supposes that all the messages have been sent to the
/// verifier previously, and the attribute [self.prover_sponge_state] has
/// been updated accordingly by absorbing all the messages correctly.
///
/// The side-effect of this method will be to run a permutation on the
/// sponge state _after_ coining the challenge.
/// There is an hypothesis on the sponge state that the inner permutation
/// has been correctly executed if the absorbtion rate had been reached at
/// the last absorbtion.
///
/// The challenge will be added to the [self.challenges] attribute at the
/// position given by the challenge `chal`.
///
/// Internally, the method is implemented by simply loading the prover
/// sponge state, and squeezing a challenge from it, relying on the
/// implementation of the sponge. Usually, the challenge would be the first
/// N bits of the first element, but it is left as an implementation detail
/// of the sponge given by the curve.
pub fn coin_challenge(&mut self, chal: ChallengeTerm) {
if self.current_iteration % 2 == 0 {
let mut sponge = E1::create_new_sponge();
self.prover_sponge_state.iter().for_each(|x| {
E1::absorb_fq(
&mut sponge,
E1::BaseField::from_biguint(&x.to_biguint().unwrap()).unwrap(),
)
});
let verifier_answer = E1::squeeze_challenge(&mut sponge).to_biguint().into();
self.challenges[chal] = verifier_answer;
sponge.sponge.poseidon_block_cipher();
Copy link
Member Author

Choose a reason for hiding this comment

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

I want to abstract it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

why do we need to add a pass of block_cipher there ?

Copy link
Member Author

Choose a reason for hiding this comment

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

We load the state in the sponge earlier in the code (the state is always kept in the environment), instead of the Sponge structure itself, to have a more granular control on how to manipulate the sponge state. In particular, I want to always run a permutation (i.e. change the state) when we coin a value, as the code is doing here. The current implementation of the Sponge structure does not do that: it allows squeezing two elements without running a state permutation (as verified in this pull request). It is not the behavior I want to have for the circuit. I want to always run the permutation, as it would also make the circuit easier to implement and the gadget easier to reuse.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, if we don't run the permutation, the next time we load the sponge state, it will give the same challenges, as we don't keep the information that a previous challenge has been already coined with this state.

} else {
let mut sponge = E2::create_new_sponge();
self.prover_sponge_state.iter().for_each(|x| {
E2::absorb_fq(
&mut sponge,
E2::BaseField::from_biguint(&x.to_biguint().unwrap()).unwrap(),
)
});
let verifier_answer = E2::squeeze_challenge(&mut sponge).to_biguint().into();
self.challenges[chal] = verifier_answer;
sponge.sponge.poseidon_block_cipher();
Copy link
Member Author

Choose a reason for hiding this comment

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

I want to abstract it later.

Copy link
Contributor

Choose a reason for hiding this comment

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

same comment as line 1272

};
}
}
Loading