Skip to content

tests: LSPS client against a misbehaving LSP - #9749

Open
nepet wants to merge 4 commits into
ElementsProject:masterfrom
nepet:lsps-mock-5-malicious-lsp
Open

nepet wants to merge 4 commits into
ElementsProject:masterfrom
nepet:lsps-mock-5-malicious-lsp

Conversation

@nepet

@nepet nepet commented Nov 19, 2026

Copy link
Copy Markdown
Member

Important

26.09 FREEZE August 5th: Non-bugfix PRs not ready by this date will wait for 26.12.

RC1 is scheduled on August 17th

The final release is scheduled for September 7th.

Checklist

Before submitting the PR, ensure the following tasks are completed. If an item is not applicable to your PR, please mark it as checked:

  • The changelog has been updated in the relevant commit(s) according to the guidelines.
  • Tests have been added or modified to reflect the changes.
  • Documentation has been reviewed and updated as needed.
  • Related issues have been listed and linked, including any that this PR closes.
  • Important All PRs must consider how to reverse any persistent changes for tools/lightning-downgrade

This adds tests/test_lsps2_malicious_lsp.py. In each case the mock misbehaves in one specific way; the test checks how the client reacts, then runs the invariant checks.

  • Fee deduction:
    • 1 msat more than the fee on a fixed invoice, and a fee on a rounding boundary;
    • the fee spread over MPP parts, correctly and adding up to 1 msat more;
    • only some parts forwarded;
    • the fee taken again on a later payment;
    • an overpaid invoice.
  • JSON-RPC transport:
    • a response with the wrong id, or none at all;
    • unsolicited and duplicate responses;
    • malformed amounts and unknown keys;
    • full-size garbage and deeply nested JSON;
    • an error with a huge message.
  • Opening fee params:
    • expired entries, and entries expiring within the client's margin;
    • inverted size limits;
    • fees that eat the payment or overflow;
    • a large max_client_to_self_delay and a min_lifetime of 0;
    • a menu filling a whole message;
    • promises over 512 bytes or with forbidden characters, and valid ones at the limits;
    • duplicate entries;
    • entries missing a field, or with one bLIP-52 does not define.
  • Buy result and channel opens:
    • invalid SCIDs;
    • an lsp_cltv_expiry_delta of 0;
    • an unchanged promise rejected as invalid;
    • a second buy result;
    • zero-conf opens without a purchase, a second one for the same purchase, and one from another node.

Cases that wait for the client's 60 s request timeout or lightningd's 70 s MPP timeout are marked slow_test. The client itself is not changed.

Changelog-None

Add tests/test_lsps2_malicious_lsp.py, for tests of the client against
an LSP that misbehaves, starting with an LSP that deducts the wrong
fee from the JIT payment. Each case of one parametrized test ends with
the oracles; the fee taken again from a later payment needs two
payments and has its own test:

- 1 msat more than the opening fee, on a fixed invoice paid in parts;
- a fee on the rounding boundary, accepted exactly;
- the fee spread over MPP parts, correctly, and adding up to 1 msat
  more;
- only some of the MPP parts forwarded;
- the fee deducted again from a later payment;
- an overpaid fixed invoice.

Cases that rely on the MPP timeout of 70 seconds are marked slow. A
forward below the client's htlc_minimum_msat cannot be produced by an
LSP running Core Lightning, so there is no case for it.
Test how the client handles what the LSP sends over the LSPS0
transport, one parametrized case each, ending with the oracles:

- a response with the wrong id, or none: the request times out;
- a response to no request is ignored;
- of two responses, the first counts;
- a negative msat or one above u64: a clean error;
- unknown keys in a result are ignored;
- a full-size message of garbage or deeply nested JSON is ignored;
- an error with a huge message does not fill the log.

lightningd hands the client one custom message from a peer at a time,
so a request answered after the mock's unsolicited messages shows they
were handled; every case also checks the client still gets an honest
menu afterwards. The cases that wait for the client's 60 second
request timeout are marked slow.
Test which entry of an LSP's get_info menu the client buys, if any,
one parametrized case each, ending with the oracles:

- an expired entry, or one expiring within the client's margin;
- a minimum payment size above the maximum;
- a fee that eats the payment, or overflows;
- a large max_client_to_self_delay;
- min_lifetime 0;
- a menu filling a whole message, usable only at its end;
- promises too long or with forbidden characters, which abort the flow
  even in an entry not picked, and valid ones at the limits;
- duplicate entries;
- an entry missing a field, or with one bLIP-52 does not define.

The invoice call is waited for at most 30 seconds, so a hang fails the
case instead of the run.
Test how the client handles the LSP's lsps2.buy result and channel
opens it did not ask for, each case ending with the oracles:

- a jit_channel_scid that is no SCID;
- an lsp_cltv_expiry_delta of 0;
- "invalid promise" for an unchanged promise: no retries;
- a second buy result with another SCID;
- a zero-conf open from the LSP before any buy or after the session's
  channel;
- a second zero-conf open for the session;
- a zero-conf open from another node during a session.

Core Lightning refuses the unsolicited zero-conf opens because the
client allows zero-conf only for the LSP it just bought from, once.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant