Changing the Issuance Authorization Signature to the BIP 340 Schnorr scheme#93
Changing the Issuance Authorization Signature to the BIP 340 Schnorr scheme#93vivek-arte merged 39 commits intozsa1from
Conversation
…norr random key generation algorithm
…sting part of the code
ConstanceBeguier
left a comment
There was a problem hiding this comment.
Good work !
Some suggestions to improve the implementation
… the keys are picked randomly
… since some entries are picked randomly
…the remaining asset_id are the ones that use the spec defined term for asset_id)
PaulLaux
left a comment
There was a problem hiding this comment.
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"
),
},There was a problem hiding this comment.
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>;…nstantiating the Rng inside the random function to avoid propagating the CryptoRngCore trait requirement
…eValidatingKey to contain PublicKey
…ance authorization signature function
PaulLaux
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
this can fail. Convert from to try_from to make sure we are not ignoring potential errors.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Oh I see, missed that. I'll update that
There was a problem hiding this comment.
Updated this with some changes, that I will summarize here:
- We don't actually need to allow for the generic conversion from
SpendingKeytoIssuanceAuthorizationKeyanymore, 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 thefrom_zip32_seedfunction. - In there, I allowed for the generation of an error if the
IssuanceAuthorizingKey::from_bytesfunction fails, as pointed out in the original comment in this thread.
PaulLaux
left a comment
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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
…t logic to the from_zip32_seed function
PaulLaux
left a comment
There was a problem hiding this comment.
approved with minor fixes
This PR switches the issuance authorization signature from the redpallas signature scheme to the Schnorr signature scheme, as detailed in ZIP 227.