RustFund

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

Missing `amount_raised` Reset After Withdrawal

Description

The withdraw function transfers the total amount_raised to the creator but does not reset fund.amount_raised to 0 afterward. This allows the creator to repeatedly withdraw the same funds, draining the fund account.


Impact

  • Fund Drainage: The creator can withdraw the amount_raised multiple times, even after funds have already been transferred.

  • Protocol Integrity Loss: The amount_raised value becomes untrustworthy, breaking fund accounting logic.


Affected Code

pub fn withdraw(ctx: Context<FundWithdraw>) -> Result<()> {
let amount = ctx.accounts.fund.amount_raised;
// Transfers funds to creator...
**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)?;
// MISSING: Reset amount_raised to 0!
Ok(())
}

Recommendation

Reset amount_raised to 0 after withdrawal:

// After transferring funds:
fund.amount_raised = 0;
Updates

Appeal created

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

`amount_raised` is not reset to 0 in `withdraw` function

Support

FAQs

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