RustFund

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

Contribution Amounts is not updated in RustFund

Summary

An accounting vulnerability exists in the RustFund program where contribution amounts are not properly tracked at the individual contributor level. While funds are successfully transferred from contributors to the fund account and the global fund.amount_raised is updated, the individual contribution amount is initialized to 0 but never incremented when users make contributions.

Vulnerability Details

In the contribute function, the program correctly transfers SOL from the contributor to the fund account using system_program::transfer and updates the fund.amount_raised variable. However, it fails to update the individual contributor's amount field.

system_program::transfer(cpi_context, amount)?;
fund.amount_raised += amount;
// @audit individual contribution amount is not tracked

This means that while the total amount raised is tracked correctly at the fund level, individual contribution records remain at 0 regardless of how much a user contributes.

Impact

The refund function relies on contribution.amount to determine how much to refund to contributors. Since this value is always 0, contributors can never receive refunds, effectively locking their funds in the contract permanently.

Tools Used

Manual Review

Recommendations

Modify the contribute function to properly update the individual contribution records:

pub fn contribute(ctx: Context<FundContribute>, amount: u64) -> Result<()> {
// Existing code...
system_program::transfer(cpi_context, amount)?;
fund.amount_raised += amount;
// Add this line
ctx.accounts.contribution.amount += amount;
Ok(())
}
Updates

Appeal created

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

Contribution amount is not updated

Support

FAQs

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