_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.
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.
Manual review
Introduce a scaling factor to inflate tokenAmountIn before the division operation to maintain precision throughout the calculation.
Add logic to round the result to the nearest whole number or implement a consistent rounding policy (up or down) post-calculation.
Define minimum input amounts for tokenAmountIn to ensure that the output is always greater than zero when the input amount is non-zero
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
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.