diff --git a/doc/release-notes-psbt-bls-finalize.md b/doc/release-notes-psbt-bls-finalize.md new file mode 100644 index 000000000..f7ea0d011 --- /dev/null +++ b/doc/release-notes-psbt-bls-finalize.md @@ -0,0 +1,8 @@ +Wallet +------ + +- `walletprocesspsbt` with `finalize=false` now finalizes an input it signs + with a BLS key. A BLS signature does not fit the partial signature record of + a PSBT, so the PSBT the wallet returned was refused by the next step, + `decodepsbt`, `combinepsbt` and `finalizepsbt` of the same node included. + Inputs signed with ECDSA keys stay partial signatures as before. diff --git a/src/psbt.cpp b/src/psbt.cpp index a08cef7f2..78534665f 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -11,6 +11,7 @@ #include #include +#include #include PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) : tx(tx) @@ -271,8 +272,13 @@ bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& sig_complete = ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata); } - // If we are not finalizing, set sigdata.complete to false to not set the scriptSig - if (!finalize && sigdata.complete) sigdata.complete = false; + // If we are not finalizing, set sigdata.complete to false to not set the scriptSig. Not for a BLS signature: a + // partial signature record (PSBT_IN_PARTIAL_SIG) holds a 33- or 65-byte ECDSA key, and with the 48-byte key of a + // BLS signature the PSBT could not be read back, not even by this node. A BLS signature only spends a + // pay-to-BLS-pubkey script, which that one signature completes, so such an input is finalized instead. + const bool bls_signature{std::any_of(sigdata.signatures.begin(), sigdata.signatures.end(), + [](const auto& entry) { return entry.second.first.IsBLS(); })}; + if (!finalize && sigdata.complete && !bls_signature) sigdata.complete = false; input.FromSignatureData(sigdata); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index c615c5e71..488c67ad1 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4859,7 +4859,7 @@ RPCHelpMan walletprocesspsbt() " \"NONE|ANYONECANPAY\"\n" " \"SINGLE|ANYONECANPAY\""}, {"bip32derivs", RPCArg::Type::BOOL, RPCArg::Default{true}, "Include BIP 32 derivation paths for public keys if we know them"}, - {"finalize", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also finalize inputs if possible"}, + {"finalize", RPCArg::Type::BOOL, RPCArg::Default{true}, "Also finalize inputs if possible. An input signed with a BLS key is finalized either way"}, }, RPCResult{ RPCResult::Type::OBJ, "", "", diff --git a/src/wallet/test/bls_wallet_tests.cpp b/src/wallet/test/bls_wallet_tests.cpp index 3642af1e3..6c873ef96 100644 --- a/src/wallet/test/bls_wallet_tests.cpp +++ b/src/wallet/test/bls_wallet_tests.cpp @@ -5,11 +5,15 @@ #include #include #include +#include #include +#include