From d42b7699808cf896751d02ad0226136a37893e53 Mon Sep 17 00:00:00 2001 From: aniokedianne Date: Fri, 29 May 2026 03:01:19 +0100 Subject: [PATCH] fix: defer revenue share division to prevent zero claimable on small pools Closes #373 Closes #375 --- src/lib.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index c26d29f..11ac588 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -861,10 +861,13 @@ impl ProofOfHeart { } let total_pool = get_revenue_pool(&env, campaign_id); - let contributor_pool = (total_pool * (campaign.revenue_share_percentage as i128)) / 10000; + // Defer all division to the last step to avoid intermediate truncation to zero + // when total_pool is small relative to 10_000 / revenue_share_percentage (#375). let total_due = contribution - .checked_mul(contributor_pool) + .checked_mul(total_pool) + .and_then(|n| n.checked_mul(campaign.revenue_share_percentage as i128)) .and_then(|n| n.checked_div(campaign.effective_amount_raised)) + .and_then(|n| n.checked_div(10000)) .ok_or(Error::Overflow)?; let already_claimed = get_revenue_claimed(&env, campaign_id, &contributor); let claimable = total_due - already_claimed;