Skip to content

Commit 44d45ef

Browse files
committed
wallet: Keep secnonces in DescriptorScriptPubKeyMan
1 parent 71d507f commit 44d45ef

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/wallet/scriptpubkeyman.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -2486,6 +2486,10 @@ std::unique_ptr<FlatSigningProvider> DescriptorScriptPubKeyMan::GetSigningProvid
24862486
FlatSigningProvider master_provider;
24872487
master_provider.keys = GetKeys();
24882488
m_wallet_descriptor.descriptor->ExpandPrivate(index, master_provider, *out_keys);
2489+
2490+
// Always include musig_secnonces as this descriptor may have a participant private key
2491+
// but not a musig() descriptor
2492+
out_keys->musig2_secnonces = &m_musig2_secnonces;
24892493
}
24902494

24912495
return out_keys;

src/wallet/scriptpubkeyman.h

+15
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <common/signmessage.h>
1111
#include <common/types.h>
1212
#include <logging.h>
13+
#include <musig.h>
1314
#include <node/types.h>
1415
#include <psbt.h>
1516
#include <script/descriptor.h>
@@ -603,6 +604,20 @@ class DescriptorScriptPubKeyMan : public ScriptPubKeyMan
603604
//! Number of pre-generated keys/scripts (part of the look-ahead process, used to detect payments)
604605
int64_t m_keypool_size GUARDED_BY(cs_desc_man){DEFAULT_KEYPOOL_SIZE};
605606

607+
/** Map of a session id to MuSig2 secnonce
608+
*
609+
* Stores MuSig2 secnonces while the MuSig2 signing session is still ongoing.
610+
* Note that these secnonces must not be reused. In order to avoid being tricked into
611+
* reusing a nonce, this map is held only in memory and must not be written to disk.
612+
* The side effect is that signing sessions cannot persist across restarts, but this
613+
* must be done in order to prevent nonce reuse.
614+
*
615+
* The session id is an arbitrary value set by the signer in order for the signing logic
616+
* to find ongoing signing sessions. It is the SHA256 of aggregate xonly key, + participant pubkey + sighash.
617+
*/
618+
// TODO: Check thread safety of this
619+
mutable std::map<uint256, MuSig2SecNonce> m_musig2_secnonces;
620+
606621
bool AddDescriptorKeyWithDB(WalletBatch& batch, const CKey& key, const CPubKey &pubkey) EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);
607622

608623
KeyMap GetKeys() const EXCLUSIVE_LOCKS_REQUIRED(cs_desc_man);

0 commit comments

Comments
 (0)