-
Notifications
You must be signed in to change notification settings - Fork 47
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
DO NOT MERGE: feat: upgrade to new crypto primitives #81
Conversation
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
/// Builds a new [`State`] from `state`. | ||
#[inline] | ||
pub fn new(state: Box<[S::Field]>) -> Self { | ||
assert_eq!(state.len(), S::WIDTH); |
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.
assert_eq
makes code slower. Should we change to the following?
if state.len() != S::WIDTH {
return None;
}
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.
How does it make it slower? Using None
here is slower.
let linear_combination = state | ||
.iter() | ||
.enumerate() | ||
.map(|(j, elem)| S::mul_const(elem, &self.mds_matrix[S::WIDTH * i + j], compiler)) | ||
.collect::<Vec<_>>(); | ||
next.push( | ||
linear_combination | ||
.into_iter() | ||
.reduce(|acc, next| S::add(&acc, &next, compiler)) | ||
.unwrap(), | ||
); |
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.
Consider using the following:
next.push(
state
.iter()
.enumerate()
.map(|(j, elem)| S::mul_const(elem, &self.mds_matrix[S::WIDTH * i + j], compiler))
.reduce(|acc, next| S::add(&acc, &next, compiler))
.unwrap(),
);
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.
This doesn't work because of the double borrow of compiler
. See the clippy
false-positive note above.
#[inline] | ||
fn first_round_with_domain_tag_unchecked<const N: usize>( | ||
&self, | ||
domain_tag: &S::Field, |
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.
Following our discussion with Dmitry, we can set domain_tag
as S::ParamterField
to reduce a few constraints.
S: Specification<COM>, | ||
S::ParameterField: Field + FieldGeneration + PartialEq + Sample<D>, | ||
{ | ||
/// Samples random Poseidon parameters. |
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.
Should we delete this comment to match the code style of other impl
?
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.
Yes.
/// The encryption key is the information required to produce a valid ciphertext that is targeted | ||
/// towards some [`DecryptionKey`](DecryptionKeyType::DecryptionKey). In the case when the | ||
/// decryption key is linked by some computable protocol to the encryption key, [`Derive`] should be | ||
/// implemented to fascilitate this derivation. |
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.
fascilitate
=> facilitate
/// The decryption key is the information required to open a valid ciphertext that was encrypted | ||
/// with the [`EncryptionKey`](EncryptionKeyType::EncryptionKey) that was targeted towards it. In | ||
/// the case when the decryption key is linked by some computable protocol to the encryption key, | ||
/// [`Derive`] should be implemented to fascilitate this derivation. |
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.
fascilitate
=> facilitate
/// Encryption | ||
pub trait Encrypt<COM = ()>: EncryptionTypes { | ||
/// Encrypts `plaintext` with the `encryption_key` and the one-time encryption `randomness`, | ||
/// including `header`, but not necessarily encrypting it. |
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.
What it
refers to here?
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.
The header
. I'll rewrite.
CLOSE WHEN #149 IS MERGED
We need to add the following cryptographic primitives to get ready for the v1.0.0 release:
Before we can merge this PR, please make sure that all the following items have been checked off:
CHANGELOG.md
and added the appropriatechangelog
label to the PR.Files changed
in the GitHub PR explorer.CONTRIBUTING.md
.