diff --git a/ci/test/03_test_script.sh b/ci/test/03_test_script.sh index 8a88f9343e43..ab6c5251a50a 100755 --- a/ci/test/03_test_script.sh +++ b/ci/test/03_test_script.sh @@ -231,7 +231,7 @@ if [[ "${RUN_IWYU}" == true ]]; then mv "${BASE_BUILD_DIR}/compile_commands_no_subtrees.json" "${BASE_BUILD_DIR}/compile_commands.json" # TODO: Consider enforcing IWYU across the entire codebase. - FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|rpc|script|univalue/(lib|test)|util|zmq)/.*|node/(block_template_manager|blockstorage|interfaces|miner|mining_args|utxo_snapshot)|test/fuzz/(kitchen_sink|minisketch|parse_univalue)|clientversion|core_io|rest|signet|init)\.cpp' + FILES_WITH_ENFORCED_IWYU='/src/((bench|common|consensus|crypto|index|init|kernel|primitives|rpc|script|univalue/(lib|test)|util|zmq)/.*|node/(block_template_manager|blockstorage|interfaces|miner|mining_args|utxo_snapshot)|test/fuzz/(kitchen_sink|minisketch|parse_univalue)|clientversion|core_io|external_signer|rest|signet|init)\.cpp' jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json" jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns) | not))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_warnings.json" diff --git a/doc/external-signer.md b/doc/external-signer.md index 8b02edd6b8ab..0a2158eece78 100644 --- a/doc/external-signer.md +++ b/doc/external-signer.md @@ -148,6 +148,10 @@ A future extension could add an optional return field `reachable`, in case `` and MUST return a JSON object. On success, it MUST contain `{"psbt": ""}` updated to include any new signatures. On failure, it SHOULD contain `{"error": ""}`. Presence of a key `error` with value `null` is not considered an error. +The returned PSBT MUST use the same PSBT version as the request. + +The returned PSBT MUST NOT contain finalized inputs (`PSBT_IN_FINAL_SCRIPTSIG` or `PSBT_IN_FINAL_SCRIPTWITNESS`). Signatures MUST remain in the partial signature or Taproot signature fields so Bitcoin Core can check their sighash types. + PSBT SHOULD include BIP32 derivations. The command SHOULD fail if none of the BIP32 derivations match a key owned by the device. The command SHOULD fail if the user cancels. diff --git a/doc/multisig-tutorial.md b/doc/multisig-tutorial.md index fd74e62ed28f..0a9379d9caf7 100644 --- a/doc/multisig-tutorial.md +++ b/doc/multisig-tutorial.md @@ -20,15 +20,27 @@ This tutorial also uses the default PKH derivation path to get the xpubs and doe For a 2-of-3 multisig, create 3 wallets. These wallets contain HD seed and private keys, which will be used to sign the PSBTs and derive the xpub. -These three wallets should not be used directly for privacy reasons (public key reuse). They should only be used to sign transactions for the (watch-only) multisig wallet. +These three wallets should not be used directly for privacy reasons (public key reuse). They should only be used to sign transactions for the (watch-only) multisig wallet. To make that less likely to happen by accident, participant wallets only have singlesig legacy addresses, and no singlesig Bech32 addresses. + +`addhdkey` adds an HD key to the blank wallet, which `createwalletdescriptor` then uses: ```bash for ((n=1;n<=3;n++)) do - ./build/bin/bitcoin rpc -signet createwallet "participant_${n}" + ./build/bin/bitcoin rpc -signet -named createwallet wallet_name="participant_${n}" blank=true + ./build/bin/bitcoin rpc -signet -rpcwallet="participant_${n}" addhdkey + ./build/bin/bitcoin rpc -signet -rpcwallet="participant_${n}" createwalletdescriptor legacy done ``` +The `legacy` descriptor is only there to hold the private keys: it derives from `m/44h/1h/0h/<0;1>/*`, the same paths as the multisig descriptor defined below, and a wallet can only sign for a derivation path that one of its descriptors uses. + +A later step spends from the multisig wallet, so create one more wallet to receive that payment. This one is an ordinary singlesig wallet, standing in for whoever is being paid: + +```bash +./build/bin/bitcoin rpc -signet createwallet "recipient" +``` + Extract the xpub of each wallet. To do this, the `derivehdkey` RPC is used. Note that previously at least two descriptors were usually used, one for external derivation paths and one for internal ones. Since https://github.com/bitcoin/bitcoin/pull/22838 this redundancy has been eliminated by a multipath descriptor with <0;1> at the [BIP-44](https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki#change) change level expanding to external and internal descriptors when imported. @@ -100,6 +112,7 @@ Once the wallets have already been created and this tutorial needs to be repeate ```bash for ((n=1;n<=3;n++)); do ./build/bin/bitcoin rpc -signet loadwallet "participant_${n}"; done ./build/bin/bitcoin rpc -signet loadwallet "multisig_wallet_01" +./build/bin/bitcoin rpc -signet loadwallet "recipient" ``` ### 1.4 Fund the wallet @@ -138,7 +151,7 @@ PSBT is a data format that allows wallets and other tools to exchange informatio The current PSBT version (v0) is defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki). -For simplicity, the destination address is taken from the `participant_1` wallet in the code above, but it can be any valid bitcoin address. +The destination address is taken from the `recipient` wallet. The `walletcreatefundedpsbt` RPC is used to create and fund a transaction in the PSBT format. It is the first step in creating the PSBT. @@ -147,7 +160,7 @@ balance=$(./build/bin/bitcoin rpc -signet -rpcwallet="multisig_wallet_01" getbal amount=$(echo "$balance * 0.8" | bc -l | sed -e 's/^\./0./' -e 's/^-\./-0./') -destination_addr=$(./build/bin/bitcoin rpc -signet -rpcwallet="participant_1" getnewaddress) +destination_addr=$(./build/bin/bitcoin rpc -signet -rpcwallet="recipient" getnewaddress "" bech32m) funded_psbt=$(./build/bin/bitcoin rpc -signet -rpcwallet="multisig_wallet_01" walletcreatefundedpsbt outputs="{\"$destination_addr\": $amount}" | jq -r '.psbt') ``` diff --git a/doc/release-notes-32857.md b/doc/release-notes-32857.md new file mode 100644 index 000000000000..24cdb811e794 --- /dev/null +++ b/doc/release-notes-32857.md @@ -0,0 +1,8 @@ +Updated RPCs +------------ + +- The `send`, `sendall`, `walletprocesspsbt`, `walletcreatefundedpsbt`, and + `descriptorprocesspsbt` RPCs now accept a `keypath_only` option. When enabled, + they do not add new Taproot script-path data, sign script paths, or finalize + script-path spends. Existing script-path data and signatures remain in a + supplied PSBT. (#32857) diff --git a/doc/release-notes-32861.md b/doc/release-notes-32861.md new file mode 100644 index 000000000000..9030ee57f9f9 --- /dev/null +++ b/doc/release-notes-32861.md @@ -0,0 +1,9 @@ +Updated RPCs +------------ + +- `createwalletdescriptor` no longer requires the `hdkey` argument when the + wallet has no active descriptors but does have exactly one HD key added with + `addhdkey`. Previously the user had to look the key up with `listdescriptors` + and pass it in. This makes it easier to set up a blank wallet that only has + the descriptors it actually needs, which `doc/multisig-tutorial.md` now + demonstrates. (#32861) diff --git a/src/bench/descriptors.cpp b/src/bench/descriptors.cpp index af5dc46b0588..81f8c806396c 100644 --- a/src/bench/descriptors.cpp +++ b/src/bench/descriptors.cpp @@ -24,12 +24,12 @@ static void ExpandDescriptor(benchmark::Bench& bench) const std::pair range = {0, 1000}; FlatSigningProvider provider; std::string error; - auto descs = Parse(desc_str, provider, error); + auto desc = Parse(desc_str, provider, error); bench.run([&] { for (int i = range.first; i <= range.second; ++i) { std::vector scripts; - bool success = descs[0]->Expand(i, provider, scripts, provider); + bool success = desc->Expand(i, provider, scripts, provider); assert(success); } }); diff --git a/src/bench/wallet_encrypt.cpp b/src/bench/wallet_encrypt.cpp index b4883382362b..e20a8cc00886 100644 --- a/src/bench/wallet_encrypt.cpp +++ b/src/bench/wallet_encrypt.cpp @@ -49,8 +49,8 @@ static void WalletEncrypt(benchmark::Bench& bench, unsigned int key_count) CKey key = GenerateRandomKey(); FlatSigningProvider keys; std::string error; - std::vector> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false); - WalletDescriptor w_desc(std::move(desc.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0); + std::unique_ptr desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false); + WalletDescriptor w_desc(std::move(desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0); descs.emplace_back(w_desc, keys); } diff --git a/src/bench/wallet_ismine.cpp b/src/bench/wallet_ismine.cpp index 8bb84e223e18..44c814c2500b 100644 --- a/src/bench/wallet_ismine.cpp +++ b/src/bench/wallet_ismine.cpp @@ -23,7 +23,6 @@ #include #include #include -#include namespace wallet { static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0) @@ -49,8 +48,8 @@ static void WalletIsMine(benchmark::Bench& bench, int num_combo = 0) key.MakeNewKey(/*fCompressed=*/true); FlatSigningProvider keys; std::string error; - std::vector> desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false); - WalletDescriptor w_desc(std::move(desc.at(0)), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0); + std::unique_ptr desc = Parse("combo(" + EncodeSecret(key) + ")", keys, error, /*require_checksum=*/false); + WalletDescriptor w_desc(std::move(desc), /*creation_time=*/0, /*range_start=*/0, /*range_end=*/0, /*next_index=*/0); Assert(wallet->AddWalletDescriptor(w_desc, keys, /*label=*/"", /*internal=*/false)); } } diff --git a/src/common/types.h b/src/common/types.h index 1ffcd392d609..efcebc9062df 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -48,6 +48,12 @@ struct PSBTFillOptions { * Whether to fill in bip32 derivation information if available. */ bool bip32_derivs{true}; + + /** + * Only add new Taproot key-path data, and only sign and finalize Taproot + * inputs using the key path. Existing script-path data is left intact. + */ + bool taproot_keypath_only{false}; }; } // namespace common diff --git a/src/external_signer.cpp b/src/external_signer.cpp index cb49cedc69c2..dd85e3e86f11 100644 --- a/src/external_signer.cpp +++ b/src/external_signer.cpp @@ -4,16 +4,29 @@ #include -#include #include #include #include +#include +#include