Derive MuSig2 nonces from the untweaked aggregate key
What changed, and why it matters
This commit changes how cryptographic 'nonces' (one-time random numbers used in multi-signature Bitcoin signing) are derived in Ledger's Bitcoin app. Previously, the nonce was tied to details of the exact transaction being signed, which could cause problems if a wallet wanted to prepare nonces before the final transaction was known. The change makes the nonce depend only on secret device randomness and wallet policy, not on transaction details. The commit frames this as a usability/protocol correctness improvement and explicitly states it is not a security vulnerability, because the old design still did not let an attacker predict or control the nonces.
Treat as a protocol-correctness/usability improvement rather than a security fix. Reviewers may still want to confirm that musig_nonce_gen handles the untweaked aggregate key correctly and that the change does not affect partial signature verification against the tweaked key in round 2. No urgent security response is indicated by the supplied materials.
Security signals we found
Change to cryptographic nonce derivation input (aggpk) in MuSig2 signing
Removal of transaction-dependent tweak from nonce generation entropy
Documentation explicitly states prior behavior was not a security risk and that attacker could not predict or control nonces
No CVE, advisory, or independent researcher attribution present in commit materials
Evidence from the diff
In the MuSig2 signing flow, the app now passes the untweaked aggregate public key (keyexpr_info->pubkey.compressed_pubkey + 1) to musig_nonce_gen as the aggpk argument, instead of the tweaked aggregate key (musig_per_input_info.agg_key_tweaked.compressed_pubkey + 1). The tweaked key incorporates BIP-32 derivation and BIP-341 taptweak data that depend on the specific UTXO/input, while the untweaked key does not. The commit removes the aggpk parameter from musig_derive_nonce and updates documentation to explain that aggpk, msg, and extra_in are omitted or chosen to be transaction-independent so that round-1 nonce generation can happen before the PSBT is finalized. The commit message and docs describe the prior behavior as a design limitation, not a security flaw, and emphasize that the old parameters were only defense-in-depth entropy and did not enable nonce prediction or manipulation.
Changed components
src/handler/sign_psbt/musig_signing.cdoc/musig.mdLedger Bitcoin app MuSig2 nonce generation (round 1 and round 2 recomputation)Inspect captured patch +29 / −19
### doc/musig.md
@@ -43,6 +43,13 @@ In the concatenation, a fixed-length encoding of $i$ and $j$ is used in order to
The *j* parameter allows to handle wallet policies that contain more than one `musig()` key expression involving the signing device.
+The other arguments of *NonceGen* are chosen so that they do not depend on the transaction, nor on the UTXO being spent:
+- *pk* is the public key of the signing device in the `musig()` key expression;
+- *aggpk* is the aggregate public key of the `musig()` key expression _before_ any tweak, that is, before the BIP-32 derivation steps and the BIP-0341 taptweak that depend on the UTXO;
+- *msg* and *extra_in* are omitted.
+
+Therefore, each *(secnonce, pubnonce)* pair only depends on `rand_root`, on $i$ and $j$, and on the wallet policy.
+
#### Signing flow in detail
This section describes the handling of the psbt-level sessions, plugging on top of the default signing flow of BIP-0327.
@@ -58,13 +65,13 @@ The term *persistent memory* refers to secure storage that is not wiped out when
- A new session is created in volatile memory.
- The device produces a fresh random number $rand\_{root}$, and saves it in the current session.
- The device generates the randomness for the $i$-th input and for the $j$-th key as: $rand_{i,j} = SHA256(rand\_{root} \| i \| j)$.
-- Compute each *(secnonce, pubnonce)* as per the `NonceGen` algorithm.
+- Compute each *(secnonce, pubnonce)* as per the `NonceGen` algorithm, with the arguments described above.
- At completion (after all the pubnonces are returned), the session secret $rand\_{root}$ is copied into the persistent memory.
**Phase 2: partial signature generation:** A PSBT containing all the pubnonces is sent to the device.
- *A copy of the session is stored in the volatile memory, and the session is deleted from the persistent memory*.
- For each input/musig-key pair $(i, j)$:
- - Recompute the pubnonce/secnonce pair using `NonceGen` with the synthetic randomness $rand_{i,j}$ as above.
+ - Recompute the pubnonce/secnonce pair using `NonceGen` with the synthetic randomness $rand_{i,j}$ and the other arguments as above.
- Verify that the pubnonce contained in the PSBT matches the one synthetically recomputed.
- Continue the signing flow as per BIP-0327, generating the partial signature.
@@ -76,10 +83,10 @@ Storing the session in persistent memory only at the end of Phase 1, and deletin
Generating $rand_{i, j}$ synthetically is not a problem, since the $rand\_{root}$ value is kept secret and never leaves the device. This ensures that all the values produced for different $i$ and $j$ are not predictable for an attacker.
-#### Malleability of the PSBT
-If the optional parameters are passed to the _NonceGen_ function, they will depend on the transaction data present in the PSBT. Therefore, there is no guarantee that they will be unchanged the next time the PSBT is provided.
+#### Optional arguments of NonceGen
+In BIP-0327, *aggpk*, *msg* and *extra_in* are optional arguments of _NonceGen_. They only add entropy, as a defense in depth against a faulty source of randomness. They are not needed for the uniqueness of the nonces, which comes from $rand\_{root}$ being generated by the hardware RNG, and from the $(i, j)$ domain separation in $rand_{i,j}$.
-However, that does not constitute a security risk, as those parameters are only used as additional sources of entropy in _NonceGen_. A malicious software wallet can't affect the _secnonce_/_pubnonce_ pairs in any predictable way. Changing any of the parameters used in _NonceGen_ would cause a failure during Phase 2, as the recomputed _pubnonce_ would not match the one in the psbt.
+BIP-0327 suggests using the tweaked aggregate key as *aggpk*. Using the untweaked one instead is what makes the pubnonces independent of the transaction, and of the (change, address index) of the UTXO being spent. Since none of the arguments depend on the PSBT, a malicious software wallet can't affect the _secnonce_/_pubnonce_ pairs in any way. A PSBT whose pubnonces were not produced by the current session makes Phase 2 fail, as the recomputed _pubnonce_ does not match the one in the PSBT.
### Generalization to multiple PSBT signing sessions
### src/handler/sign_psbt/musig_signing.c
@@ -169,11 +169,22 @@ bool compute_musig_per_input_info(dispatcher_context_t *dc,
* Derives the (secnonce, pubnonce) pair for the given (input index, key expression) pair, out of
* the synthetic randomness of the psbt-level MuSig2 session.
*
+ * The nonce deliberately depends only on the session randomness, the two indices and the wallet
+ * policy; it does _not_ depend on the transaction, nor on the input's (change, address_index).
+ * Therefore, the `aggpk` argument of NonceGen is the aggregate key of the musig() key expression
+ * _before_ any of the tweaks, rather than the tweaked key that is actually being signed for.
+ * In BIP-0327, `aggpk` (like `msg`, which this app already omits) is an optional argument whose
+ * only purpose is to add further entropy to the derivation, as a defense in depth; it is not
+ * needed for the uniqueness of the nonce, which here is guaranteed by `rand_root` coming from
+ * the hardware RNG and by the (input_index, keyexpr_index) domain separation in compute_rand_i_j.
+ *
+ * Making the nonce independent of the transaction is what allows a client to run round 1 of MuSig2
+ * before knowing the transaction that will be signed. See doc/musig.md.
+ *
* On failure, the secnonce is zeroed out before returning.
*/
static bool __attribute__((noinline)) musig_derive_nonce(const musig_psbt_session_t *psbt_session,
const keyexpr_info_t *keyexpr_info,
- const uint8_t aggpk[static 32],
unsigned int input_index,
musig_secnonce_t *secnonce,
musig_pubnonce_t *pubnonce) {
@@ -183,7 +194,8 @@ static bool __attribute__((noinline)) musig_derive_nonce(const musig_psbt_sessio
int res = musig_nonce_gen(rand_i_j,
sizeof(rand_i_j),
keyexpr_info->internal_pubkey.compressed_pubkey,
- aggpk,
+ // untweaked aggregate key of the musig() key expression
+ keyexpr_info->pubkey.compressed_pubkey + 1,
secnonce,
pubnonce);
@@ -323,12 +335,8 @@ bool produce_and_yield_pubnonce(dispatcher_context_t *dc,
musig_secnonce_t secnonce;
musig_pubnonce_t pubnonce;
- bool nonce_ok = musig_derive_nonce(psbt_session,
- keyexpr_info,
- musig_per_input_info.agg_key_tweaked.compressed_pubkey + 1,
- cur_input_index,
- &secnonce,
- &pubnonce);
+ bool nonce_ok =
+ musig_derive_nonce(psbt_session, keyexpr_info, cur_input_index, &secnonce, &pubnonce);
// round 1 only publishes the pubnonce; the secnonce is recomputed in round 2
explicit_bzero(&secnonce, sizeof(secnonce));
@@ -459,12 +467,7 @@ bool __attribute__((noinline)) sign_sighash_musig_and_yield(dispatcher_context_t
musig_secnonce_t secnonce;
musig_pubnonce_t pubnonce;
- if (!musig_derive_nonce(psbt_session,
- keyexpr_info,
- musig_per_input_info.agg_key_tweaked.compressed_pubkey + 1,
- cur_input_index,
- &secnonce,
- &pubnonce)) {
+ if (!musig_derive_nonce(psbt_session, keyexpr_info, cur_input_index, &secnonce, &pubnonce)) {
SEND_SW(dc, SW_BAD_STATE); // should never happen
return false;
}Why this scored 30/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.