RustFund

First Flight #36
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: medium
Invalid

M-1: Contributions Allowed Without a Defined Deadline

Summary

The contribute function allows users to donate to a fund even if the deadline has not been set (fund.deadline == 0). This could result in contributions being made to a fund without a predefined fundraising period, potentially leading to unexpected behavior.

Vulnerability Details

In the contribute function, the logic checks whether fund.deadline has already passed, but it does not validate whether a deadline has actually been set.

  • If fund.deadline == 0, the condition fund.deadline < Clock::get().unwrap().unix_timestamp.try_into().unwrap() will always evaluate to false, allowing contributions to proceed.

  • This means funds can receive donations indefinitely if the deadline is never explicitly set.

Impact

A fund could be created without a deadline, allowing indefinite contributions and making it unclear when withdrawals or refunds should occur.

  • If the contract logic assumes a deadline is always set, other functions like refund or withdraw may behave unpredictably.

  • Attackers or fund creators could exploit this loophole to receive funds indefinitely, without clear rules on when the fundraising should end.

Tools Used

  • Manual code review

Recommendations

  • Modify contribute to require that fund.deadline is set before allowing contributions.

  • Add a check:

    if fund.deadline == 0 {
    return Err(ErrorCode::DeadlineNotSet.into());
    }
    if fund.deadline < Clock::get().unwrap().unix_timestamp.try_into().unwrap() {
    return Err(ErrorCode::DeadlineReached.into());
    }
  • Introduce an appropriate error code (DeadlineNotSet) to ensure contributors are aware that they cannot donate until a valid deadline is established.

  • Consider requiring that the deadline is set at the time of fund creation to enforce stricter invariants.

By applying these fixes, the contract will ensure that contributions only occur within a well-defined timeframe, preventing funds from being left open indefinitely.

Updates

Appeal created

bube Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Design choice
Assigned finding tags:

[Invalid] Contributions are allowed before the deadline is initialized.

There is no problem users to contribute to a given campaign before the deadline is initialized. The issue is when the users refund before the deadline is set.

Support

FAQs

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