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.
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.
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.
Manual code review
Modify contribute
to require that fund.deadline
is set before allowing contributions.
Add a check:
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.
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.
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.