Skip to content

Commit 5cc46c9

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 79b3976 commit 5cc46c9

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
@@ -931,6 +931,11 @@ fn check_range(min: u64, max: u64, value: u64) -> bool {
931931
}
932932

933933
fn is_valid(order: &LSPS1OrderParams, options: &LSPS1Options) -> bool {
934+
let channel_balance_sat = match order.lsp_balance_sat.checked_add(order.client_balance_sat) {
935+
Some(sum) => sum,
936+
None => return false,
937+
};
938+
934939
check_range(
935940
options.min_initial_client_balance_sat,
936941
options.max_initial_client_balance_sat,
@@ -943,5 +948,10 @@ fn is_valid(order: &LSPS1OrderParams, options: &LSPS1Options) -> bool {
943948
1,
944949
options.max_channel_expiry_blocks.into(),
945950
order.channel_expiry_blocks.into(),
946-
)
951+
) && check_range(
952+
options.min_channel_balance_sat,
953+
options.max_channel_balance_sat,
954+
channel_balance_sat,
955+
) && order.required_channel_confirmations >= options.min_required_channel_confirmations
956+
&& order.funding_confirms_within_blocks >= options.min_funding_confirms_within_blocks
947957
}

0 commit comments

Comments
 (0)