Skip to content

staticaddr/loopin: Reject mismatched server nonce counts - #1300

Merged
hieblmi merged 2 commits into
lightninglabs:masterfrom
hieblmi:hai/fix-static-loopin-nonce-count
Nov 17, 2026
Merged

hieblmi merged 2 commits into
lightninglabs:masterfrom
hieblmi:hai/fix-static-loopin-nonce-count

Conversation

@hieblmi

@hieblmi hieblmi commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

A static-address Loop In response with fewer server nonces than deposits can panic loopd during HTLC signing. Require exactly one nonce per deposit for all three fee tiers during initialization, using the existing abort path to notify the server, cancel the invoice, and release deposits.

Includes regression coverage for malformed nonce counts across all fee tiers, successful initialization with two deposits, the fee guard, and invoice/deposit cleanup, plus a release note.

Validation:

  • make fmt
  • go test ./staticaddr/loopin -count=1
  • go test -race ./staticaddr/loopin -run '^TestInitHtlcAction' -count=1
  • New nonce-count cases fail against the original production code using a Go overlay.
  • Repository-pinned golangci-lint v2.15.0, built with Go 1.27.3: zero issues in ./staticaddr/loopin/....
  • make commitmsg-lint range='upstream/master..HEAD'

A server response can contain valid signing-info messages but fewer
nonces than deposits. Signing indexes those lists by deposit and panics.
Reject missing or extra nonces for every fee tier during initialization,
using the existing invoice cancellation and deposit release path.

Cover each fee tier and retain valid initialization coverage.

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

LGTM! 💾

The fix is great! Two issues in tests and a bunch of nits.

  1. The fee-guard test no longer tests the fee guard. TestInitHtlcActionCancelsInvoiceOnFeeGuardFailure builds its response inline with one deposit and no nonces. It now fails at the new nonce-count check and never reaches the fee guard. It still passes because it only asserts OnError and the invoice cancellation, and it is the only test of the fee-guard error path. Please give each tier one musig2.PubNonceSize nonce and assert require.ErrorIs(t, f.LastActionError, ErrFeeTooHigh).

  2. No success case with more than one deposit. Every InitHtlcAction test uses one deposit, so a check hard-coded to one nonce per tier would pass all of them. Could one existing success case use two deposits and two nonces per tier? testStaticAddressLoopInResponse hard-codes one nonce per tier; a count parameter would make that fixture easy to reuse.

Nits:

  • TestInitHtlcActionRejectsInvalidSigningInfo sets no Store. If the nonce-count check were missing, the new cases would panic at CreateLoopIn rather than fail the OnError assertion. Setting Store: &mockStore{} would make that kind of regression fail cleanly.
  • The loop variable is still named missing, but it now also covers the "extra ..." cases.
  • wantErr is worked out after the switch, from whether all three tiers are non-nil. Setting the expected error per case would be easier to read.
  • The error message doesn't say which tier failed or give the actual and expected nonce counts.

Keep the fee-guard test reaching its intended error path and cover a
successful two-deposit initialization. Make malformed-response tests
fail cleanly without the guard and specify their expected errors.

Include the fee tier and actual and expected counts in nonce errors.
@hieblmi
hieblmi merged commit b41a3a3 into lightninglabs:master Nov 17, 2026
12 checks passed
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.

2 participants