RustFund

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

No withdrawal condition check

Summary

The Withdraw function allows the creator to withdraw the entire amount_raised at any time, with no checks

Vulnerability Details

The Withdraw function allows the creator to withdraw the entire amount_raised at any time, with no checks for whether the fundraising goal is met or the deadline has passed

Impact

In a crowdfunding context, this could allow premature withdrawals, violating typical rules where funds are only released if the goal is achieved or after a deadline. This reduces trust in the program.

Tools Used

Manual code review

Recommendations

Add conditions for withdrawal

pub fn withdraw(ctx: Context<FundWithdraw>) -> Result<()> {
let amount = ctx.accounts.fund.amount_raised;
+ let current_time = Clock::get()?.unix_timestamp as u64;
+ if ctx.accounts.fund.deadline != 0 && current_time < ctx.accounts.fund.deadline && amount < ctx.accounts.fund.goal {
+ return Err(ErrorCode::WithdrawalNotAllowed.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.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 3 months ago
Submission Judgement Published
Validated
Assigned finding tags:

No deadline check in `withdraw` function

No goal achievement check in `withdraw` function

Support

FAQs

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