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

DO NOT MERGE: feat: upgrade to new crypto primitives #81

Closed
wants to merge 50 commits into from

Conversation

bhgomes
Copy link
Contributor

@bhgomes bhgomes commented May 26, 2022

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:

  • Linked to an issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Added one line describing your change in CHANGELOG.md and added the appropriate changelog label to the PR.
  • Re-reviewed Files changed in the GitHub PR explorer.
  • Checked that changes and commits conform to the standards outlined in CONTRIBUTING.md.

@bhgomes bhgomes added this to the Version 0 milestone May 26, 2022
manta-crypto/src/mac.rs Outdated Show resolved Hide resolved
manta-crypto/src/mac.rs Outdated Show resolved Hide resolved
manta-crypto/src/mac.rs Outdated Show resolved Hide resolved
@bhgomes bhgomes mentioned this pull request Jun 9, 2022
@bhgomes bhgomes changed the title Add Crypto Primitives for v1.0 Merge feat: upgrade to new crypto primitives Jun 9, 2022
manta-crypto/Cargo.toml Show resolved Hide resolved
manta-crypto/src/algebra.rs Outdated Show resolved Hide resolved
manta-crypto/src/eclair/alloc.rs Show resolved Hide resolved
manta-crypto/src/eclair/execution.rs Show resolved Hide resolved
manta-crypto/src/eclair/measure.rs Outdated Show resolved Hide resolved
manta-crypto/src/signature.rs Outdated Show resolved Hide resolved
manta-crypto/src/signature.rs Show resolved Hide resolved
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
@bhgomes bhgomes linked an issue Jun 21, 2022 that may be closed by this pull request
@bhgomes bhgomes requested a review from BoyuanFeng June 21, 2022 02:16
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
Signed-off-by: Brandon H. Gomes <bhgomes@pm.me>
@bhgomes bhgomes marked this pull request as ready for review June 21, 2022 04:37
/// Builds a new [`State`] from `state`.
#[inline]
pub fn new(state: Box<[S::Field]>) -> Self {
assert_eq!(state.len(), S::WIDTH);
Copy link
Contributor

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;
}

Copy link
Contributor Author

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.

Comment on lines +280 to +290
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(),
);
Copy link
Contributor

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(),
            );

Copy link
Contributor Author

@bhgomes bhgomes Jun 21, 2022

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,
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.
Copy link
Contributor

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.
Copy link
Contributor

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.
Copy link
Contributor

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?

Copy link
Contributor Author

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.

manta-crypto/src/permutation/duplex.rs Show resolved Hide resolved
manta-crypto/src/permutation/sponge.rs Show resolved Hide resolved
@bhgomes bhgomes changed the title feat: upgrade to new crypto primitives DO NOT MERGE: feat: upgrade to new crypto primitives Jun 21, 2022
@bhgomes bhgomes marked this pull request as draft June 21, 2022 21:22
@bhgomes bhgomes modified the milestones: v0.5.2, v0.5.3 Jun 28, 2022
@bhgomes bhgomes added DO-NOT-MERGE Labels a PR that should not be merged P-high Priority: High labels Jul 6, 2022
@bhgomes bhgomes closed this Jul 8, 2022
@bhgomes bhgomes deleted the feat/add-crypto-primitives branch January 10, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DO-NOT-MERGE Labels a PR that should not be merged P-high Priority: High
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Setup Poseidon as a Permutation
3 participants