Merge bitcoin/bitcoin#37040: test: fix private key check in wallet_listdescriptors.py
What changed, and why it matters
This commit fixes a bug in a Bitcoin Core test script. The test was supposed to check that the listdescriptors command does not leak private keys when private=false, but it was checking the wrong thing—so the test would always pass even if a private key appeared. The fix makes the test inspect the actual descriptor strings. This is only a test-code correction; the underlying wallet behavior is unchanged and there is no indication that private keys were actually being leaked.
No security action required. Treat as a normal test-quality improvement. If backporting, include only for test correctness; the production wallet code is unaffected.
Security signals we found
Test-only fix
Corrects a vacuously-true assertion
No change to wallet/RPC implementation
No evidence of actual private-key leakage
Evidence from the diff
In test/functional/wallet_listdescriptors.py, the assertion all(‘tprv’ not in d for d in encrypted_output) iterated over dictionary keys of the RPC result object rather than over the descriptors list. Because ‘tprv’ would never appear as a top-level key, the assertion was vacuously true. The patch changes the iteration to encrypted_output[‘descriptors’] and checks d[‘desc’], correctly validating that no descriptor contains the tprv extended private key prefix when private=false.
Changed components
test/functional/wallet_listdescriptors.pyInspect captured patch +2 / −2
### test/functional/wallet_listdescriptors.py
@@ -37,12 +37,12 @@ def test_encrypted_wallet(self):
encrypted_wallet = self.nodes[0].get_wallet_rpc("encrypted")
self.log.info("- With private=false, Works when locked.")
encrypted_locked_output = encrypted_wallet.listdescriptors()
- assert all("tprv" not in d for d in encrypted_locked_output)
+ assert all("tprv" not in d["desc"] for d in encrypted_locked_output["descriptors"])
self.log.info("- With private=false, output is equivalent when locked and unlocked.")
with WalletUnlock(encrypted_wallet, self.default_wallet_pass):
encrypted_unlocked_output = encrypted_wallet.listdescriptors()
assert_equal(encrypted_locked_output, encrypted_unlocked_output)
- assert all("tprv" not in d for d in encrypted_unlocked_output)
+ assert all("tprv" not in d["desc"] for d in encrypted_unlocked_output["descriptors"])
self.log.info('- With private=true, errors when the wallet is locked.')
assert_raises_rpc_error(-13, 'Please enter the wallet passphrase with walletpassphrase first.', encrypted_wallet.listdescriptors, True)Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.