RustFund

First Flight #36
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: medium
Valid

`amount_raised` Not Reduced on Refund

Description

When a contributor requests a refund, the fund.amount_raised value is not reduced by the refunded amount. This results in an inflated total of raised funds, misrepresenting the actual balance held by the fund.


Impact

  • Inaccurate Accounting: The protocol will report a higher amount_raised than the actual SOL held in the fund.

  • Operational Risks: Creators may withdraw more funds than available, or contributors might be denied refunds due to insufficient SOL.


Affected Code

// Line 83
pub fn refund(ctx: Context<FundRefund>) -> Result<()> {
let amount = ctx.accounts.contribution.amount;
// ...
ctx.accounts.contribution.amount = 0;
// MISSING: fund.amount_raised -= amount;
}

Recommendation

Use checked_sub to safely decrement amount_raised and handle underflow:

fund.amount_raised = fund.amount_raised
.checked_sub(amount)
.ok_or(ErrorCode::CalculationOverflow)?;
Updates

Appeal created

bube Lead Judge 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

`amount_raised` not updated in `refund` function

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.