Skip to content

btc: require verified silent payment outputs - #190

Open
benma-agent wants to merge 2 commits into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/fix-silent-payment-completeness
Open

benma-agent wants to merge 2 commits into
BitBoxSwiss:masterfrom
benma-agent:benma-agent/fix-silent-payment-completeness

Conversation

@benma-agent

@benma-agent benma-agent commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

BTCSign could succeed when the device omitted a generated silent payment script
or skipped the output exchange entirely. Require a verified generated script for
every requested silent payment before returning signatures, and reject generated
silent payment data on ordinary outputs.

Add regression coverage for omitted exchanges, missing or invalid proofs,
duplicate output requests, and valid mixed outputs. Keep the shared firmware
vectors unchanged and handle older firmware's acceptance of silent payment
metadata on owned outputs in the Go runner. Failed signing must leave PSBT
signatures and output scripts unchanged.

Includes commit ac372fc from #188 before the signing fix to disable goconst for
test files while retaining the rule for production code.

Repeated literals keep test inputs and expected results readable.
Exclude goconst from all _test.go files while retaining it for
production code.
@benma
benma requested a review from Beerosagos October 4, 2026 08:23
BTCSign could return successfully when the device omitted a generated
silent payment script or skipped the output exchange entirely. In both
cases the host skipped proof verification and left the original PSBT
output script unchanged.

Require a generated script for each silent payment output exchange,
verify it before recording it, and reject completion unless every
requested silent payment has a verified output. Reject generated silent
payment data on ordinary outputs as well.

Add regressions for omitted exchanges, missing or invalid proofs,
duplicate output requests, and valid mixed outputs. Keep the shared
firmware vectors unchanged and handle older firmware's acceptance of
silent payment metadata on owned outputs in the Go runner, expecting
the host to reject the missing script. Failed signing must leave PSBT
signatures and output scripts unchanged.
@benma-agent
benma-agent force-pushed the benma-agent/fix-silent-payment-completeness branch from 4033c84 to ec282be Compare October 4, 2026 08:24
@benma
benma marked this pull request as ready for review October 4, 2026 08:24
Comment thread api/firmware/btc.go
if next.GeneratedOutputPkscript != nil {
generatedOutputs[int(outputIndex)] = next.GeneratedOutputPkscript
if output.SilentPayment != nil {
if len(next.GeneratedOutputPkscript) == 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nit: could we drop the explicit script-length check and let silentPaymentOutputVerify reject the missing/empty script? Now that verification is triggered by output.SilentPayment != nil, it already covers this case. Unless we specifically want the more precise error message, the extra check seems redundant.

@Beerosagos Beerosagos 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.

utACK, with a small nit. See comment

@beerosagos-agent

Copy link
Copy Markdown

[P2] Clear the signing workflow before returning this error

For silent-payment-owned-output on firmware v9.21.0–v9.26.1, firmware returns INPUT for index 0 without a generated script. This new return exits while firmware is still awaiting that input, so the next request fails with can't call this endpoint: wrong state. An immediate BTCSignPSBT retry—even with corrected metadata—fails at its initial RootFingerprint() call.

Reproduced with both signing APIs across all six affected simulators; base-revision follow-up requests succeed. The failed follow-up clears the workflow, but unnecessarily costs the caller another request/retry.

Please reject conflicting Ours/SilentPayment metadata before starting signing, or unwind the workflow before returning. Add a successful follow-up-request assertion before simulator teardown; the current vector test passes without checking this.

@Beerosagos Beerosagos 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.

Found out a small regression, see comment

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants