RustFund

First Flight #36
Beginner FriendlyRust
100 EXP
View results
Submission Details
Severity: low
Valid

Improper Deadline Check in Refund Function Allows Early Refunds

01. Relevant GitHub Links

02. Summary

The refund function in the RustFund contract has a flaw in its deadline check. If the deadline is not set (i.e., remains 0), users can trigger refunds at any time, bypassing the intended restriction that refunds should only occur after the deadline passes and goals are unmet.

03. Vulnerability Details

The refund function allows contributors to request a refund if the fund’s goals are not met after the deadline. According to the documentation, refunds should only be possible when the deadline has passed and goals are unmet. However, the deadline check is flawed:

if ctx.accounts.fund.deadline != 0 && ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap() {
return Err(ErrorCode::DeadlineNotReached.into());
}

If ctx.accounts.fund.deadline is 0 (the default value when a fund is created), the condition is skipped entirely, allowing refunds even when no deadline has been set. This means contributors can withdraw their contributions immediately after contributing, regardless of the fund’s state.

04. Impact

This vulnerability allows contributors to bypass the intended refund restrictions, potentially disrupting the fund’s operation. Funds could be drained prematurely, undermining the creator’s ability to reach the goal. While the impact is limited to contributed amounts and does not affect the entire contract, it can still lead to significant loss of trust and functionality in the funding process.

05. Tools Used

Manual Code Review and Foundry

06. Recommended Mitigation

- if ctx.accounts.fund.deadline != 0 && ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap() {
+ if ctx.accounts.fund.deadline != 0 && ctx.accounts.fund.deadline > Clock::get().unwrap().unix_timestamp.try_into().unwrap() || !ctx.accounts.fund.dealine_set {
return Err(ErrorCode::DeadlineNotReached.into());
}
Updates

Appeal created

bube Lead Judge 2 months ago
Submission Judgement Published
Validated
Assigned finding tags:

Possible refund before the deadline is initialized

Support

FAQs

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