RustFund

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

The author can withdraw money at any time without meeting any conditions.

Summary

The creator can withdraw the raised funds at any time without meeting any successful conditions.

Vulnerability Details

  1. The creator initiated an activity with a goal of 1,000 SOL.

  2. Call withdraw immediately after receiving 10 SOL.

  3. The contract will transfer 10 SOL to the creator's account without any obstacles.

Impact

Malicious creators can abscond with funds,Destroying the basic logic of crowdfunding models.

Tools Used

Manual Review

Recommendations

Implement checks to ensure that funds can only be withdrawn after the objectives of the activity have been achieved.

pub fn withdraw(ctx: Context<FundWithdraw>) -> Result<()> {
let fund = &mut ctx.accounts.fund;
// Check if the target has been reached
if fund.amount_raised < fund.goal {
return Err(ErrorCode::GoalNotReached.into());
}
// Prevent duplicate withdrawals
if fund.amount_raised == 0 {
return Err(ErrorCode::InsufficientFunds.into());
}
let amount = fund.amount_raised;
fund.amount_raised = 0; // Reset amount
// Transfer funds
**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.creator.to_account_info().try_borrow_mut_lamports()? =
ctx.accounts.creator.to_account_info().lamports()
.checked_add(amount)
.ok_or(ErrorCode::CalculationOverflow)?;
Ok(())
}

}

Updates

Appeal created

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

No goal achievement check in `withdraw` function

Support

FAQs

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