The refund()
function in the rustfund
program contains a vulnerability that allows contributors to withdraw funds at any time when the campaign creator has not set a deadline. The deadline is initialized to 0 during campaign creation, and if the creator never sets a deadline, the refund check condition is bypassed due to a logical flaw in the condition:
The key issue is that the function only blocks refunds when both conditions are true:
The deadline is not 0 (deadline != 0)
The deadline has not been reached (deadline > current_time)
This means that when a deadline is set to 0 (the default value), the first condition fails, the entire check is skipped, and refunds are allowed regardless of goal achievement or time constraints.
Premature fund withdrawal: Contributors can withdraw their funds at any time if no deadline is set, which violates the stated project documentation that refunds should "only be possible if the goal is not reached and the deadline is exceeded."
Campaign destabilization: Creators who intend to set a deadline later (but haven't yet) may find their campaigns undermined by contributors withdrawing funds prematurely.
Trust model violation: The platform's trust model is based on rules that ensure funds remain locked until specific conditions are met. This vulnerability allows contributors to bypass these conditions.
Campaign failure: Active campaigns may fail unexpectedly if contributors choose to withdraw funds due to this vulnerability, even when the project is progressing as expected.
The following test demonstrates how a contributor can withdraw funds from a campaign that has no deadline set:
Save the above test as tests/03.ts
in your project's test directory and run the test:
To illustrate the real-world impact of this vulnerability, consider this scenario:
A creator launches a campaign to fund a 100 SOL project without immediately setting a deadline.
The creator plans to finalize and set the deadline once initial interest is confirmed.
Contributors begin funding the campaign, reaching 50 SOL.
Before the creator sets a deadline, contributors discover they can withdraw their funds at any time.
Contributors begin withdrawing funds unexpectedly, causing the campaign balance to drop.
The creator is unable to prevent these withdrawals without setting a deadline.
Even after setting a deadline, any contributions made before the deadline was set could have already been withdrawn.
The refund()
function should be modified to enforce the business rules stated in the documentation:
Additionally, a new error code should be added to the ErrorCode
enum:
This fix ensures that refunds are only possible when:
A deadline has been set
The deadline has been reached
The funding goal has not been met
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.