Skip to content

Commit 4bec6db

Browse files
committed
Validate all common fields in LSPS1 is_valid order check
Add missing cross-validation of `LSPS1OrderParams` against `LSPS1Options` as required by bLIP-51: - Check `required_channel_confirmations` >= `min_required_channel_confirmations` - Check `funding_confirms_within_blocks` >= `min_funding_confirms_within_blocks` - Check total channel balance (`lsp_balance_sat` + `client_balance_sat`) is within [`min_channel_balance_sat`, `max_channel_balance_sat`], using `checked_add` to guard against overflow Co-Authored-By: HAL 9000
1 parent 15dbb21 commit 4bec6db

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

lightning-liquidity/src/lsps1/service.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,11 @@ fn check_range(min: u64, max: u64, value: u64) -> bool {
929929
}
930930

931931
fn is_valid(order: &LSPS1OrderParams, options: &LSPS1Options) -> bool {
932+
let channel_balance_sat = match order.lsp_balance_sat.checked_add(order.client_balance_sat) {
933+
Some(sum) => sum,
934+
None => return false,
935+
};
936+
932937
check_range(
933938
options.min_initial_client_balance_sat,
934939
options.max_initial_client_balance_sat,
@@ -941,5 +946,10 @@ fn is_valid(order: &LSPS1OrderParams, options: &LSPS1Options) -> bool {
941946
1,
942947
options.max_channel_expiry_blocks.into(),
943948
order.channel_expiry_blocks.into(),
944-
)
949+
) && check_range(
950+
options.min_channel_balance_sat,
951+
options.max_channel_balance_sat,
952+
channel_balance_sat,
953+
) && order.required_channel_confirmations >= options.min_required_channel_confirmations
954+
&& order.funding_confirms_within_blocks >= options.min_funding_confirms_within_blocks
945955
}

0 commit comments

Comments
 (0)