Skip to content

feat(key-wallet): verify owner authorization of a pending spend - #1416

Open
lklimek wants to merge 17 commits into
devfrom
feat/key-wallet-spend-authorization
Open

lklimek wants to merge 17 commits into
devfrom
feat/key-wallet-spend-authorization

Conversation

@lklimek

@lklimek lklimek commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

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_ALL owner 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 with OP_CAT) return false. 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

  • Bots — coderabbitai skipped after the window
  • Self-review — address ZocoLini requested changes, then post /self-reviewed
  • Build green
  • Approvals
    • files with no dedicated owner (dash/src/blockdata/constants.rs, dash/src/crypto/sighash.rs) — QuantumExplorer or ZocoLini or xdustinface
    • key-wallet (key-wallet/src/transaction_checking/mod.rs, key-wallet/src/transaction_checking/spend_authorization.rs) — QuantumExplorer or ZocoLini or xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

Summary by CodeRabbit

  • New Features
    • Added transaction-input authorization verification against the supplied funding output, including checks for owner signatures, matching keys, duplicate inputs, and malformed scripts.
    • Authorization checks distinguish unsupported funding scripts, signature hash modes, and certain valid but unsupported input-script forms from invalid or unverifiable signatures.
    • Added a 10,000-byte maximum script-size constant.
    • Added coverage for matching each input to its own funding output and for compatibility with wallet-generated signatures.

