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

Precision Loss Due to Integer Division in Fertilizer Minting Calculation

Vulnerability Details

_getMintFertilizerOut is responsible for calculating the amount of Fertilizer that can be minted based on the input amount of Barn Raise tokens (tokenAmountIn). This calculation is performed using integer division, which can lead to precision loss when the tokenAmountIn is not large enough relative to the USD price per token. Solidity's integer division truncates any remainder, potentially resulting in a calculated amount of zero Fertilizer for small but non-zero inputs.

Impact

Users attempting to mint Fertilizer with a small number of Barn Raise tokens may receive no Fertilizer due to rounding down in the division operation. This could lead to user dissatisfaction, a loss of trust in the platform, and potential financial loss for users who pay transaction fees without receiving the expected Fertilizer.

Tools Used

Manual review

Recommendations

  1. Introduce a scaling factor to inflate tokenAmountIn before the division operation to maintain precision throughout the calculation.

  2. Add logic to round the result to the nearest whole number or implement a consistent rounding policy (up or down) post-calculation.

  3. Define minimum input amounts for tokenAmountIn to ensure that the output is always greater than zero when the input amount is non-zero

  4. Allow users to specify a minimum amount of Fertilizer they expect to receive (minFertilizerOut) and enforce this minimum within the minting function to protect against unfavorable precision loss

Updates

Lead Judging Commences

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

Precision loss

Support

FAQs

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