RustFund

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

Unchecked Arithmetic in amount_raised Field

Summary

The contribute function updates the amount_raised field using unchecked arithmetic (+=), which can lead to integer overflow. This vulnerability could result in incorrect accounting of funds, potentially allowing malicious users to exploit the contract.

Vulnerability Details

In the contribute function, the amount_raised field is updated as follows:

fund.amount_raised += amount;

This operation does not check for overflow, which can occur if amount_raised + amount exceeds the maximum value of a u64.

Impact

If an overflow occurs, the amount_raised field will wrap around to a small value, leading to incorrect accounting of funds.

Tools Used

manual review

Recommendations

Replace the unchecked arithmetic with checked_add to handle overflow safely:

fund.amount_raised = fund.amount_raised.checked_add(amount).ok_or(ErrorCode::CalculationOverflow)?;
Updates

Appeal created

bube Lead Judge 3 months ago
Submission Judgement Published
Invalidated
Reason: Non-acceptable severity
Assigned finding tags:

[Invalid] Arithmetic overflow in `contribute` function

The max value of u64 is: 18,446,744,073,709,551,615 or around 18.4 billion SOL, given that the total supply of SOL on Solana is 512.50M, the scenario when the `contribute` function will revert due to overflow is very very unlikely to happen. Therefore, this is informational finding.

Support

FAQs

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