`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]>
@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • Resume reviews
  • Trigger review

No actionable comments were generated in the recent review.

Walkthrough

The transaction-checking module now exposes a P2PKH input authorization verifier and its error type. The verifier checks an input against its funding output and signature. The change also adds a public script-size constant and tests for authorization cases and asset-lock payload changes to legacy signature hashes.

Changes: Spend Authorization

Layer / File(s) Summary
Verifier API and checks
key-wallet/src/transaction_checking/mod.rs, key-wallet/src/transaction_checking/spend_authorization.rs, dash/src/blockdata/constants.rs
Adds and exports SpendAuthorizationError and verify_input_authorization. The verifier checks matching outpoints, P2PKH funding scripts, input scripts, owner keys, and signatures. It uses the public MAX_SCRIPT_SIZE constant, set to 10,000 bytes.
Authorization and sighash tests
key-wallet/src/transaction_checking/spend_authorization.rs, dash/src/crypto/sighash.rs
Adds tests for valid and invalid authorization, input-to-prevout matching, wallet-produced signatures, malformed scripts, and unsupported scripts and sighash modes. Adds a test that changing an asset-lock credit output value changes the legacy SIGHASH_ALL result.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Feature

Suggested reviewers: xdustinface, quantumexplorer

Merge Risk: Minimal · previous review f1349

This adds a verifier that checks whether an input carries a valid owner signature for a P2PKH funding output. Owner-signed inputs with extra script instructions now return a typed error instead of a misleading false, and no remaining defect was found. Resolve the merge conflict and finish self-review before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a new feature in the key-wallet crate that verifies owner authorization of a pending spend. The changeset adds verify_input_authorization and SpendAuthorizationError i…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: a new feature in the key-wallet crate that verifies owner authorization of a pending spend. The changeset adds verify_input_authorization and SpendAuthorizationError in the spend_authorization module, which checks whether a transaction input carries a valid P2PKH SIGHASH_ALL owner signature. The title is specific, follows conventional commit form, and contains no file lists or vague terms.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between d85f215 and f134961.

Files selected for processing: 3

  • dash/src/crypto/sighash.rs
  • key-wallet/src/transaction_checking/mod.rs
  • key-wallet/src/transaction_checking/spend_authorization.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.62044% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.77%. Comparing base (09e4087) to head (116fa9a).
⚠️ Report is 24 commits behind head on dev.

Files with missing lines Patch % Lines
...et/src/transaction_checking/spend_authorization.rs 95.29% 12 Missing ⚠️
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     
Flag Coverage Δ
core 83.52% <95.62%> (+1.30%) ⬆️
rpc 83.52% <95.62%> (+1.30%) ⬆️
spv 95.21% <ø> (+0.22%) ⬆️
wallet 83.52% <95.62%> (+1.30%) ⬆️
Files with missing lines Coverage Δ
dash/src/blockdata/constants.rs 100.00% <ø> (ø)
dash/src/crypto/sighash.rs 88.75% <100.00%> (+0.92%) ⬆️
...et/src/transaction_checking/spend_authorization.rs 95.29% <95.29%> (ø)

... and 24 files with indirect coverage changes

@lklimek
lklimek marked this pull request as ready for review November 16, 2026 08:28
@manki-review

manki-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Review complete in 7m 4s

Planner (4s)
    feat · 407 lines · 2 agents
    judge effort: high

Review (security · pair): 5 findings
    ✅ Claude Sonnet 5.5 · high: 2 findings (1m 55s)
    ✅ Claude Opus 5.5 · high: 3 findings (4m 21s)

Judge: 3 kept · 1 dropped (2m 3s)
    kept: 3 suggestions
    dropped: 1 suggestion

Review metadata

Config:

  • Models: reviewer=claude-sonnet-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths, CI or dependency paths)
  • Team: Claude Sonnet 5.5 · high, Claude Opus 5.5 · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 28% (resets 2026-11-20 20:00 UTC)

Judge decisions:

  • Not finished: "Non-standard sighash bytes may become Ok(false) instead of UnsupportedSighash" (warning): "Blocker cell, held at warning by an unsettled premise. At spend_authorization.rs:69-71 the whole pushed signature, hash byte included, goes to Signature::from_slice, and any parse error becomes Ok(false). Signature is re-exported from the external bitcoin_crypto crate (crypto/src/ecdsa.rs:30). In the rust-bitcoin design that crate follows, from_slice parses the hash byte with from_standard and rejects undefined values. If this one does the same, an owner signature with mode 0, 4 or 0xff returns Ok(false) at line 70 and never reaches the UnsupportedSighash branch at line 87. Such a signature is consensus-valid: Core rejects these hash types only under the STRICTENC policy flag (dashpay/dash:src/script/interpreter.cpp:211). So the caller treats an authorized spend as unauthorized and releases the hold, against the doc at lines 28-29. The test at line 384 would then fail, but no CI result is shown. The crate source is not in the code shown, so test 4 is unsettled.
    Refutation unsettled: Whether bitcoin_crypto::ecdsa::Signature::from_slice rejects non-standard sighash bytes decides whether line 69 returns Ok(false) before the UnsupportedSighash check at line 87, but the external crate (Cargo.toml:70, not patched or vendored) cannot be read here. The crate's EcdsaSighashType has a NonStandard variant that from_consensus returns (CHANGELOG.md:120-124, crypto/src/sighash.rs:42), which weakens the finding but does not show which conversion from_slice uses. Rule checked: A parser that maps the trailing sighash byte through a standard-only conversion (rust-bitcoin's EcdsaSighashType::from_standard) rejects undefined hash types, whereas from_consensus keeps them as a NonStandard value.
  • Premise "bitcoin_crypto::ecdsa::Signature::from_slice returns an error when the last byte is not one of 0x01, 0x02, 0x03, 0x81, 0x82, 0x83 (for example via EcdsaSighashType::from_standard)" unsettled. The source of bitcoin_crypto::ecdsa::Signature::from_slice is in an external crates.io dependency that is not in the checkout; the changelog shows its sighash type has a NonStandard variant reachable via from_consensus but also names from_standard, so which one from_slice uses cannot be read.
  • Premise "A caller that gets Ok(false) from verify_input_authorization releases the pending hold on the coin, while Err(UnsupportedSighash) keeps it" confirmed. No in-repo caller exists (only the module declaration), but the function's documented contract says errors are returned so an existing pending hold is not silently released, while false marks the input as not authorized, which is the documented usage the premise describes."
  • Dropped: "Structural Ok(false) checks run before the unsupported-script check" (ignore): "ignore. Neither early return is an unsupported authorization form. An input_index past the end (spend_authorization.rs:35-37) names an input that does not exist, so no spend of the coin is claimed. A transaction that spends the same outpoint twice (lines 38-46) is consensus-invalid and can never confirm, so it cannot spend the coin whatever the funding script is. Returning false for both matches the doc at line 29, which reserves the error for unsupported forms of an otherwise well-formed spend."
  • Kept: "normalize_s does nothing, so the high-S test passes without it" (suggestion): "note. EcdsaPublicKey::verify already accepts a high-S signature: crypto/src/ecdsa.rs:370 asserts that it verifies without normalization. So the normalize_s() call at spend_authorization.rs:73 and its comment change nothing. should_accept_high_s_owner_authorization still passes with that call removed, so it guards no line of this change. Results stay correct, so this is cleanup and test clarity."
  • Kept: "Doc comment on verify_input_authorization runs to eight lines, over the three-line ceiling" (suggestion): "note. The Comments and docs section of AGENTS.md sets three lines as the ceiling, and its own good example is a three-line doc comment. The added /// block at spend_authorization.rs:22-29 runs to eight lines. This is a comment-length convention with no effect at run time."
  • Kept: "Test calls hex_conservative::decode_to_vec by full path instead of importing it" (suggestion): "note. AGENTS.md forbids writing a fully qualified path to avoid an import. Line 337 calls hex_conservative::decode_to_vec(...) with no use at the top of mod tests. This is an import-style convention in test code."

Timing:

  • Parse: 4.3s
  • Review agents: 296.8s
  • Judge: 123.4s
  • Total: 424.5s

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Nov 16, 2026
manki-review[bot]
manki-review Bot previously approved these changes Nov 16, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

  1. Sign a one-input P2PKH transaction with SIGHASH_ALL and call verify_input_authorization with its funding output. Expect Ok(true).
  2. Change an output amount after signing. Expect Ok(false).
  3. Pass the funding output of a different key. Expect Ok(false).
  4. Sign with mode 2 (NONE) or 0x81 (ALL with ANYONECANPAY). Expect Err(UnsupportedSighash(mode)).
  5. Pass a funding output whose script is not P2PKH. Expect Err(UnsupportedScript).
  6. Flip the hash-type byte of a valid signature without re-signing. Expect Ok(false), not an error.
  7. Edge case: add a second input with the same outpoint. Expect Ok(false).
  8. Edge case: replace the signature with its high-S form. Expect Ok(true).

Checked and left out: 1 finding

Not finished checking · 1 lead

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-5 and claude-opus-5-5, judged by claude-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]>
@manki-review

manki-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Review complete in 5m 15s

Planner (4s)
    feat · 410 lines · 2 agents
    judge effort: high

Review (security · pair): 2 findings
    ✅ Claude Sonnet 5.5 · high: 0 findings (1m 18s)
    ✅ Claude Opus 5.5 · high: 2 findings (3m 33s)

Judge: 2 kept · 0 dropped (57s)
    kept: 2 suggestions

Review metadata

Config:

  • Models: reviewer=claude-sonnet-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths, CI or dependency paths)
  • Team: Claude Sonnet 5.5 · high, Claude Opus 5.5 · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 30% (resets 2026-11-20 20:00 UTC)

Judge decisions:

  • Kept: "Signature parsing takes a detour through Signature::from_slice and a redundant normalize_s" (suggestion): "note. This is the same point as P1, and the code at lines 69-74 has not changed, so the prior cell stays. The doc at crypto/src/ecdsa.rs:75-77 says EcdsaPublicKey::verify accepts high-S signatures, so normalize_s at line 73 changes no result. dash/src/crypto/sighash.rs:412-420 already shows the simpler split_at plus EcdsaSignature::from_der path. The remark about how from_slice handles non-standard hash bytes is unverified. The test should_preserve_unsupported_authorization_as_an_error (modes 0, 4, 0xff) passes with a green build, which suggests from_slice accepts those bytes. The point is a simplification, not a defect."
  • Kept: "Doc comment on verify_input_authorization runs to eight lines, over the three-line ceiling" (suggestion): "note. This is the same point as P2, and the doc comment is unchanged. AGENTS.md sets three lines as the ceiling for a comment. The doc comment at lines 22-29 added by this PR is eight lines long. It is a docs convention only, so it falls on the style row."

Timing:

  • Parse: 6.0s
  • Review agents: 252.4s
  • Judge: 56.8s
  • Total: 315.1s

@github-actions

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

manki-review[bot]
manki-review Bot previously approved these changes Nov 16, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

  1. Sign a one-input P2PKH transaction with SIGHASH_ALL and verify it against its funding output. Expect Ok(true).
  2. Sign it with the wallet's own sign_tx. Expect Ok(true).
  3. Change an output value after signing. Expect Ok(false).
  4. Verify against a funding output whose script is not P2PKH. Expect Err(UnsupportedScript).
  5. Sign with SIGHASH_NONE or SIGHASH_SINGLE|ANYONECANPAY. Expect Err(UnsupportedSighash(mode)).
  6. Overwrite only the hash type byte of a valid SIGHASH_ALL signature with 0x82. Expect Ok(false), not an error.
  7. Edge case: list the same outpoint twice in the inputs. Expect Ok(false).
  8. 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-5 and claude-opus-5-5, judged by claude-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]>
@manki-review

manki-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Review complete in 4m 53s

Planner (5s)
    feat · 370 lines · 2 agents
    judge effort: high

Review (security · pair): 3 findings
    ✅ Claude Sonnet 5.5 · high: 1 finding (47s)
    ✅ Claude Opus 5.5 · high: 2 findings (1m 45s)

Judge: 0 kept · 3 dropped (1m 11s)
    dropped: 1 warning · 2 suggestions

Review metadata

Config:

  • Models: reviewer=claude-sonnet-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths, CI or dependency paths)
  • Team: Claude Sonnet 5.5 · high, Claude Opus 5.5 · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 33% (resets 2026-11-20 20:00 UTC)

Judge decisions:

  • Dropped: "Consensus-valid high-S owner signatures now return Ok(false)" (ignore): "ignore. The finding's premise is that EcdsaPublicKey::verify rejects high-S signatures. The cited code contradicts it: the doc on verify at crypto/src/ecdsa.rs:75-77 says a high-S signature verifies like its low-S twin, and Finding 3 cites the same behaviour. Removing normalize_s is also the fix an earlier round asked for in P1. This finding objects to applying that fix and shows no new defect, so it is a flip-flop."
  • Not listed, on code an earlier round reviewed: "Owner-signed CoinJoin spends always return UnsupportedSighash(0x81)" (suggestion): "note. The behaviour is intended but surprising. The comment at spend_authorization.rs:78-79 and the test at spend_authorization.rs:350 show the author chose to reject every mode other than SIGHASH_ALL, 0x81 included. The comment is accurate: 0x81 does not commit to the other inputs. The result is a typed error, so the caller keeps its hold rather than releasing it. The open question is whether Dash Core's CoinJoin client signing with 0x81 (dashpay/dash:src/coinjoin/client.cpp:595) means real wallet spends should be accepted, since every owner-signed CoinJoin spend lands on the error path."
  • Dropped: "No test covers high-S owner signatures since the normalization and its test were removed" (ignore): "ignore. The fix an earlier round asked for in P1 offered dropping the high-S test as an option, and the author took it. Asking for the test back reverses that answer. The behaviour the test pinned belongs to EcdsaPublicKey::verify in the crypto crate (crypto/src/ecdsa.rs:75), not to any line in this function. At most this would be a missing-test note, and a note that flip-flops on an earlier answer is not worth posting."

Timing:

  • Parse: 12.5s
  • Review agents: 209.1s
  • Judge: 71.2s
  • Total: 292.8s

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 16, 2026
manki-review[bot]
manki-review Bot previously approved these changes Nov 16, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

  1. Sign a one-input P2PKH spend with SIGHASH_ALL using the wallet's sign_tx and call verify_input_authorization with the funding output. Expect Ok(true).
  2. Change one output value of that signed transaction and verify again. Expect Ok(false).
  3. Pass a funding output that belongs to a different key. Expect Ok(false).
  4. Re-sign the input with SIGHASH_NONE (2) or SIGHASH_ALL|ANYONECANPAY (0x81). Expect Err(UnsupportedSighash(mode)).
  5. Overwrite only the last byte of a valid SIGHASH_ALL signature with 0x82, without re-signing. Expect Ok(false), not an error.
  6. Pass a funding output with an empty or P2SH script. Expect Err(UnsupportedScript).
  7. Edge case: build a transaction that lists the same outpoint twice and sign it properly. Expect Ok(false).
  8. Edge case: sign with SIGHASH_SINGLE on an input that has no matching output, then change lock_time. Expect Err(UnsupportedSighash(3)) both times.
About this review
  • Reviewed 5e9a975, round 3
  • 370 changed lines read in 4m 53s
  • Found by claude-sonnet-5-5 and claude-opus-5-5, judged by claude-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

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: address ZocoLini requested changes, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 16, 2026

@ZocoLini ZocoLini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The verification logic looks correct. A few changes to match the crate's conventions and one behavior issue with out-of-range indexes.

Comment thread key-wallet/Cargo.toml Resolved
}

#[test]
fn should_not_turn_an_unauthenticated_hash_flag_into_an_unsupported_error() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In c4c4a60 the SIGHASH_SINGLE constant-digest case is a second loop in should_preserve_unsupported_authorization_as_an_error.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]>
@manki-review

manki-review Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Review complete in 6m 56s

Planner (3s)
    feat · 347 lines · 2 agents
    judge effort: high

Review (security · pair): 2 findings
    ✅ Claude Sonnet 5.5 · high: 0 findings (1m 31s)
    ✅ Claude Opus 5.5 · high: 2 findings (4m 14s)

Judge: 1 kept · 1 dropped (1m 59s)
    kept: 1 warning
    dropped: 1 suggestion

Review metadata

Config:

  • Models: reviewer=claude-sonnet-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Sonnet 5.5 · high, Claude Opus 5.5 · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 34% (resets 2026-11-20 20:00 UTC)

Judge decisions:

  • Kept: "A valid owner-signed spend with a padded scriptSig is reported as not authorized" (warning): "Blocker cell, held at warning by doubts.

The defect. Lines 60-68 return Ok(false) unless the scriptSig is exactly two PushBytes instructions. The legacy sighash serializes the prevout script as the script code, not the input's scriptSig (dash/src/crypto/sighash.rs:210-211, matching dashpay/dash:src/script/interpreter.cpp:1392-1396). Prepending OP_0 or OP_NOP therefore leaves the owner's signature valid.

Why consensus allows it. dashpay/dash:src/policy/policy.h:70-77 lists CLEANSTACK and STRICTENC as standard-only flags on top of the mandatory ones. This suggests a miner can include such a spend in a block.

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 Ok(false) for a spend the owner did sign. Outside input triggers it, so the column is normal.

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.
Refutation unsettled: The legacy sighash puts the prevout script in place of the signed input's scriptSig (sighash.rs:210-211). So 'OP_0 ' or 'OP_NOP ' still carries a valid owner signature. For that scriptSig, lines 60-67 return Ok(false): OP_NOP is not PushBytes, and with OP_0 there is a third instruction. That is the 'not authorized' answer the doc at line 39 says unsupported forms should not get. Rule checked: The legacy Dash sighash puts the prevout scriptPubKey in place of the signed input's script and leaves out every scriptSig, so padding the scriptSig does not break the signature; Dash consensus applies push-only and clean-stack rules only when SIGPUSHONLY and CLEANSTACK flags are set.

  • Premise "Dash Core block validation (GetBlockScriptFlags in dashpay/dash src/validation.cpp) does not enforce SCRIPT_VERIFY_SIGPUSHONLY or SCRIPT_VERIFY_CLEANSTACK for P2PKH inputs. A block can therefore hold an input whose scriptSig is OP_0 <sig> <pubkey> or OP_NOP <sig> <pubkey>." confirmed. GetBlockScriptFlags sets only P2SH, DERSIG, CLTV, CSV and NULLDUMMY, and VerifyScript checks push-only only when SIGPUSHONLY is set, so a block can hold a padded P2PKH scriptSig.
  • Premise "The pending-spend path that calls verify_input_authorization receives spends from blocks that are not yet ChainLocked, not only from standard-policy mempool relay." unsettled. Nothing in this repository calls verify_input_authorization except its own tests (it is only re-exported in mod.rs:18), and the fetched dashpay/platform has no caller either, so I could not find the pending-spend path or where its spends come from.
  • Premise "When verify_input_authorization returns Ok(false), Platform's persisted-history restoration releases the hold on the coin and treats it as spendable, although the owner-signed spend is in a block." unsettled. The fetched dashpay/platform code has no use of verify_input_authorization, so I could not check how Platform's persisted-history restoration handles Ok(false)."
  • Dropped: "Fully qualified core::fmt and std::error paths instead of imports" (ignore): "Note. AGENTS.md forbids a fully qualified path written to avoid an import. The new impls write core::fmt::Display, core::fmt::Formatter and core::fmt::Result at lines 19-20, and std::error::Error at line 35, with no use for them. The rule is broken, but this is a naming and imports convention with no runtime effect."

Timing:

  • Parse: 7.8s
  • Review agents: 289.4s
  • Judge: 119.0s
  • Total: 416.1s

@lklimek
lklimek requested a review from ZocoLini November 16, 2026 14:17
@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 23, 2026
coderabbitai[bot]
coderabbitai Bot previously approved these changes Nov 23, 2026
@github-actions

github-actions Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: address manki-review[bot] requested changes; ZocoLini requested changes, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Nov 23, 2026
manki-review[bot]
manki-review Bot previously requested changes Nov 23, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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

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-5 and gpt-6.2-sol, judged by claude-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

@lklimek
lklimek requested a review from ZocoLini November 23, 2026 14:31
PastaPastaPasta added a commit that referenced this pull request Nov 25, 2026
…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]>
@lklimek

lklimek commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

ZocoLini, on your reviews 5955329344 and 5919634723:

  1. One parametrized test for the branches: done in eb29ae8; the non-SIGHASH_ALL cases moved into the shared table-driven test.
  2. Tests that check the sighash itself: removed from the wallet tests; the asset-lock binding test lives in dash/src/crypto/sighash.rs.
  3. Reuse existing helpers: spend_of is gone, Transaction::dummy is used, and the two-owner setup is inline in its test.
  4. Crate conventions and out-of-range index: manual Display/Error, and an out-of-range input index returns an error (tested).

Also new in eb29ae8: a signature hash that cannot be computed returns SpendAuthorizationError::Sighash instead of Ok(false).

🤖 Co-authored by Claudius the Magnificent AI Agent

@manki-review

manki-review Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

✅ Review complete in 8m 10s

Planner (3s)
    feat · 399 lines · 2 agents
    judge effort: high

Review (security · full): 10 findings
    ✅ Claude Opus 5.5 · high: 1 finding (1m 43s)
    ✅ GPT 6.2 Sol · high: 9 findings (2m 46s)
    ✅ Related checks, claim checks and pattern checks: 14 of 14 done (1m 35s)

Judge (4m 37s)
    graded 10 findings: 6 kept · 4 dropped
    dropped, as the finders filed them: 2 blockers · 2 suggestions
    refuter: 2 checked · 2 disproved
    verdict reader: read the diff (1m 17s)

Posted: 2 findings
    2 suggestions
    not posted: 2 on code an earlier round reviewed · 2 disproved by a check of the code

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 51% (resets 2026-12-02 17:00 UTC)
  • ChatGPT subscription: weekly 7% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "Owner-signed CoinJoin inputs always return UnsupportedSighash(0x81)" (suggestion): "note. Dash Core's CoinJoin client signs with SIGHASH_ALL | SIGHASH_ANYONECANPAY (dashpay/dash:src/coinjoin/client.cpp:595). The check at spend_authorization.rs:131 rejects 0x81, and the signed ALL ANYONECANPAY test pins that result. The comment at spend_authorization.rs:129-130 shows the author chose to reject every mode except ALL, and the error keeps the hold, so the code fails safe. This is a question about the choice: callers are not told that every owner CoinJoin spend lands on this error and needs another release path. A line in the doc comment of verify_input_authorization would tell them."
  • Dropped: "Authorization can allocate a second copy of an unbounded payload before checking the signature" (ignore): "ignore. The buffer at dash/src/blockdata/transaction/mod.rs:660-661 is unchanged code. It holds one copy of a payload the caller already keeps in memory as part of transaction, and it is freed when each digest is done. The digests are computed one after another (spend_authorization.rs:114-118), so peak memory is at most twice what the caller already allocated. That is not resource exhaustion. The repeated hashing cost was the subject of an earlier round's finding."
  • Kept: "Checking each input rescans the entire transaction even when every input is unsigned" (suggestion): "note. The duplicate scan at spend_authorization.rs:70-75 compares 36-byte outpoints across every input on each call, which is O(inputs) per call. Each signed input already pays the larger cost of legacy_signature_hash, which serializes the whole transaction (spend_authorization.rs:115-116). So the scan adds at most a constant factor to work the function already does. For unsigned inputs it is the only cost, and it is cheaper than one digest. A cost nobody would notice beyond the already accepted hashing."
  • Not listed, on code an earlier round reviewed: "Equivalent pushes can produce different hold decisions" (suggestion): "note. The split is real. Instruction::push_bytes does not count OP_1..OP_16 as pushes (spend_authorization.rs:90-93), so a trailing OP_1 takes the fallback path and returns UnsupportedScriptSig, while a literal push returns Ok(false). Both scripts leave a non-key value on top, so neither spends the P2PKH output. The comment at spend_authorization.rs:96-97 shows the author treats every non-push opcode as one that may reorder the stack. That only keeps the hold in a case where Ok(false) would also be right, so it fails safe and nothing wrong reaches a caller. Classifying the small-integer opcodes as pushes is a refinement."
  • Dropped: "Malformed registrar payloads can panic in public hashing APIs" (ignore): "ignore. The expect calls at dash/src/blockdata/transaction/mod.rs:256 and provider_update_registrar.rs:130 sit in files this PR does not change. The new verifier never calls txid, instance_hash or base_payload_hash. It calls legacy_signature_hash, which returns the error (spend_authorization.rs:115-121). The PR neither causes nor exposes the panic."
  • Dropped: "The asset-lock test does not exercise the new authorization API" (ignore): "ignore. The test at dash/src/crypto/sighash.rs:475 checks what its name says: the public legacy_signature_hash commits to asset-lock credit outputs. It would fail if that property broke. The verifier relies on that property through its call at spend_authorization.rs:115-116. Testing it through verify_input_authorization instead is a matter of preference."
  • Dropped: "The public sighash error documentation excludes the failure the new test observes" (ignore): "ignore. The doc comment at dash/src/crypto/sighash.rs:50-52 and the payload encoder that can fail are both unchanged. They were already inconsistent before this PR. The PR adds only a test in that file, so it neither changes nor affects the comment."
  • Not listed, on code an earlier round reviewed: "The public verifier bypasses the wallet crate's error type" (suggestion): "note. key-wallet/AGENTS.md requires returning key_wallet::Error through Result, including for untrusted input. The new public verify_input_authorization returns Result<bool, SpendAuthorizationError> (spend_authorization.rs:66). Nothing goes wrong at run time, and the typed variants could be kept inside a key_wallet::Error variant."
  • Dropped: "The signature parser may discard nonstandard hash modes before the verifier can classify them" (ignore): "warning. Line 113 discards any Signature::from_slice error with .ok()?. If the parser rejects nonstandard hash bytes, an owner signature with mode 0, 4 or 0xff is skipped and the function returns Ok(false) instead of UnsupportedSighash. Dash Core accepts such a signature as consensus-valid, so the caller could release a hold on a coin the owner did spend. The parser's body is not shown. The new signed mode 0, signed mode 4 and signed mode 0xff cases expect UnsupportedSighash, so they would fail if the parser rejected these bytes. A trigger needs an owner signature with a nonstandard mode, which no wallet in normal use produces.
    Refutation disproved: from_slice reads 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 returns UnsupportedSighash as the new tests expect. Rule checked: In rust-bitcoin's bitcoin-crypto, ecdsa::Signature::from_slice reads the hash byte with EcdsaSighashType::from_consensus, which accepts every value; it fails only on an empty slice or bad DER.
  • Premise "Signature::from_slice used at spend_authorization.rs:113 returns an error for a signature whose last byte is 0x00, 0x04 or 0xff" disproved. from_slice uses from_consensus, which turns any byte other than the six standard ones into NonStandard rather than an error; only an empty slice or invalid DER makes it fail.
  • Premise "verify_input_authorization returns Ok(false) instead of UnsupportedSighash for an authentic owner signature with hash byte 0x00, 0x04 or 0xff" disproved. The parse succeeds, so the raw mode byte from split_last goes into the digest and verify step; the verified mode is not 1, so the function returns UnsupportedSighash(mode), which matches the PR's cases for modes 0, 4 and 0xff.
  • Premise "This trigger happens in realistic use: the sequence of events the description names" disproved. The sequence needs the parser to drop a nonstandard-mode signature, and it does not; whether an owner ever signs with such a mode does not matter, because the code returns an error either way.
    Pair refutation disproved: The parser does not discard valid signatures ending in 0x00, 0x04, or 0xff. The verifier saves the raw byte, uses it to verify the signature, and returns UnsupportedSighash with that byte; this matches the signed-mode test expectations, though the tests were not run. Rule checked: For valid DER, Signature::from_slice accepts nonstandard sighash bytes through the infallible from_consensus conversion.
  • Premise "Signature::from_slice used at spend_authorization.rs:113 returns an error for a signature whose last byte is 0x00, 0x04 or 0xff" disproved. The parser separates the trailing byte before DER decoding and maps each of the three values to NonStandard without an error.
  • Premise "verify_input_authorization returns Ok(false) instead of UnsupportedSighash for an authentic owner signature with hash byte 0x00, 0x04 or 0xff" disproved. For the described P2PKH input, the authentic signature verifies against the digest computed with its raw byte, and the verifier returns UnsupportedSighash because that byte is not SIGHASH_ALL.
  • Premise "This trigger happens in realistic use: the sequence of events the description names" unsettled. The tests deliberately sign with all three bytes, but the wallet signer uses SIGHASH_ALL and the code checked does not establish that callers supply these signatures in normal use."
  • Dropped: "The verifier may reject owner signatures that Dash Core accepts without the low-S policy flag" (ignore): "warning. Dash Core applies the low-S rule only under SCRIPT_VERIFY_LOW_S, a relay policy and not a consensus rule. Anyone can flip S on an owner's signature and get a consensus-valid copy. Line 123 maps every verify failure to Ok(false), so if the verifier rejects high-S without normalizing, that copy reads as unauthorized. The caller could then release a hold on a spent coin. Whether verify normalizes is not visible in the code shown. A pending spend with high S does not relay under standard policy, so the trigger is rare.
    Refutation disproved: EcdsaPublicKey::verify, called at line 123, calls dash-pkc verify_digest. That function copies the signature, calls normalize_s() on the copy, then verifies, and the crate has a test that a high-S signature verifies. So a consensus-valid owner signature with high S verifies at line 123 and does not lead to Ok(false). Rule checked: A verifier that sets S to its low form before checking (as libsecp256k1 users must, since its verify refuses high S) accepts a high-S signature, as Dash Core does when SCRIPT_VERIFY_LOW_S is not set.
  • Premise "EcdsaPublicKey::verify called at spend_authorization.rs:123 rejects a high-S signature, and neither it nor the parse at line 113 normalizes S" disproved. The verify behind line 123 calls normalize_s() on a copy of the signature before it verifies, so it does not reject high S. The line-113 parse adds no S check of its own: it splits off the sighash byte and calls secp256k1 from_der, whose source I did not read.
  • Premise "verify_input_authorization returns Ok(false) for a consensus-valid owner signature whose S value is high" disproved. A high-S owner signature over the right digest verifies after normalize_s, so verify(...).ok()? does not return None and the function goes on to the SIGHASH_ALL and push-only checks, not to Ok(false).
  • Premise "This trigger happens in realistic use: the sequence of events the description names" unsettled. Even if a high-S pending spend reaches the function, the code accepts it, so the sequence the finding names does not lead to the failure; how often such spends occur on the network cannot be read from code.
    Pair refutation disproved: The wallet verifier delegates to dash-pkc, which normalizes S before calling the secp256k1 backend. An otherwise valid owner signature therefore does not return Ok(false) just because S is high. Rule checked: For ECDSA, replacing S with its low-S equivalent preserves signature validity.
  • Premise "EcdsaPublicKey::verify called at spend_authorization.rs:123 rejects a high-S signature, and neither it nor the parse at line 113 normalizes S" disproved. EcdsaPublicKey::verify delegates to verify_digest, which normalizes S before verification.
  • Premise "verify_input_authorization returns Ok(false) for a consensus-valid owner signature whose S value is high" disproved. An otherwise valid two-push P2PKH SIGHASH_ALL owner signature passes verification even with high S and reaches Ok(true).
  • Premise "This trigger happens in realistic use: the sequence of events the description names" unsettled. The verifier is publicly exported, but no restore caller or documented restore path was found that supplies a historical high-S spend."

Timing:

  • Parse: 6.7s
  • Review agents: 206.3s
  • Judge: 276.9s
  • Total: 489.9s

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Nov 29, 2026

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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):


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.

  1. Sign a spend with the wallet signer and verify input 0. Expect Ok(true).
  2. Verify the same input against another address's funding output. Expect Ok(false).
  3. Sign the input with a different key. Expect Ok(false).
  4. Sign with SIGHASH_NONE (2) or SIGHASH_ALL|ANYONECANPAY (0x81) using the owner key. Expect Err(UnsupportedSighash(mode)).
  5. Append OP_NOP to a valid owner scriptSig. Expect Err(UnsupportedScriptSig).
  6. Pass a funding output whose script is not P2PKH. Expect Err(UnsupportedScript).
  7. Duplicate input 0 in the transaction, or pad its scriptSig past 10,000 bytes. Expect Ok(false).
  8. 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_slice reads 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 returns UnsupportedSighash as 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-pkc verify_digest. That function copies the signature, calls normalize_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-5 and gpt-6.2-sol, judged by claude-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

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@manki-review

manki-review Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

✅ Review complete in 7m 38s

Planner (5s)
    feat · 401 lines · 2 agents
    judge effort: high

Review (security · full): 8 findings
    ✅ Claude Opus 5.5 · high: 2 findings (2m 31s)
    ✅ GPT 6.2 Sol · high: 6 findings (3m 9s)
    ✅ Related checks, claim checks and pattern checks: 14 of 14 done (2m 45s)

Judge (2m 55s)
    before the judge: 1 dropped as a repeat of an earlier resolved finding
    graded 7 findings: 4 kept · 2 dropped · 1 merged
    dropped, as the finders filed them: 1 blocker · 1 suggestion
    refuter: 1 checked · 1 disproved
    verdict reader: read the diff (45s)

Posted: 1 finding
    1 suggestion
    not posted: 2 on code an earlier round reviewed · 1 disproved by a check of the code

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 52% (resets 2026-12-02 17:00 UTC)
  • ChatGPT subscription: weekly 7% (resets 2026-12-02 01:49 UTC)

Judge decisions:

  • Kept: "The doc comment on verify_input_authorization grows to six lines and describes the caller's hold" (suggestion): "note. AGENTS.md says "three is the ceiling", which is a requirement. The /// block at key-wallet/src/transaction_checking/spend_authorization.rs:58-63 runs six lines, so the rule is broken. An earlier round cut an eight-line version, and the comment is still over the limit. The CoinJoin claim itself is correct: dashpay/dash:src/coinjoin/client.cpp:595 signs with SIGHASH_ALL | SIGHASH_ANYONECANPAY. A long comment does no harm when the code runs, so this is the style row."
  • Dropped: "The new sighash test checks behaviour that existed before this PR" (ignore): "ignore. The test pins an invariant the new verifier relies on: legacy SIGHASH_ALL commits to the special payload through encode_special_payload at dash/src/crypto/sighash.rs:241. A test that guards an existing assumption is not a defect. The finding itself asks for no code change."
  • Dropped: "The script size limit does not bound authorization work" (ignore): "ignore. Earlier rounds raised the same cost twice: "script limit does not bound the work" in round 7 and "repeatedly hash an unbounded transaction" in round 8. Both threads were settled in agreement with the author. Project memory also records that per-script signature-candidate work is not a finding here. Since then the code added per-mode digest caching at key-wallet/src/transaction_checking/spend_authorization.rs:112-120. Hashing the transaction once per input and per hash mode is the cost legacy sighash verification has in Dash Core too. The finding names no new failure beyond those settled threads."
  • Dropped: "The signature parser may reject nonstandard modes before they can return a typed error" (ignore): "warning. Line 114 splits off the raw mode byte. Line 115 then passes the whole signature, mode byte included, to Signature::from_slice and maps any error to None. rust-bitcoin's from_slice validates the byte with from_standard, and the dashcore parser's body is not shown. If it does the same, a valid owner signature with mode 0, 4 or 0xff returns Ok(false) instead of UnsupportedSighash, and a caller may release a hold it should keep. The test cases signed mode 0, signed mode 4 and signed mode 0xff would then fail, so the author should check that the tests pass. Parsing only the DER part (Signature::from_der on the slice without the last byte) avoids the question.
    Refutation disproved: dashcore::ecdsa::Signature is a re-export of bitcoin_crypto::ecdsa::Signature. Its from_slice maps any trailing byte with EcdsaSighashType::from_consensus, which wraps unknown values such as 0, 4 or 0xff in NonStandard and never fails. So a valid DER signature with mode 0, 4 or 0xff gets through line 115, is verified, and reaches the UnsupportedSighash return instead of Ok(false). Manki read bitcoin-crypto 0.4.0, the version a fresh install picks, because no lockfile is committed. Rule checked: Whether a valid owner signature with a nonstandard mode reaches the UnsupportedSighash check depends only on whether the parser rejects it, and bitcoin-crypto 0.4.0's Signature::from_slice reads the trailing byte with the infallible from_consensus, so only an empty slice or bad DER makes it fail.
  • Premise "dashcore::ecdsa::Signature::from_slice returns an error when the trailing sighash byte is not a standard mode (for example 0, 4 or 0xff)" disproved. from_slice calls from_consensus, not from_standard, and from_consensus turns every non-listed value into NonStandard without an error, so the only errors are an empty slice or invalid DER.
    Pair refutation disproved: The re-exported parser uses from_consensus, not from_standard, so it accepts valid DER signatures with modes 0, 4, and 0xff. The three test cases sign with the same raw byte the verifier hashes and reports as UnsupportedSighash after verification. Rule checked: A signature parser that separates the trailing sighash byte and decodes it with infallible from_consensus cannot reject a valid DER signature because its mode is nonstandard.
  • Premise "dashcore::ecdsa::Signature::from_slice returns an error when the trailing sighash byte is not a standard mode (for example 0, 4 or 0xff)" disproved. from_slice strips the last byte before DER parsing and maps every nonstandard mode to NonStandard rather than returning an error."
  • Not listed, on code an earlier round reviewed: "The new wallet API returns an error outside the crate error type" (suggestion): "note. key-wallet/AGENTS.md says to "Return key_wallet::Error through Result, including for malformed or untrusted input". The new public function at key-wallet/src/transaction_checking/spend_authorization.rs:68 returns Result<bool, SpendAuthorizationError> instead. The typed error works correctly at run time, so the only cost is consistency: the improvement row. Wrapping it as a key_wallet::Error variant keeps the specific cases and follows the rule."
  • Not listed, on code an earlier round reviewed: "The error formatter uses fully qualified paths instead of an import" (suggestion): "note. Root AGENTS.md allows a single qualifier but forbids fully qualified paths used to avoid an import. Lines 27-28 write core::fmt::Display, core::fmt::Formatter and core::fmt::Result, so the rule is broken. Adding use core::fmt; fixes it. This is formatting only."

Timing:

  • Parse: 11.1s
  • Review agents: 271.3s
  • Judge: 175.2s
  • Total: 457.6s

Last reviewed 116fa9a · head 116fa9a · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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):


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.

  1. Call verify_input_authorization on an input signed SIGHASH_ALL by the owner. Expect Ok(true).
  2. Sign the same input with another key. Expect Ok(false).
  3. Sign the input with SIGHASH_ALL | SIGHASH_ANYONECANPAY (0x81). Expect Err(UnsupportedSighash(0x81)).
  4. Append OP_NOP to a valid owner input script. Expect Err(UnsupportedScriptSig).
  5. Change only the sighash byte of a valid signature to 0x02. Expect Ok(false).
  6. Pass a non-P2PKH prevout. Expect Err(UnsupportedScript).
  7. Add a second input that spends the same outpoint. Expect Ok(false).
  8. 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. Its from_slice maps any trailing byte with EcdsaSighashType::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-5 and gpt-6.2-sol, judged by claude-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`

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ 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.

};
// Other modes can authorize only part of a transaction; SINGLE can even
// produce a constant digest. They cannot authorize this durable reservation.
if u32::from(mode) != EcdsaSighashType::All.to_u32() {
return Err(SpendAuthorizationError::UnsupportedSighash(mode));

  • 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 ZocoLini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_outputs moved to dash/src/crypto/sighash.rs instead of being dropped. It tests dashcore'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.

@github-actions

Copy link
Copy Markdown
Contributor

@coderabbitai review

No review for 116fa9ad yet, so PR Hygiene is asking once. If nothing arrives, the requirement is dropped for this commit and the pull request is labelled bot-review-skipped.

@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: address ZocoLini requested changes, then post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants