RustFund

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

Contribution amount not tracked (contribution amount record is missing from the contribute function)

Summary

In the contribute function, the amount contributed by each user was not properly recorded in the Contribution account, making it impossible to accurately track the total amount contributed by each contributor.

Vulnerability Details

// The current contribution logic lacks amount recording.
if contribution.contributor == Pubkey::default() {
contribution.contributor = ctx.accounts.contributor.key();
contribution.fund = fund.key();
contribution.amount = 0;
}

1. Here the Contribution account is initialized, but contribution.amount is not updated after the SOL transfer is completed.

2 .This means that even if the user contributes multiple times, the amount in the Contribution account remains at 0, which does not accurately reflect the user's contribution history.

3.Contribution.amount is relied upon in the refund logic, but because the value is always 0, it may not be refunded correctly, or may result in an issue where the refund amount is 0.

Impact

It is unknown how much SOL each contributor donated, and if the refund logic depends on contribution.amount, it may result in incorrect refunds or

Tools Used

Manual review

Recommendations

After the fund transfer in the contribute function is successful, update contribution.amount to record the cumulative contribution amount of each user:

pub fn contribute(ctx: Context<FundContribute>, amount: u64) -> Result<()> {
let fund = &mut ctx.accounts.fund;
let contribution = &mut ctx.accounts.contribution;
if fund.deadline != 0 && fund.deadline < Clock::get().unwrap().unix_timestamp.try_into().unwrap() {
return Err(ErrorCode::DeadlineReached.into());
}
// Initialize or update contribution record
if contribution.contributor == Pubkey::default() {
contribution.contributor = ctx.accounts.contributor.key();
contribution.fund = fund.key();
contribution.amount = 0;
}
// Transfer SOL from contributor to fund account
let cpi_context = CpiContext::new(
ctx.accounts.system_program.to_account_info(),
system_program::Transfer {
from: ctx.accounts.contributor.to_account_info(),
to: fund.to_account_info(),
},
);
system_program::transfer(cpi_context, amount)?;
fund.amount_raised += amount;
// ✅ Record each amount
contribution.amount += amount;
Ok(())
}
Updates

Appeal created

bube Lead Judge 8 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.