The withdraw function attempts to transfer the entire amount_raised value from the fund account to the creator account, regardless of the actual lamport balance available in the fund.
In the withdraw function, since amount_raised is not reset after a withdrawal and continues to accumulate with new contributions, subsequent withdrawal attempts may fail when the requested amount exceeds the current balance. This can leave contributed funds inaccessible if no further contributions increase the balance to match or exceed amount_raised.
In scenarios where the creator withdraws an initial amount (e.g., 1000 lamports) and new contributions are added (e.g., 500 lamports), the function tries to withdraw the total amount_raised (1500 lamports) despite only 500 lamports being available. This results in a transaction failure due to insufficient funds, leaving the 500 lamports stuck in the fund account
manual code review
To resolve this issue and ensure all contributed funds can be withdrawn without getting stuck, modify the withdraw function to:
Transfer the current lamport balance of the fund account instead of amount_raised.
Reset amount_raised to 0 after each withdrawal to maintain state consistency.
Include a check to prevent unnecessary withdrawals when no funds are available.
add this error code
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.