-
Notifications
You must be signed in to change notification settings - Fork 102
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
Added the support for GR1CS and added rescue hash function #161
base: main
Are you sure you want to change the base?
Conversation
assert!(cs.is_satisfied().unwrap()); | ||
} | ||
} | ||
// #[cfg(test)] |
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.
Uncomment this
let _ = TestCRHGadget::evaluate(¶meters_var, &input_var).unwrap(); | ||
} | ||
} | ||
// #[cfg(test)] |
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.
Uncomment this
@@ -10,7 +10,7 @@ use ark_serialize::{CanonicalDeserialize, CanonicalSerialize}; | |||
#[cfg(not(feature = "std"))] | |||
use ark_std::vec::Vec; | |||
use ark_std::{borrow::Borrow, fmt::Debug, hash::Hash, marker::PhantomData, rand::Rng}; | |||
#[cfg(feature = "r1cs")] | |||
#[cfg(any(feature = "r1cs", feature = "gr1cs"))] |
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.
We shouldn't have two features, just use gr1cs.
assert!(cs.is_satisfied().unwrap()); | ||
} | ||
} | ||
// #[cfg(test)] |
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.
Uncomment this
mod test { | ||
use crate::encryption::constraints::AsymmetricEncryptionGadget; | ||
use ark_std::{test_rng, UniformRand}; | ||
// #[cfg(test)] |
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.
Uncomment this
state: &mut [FpVar<F>], | ||
exponent: &[u64], | ||
alpha: u64, | ||
// round: usize |
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.
Take is_forward_pass
as input
FpVar::new_witness(self.cs(), || Ok(state_item.value()?.pow(exponent))) | ||
.unwrap(); | ||
match (&state_item, &new_state_item) { | ||
(FpVar::Var(alloc_fp), FpVar::Var(new_alloc_fp)) => { |
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.
Maybe change to use is_constant()
?
loop { | ||
// if we can finish in this call | ||
if rate_start_index + remaining_elements.len() <= self.parameters.rate { | ||
for (i, element) in remaining_elements.iter().enumerate() { | ||
self.state[self.parameters.capacity + i + rate_start_index] += element; | ||
} | ||
self.mode = DuplexSpongeMode::Absorbing { | ||
next_absorb_index: rate_start_index + remaining_elements.len(), | ||
}; | ||
|
||
return Ok(()); | ||
} | ||
// otherwise absorb (rate - rate_start_index) elements | ||
let num_elements_absorbed = self.parameters.rate - rate_start_index; | ||
for (i, element) in remaining_elements | ||
.iter() | ||
.enumerate() | ||
.take(num_elements_absorbed) | ||
{ | ||
self.state[self.parameters.capacity + i + rate_start_index] += element; | ||
} | ||
self.permute()?; | ||
// the input elements got truncated by num elements absorbed | ||
remaining_elements = &remaining_elements[num_elements_absorbed..]; | ||
rate_start_index = 0; | ||
} | ||
} | ||
|
||
// Squeeze |output| many elements. This does not end in a squeeze | ||
fn squeeze_internal( | ||
&mut self, | ||
mut rate_start_index: usize, | ||
output: &mut [FpVar<F>], | ||
) -> Result<(), SynthesisError> { | ||
let mut remaining_output = output; | ||
loop { | ||
// if we can finish in this call | ||
if rate_start_index + remaining_output.len() <= self.parameters.rate { | ||
remaining_output.clone_from_slice( | ||
&self.state[self.parameters.capacity + rate_start_index | ||
..(self.parameters.capacity + remaining_output.len() + rate_start_index)], | ||
); | ||
self.mode = DuplexSpongeMode::Squeezing { | ||
next_squeeze_index: rate_start_index + remaining_output.len(), | ||
}; | ||
return Ok(()); | ||
} | ||
// otherwise squeeze (rate - rate_start_index) elements |
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.
Update to match updated Poseidon implementation
} | ||
|
||
#[cfg(feature = "r1cs")] | ||
fn apply_s_box( |
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.
Add tracing instrumentation everywhere.
|
||
impl<F: PrimeField> RescueConfig<F> { | ||
/// Initialize the parameter for Rescue Sponge. | ||
pub fn new( |
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.
Update the Rescue sponge impl to match changed Poseidon impl
Description
closes: #XXXX
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pending
section inCHANGELOG.md
Files changed
in the Github PR explorer