Repository navigation
rpc: add key-origin modes to PSBT processing RPCs - #35370
junbyjun1238 wants to merge 2 commits into
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
willcl-ark
left a comment
There was a problem hiding this comment.
Approach ACK.
This looks like the correct approach (in contrast to #30341), putting strip functionality in walletprocesspsbt (and also descriptorprocesspsbt).
|
The option does more than stripping bip32 derivation paths and it's name should reflect that. I'm not sure about stacking yet another bool argument. Maybe it would be better to convert the existing |
|
Concept ACK 2ec9650 for stripping away the bip32 derivations data if the user intends so.
I'm inclining to agree with this. I think it'd be good to avoid having a new similar looking argument that sort of overlaps with the existing one (based on what's described in the "Behaviour" section). I also believe that updating the existing bip32derivs to accept an enum would be worth the breaking change. Fortunately, the name of the bip32derivs argument already is generic enough that it's functionality can be extended. |
|
Reworked in e5adbdfbe9. The separate The helper and RPC documentation now describe the full key-origin scope: global xpubs and legacy and Taproot BIP32 derivation fields. Normal processing and finalization behavior remain unchanged. |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
maflcko
left a comment
There was a problem hiding this comment.
Given that this is LLM generated, please make sure to adhere to the https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md
| ADD, | ||
| PRESERVE, | ||
| STRIP, |
There was a problem hiding this comment.
nit: would be good to avoid ALL_CAPS going forward for new code. The dev notes aren't updated yet (c.f. #35588 (comment)), but lately there was a scripted-diff roughly every two weeks to rename an ALL_CAPS to PascalCase or snake_case, due to a third-party macro clash.
| finalize=False, | ||
| ) | ||
|
|
||
| cli_stripped = self.nodes[1].cli.walletprocesspsbt( |
There was a problem hiding this comment.
The test supports --usecli, so why is this duplicate?
|
I authored the original PR and the initial revisions myself. For these additional changes, I used an LLM as a tool. Unfortunately, I failed to properly catch the issues before pushing. I have now personally reviewed both the original and current changes, and I fully understand the content. I have also reviewed the AI policy, and going forward, I will take personal responsibility for reviewing changes and responding to feedback. |
You can remove this whole LLM generated redundant section. A human can see that you modified |
Remove global xpubs and input and output BIP32 derivation fields while leaving other PSBT data unchanged.
Allow bip32derivs to select add, preserve, or strip behavior in walletprocesspsbt and descriptorprocesspsbt. Keep true and false as aliases for add and preserve.
2e2070a to
af75215
Compare
fametrano
left a comment
There was a problem hiding this comment.
With "strip", a tr(musig(A,B)/<0;1>/*) wallet makes no MuSig2 nonce and no partial signature on a PSBT that has no key origins yet. The signer needs the aggregate key's derivation path to find the tweak, and "strip" runs it with key origins hidden, as false already does on master.
I tested af75215 on top of master 7988380 with a 2-of-2 MuSig2 wallet pair. With "add" both rounds work and the transaction is accepted. With "strip", walletprocesspsbt returns no musig2_pubnonces. Legacy, p2sh-segwit, wpkh, taproot key and script path, and wsh multisig all sign fine with "strip".
Processing with origins and stripping at the end fixes the signing, as in the two inline suggestions. With that change I get nonces and partial signatures, the outputs still carry no derivations, and rpc_psbt.py passes. finalizepsbt still cannot finalize the stripped PSBT, because the aggregate's derivation is gone. I have not tried finalizing inside the walletprocesspsbt call.
| bool sign = request.params[1].isNull() ? true : request.params[1].get_bool(); | ||
| bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool(); | ||
| const PSBTKeyOriginMode key_origin_mode{ParseBip32DerivsMode(self.Arg<UniValue>("bip32derivs"))}; | ||
| const bool bip32derivs{key_origin_mode == PSBTKeyOriginMode::Add}; |
There was a problem hiding this comment.
Fill with key origins and strip them afterwards, so "strip" can still sign MuSig2 inputs:
| const bool bip32derivs{key_origin_mode == PSBTKeyOriginMode::Add}; | |
| const bool bip32derivs{key_origin_mode != PSBTKeyOriginMode::Preserve}; |
| std::optional<int> sighash_type = ParseSighashString(request.params[2]); | ||
| bool bip32derivs = request.params[3].isNull() ? true : request.params[3].get_bool(); | ||
| const PSBTKeyOriginMode key_origin_mode{ParseBip32DerivsMode(self.Arg<UniValue>("bip32derivs"))}; | ||
| const bool bip32derivs{key_origin_mode == PSBTKeyOriginMode::Add}; |
There was a problem hiding this comment.
Same change as in walletprocesspsbt:
| const bool bip32derivs{key_origin_mode == PSBTKeyOriginMode::Add}; | |
| const bool bip32derivs{key_origin_mode != PSBTKeyOriginMode::Preserve}; |
fametrano
left a comment
There was a problem hiding this comment.
bip32derivs=false is only tested on a PSBT without key origins, where "preserve" and "strip" give the same result. So mapping false to Strip in ParseBip32DerivsMode still passes rpc_psbt.py. One check after the "preserve" call on psbt_with_derivs catches it, as in the inline suggestion. It passes on af75215 and fails with that change.
| decoded = self.nodes[0].decodepsbt(preserved) | ||
| assert "bip32_derivs" in decoded["inputs"][0] | ||
| assert "bip32_derivs" in decoded["outputs"][0] | ||
| assert_equal(len(decoded["global_xpubs"]), 1) |
There was a problem hiding this comment.
| assert_equal(len(decoded["global_xpubs"]), 1) | |
| assert_equal(len(decoded["global_xpubs"]), 1) | |
| assert_equal(self.nodes[1].walletprocesspsbt(psbt=psbt_with_derivs, sign=False, sighashtype="ALL", bip32derivs=False, finalize=False)["psbt"], preserved) |
|
With |
|
🐙 This pull request conflicts with the target branch and needs rebase. |
| removes surviving global xpubs and legacy and Taproot BIP32 derivation | ||
| fields after normal processing. The default remains `true`, equivalent to | ||
| `"add"`; `false` remains accepted as an alias for `"preserve"`. | ||
| Finalization may remove input key-origin fields in any mode. |
There was a problem hiding this comment.
| Finalization may remove input key-origin fields in any mode. | |
| Finalization may remove input key-origin fields in any mode. (#35370) |

This PR extends the existing
bip32derivsargument of thewalletprocesspsbtanddescriptorprocesspsbtRPCs with explicit key-originmodes.
Motivation
Setting
bip32derivs=falseprevents new key-origin fields from being added, butdoes not explicitly remove fields already present in an input PSBT. Some
collaborative PSBT workflows need to remove that metadata before sharing the
PSBT.
Behavior
trueor"add"allows known key-origin fields to be added.falseor"preserve"does not add or explicitly remove key-origin fields."strip"does not add key-origin fields and removes surviving standardkey-origin fields after normal processing.
The default remains
true. The existing boolean values remain accepted forcompatibility.
Stripping removes global xpubs and legacy and Taproot BIP32 derivation fields
from inputs and outputs. Unknown and proprietary PSBT fields are left
unchanged. Finalization may independently remove input key-origin fields.
Closes #30294.