Repository navigation
Closed
Description
Problem statement
signdatapqchash consumes a bounded PQC signature outside normal transaction signing. The implementation appears to use wallet-backed counter reservation through the same provider path as transaction signing, but coverage does not fully prove the intended policy for data-hash signing: pre-reservation failures must not move counters, and wallet-backed reservations that are already persisted should be treated as consumed rather than rolled back.
The same fix should make that policy explicit, test it, and improve visibility when signdatapqchash consumes a counter, especially around multi-leaf retries and post-reservation failures.
Evidence
signdatapqchashbuilds aPQCUsageRecorder, calls wallet data-hash signing, then appends usage only on success:src/wallet/rpc/signmessage.cpp:219.- Wallet data-hash signing delegates through matching SPKMs:
src/wallet/wallet.cpp:2806. DescriptorScriptPubKeyMan::SignDataPQCHashobtains a privateFlatSigningProviderwith the observer wired in:src/wallet/scriptpubkeyman.cpp:2499.- Wallet-backed providers install reserver, batch reserver, and observer hooks:
src/wallet/scriptpubkeyman.cpp:1951. SignP2MRDataHashfilters candidate leaves and may continue to later leaves after a signing failure:src/wallet/scriptpubkeyman.cpp:2454.FlatSigningProvider::SignPQCreserves before raw signing. Rollback currently exists only for the older writer path, not the wallet-backed reserver path:src/script/signingprovider.cpp:173,src/script/signingprovider.cpp:206.- Functional data-hash coverage checks the happy path and
include_pqc_usage=false, but not persistence, failures, or lifecycle accounting:test/functional/feature_p2mr.py:528. wallet_pqc_usage.pycovers transaction signing RPC usage surfaces but notsigndatapqchash:test/functional/wallet_pqc_usage.py:5.
Proposed acceptance criteria
- Document/enforce policy: wallet-backed PQC reservations are committed once persisted; post-reservation signing failure must not reuse the reserved counter.
- Pre-reservation
signdatapqchashfailures leave counters unchanged. - Successful
signdatapqchashadvances exactly one counter and reports the same usage fields as transaction signing. - If a post-reservation failure consumes a counter, it is visible: either included in the success usage report when a later leaf succeeds, or logged clearly when the RPC ultimately fails.
- Near-limit behavior is tested:
PQC_MAX_SIGNATURES - 1signs once and reports exhausted/warnings;PQC_MAX_SIGNATURESfails without movement. include_pqc_usage=falsehides fields only; it must not change reservation or persistence behavior.
Suggested success and failure cases
- Success: default leaf, explicit pubkey/leaf/control block, multi-leaf selected leaf, reload persistence.
- Pre-reservation failure: bad requested pubkey, leaf mismatch, control block mismatch, missing/watch-only key, locked wallet, plaintext PQC validation blocked.
- Post-reservation failure: forced raw signing failure after wallet reservation.
- Multi-leaf: first candidate unavailable, first candidate post-reservation fails then later leaf succeeds, explicit failing leaf.
- Limit: one remaining signature, no remaining signatures.
Recommended test location
- Add focused unit tests in
src/wallet/test/wallet_tests.cpporsrc/test/pqc_tests.cppfor reservation-commit and post-reservation failure semantics. - Extend
test/functional/wallet_pqc_usage.pywithsigndatapqchashlifecycle/reporting cases. - Keep proof/verification behavior in
test/functional/feature_p2mr.py.
Recommended resolutions
- Treat wallet-backed PQC counter reservations as committed once persisted. Do not add rollback for the wallet reserver path unless there is a stronger guarantee that raw signing did not consume the reserved signing slot.
- Make consumed reservations observable even when raw signing fails after reservation. For wallet-backed
pqc_counter_reserver, invoke the usage observer for the committed range even ifCPQCKey::Signlater returns false. - If multi-leaf
signdatapqchashconsumes a counter on one candidate and later succeeds on another, include both consumed keys inpqc_key_statesand warnings. - If
signdatapqchashultimately fails after consuming a counter, log the consumed counter movement in the wallet log. Avoid changing the RPC error shape in this issue. - Keep pre-reservation failures counter-neutral. Requested pubkey/leaf/control mismatches, missing keys, locked wallets, plaintext validation blocks, and exhausted counters should fail before reservation and leave usage unchanged.
- Distinguish exhausted PQC budget from missing private key where practical, so operators can tell "cannot sign because the key is exhausted" from "cannot sign because the wallet lacks the key."
- Add comments/tests that align data-hash signing with transaction signing's conservative policy: once a wallet counter is durably reserved, the signature slot is not reused.
Metadata
Metadata
Assignees
Labels
No labels
Activity