Skip to content

Commit d611a4f

Browse files
committed
musig: weaken/simplify warnings about nonce reuse
These warnings were repetitive and a bit overwrought. "Will leak your key in two signatures" is clear enough. The text also said some out-of-date things about whether it's possible to reuse a nonce -- you can do it directly now with dangerous_into_bytes, and also you could always do it indirectly by just constructing the same nonce twice by using a bad rng.
1 parent 8a43317 commit d611a4f

File tree

1 file changed

+15
-24
lines changed

1 file changed

+15
-24
lines changed

src/musig.rs

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -572,24 +572,15 @@ impl KeyAggCache {
572572

573573
/// Musig Secret Nonce.
574574
///
575-
/// This structure MUST NOT be copied or
576-
/// read or written to it directly. A signer who is online throughout the whole
577-
/// process and can keep this structure in memory can use the provided API
578-
/// functions for a safe standard workflow. See
579-
/// <https://blockstream.com/2019/02/18/musig-a-new-multisignature-standard/> for
580-
/// more details about the risks associated with serializing or deserializing
581-
/// this structure. There are no serialization and parsing functions (yet).
575+
/// A signer who is online throughout the whole process and can keep this structure
576+
/// in memory can use the provided API functions for a safe standard workflow.
582577
///
583-
/// Note this deliberately does not implement `Copy` or `Clone`. After creation, the only
584-
/// use of this nonce is [`Session::partial_sign`] API that takes ownership of this
585-
/// and drops it. This is to prevent accidental misuse of this nonce.
578+
/// This structure does not implement `Copy` or `Clone`; after construction the only
579+
/// thing that can or should be done with this nonce is to call [`Session::partial_sign`],
580+
/// which will take ownership. This is to prevent accidental reuse of the nonce.
586581
///
587-
/// A signer who is online throughout the whole process and can keep this
588-
/// structure in memory can use the provided API functions for a safe standard
589-
/// workflow.
590-
///
591-
/// Signers that pre-compute and save these nonces are not yet supported. Users
592-
/// who want to serialize this must use unsafe rust to do so.
582+
/// See the warning on [`Self::dangerous_into_bytes`] for more information about
583+
/// the risks of non-standard workflows.
593584
#[allow(missing_copy_implementations)]
594585
#[derive(Debug)]
595586
pub struct SecretNonce(ffi::MusigSecNonce);
@@ -612,20 +603,20 @@ impl SecretNonce {
612603
/// Function to return a copy of the internal array. See WARNING before using this function.
613604
///
614605
/// # Warning:
615-
/// This structure MUST NOT be copied or read or written to directly. A
616-
/// signer who is online throughout the whole process and can keep this
617-
/// structure in memory can use the provided API functions for a safe standard
618-
/// workflow.
619606
///
620-
/// We repeat, copying this data structure can result in nonce reuse which will
621-
/// leak the secret signing key.
607+
/// Storing and re-creating this structure may leak to nonce reuse, which will leak
608+
/// your secret key in two signing sessions, even if neither session is completed.
609+
/// These functions should be avoided if possible and used with care.
610+
///
611+
/// See <https://blockstream.com/2019/02/18/musig-a-new-multisignature-standard/>
612+
/// for more details about these risks.
622613
pub fn dangerous_into_bytes(self) -> [u8; secp256k1_sys::MUSIG_SECNONCE_LEN] {
623614
self.0.dangerous_into_bytes()
624615
}
625616

626-
/// Function to create a new MusigKeyAggCoef from a 32 byte array. See WARNING before using this function.
617+
/// Function to create a new [`SecretNonce`] from a 32 byte array.
627618
///
628-
/// Refer to [`SecretNonce::dangerous_into_bytes`] for more details.
619+
/// Refer to the warning on [`SecretNonce::dangerous_into_bytes`] for more details.
629620
pub fn dangerous_from_bytes(array: [u8; secp256k1_sys::MUSIG_SECNONCE_LEN]) -> Self {
630621
SecretNonce(ffi::MusigSecNonce::dangerous_from_bytes(array))
631622
}

0 commit comments

Comments
 (0)