Repository navigation
Conversation
`verify_input_authorization` checks that a transaction input carries a valid P2PKH / `SIGHASH_ALL` owner signature for the funding output it claims. A wallet can use it to decide whether a pending spend may reserve one of its coins before the spend is final. Unsupported funding scripts and signature hash types return a typed `SpendAuthorizationError`, so a caller does not release an existing hold by mistake. Malformed or invalid signatures return `false`. The check covers authorization only: it validates neither amounts nor consensus rules, and it is no evidence of finality. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## dev #1416 +/- ##
==========================================
+ Coverage 86.78% 87.77% +0.99%
==========================================
Files 270 271 +1
Lines 71309 72442 +1133
==========================================
+ Hits 61883 63584 +1701
+ Misses 9426 8858 -568
|
|
✅ Review complete in 7m 4s Planner (4s) Review (security · pair): 5 findings Judge: 3 kept · 1 dropped (2m 3s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
✅ Approved. 3 suggestions, none of which block.
What this does: Adds a function that checks whether a transaction input carries a valid owner signature for the coin it spends. It accepts only P2PKH coins signed over the whole transaction.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run cargo test -p key-wallet --all-features spend_authorization.
- Sign a one-input P2PKH transaction with
SIGHASH_ALLand callverify_input_authorizationwith its funding output. ExpectOk(true). - Change an output amount after signing. Expect
Ok(false). - Pass the funding output of a different key. Expect
Ok(false). - Sign with mode
2(NONE) or0x81(ALL with ANYONECANPAY). ExpectErr(UnsupportedSighash(mode)). - Pass a funding output whose script is not P2PKH. Expect
Err(UnsupportedScript). - Flip the hash-type byte of a valid signature without re-signing. Expect
Ok(false), not an error. - Edge case: add a second input with the same outpoint. Expect
Ok(false). - Edge case: replace the signature with its high-S form. Expect
Ok(true).
Checked and left out: 1 finding
Not finished checking · 1 lead
- Non-standard sighash bytes may become
Ok(false)instead ofUnsupportedSighash·key-wallet/src/transaction_checking/spend_authorization.rs:71
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
a4b7cf9, round 1 - 407 changed lines read in 7m 4s
- Found by
claude-sonnet-5-5andclaude-opus-5-5, judged byclaude-opus-5-5 - Tokens: 3.7M in (3.3M from cache) · 60k out · about $3.24 at API prices
- Runner: self-hosted · started after 6s · peak memory 2.5 GiB of 30.0 GiB
- How Manki reviews
The repeated-outpoint case appended the duplicate input after signing, so the signature check alone rejected it and no test failed without the uniqueness guard. The owner now signs the transaction with the outpoint already listed twice, so only the guard rejects it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
✅ Review complete in 5m 15s Planner (4s) Review (security · pair): 2 findings Judge: 2 kept · 0 dropped (57s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
✅ Approved.
What this does: Adds a public check that a pending transaction input is really signed by the owner of the P2PKH coin it spends, using a signature that covers the whole transaction. A wallet can use this to decide whether to hold that coin as spent before the transaction is final.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run cargo test -p key-wallet --all-features spend_authorization, or call verify_input_authorization from a small harness with a signed transaction and its funding output.
- Sign a one-input P2PKH transaction with
SIGHASH_ALLand verify it against its funding output. ExpectOk(true). - Sign it with the wallet's own
sign_tx. ExpectOk(true). - Change an output value after signing. Expect
Ok(false). - Verify against a funding output whose script is not P2PKH. Expect
Err(UnsupportedScript). - Sign with
SIGHASH_NONEorSIGHASH_SINGLE|ANYONECANPAY. ExpectErr(UnsupportedSighash(mode)). - Overwrite only the hash type byte of a valid
SIGHASH_ALLsignature with0x82. ExpectOk(false), not an error. - Edge case: list the same outpoint twice in the inputs. Expect
Ok(false). - Edge case: replace the signature with its high-S form. Expect
Ok(true).
About this review
- Reviewed
10bbbb9, round 2 - 410 changed lines read in 5m 15s
- Found by
claude-sonnet-5-5andclaude-opus-5-5, judged byclaude-opus-5-5 - Tokens: 3.0M in (2.6M from cache) · 50k out · about $2.67 at API prices
- Runner: self-hosted · started after 6s · peak memory 2.6 GiB of 30.0 GiB
- How Manki reviews
`EcdsaPublicKey::verify` already accepts high-S signatures, which `dashcore-crypto`'s `verify_accepts_high_s` covers, so the `normalize_s` call before it changed nothing and `should_accept_high_s_owner_authorization` passed without it. Both are removed, along with that test's copy of the group-order subtraction. The doc comment of `verify_input_authorization` is cut to three lines. The scope caveats it dropped are in the PR description. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
✅ Review complete in 4m 53s Planner (5s) Review (security · pair): 3 findings Judge: 0 kept · 3 dropped (1m 11s) Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
✅ Approved.
What this does: Adds a check that a transaction input carries a valid signature from the owner of the coin it spends, and that the signature covers the whole transaction. A wallet can use it to decide whether to reserve a coin before the spend is final.
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Run the new tests with cargo test -p key-wallet --all-features --lib spend_authorization.
- Sign a one-input P2PKH spend with
SIGHASH_ALLusing the wallet'ssign_txand callverify_input_authorizationwith the funding output. ExpectOk(true). - Change one output value of that signed transaction and verify again. Expect
Ok(false). - Pass a funding output that belongs to a different key. Expect
Ok(false). - Re-sign the input with
SIGHASH_NONE(2) orSIGHASH_ALL|ANYONECANPAY(0x81). ExpectErr(UnsupportedSighash(mode)). - Overwrite only the last byte of a valid
SIGHASH_ALLsignature with 0x82, without re-signing. ExpectOk(false), not an error. - Pass a funding output with an empty or P2SH script. Expect
Err(UnsupportedScript). - Edge case: build a transaction that lists the same outpoint twice and sign it properly. Expect
Ok(false). - Edge case: sign with
SIGHASH_SINGLEon an input that has no matching output, then changelock_time. ExpectErr(UnsupportedSighash(3))both times.
About this review
- Reviewed
5e9a975, round 3 - 370 changed lines read in 4m 53s
- Found by
claude-sonnet-5-5andclaude-opus-5-5, judged byclaude-opus-5-5 - Tokens: 1.8M in (1.4M from cache) · 30k out · about $1.94 at API prices
- Runner: self-hosted · started after 14s · peak memory 1.9 GiB of 30.0 GiB
- How Manki reviews
|
Bots are done — your move: address ZocoLini requested changes, then post |
ZocoLini
left a comment
There was a problem hiding this comment.
The verification logic looks correct. A few changes to match the crate's conventions and one behavior issue with out-of-range indexes.
| } | ||
|
|
||
| #[test] | ||
| fn should_not_turn_an_unauthenticated_hash_flag_into_an_unsupported_error() { |
There was a problem hiding this comment.
This test overlaps with should_preserve_unsupported_authorization_as_an_error. Both feed non-ALL modes, and the difference is whether the signature is redone. Could one test cover both cases?
There was a problem hiding this comment.
Yes. In c4c4a60 the SIGHASH_SINGLE constant-digest case is a second loop in should_preserve_unsupported_authorization_as_an_error.
There was a problem hiding this comment.
Done in 6633d1a: should_not_turn_an_unauthenticated_hash_flag_into_an_unsupported_error is folded into should_preserve_unsupported_authorization_as_an_error. For each mode the test re-signs and expects UnsupportedSighash, then swaps only the flag of the ALL signature and expects Ok(false).
🤖 Co-authored by Claudius the Magnificent AI Agent
There was a problem hiding this comment.
Done: the shared table-driven test covers both cases for every non-SIGHASH_ALL mode: re-signing with that mode returns UnsupportedSighash(mode), and only flipping the flag byte of a valid signature returns Ok(false).
🤖 Co-authored by Claudius the Magnificent AI Agent
…zation `SpendAuthorizationError` implements `Display` and `std::error::Error` by hand like the crate's other error types, so `key-wallet` no longer depends on `thiserror`. The module is declared with its siblings in `transaction_checking`, which re-exports `verify_input_authorization` and `SpendAuthorizationError`, and loses its doc comments. An out-of-range `input_index` returns `SpendAuthorizationError::InputIndexOutOfRange` instead of `Ok(false)`. It is a caller bug, and reading it as "not authorized" could release a hold. The tests share one transaction builder and call `sign_input` directly. The SIGHASH_SINGLE constant-digest case is folded into `should_preserve_unsupported_authorization_as_an_error`, and the witness test is removed: Dash has no segwit and never serializes the witness. Co-Authored-By: Claude Opus 5.5 <[email protected]>
c4c4a60
|
✅ Review complete in 6m 56s Planner (3s) Review (security · pair): 2 findings Judge: 1 kept · 1 dropped (1m 59s) Review metadataConfig:
Account limits:
Judge decisions:
The defect. Lines 60-68 return Why consensus allows it. dashpay/dash:src/policy/policy.h:70-77 lists Why it matters. The function's contract at lines 37-39 and the PR description say unsupported forms return an error so the hold is kept. Here it returns Open doubts. Whether block consensus truly omits push-only and clean-stack checks is not settled by the code shown. Neither is whether the consumer feeds block-included pending spends into this check.
Timing:
|
|
Bots are done — your move: address manki-review[bot] requested changes; ZocoLini requested changes, then post |
There was a problem hiding this comment.
🔴 Changes requested: 1 new blocker, plus 1 suggestion in threads.
What blocks: The verifier discards errors from legacy_signature_hash and eventually returns Ok(false) if no candidate remains. If a caller-supplied special payload can fail to serialize, the caller can release a hold even though the signature was never checked.
Checked and left out: 1 finding
Not finished checking · 1 possible problem
- Owner signatures with a non-standard hash type byte may return
Ok(false)instead ofUnsupportedSighash·key-wallet/src/transaction_checking/spend_authorization.rs:100
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
f134961, round 8 - 344 changed lines read in 10m 36s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 5.9M in (5.0M from cache) · 107k out · about $6.44 at API prices
- Runner: self-hosted · started after 14s · peak memory 3.4 GiB of 30.0 GiB
- How Manki reviews
…ture Merges fix/pending-spend-authorization at 920f103 (built on #1416 at f134961). Conflict resolutions: - key-wallet-manager events.rs and process_block.rs: R9's wording for the drop trigger combined with #1507's `winner_block` field; R9's event test reads `winner_block: None`. - key-wallet helpers.rs: #1518/#1519's dismissal and give-back helpers and R9's authorization helpers are kept side by side; imports are merged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…n error verify_input_authorization turned a failed sighash computation into Ok(false), so "not authorized" and "cannot decide" looked the same. Return SpendAuthorizationError::Sighash instead, keeping the per-mode cache and the Ok(false) answer for bad signatures. The non-SIGHASH_ALL cases now live in the shared table-driven test. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
ZocoLini, on your reviews 5955329344 and 5919634723:
Also new in eb29ae8: a signature hash that cannot be computed returns 🤖 Co-authored by Claudius the Magnificent AI Agent |
|
✅ Review complete in 8m 10s Planner (3s) Review (security · full): 10 findings Judge (4m 37s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
✅ Approved. 2 suggestions, none of which block.
What this does: Adds verify_input_authorization, which checks that a pending transaction input really carries the owner's P2PKH signature covering the whole transaction (SIGHASH_ALL). Unsupported scripts, sighash types or extra script instructions return an error instead of a yes or no.
Findings dismissed by the PR author @lklimek (admin role):
- Owner-signed spends with instructions after the public key still return
Ok(false) - A sighash serialization error may be mistaken for a missing owner signature
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Use a regtest wallet with a funded P2PKH UTXO, and call verify_input_authorization with the spending transaction and the funding TxOut.
- Sign a spend with the wallet signer and verify input 0. Expect
Ok(true). - Verify the same input against another address's funding output. Expect
Ok(false). - Sign the input with a different key. Expect
Ok(false). - Sign with
SIGHASH_NONE(2) orSIGHASH_ALL|ANYONECANPAY(0x81) using the owner key. ExpectErr(UnsupportedSighash(mode)). - Append
OP_NOPto a valid owner scriptSig. ExpectErr(UnsupportedScriptSig). - Pass a funding output whose script is not P2PKH. Expect
Err(UnsupportedScript). - Duplicate input 0 in the transaction, or pad its scriptSig past 10,000 bytes. Expect
Ok(false). - Pass an input index past the end of the inputs. Expect
Err(InputIndexOutOfRange(index)).
Checked and left out: 2 findings
Disproved by a check of the code · 2 findings
- The signature parser may discard nonstandard hash modes before the verifier can classify them ·
key-wallet/src/transaction_checking/spend_authorization.rs:113
from_slicereads the last byte with from_consensus, which maps every value, including 0x00, 0x04 and 0xff, to a type without failing. So an authentic signature with those modes passes line 113, verifies, and reaches the check at line 131, which returnsUnsupportedSighashas the new tests expect. - The verifier may reject owner signatures that Dash Core accepts without the low-S policy flag ·
key-wallet/src/transaction_checking/spend_authorization.rs:123
EcdsaPublicKey::verify, called at line 123, calls dash-pkcverify_digest. That function copies the signature, callsnormalize_s()on the copy, then verifies, and the crate has a test that a high-S signature verifies.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
eb29ae8, round 9 - 399 changed lines read in 8m 10s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 4.1M in (3.3M from cache) · 92k out · about $5.40 at API prices
- Runner: self-hosted · started after 7s · peak memory 4.4 GiB of 30.0 GiB
- How Manki reviews
<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post |
|
✅ Review complete in 7m 38s Planner (5s) Review (security · full): 8 findings Judge (2m 55s) Posted: 1 finding Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
✅ Approved. 1 suggestion, which doesn't block.
What this does: Adds verify_input_authorization, which checks whether a transaction input carries the owner's P2PKH signature over the whole transaction (SIGHASH_ALL), so a wallet can decide whether a pending spend was really authorized. It also adds the MAX_SCRIPT_SIZE constant and a sighash test for asset-lock payloads.
Findings dismissed by the PR author @lklimek (admin role):
- Owner-signed spends with instructions after the public key still return
Ok(false) - A sighash serialization error may be mistaken for a missing owner signature
What to test
The review model wrote these steps. Check what a step runs before you follow it.
Setup: Build a P2PKH funding output and a spending transaction signed with the wallet signer or a test key.
- Call
verify_input_authorizationon an input signedSIGHASH_ALLby the owner. ExpectOk(true). - Sign the same input with another key. Expect
Ok(false). - Sign the input with
SIGHASH_ALL | SIGHASH_ANYONECANPAY(0x81). ExpectErr(UnsupportedSighash(0x81)). - Append
OP_NOPto a valid owner input script. ExpectErr(UnsupportedScriptSig). - Change only the sighash byte of a valid signature to 0x02. Expect
Ok(false). - Pass a non-P2PKH
prevout. ExpectErr(UnsupportedScript). - Add a second input that spends the same outpoint. Expect
Ok(false). - Pass an input index past the end. Expect
Err(InputIndexOutOfRange(index)).
Checked and left out: 1 finding
Disproved by a check of the code · 1 finding
- The signature parser may reject nonstandard modes before they can return a typed error ·
key-wallet/src/transaction_checking/spend_authorization.rs:115
dashcore::ecdsa::Signature is a re-export of bitcoin_crypto::ecdsa::Signature. Itsfrom_slicemaps any trailing byte withEcdsaSighashType::from_consensus, which wraps unknown values such as 0, 4 or 0xff in NonStandard and never fails.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
116fa9a, round 10 - 401 changed lines read in 7m 38s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 4.6M in (3.9M from cache) · 78k out · about $4.95 at API prices
- Runner: self-hosted · started after 10s · peak memory 3.5 GiB of 30.0 GiB
- How Manki reviews
| /// Whether input `input_index` carries the owner's P2PKH `SIGHASH_ALL` signature for `prevout`. | ||
| /// The caller takes `prevout` from the funding transaction of that input's outpoint. | ||
| /// An unsupported form, missing input or failed signature hash returns an error, preserving the hold. | ||
| /// That includes an owner's CoinJoin input, which Dash Core signs `SIGHASH_ALL | SIGHASH_ANYONECANPAY` |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Documentation · Quick fix
The doc comment on verify_input_authorization grows to six lines and describes the caller's hold
Why: The two lines added in this revision make the doc comment six lines long, above the repository's three-line ceiling. Like the comment at line 131 (this durable reservation), they describe how a caller uses the result (preserving the hold, such a hold needs another release path) rather than what the function does. The CoinJoin statement itself is correct: Dash Core signs CoinJoin inputs with SIGHASH_ALL | SIGHASH_ANYONECANPAY.
How to fix it, 2 places read, and 1 other check · breaks a repository rule
How to fix it
Cut the doc comment to at most three lines that say what the function returns. For example: Ok(true) only for a push-only <sig> <pubkey> P2PKH SIGHASH_ALL owner signature, and errors such as UnsupportedSighash(0x81) for CoinJoin inputs signed ALL|ANYONECANPAY. Move the note about holds and release paths into the PR description or the consumer's code. Reword line 131 so it does not refer to a reservation.
Repository rule
This PR breaks a required rule of AGENTS.md: One line is normal, three is the ceiling.
Checked in the code
On the commented line: Is a six-line /// block that ends with so such a hold needs another release path.
Says They cannot authorize this durable reservation.
rust-dashcore/key-wallet/src/transaction_checking/spend_authorization.rs
Lines 130 to 134 in 116fa9a
- dashpay/dash:src/coinjoin/client.cpp:595 calls
m_wallet->SignTransaction(finalMutableTransaction, coins, SIGHASH_ALL | SIGHASH_ANYONECANPAY, signing_errors);…
- Create an issue for this
- Dismiss this finding
ZocoLini
left a comment
There was a problem hiding this comment.
The previous round is only partly addressed:
- The sighash cases still cover every mode, signed (9 cases) and with a changed flag (8 cases). One or two of each are enough.
legacy_sighash_all_commits_to_asset_lock_credit_outputsmoved todash/src/crypto/sighash.rsinstead of being dropped. It testsdashcore's sighash, not this PR. Please remove it.
Also, #1523 builds on an older version of this PR and changes the verifier's contract: it drops Sighash and adds RuntimeAuthorization. Please agree on one version with #1523 here, so the public API doesn't change again right after it merges.
|
@coderabbitai review No review for |
|
Bots are done — your move: address ZocoLini requested changes, then post |
A wallet that restores its history can see a pending spend of one of its coins before the spend is final, with no way to tell whether the coin's owner actually signed it. This PR adds
key_wallet::transaction_checking::spend_authorization::verify_input_authorization, which checks that an input carries a valid P2PKH /SIGHASH_ALLowner signature for the funding output it claims.Unsupported funding scripts, signature hash types, an owner signature next to extra input-script instructions and an out-of-range input index return a typed
SpendAuthorizationError, so a caller does not release an existing hold by mistake. Malformed or invalid signatures, input scripts over Dash Core's size limit, and a signature or key built at run time (for example withOP_CAT) returnfalse. The check covers authorization only: it validates neither amounts nor consensus rules, and it is no evidence of finality.Split out of #1336 at a maintainer's request, since it shares no code with the InstantLock changes there. The consumer is Platform's persisted-history restoration (dashpay/platform#5220).
🤖 Generated with Claude Code
PR Hygiene ·
116fa9a/self-revieweddash/src/blockdata/constants.rs,dash/src/crypto/sighash.rs) — QuantumExplorer or ZocoLini or xdustinfacekey-wallet(key-wallet/src/transaction_checking/mod.rs,key-wallet/src/transaction_checking/spend_authorization.rs) — QuantumExplorer or ZocoLini or xdustinfaceWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.Summary by CodeRabbit