From c0e2e192b072912bf0e81f14c93e81438ffc7640 Mon Sep 17 00:00:00 2001 From: Lagrang3 Date: Thu, 13 Aug 2026 09:16:56 +0100 Subject: [PATCH] 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 --- plugins/offers_invreq_hook.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/offers_invreq_hook.c b/plugins/offers_invreq_hook.c index b6202d33eba1..0cd21f2d09ec 100644 --- a/plugins/offers_invreq_hook.c +++ b/plugins/offers_invreq_hook.c @@ -563,10 +563,13 @@ static struct command_result *check_period(struct command *cmd, u64 end = offer_period_start(basetime, period_idx + 1, invreq_recurrence(ir->invreq)); - if (*ir->inv->invoice_created_at > start) { + assert(end > start); + if (*ir->inv->invoice_created_at >= end) { + *ir->inv->invoice_amount = 1; + } else if (*ir->inv->invoice_created_at > start) { *ir->inv->invoice_amount - *= (double)((*ir->inv->invoice_created_at - start) - / (end - start)); + *= ((double)end - *ir->inv->invoice_created_at) + / (end - start); /* Round up to make it non-zero if necessary. */ if (*ir->inv->invoice_amount == 0) *ir->inv->invoice_amount = 1;