Skip to content

Changing the Issuance Authorization Signature to the BIP 340 Schnorr scheme#93

Merged
vivek-arte merged 39 commits intozsa1from
switch_issueauthsig_to_schnorr
Jan 31, 2024
Merged

Changing the Issuance Authorization Signature to the BIP 340 Schnorr scheme#93
vivek-arte merged 39 commits intozsa1from
switch_issueauthsig_to_schnorr

Conversation

@vivek-arte
Copy link

This PR switches the issuance authorization signature from the redpallas signature scheme to the Schnorr signature scheme, as detailed in ZIP 227.

Copy link
Collaborator

@ConstanceBeguier ConstanceBeguier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work !
Some suggestions to improve the implementation

@QED-it QED-it deleted a comment from what-the-diff bot Dec 21, 2023
Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good overall, some more work is required.

In addition we want to test against the same test vectors like in k256/src/schnorr.rs (at least 2 first test values). Just manually copy the values to our repo as tests and add the same comment as in the following code from k256/src/schnorr.rs.

// Test vectors from:
// https://github.com/bitcoin/bips/blob/master/bip-0340/test-vectors.csv
#[cfg(test)]
mod tests {
    use super::{Signature, SigningKey, VerifyingKey};
    use hex_literal::hex;
    use signature::hazmat::PrehashVerifier;

    /// Signing test vector
    struct SignVector {... }

    /// BIP340 signing test vectors: index 0-3
    const BIP340_SIGN_VECTORS: &[SignVector] = &[
        SignVector {
            index: 0,
            secret_key: hex!("0000000000000000000000000000000000000000000000000000000000000003"),
            public_key: hex!("F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9"),
            aux_rand: hex!("0000000000000000000000000000000000000000000000000000000000000000"),
            message: hex!("0000000000000000000000000000000000000000000000000000000000000000"),
            signature: hex!(
                "E907831F80848D1069A5371B402410364BDF1C5F8307B0084C55F1CE2DCA8215
                 25F66A4A85EA8B71E482A74F382D2CE5EBEEE8FDB2172F477DF4900D310536C0"
            ),
        },

Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move to NonZeroScalar for pub struct IssuanceAuthorizingKey([u8; 32]);

/// Non-zero secp256k1 (K-256) scalar field element.
#[cfg(feature = "arithmetic")]
pub type NonZeroScalar = elliptic_curve::NonZeroScalar<Secp256k1>;

/// secp256k1 (K-256) public key.
#[cfg(feature = "arithmetic")]
pub type PublicKey = elliptic_curve::PublicKey<Secp256k1>;

Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good overall, added comments and questions.

src/keys.rs Outdated
impl ConstantTimeEq for IssuanceAuthorizingKey {
fn ct_eq(&self, other: &Self) -> Choice {
self.to_bytes().ct_eq(other.to_bytes())
IssuanceAuthorizingKey::from_bytes(*sk.to_bytes()).unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can fail. Convert from to try_from to make sure we are not ignoring potential errors.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if IssuanceAuthorizingKey::from_bytes(*sk.to_bytes()) is None
I don't want to ignore this case so I suggested to move to try_from

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, missed that. I'll update that

Copy link
Author

@vivek-arte vivek-arte Jan 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this with some changes, that I will summarize here:

  • We don't actually need to allow for the generic conversion from SpendingKey to IssuanceAuthorizationKey anymore, since we are deriving it directly from ZIP 32 seeds.
  • So I removed the From<SpendingKey> implementation altogether, and I instead took the relevant part of logic and moved it to the only place we were using it, which is in the from_zip32_seed function.
  • In there, I allowed for the generation of an error if the IssuanceAuthorizingKey::from_bytes function fails, as pointed out in the original comment in this thread.

@vivek-arte vivek-arte changed the title Switching the Issuance Authorization Signature to the BIP 340 Schnorr scheme Changing the Issuance Authorization Signature to the BIP 340 Schnorr scheme Jan 31, 2024
Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good overall, see last comments to finalize.

src/keys.rs Outdated
impl ConstantTimeEq for IssuanceAuthorizingKey {
fn ct_eq(&self, other: &Self) -> Choice {
self.to_bytes().ct_eq(other.to_bytes())
IssuanceAuthorizingKey::from_bytes(*sk.to_bytes()).unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if IssuanceAuthorizingKey::from_bytes(*sk.to_bytes()) is None
I don't want to ignore this case so I suggested to move to try_from

Copy link
Collaborator

@PaulLaux PaulLaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approved with minor fixes

@vivek-arte vivek-arte merged commit 1a1f3e7 into zsa1 Jan 31, 2024
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.

3 participants