In a properly functioning crowdfunding smart contract, when a creator calls the set_deadline() function to establish the campaign's end date, the contract must permanently lock this deadline to prevent manipulation [file:1]. The function implements a protection mechanism using the fund.dealine_set boolean flag—after the first deadline is set, this flag should be updated to true, and any subsequent calls to set_deadline() should be rejected with the ErrorCode::DeadlineAlreadySet error. This ensures contributors know the exact timeframe within which the campaign must reach its goal, and if it fails, they can reclaim their funds through the refund mechanism without the creator being able to arbitrarily extend or modify the deadline.
The set_deadline() function contains a critical state update omission on line 62 of lib.rs where fund.dealine_set is never set to true after updating the deadline [file:1]. While the function correctly checks whether dealine_set is true at line 57 and updates the fund.deadline value at line 61, it completely fails to set fund.dealine_set = true; before returning. Consequently, the protection mechanism is non-functional—creators can call set_deadline() an unlimited number of times, arbitrarily extending or modifying campaign deadlines at will. This enables malicious creators to trap contributor funds indefinitely by continuously pushing the deadline into the future whenever the campaign approaches expiry without meeting its goal, preventing contributors from ever triggering the refund mechanism and creating a soft rugpull vector where creators maintain indefinite control over campaign timelines while contributors' capital remains locked
Likelihood:
The missing state update fund.dealine_set = true; occurs on every execution of the set_deadline() function, meaning the protection flag remains permanently false from campaign creation through all subsequent deadline changes [file:1]. The bug manifests in the unconditional code path after the validation check passes, affecting all campaigns universally regardless of creator intent, campaign parameters, or timing. Any creator who attempts to call set_deadline() multiple times will discover the function has no effective protection and can be invoked repeatedly without restriction.
Rational economic actors will exploit this vulnerability when campaigns approach deadline without meeting funding goals, as it enables risk-free deadline extensions that give failing campaigns more time to succeed or allow creators to maintain control over contributor funds indefinitely [code_file:9]. The vulnerability provides immediate utility to creators facing campaign failure, requires only a single function call with no technical sophistication, carries no on-chain penalty or detection mechanism, and allows creators to avoid returning funds to contributors. The incentive structure guarantees exploitation in any scenario where deadline manipulation benefits the creator's position, making this vulnerability's activation inevitable during normal protocol operation.
Impact:
Contributors' funds become effectively held hostage with no guaranteed recovery timeline, as malicious creators can perpetually extend deadlines to prevent refund eligibility [code_file:9]. While contributors do not immediately lose funds permanently (unlike CRITICAL-01), they lose control over their capital and cannot exit failing campaigns on the promised timeline. A creator with 7 SOL raised toward a 10 SOL goal can extend the deadline infinitely, forcing contributors to either wait for an arbitrarily long period or forfeit their investment. This creates a time-value-of-money attack where contributor capital is locked without consent, preventing them from deploying funds elsewhere and causing opportunity cost losses that compound over time.
The vulnerability completely breaks the fundamental trust model of crowdfunding platforms where deadlines create accountability and risk boundaries [file:1]. Contributors make funding decisions based on stated campaign durations and risk profiles—a 30-day campaign represents a specific risk tolerance that differs fundamentally from an indefinite obligation. Deadline manipulation transforms fixed-term campaigns into open-ended commitments without contributor consent. Creators can bait-and-switch by advertising short campaigns to attract risk-averse contributors, then extend deadlines by months or years when goals aren't met. This enables soft rugpulls where funds are never technically stolen but become inaccessible for arbitrary periods, violating the core promise that unsuccessful campaigns allow timely fund recovery.
POC RESULT:
Set State Flag in set_deadline() Function
The `set_deadline()` function in the `rustfund` program contains a vulnerability that allows campaign creators to manipulate deadlines indefinitely. While the function correctly checks if `fund.dealine_set` is true before allowing the deadline to be changed, it never sets this flag to true after setting the deadline. ```rust pub fn set_deadline(ctx: Context<FundSetDeadline>, deadline: u64) -> Result<()> { let fund = &mut ctx.accounts.fund; if fund.dealine_set { return Err(ErrorCode::DeadlineAlreadySet.into()); } fund.deadline = deadline; Ok(()) } ``` The function is missing a crucial line to update the flag: `fund.dealine_set = true;` This oversight bypasses a key safeguard intended to prevent creators from manipulating deadlines after they've been set. According to the project documentation, this flag is meant to enforce deadline immutability, which is an essential part of the platform's trust model. ### Impact 1. **Refund evasion**: Creators can prevent users from obtaining refunds by continually extending the deadline whenever it approaches. This directly undermines the project's advertised "Refund Mechanism" which promises that "Contributors can get refunds if deadlines are reached and goals aren't met." 2. **Fund locking**: Contributors' funds can be effectively locked indefinitely, as the refund function is contingent upon the deadline being reached: ```rust if ctx.accounts.fund.deadline != 0 && ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap() { return Err(ErrorCode::DeadlineNotReached.into()); } ``` ### Proof of Concept (PoC) The following test demonstrates how a creator can set the deadline multiple times, effectively bypassing the intended deadline immutability: ```javascript import * as anchor from "@coral-xyz/anchor"; import { Program } from "@coral-xyz/anchor"; import { Rustfund } from "../target/types/rustfund"; import { assert } from "chai"; describe("VULN-02: set_deadline vulnerability", () => { // Configures the provider to use the local cluster const provider = anchor.AnchorProvider.env(); anchor.setProvider(provider); const program = anchor.workspace.Rustfund as Program<Rustfund>; // Test variables const fundName = "TestFund"; const description = "Testing deadline vulnerability"; const goal = new anchor.BN(1000000); let fundPda: anchor.web3.PublicKey; it("Allows you to modify the deadline several times", async () => { // Derivation of PDA address for financing account [fundPda] = await anchor.web3.PublicKey.findProgramAddress( [Buffer.from(fundName), provider.wallet.publicKey.toBuffer()], program.programId ); // Fund creation await program.rpc.fundCreate(fundName, description, goal, { accounts: { fund: fundPda, creator: provider.wallet.publicKey, systemProgram: anchor.web3.SystemProgram.programId, }, }); // First deadline assignment const deadline1 = new anchor.BN(Math.floor(Date.now() / 1000) + 3600); // 1 hour in the future await program.rpc.setDeadline(deadline1, { accounts: { fund: fundPda, creator: provider.wallet.publicKey, }, }); // Second deadline assignment (which should not be possible if the flag is set to true) const deadline2 = new anchor.BN(Math.floor(Date.now() / 1000) + 7200); // 2 hours into the future await program.rpc.setDeadline(deadline2, { accounts: { fund: fundPda, creator: provider.wallet.publicKey, }, }); // Check that the deadline has been updated to the second value const fundAccount = await program.account.fund.fetch(fundPda); assert.ok( fundAccount.deadline.eq(deadline2), "The deadline may have been modified several times, but vulnerability presents" ); }); }); ``` Save the above test as, for example, tests/02.ts in your project's test directory and run the test : ```Solidity anchor test ``` ### Concrete Impact Example To illustrate the real-world impact of this vulnerability, consider this scenario: - A creator launches a campaign to fund a project with a goal of 100 SOL - The creator sets an initial deadline of 30 days - Contributors collectively deposit 80 SOL (below the goal) - As the deadline approaches, the creator realizes they won't reach the goal - Instead of allowing refunds as promised, the creator extends the deadline by another 30 days - This pattern can repeat indefinitely, effectively locking contributor funds - Even if contributors try to request refunds, they'll be rejected with "DeadlineNotReached" errors ### Recommendation The fix for this vulnerability is straightforward. The `set_deadline()` function should be modified to set the `dealine_set` flag to true after setting the deadline: ```rust pub fn set_deadline(ctx: Context<FundSetDeadline>, deadline: u64) -> Result<()> { let fund = &mut ctx.accounts.fund; if fund.dealine_set { return Err(ErrorCode::DeadlineAlreadySet.into()); } fund.deadline = deadline; fund.dealine_set = true; // Add this line to fix the vulnerability Ok(()) } ```
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.