Rust Fund

AI First Flight #9
Beginner FriendlyRust
EXP
View results
Submission Details
Impact: low
Likelihood: low
Invalid

set_deadline does not validate the deadline value — zero or past timestamps are accepted

Description

set_deadline (programs/rustfund/src/lib.rs) stores any u64 the creator passes, with no comparison against the current time and no rejection of 0:

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; // no `deadline > now`, no `deadline != 0`
Ok(())
}

Both contribute and refund treat deadline == 0 as "no deadline" and skip their time checks entirely:

// contribute
if fund.deadline != 0 && fund.deadline < now { return Err(DeadlineReached) }
// refund
if fund.deadline != 0 && fund.deadline > now { return Err(DeadlineNotReached) }

Risk

Impact: Low — a deadline of 0 leaves the campaign with both gates open: contributions are accepted forever and refunds are available at any moment, so the campaign never reaches a defined end state. A timestamp in the past ends the campaign instantly: contribute is rejected and refund opens immediately, even seconds after creation. Combined with the missing goal check in refund, a zero deadline means contributors can pull funds at any time regardless of outcome; combined with the dead dealine_set guard, the creator can flip between these states at will.

Likelihood: Low — requires the creator to pass an invalid value, deliberately or by mistake (e.g. milliseconds instead of seconds, or an uninitialised variable yielding 0). No third party can trigger it.

Proof of Concept

Both calls are accepted by the program (same instruction builder as in tests/poc.ts):

// past deadline → contribute immediately fails with DeadlineReached (0x1771), refund opens
await send(ixSetDeadline(f, creator.publicKey, now() - 3600), creator);
// zero deadline → "no deadline": contribute and refund both skip their time checks
await send(ixSetDeadline(f, creator.publicKey, 0), creator);

Neither is rejected; there is no error code for an invalid deadline in the program.

Recommended Mitigation

let now: u64 = Clock::get()?.unix_timestamp.try_into().unwrap();
require!(deadline > now, ErrorCode::InvalidDeadline);
fund.deadline = deadline;
fund.dealine_set = true;

Add InvalidDeadline to ErrorCode. Consider also requiring a deadline to be set before contribute accepts funds, so a campaign cannot exist in the "no deadline" state.

Updates

Lead Judging Commences

ai-first-flight-judge Lead Judge about 1 hour ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

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

Give us feedback!