Skip to content

Commit 8fd68a7

Browse files
committed
musig: Add warning to SecretNonce::dangerous_into_bytes about encoding instability
libsecp256k1 states that the byte format `SecretNonce::dangerous_into_bytes` returns is not guaranteed to be stable, and therefore rust-secp256k1 users must be careful to only pass the result of `dangerous_into_bytes` to a compatible `dangerous_from_bytes`, according to version and platform. The simplest and most conservative strategy is to only consider same-versioned and same-platform bytes as compatible. In practice, the format is unlikely to change much if at all between most versions, so more permissive strategies can be employed with research and great care by the user.
1 parent f4c13b7 commit 8fd68a7

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/musig.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ impl KeyAggCache {
653653
/// thing that can or should be done with this nonce is to call [`Session::partial_sign`],
654654
/// which will take ownership. This is to prevent accidental reuse of the nonce.
655655
///
656-
/// See the warning on [`Self::dangerous_into_bytes`] for more information about
656+
/// See the warnings on [`Self::dangerous_into_bytes`] for more information about
657657
/// the risks of non-standard workflows.
658658
#[allow(missing_copy_implementations)]
659659
#[derive(Debug)]
@@ -684,13 +684,20 @@ impl SecretNonce {
684684
///
685685
/// See <https://blockstream.com/2019/02/18/musig-a-new-multisignature-standard/>
686686
/// for more details about these risks.
687+
///
688+
/// # Warning:
689+
///
690+
/// The underlying library, libsecp256k1, does not guarantee the byte format will be consistent
691+
/// across versions or platforms. Special care should be taken to ensure the returned bytes are
692+
/// only ever passed to `dangerous_from_bytes` from the same libsecp256k1 version, and the same
693+
/// platform.
687694
pub fn dangerous_into_bytes(self) -> [u8; secp256k1_sys::MUSIG_SECNONCE_SIZE] {
688695
self.0.dangerous_into_bytes()
689696
}
690697

691698
/// Function to create a new [`SecretNonce`] from a 32 byte array.
692699
///
693-
/// Refer to the warning on [`SecretNonce::dangerous_into_bytes`] for more details.
700+
/// Refer to the warnings on [`SecretNonce::dangerous_into_bytes`] for more details.
694701
pub fn dangerous_from_bytes(array: [u8; secp256k1_sys::MUSIG_SECNONCE_SIZE]) -> Self {
695702
SecretNonce(ffi::MusigSecNonce::dangerous_from_bytes(array))
696703
}

0 commit comments

Comments
 (0)