-
Notifications
You must be signed in to change notification settings - Fork 116
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
Changes from 5 commits
8aa7d51
59ac562
fb7432c
48945d4
d19d3c2
82f004f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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}, | ||
|
@@ -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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why do we need to add a pass of block_cipher there ? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to abstract it later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comment as line 1272 |
||
}; | ||
} | ||
} |
There was a problem hiding this comment.
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.