Rust Fund

AI First Flight #9
Beginner FriendlyRust
EXP
View results
Submission Details
Severity: low
Valid

Completed fund accounts retain creator rent

Description

  • The creator pays rent when fund_create initializes the Fund PDA. A completed campaign needs a close path that returns this rent.

  • withdraw transfers only amount_raised, and the program has no instruction that closes Fund. The rent reserve remains inaccessible to the creator.

#[account(init, payer = creator, ...)]
pub fund: Account<'info, Fund>,
// ...
@> let amount = ctx.accounts.fund.amount_raised;
@> // no close instruction exists for Fund

Risk

Likelihood:

  • A creator starts a campaign.

  • The campaign completes and the creator withdraws its recorded deposits.

Impact:

  • The creator cannot reclaim the fund PDA rent.

  • Every completed fund leaves rent permanently locked.

Proof of Concept

The PoC contributes and withdraws 5,000 lamports, then compares the remaining fund balance with
the rent reserve. The balance equals the rent reserve because withdraw pays only
amount_raised, and no instruction can close the account and transfer its remaining lamports.

vulnerable_contribute(&mut fund, &mut contribution, 5_000);
vulnerable_withdraw(&mut fund).unwrap();
assert_eq!(fund.lamports, fund.rent);

Recommended Mitigation

Add a settlement close path that requires the outstanding campaign balance to be zero and returns
the Fund account lamports to its creator. Keeping the close condition explicit avoids returning
rent while contributor claims or creator payouts still remain.

+pub fn close_fund(ctx: Context<CloseFund>) -> Result<()> {
+ require!(ctx.accounts.fund.amount_raised == 0, ErrorCode::OutstandingBalance);
+ Ok(())
+}
// CloseFund uses #[account(mut, close = creator, has_one = creator)]
Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 3 hours ago
Submission Judgement Published
Validated
Assigned finding tags:

[L-04] Unclaimed rent from fund and contribution accounts leads to permanent SOL lockup

## Description neither the `withdraw()` nor `refund()` functions properly close their respective accounts after the funds have been transferred. This results in the rent amount (the SOL required to keep the account allocated on the Solana blockchain) remaining locked in these accounts indefinitely. ## Vulnerability Details In Solana, accounts must maintain a minimum balance to remain "rent-exempt", ensuring they aren't purged from the blockchain. When accounts are no longer needed, best practice is to close them and return this rent to the appropriate party (typically the account creator). The RustFund protocol currently lacks this account cleanup mechanism. - The withdrawal process in `withdraw()` transfers the raised funds from the fund account to the creator - Similarly, the refund process in `refund()` transfers the contribution amount back to the contributor and resets the contribution amount In both functions, the account data is updated, but the accounts themselves remain open, with their rent amount locked. After all funds have been withdrawn or refunded, these accounts serve no further purpose but continue to consume blockchain resources and lock up SOL. ### Proof of Concept 1. Alice creates a fund with a goal of 100 SOL, which requires 0.1 SOL as rent for the fund account. 2. The fund successfully raises 100 SOL from various contributors, each of whom also paid rent for their contribution accounts (approximately 0.05 SOL each). 3. Alice calls `withdraw()` to claim the 100 SOL raised funds, but the fund account itself is not closed. 4. The 0.1 SOL rent for the fund account remains locked in the account indefinitely. 5. Similarly, when contributors request refunds through the `refund()` function, their contribution accounts are updated but not closed. 6. The rent for all contribution accounts (e.g., 10 contributors × 0.05 SOL = 0.5 SOL) remains locked indefinitely. 7. Over time, as more funds are created and more contributions are made, the amount of permanently locked SOL grows. ## Impact - Economic Inefficiency, - Blockchain bloat, - Reduced user returns ## Recommendations Implement proper account closure in both the `withdraw()` and `refund()` functions.

Support

FAQs

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

Give us feedback!