Skip to content

Commit c2ba235

Browse files
Lagrang3nGoline
authored andcommitted
offers: fix recurrence proportional amount
Reported-by: Vincenzo Palazzo (Bitcoin Security Council finding 2026-08-11) Changelog-Fixed: offers: recurrence with proportional_amount now computes the correct invoice amount based on the time remaining Signed-off-by: Lagrang3 <lagrang3@protonmail.com>
1 parent fb0c10c commit c2ba235

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

‎plugins/offers_invreq_hook.c‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,23 @@ static struct command_result *check_period(struct command *cmd,
563563
u64 end = offer_period_start(basetime, period_idx + 1,
564564
invreq_recurrence(ir->invreq));
565565

566+
if (end <= start) {
567+
return fail_invreq(cmd, ir,
568+
"period_index %"PRIu64" bad period",
569+
period_idx);
570+
}
571+
/* Paywindow can outlive the period; remaining time is then 0. */
572+
if (*ir->inv->invoice_created_at >= end) {
573+
return fail_invreq(cmd, ir,
574+
"period_index %"PRIu64
575+
" too late (ended %"PRIu64")",
576+
period_idx,
577+
end);
578+
}
566579
if (*ir->inv->invoice_created_at > start) {
567580
*ir->inv->invoice_amount
568-
*= (double)((*ir->inv->invoice_created_at - start)
569-
/ (end - start));
581+
*= ((double)end - *ir->inv->invoice_created_at)
582+
/ (end - start);
570583
/* Round up to make it non-zero if necessary. */
571584
if (*ir->inv->invoice_amount == 0)
572585
*ir->inv->invoice_amount = 1;

0 commit comments

Comments
 (0)