DeFiHardhat
35,000 USDC
View results
Submission Details
Severity: low
Invalid

Precision loss while downcasting `fertilizerAmount` to uint128

Summary

The addFertilizer function manages fertilizer addition. It validates inputs like season, token and fertilizer amounts, and min LP. After converting fertilizerAmount to uint128, it calculates beans per fertilizer. It updates system variables, including total unfertilized index & active fertilizer amount. It adds corresponding beans and LP tokens. If it's the first time for a specific ID, it logs BPF and updates the season queue. It emits an event for external notification. However, the downcasting of fertilizerAmount to uint128 could cause precision loss if the value exceeds uint128 limit.

Impact

If fertilizerAmount exceeds the maximum value that can be represented by uint128, downcasting will truncate the value and cause precision loss. This precision loss may lead to inaccurate calculations and potential inconsistencies in the system.

Recommendation

Implement a check before the downcast to ensure that fertilizerAmount does not exceed the maximum value representable by uint128.

For example:

require(
fertilizerAmount <= type(uint128).max,
"Fertilizer amount exceeds uint128 limit"
);
uint128 fertilizerAmount128 = fertilizerAmount.toUint128();
Updates

Lead Judging Commences

giovannidisiena Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement
Assigned finding tags:

Informational/Invalid

Support

FAQs

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