Repository navigation
refactor(wallet)!: remove signer and policy modules - #647
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #647 +/- ##
==========================================
- Coverage 82.04% 81.70% -0.34%
==========================================
Files 25 23 -2
Lines 6310 5056 -1254
Branches 308 217 -91
==========================================
- Hits 5177 4131 -1046
+ Misses 1030 852 -178
+ Partials 103 73 -30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7dc3b7d to
79d04a2
Compare
|
cACK thanks for getting this started! |
2cb132d to
38bb925
Compare
|
Could timelock_condition get a test where it returns None in tx_builder? Also, the Display impl for check_sighashes uses one allow list for every input, so an ECDSA input with SIGHASH_DEFAULT (0x00) passes it. I checked: |
Yes. In bitcoin 0.32.102, Psbt::sign goes through every input, writes each signature it can make into the PSBT, and only then returns Err((used, errors)), with the inputs it did sign in used. I checked with a two-input PSBT whose second input asks for sighash 0x00: check_sighashes lets it through, Psbt::sign signs input 0 and fails input 1 with InvalidSighashType, and the PSBT it leaves behind holds input 0's signature. That signature is SIGHASH_ALL over the reviewed transaction, so nothing is lost here, but the example could say that after an Err the PSBT may still carry signatures and should be dropped, not passed on. 3.2.0's Wallet::sign does the same today (it returns NonStandardSighash after signing input 0), which is #519. I also ran the adversarial PSBTs in https://github.com/KHADEVS/bitcoin-signer-cases through three setups: 3.2.0's Wallet::sign, Psbt::sign on its own, and Psbt::sign after check_prevouts and check_sighashes from this PR, copied unchanged. With the two checks, the results match Wallet::sign on all 19 cases. Without them, Psbt::sign signs a legacy input sent without its previous transaction (the fee shown is 10,000 sats, the real one 4,010,000), two segwit v0 inputs with nothing proving their amounts, and inputs asking for SIGHASH_NONE and SINGLE|ANYONECANPAY. The table is in results/MATRIX.md. Since every wallet that moves to Psbt::sign needs these exact checks, would it make sense to ship them as public functions, in bdk_wallet::psbt for instance, rather than as an example to copy? A wallet that never sees the example gets no warning from the compiler. |
38bb925 to
e5afdec
Compare
|
@muhahahmad68 Thanks, I added more
|
In one of our last calls we decided against that. Because upcoming versions of rust-psbt will cover the |
e5afdec to
54bee8d
Compare
54bee8d to
bc322f6
Compare
|
Thanks for the review @nymius. I addressed your comments. |
yanfsb
left a comment
There was a problem hiding this comment.
tACK bc322f6
Tested on regtest against master with bitcoind v28.1 across wpkh, taproot, multisig, CSV/CLTV, and an or_d timelock descriptor. Sequences, locktimes, mempool checks, and confirmations all matched master :).
I think it would help to link examples/signing_checks.rs from the electrum, esplora, and fee-bump examples, since those call Psbt::sign directly without mentioning the prevout/sighash checks, maybe.
There was a problem hiding this comment.
A final pass with the clanker flagged me the following:
tests/wallet.rs:1063: fn test_create_tx_policy_path_required() — policy_path no longer exists. The test itself is still valid: it asserts builder.finish() fails with SpendingPolicyRequired(External)
There was a problem hiding this comment.
ACK bc322f6
Looks good, well organized and rips out all the old signing code.
As @noahjoeris noted in the PR description some things still need to be documented and deprecated in the 3.x branch and a future 3.x release. I asked my LLM to help lay out what the TODOs are and it found:
sign_with_signers gap: 3.x deprecation messages say "use Wallet::sign_with_signers with caller-owned SignersContainers." Both sign_with_signers and SignersContainer are removed un-deprecated. If 3.x is meant to guide users off the old API, sign_with_signers and the signer module need deprecations that point to bitcoin::Psbt::sign + wallet.secp_ctx() instead.
…licy paths When no condition is set via `TxBuilder::set_condition`, `create_tx` now lifts each keychain's descriptor and applies the default spending-policy rule. If the timelocks are ambiguous, it returns `SpendingPolicyRequired`. Remove the deprecated `Wallet::policies` and `TxBuilder::policy_path`.
Drop `signers` and `change_signers` from `Wallet`, discard extracted secret keys when creating or loading a wallet, and remove the deprecated `Wallet::sign`, `Wallet::add_signer`, `Wallet::set_keymap`, `Wallet::set_keymaps`, `Wallet::get_signers`, `CreateParams::keymap`, `LoadParams::keymap`, and `LoadParams::extract_keys` methods.
Remove `signer.rs`, `Wallet::sign_with_signers`, `SignOptions`, `SignerError` and their re-exports. Sign PSBTs with `bitcoin::Psbt::sign`. `Wallet::finalize_psbt` no longer takes `SignOptions` and returns `IndexOutOfBoundsError` instead of `SignerError`.
bc322f6 to
2cb97ef
Compare
|
Thanks for the reviews.
|
notmandatory
left a comment
There was a problem hiding this comment.
reACK 4ad4917
Adding #[non_exhaustive] on CreateTxError makes sense for this and other Err enums.
I've mentioned this before in another PR, but we should check if is not convenient for us to do the same for all errors, as |
Closes #70
Description
Implements the signer removal planned in #70 for v4 alpha 0.
Removes the signer and descriptor policy modules, including wallet signing and keymap management. Wallets retain only public descriptors; callers manage keys and sign through
bitcoin::Psbt::signor an external signer.Notes to the reviewers
TxBuilderderives timelocks directly from descriptors, removing its dependency on the policy and signer modules. I movedConditionfrompolicytotx_builderto retainset_conditionafter removing the policy module.Psbt::signdoes not replace allSignOptionsbehavior at the moment. Callers must handle prevout validation and sighash restrictions previously controlled bytrust_witness_utxoandallow_all_sighashes. I added an example of how to do so inexamples/signing_checks.rsChangelog notice
Before submitting