Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading