Audit of RustFund anchor program revealing 3 high severity vulnerabilities and 1 medium severity vulnerability.
File: src/lib.rs
High Risk
The withdraw function lacks any validation checks regarding the campaign's success.
The creator can withdraw funds immediately after they are contributed, regardless of whether the funding goal was met or the deadline has passed.
This completely undermines the crowdfunding trust model.
Likelihood: High. A malicious creator can easily drain all funds.
Impact: Contributor funds can be stolen immediately.
Creator starts a fund with a goal of 100 SOL.
User contributes 10 SOL.
Creator immediately calls withdraw and receives 10 SOL.
User cannot refund.
Add checks to ensure the goal has been met and the deadline has passed (optional, depending on design) before allowing withdrawal.
In the contribute function, the contribution.amount state is never updated with the new contribution amount.
It is initialized to 0 and stays 0.
Only fund.amount_raised is updated.
Likelihood: Certain (100%). Every contribution fails to record.
Impact: Users can never receive a refund because the refund function calculates the refund amount from contribution.amount (which is 0). Users' funds are permanently locked in the contract if the goal is not met.
User contributes 5 SOL.
fund.amount_raised increases by 5.
contribution.amount remains 0.
Deadline passes, goal not met.
User calls refund.
Code executes let amount = ctx.accounts.contribution.amount; (which is 0).
Transfers 0 SOL.
Update the individual contribution record.
The set_deadline function checks the dealine_set flag to prevent multiple deadline updates, but it never sets this flag to true.
Consequently, the creator can call set_deadline indefinitely.
Likelihood: High.
Impact: Creator can malicious extend the deadline indefinitely to hold funds hostage or shorten it instantly to prevent refunds (if combined with other logic).
Creator sets a deadline for tomorrow.
Tomorrow comes. Users try to refund.
Creator calls set_deadline again to next year.
Users cannot refund.
Update the boolean flag after setting the deadline.
refundThe refund function performs the fund transfer (Interaction) before updating the state (Effect).
While less critical in Solana than EVM due to the account model, it is a bad practice and can lead to reentrancy vulnerabilities if complex CPIs are involved.
Likelihood: Low (in this specific simple program).
Impact: Potential for reentrancy or state desynchronization.
Update the state before performing the transfer.
The contest is live. Earn rewards by submitting a finding.
Submissions are being reviewed by our AI judge. Results will be available in a few minutes.
View all submissionsThe contest is complete and the rewards are being distributed.