RustFund

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

`Rustfund::refund` does not validate if goal already reached

Summary

refundfunction only check if the deadline are set then it would check if the deadline passed or not, if not then it would revert.

but the crucial part is the function does not check if the fundraising goal already reached or not, this would cause any contributor can call refund even when the goal are reached

Vulnerability Details

the function only check the deadline already passed or not but neglected the state of fund raising goal already reached or not. this would cause any malicious contributor can call refund when the goal already passed.

pub fn refund(ctx: Context<FundRefund>) -> Result<()> {
let amount = ctx.accounts.contribution.amount;
@> if ctx.accounts.fund.deadline != 0 && ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap() {
return Err(ErrorCode::DeadlineNotReached.into());
}
**ctx.accounts.fund.to_account_info().try_borrow_mut_lamports()? =
ctx.accounts.fund.to_account_info().lamports()
.checked_sub(amount)
.ok_or(ProgramError::InsufficientFunds)?;
**ctx.accounts.contributor.to_account_info().try_borrow_mut_lamports()? =
ctx.accounts.contributor.to_account_info().lamports()
.checked_add(amount)
.ok_or(ErrorCode::CalculationOverflow)?;
// Reset contribution amount after refund
ctx.accounts.contribution.amount = 0;
Ok(())
}

Impact

if the goal already reached and the malicious attacker call refund then the campaign fund raising would be broken because of the discrepancy between the goal amount and actual amount

Tools Used

manual review

Recommendations

refund should also check if the goal already reached, then contributor cant call these function.

Updates

Appeal created

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

There is no check for goal achievement in `refund` function

Support

FAQs

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