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

Added the support for GR1CS and added rescue hash function #161

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

alireza-shirzad
Copy link

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.

  • Targeted PR against correct branch (main)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

assert!(cs.is_satisfied().unwrap());
}
}
// #[cfg(test)]
Copy link
Member

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(&parameters_var, &input_var).unwrap();
}
}
// #[cfg(test)]
Copy link
Member

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"))]
Copy link
Member

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)]
Copy link
Member

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)]
Copy link
Member

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
Copy link
Member

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)) => {
Copy link
Member

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()?

Comment on lines +160 to +207
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
Copy link
Member

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(
Copy link
Member

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(
Copy link
Member

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

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.

None yet

2 participants