You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Insufficient Output Amount Error in SolidlyV3AMO Contract
Summary
The SolidlyV3AMO contract encounters an error during the _mintAndSellBoost function execution, where the output amount of USD received after a swap is consistently deemed insufficient. This issue arises from the comparison between the converted output amount and the expected input amount, which leads to a perpetual revert condition. The calculation of minUsdAmountOut does not account for transaction fees accurately, inflating the expectations of the output amount.
Root Cause
The primary cause of the issue is the conditional statement:
if (toBoostAmount(usdAmountOut) <= boostAmountIn)
revertInsufficientOutputAmount({outputAmount: toBoostAmount(usdAmountOut), minRequired: boostAmountIn});
In this statement, usdAmountOut, which is derived after executing the swap, is consistently lower than boostAmountIn due to the deductions from fees applied during the swap. Consequently, the function always reverts, rendering it ineffective. For reference, see the relevant line of code here.
The toBoostAmount function converts the received usdAmountOut to a boostAmount using the formula:
This conversion results in a significant difference between the expected boost amount and the actual USD output, further compounding the issue.
Internal pre-conditions
The contract must have sufficient BOOST tokens minted.
The pool should be correctly configured to handle swaps.
External pre-conditions
The Solidly V3 Pool must be operational and accessible.
The swap mechanism must support the expected trading pairs (BOOST and USD).
Attack Path
Minting BOOST: The contract mints the specified amount of BOOST tokens.
Approval for Swap: The contract approves the transfer of minted BOOST tokens to the pool.
Executing the Swap: The swap is executed, but the expected output is decreased due to fees.
Output Verification: The conditional check fails, causing the function to revert.
Reverting: The function does not complete successfully, leading to an inability to sell BOOST for USD.
Impact
Due to the faulty output condition, users will experience continuous transaction failures when attempting to perform swaps. This can result in a negative user experience and potential loss of trust in the SolidlyV3AMO contract.
PoC
To demonstrate the issue, consider the following scenario:
Assumed Fees: 10% (leading to an output of 90 USD after swap)
Execution:
After executing the swap, the usdAmountOut is 90 USD.
The conversion using toBoostAmount(90) yields 900,000,000,000,000,000 (0.9 BOOST).
The condition if (0.9 <= 1) evaluates to true, triggering the revert.
Mitigation
To mitigate this issue, the following adjustments are recommended:
Adjust the Condition: Modify the condition to account for the fees by introducing a threshold for acceptable fees or adjusting the expected output based on historical data.
Accurate Fee Calculation: Implement a more precise calculation method for minUsdAmountOut that factors in the fees expected during the swap.
Error Handling: Provide a mechanism to report the actual USD amount received and give insights into why a revert may occur, rather than simply reverting the transaction.
The text was updated successfully, but these errors were encountered:
sherlock-admin2
changed the title
Nutty Tweed Puppy - Insufficient Output Amount Error in SolidlyV3AMO Contract
UsmanAtique - Insufficient Output Amount Error in SolidlyV3AMO Contract
Oct 30, 2024
UsmanAtique
Medium
Insufficient Output Amount Error in SolidlyV3AMO Contract
Summary
The
SolidlyV3AMO
contract encounters an error during the_mintAndSellBoost
function execution, where the output amount of USD received after a swap is consistently deemed insufficient. This issue arises from the comparison between the converted output amount and the expected input amount, which leads to a perpetual revert condition. The calculation ofminUsdAmountOut
does not account for transaction fees accurately, inflating the expectations of the output amount.Root Cause
The primary cause of the issue is the conditional statement:
In this statement,
usdAmountOut
, which is derived after executing the swap, is consistently lower thanboostAmountIn
due to the deductions from fees applied during the swap. Consequently, the function always reverts, rendering it ineffective. For reference, see the relevant line of code here.The
toBoostAmount
function converts the receivedusdAmountOut
to aboostAmount
using the formula:Given that:
boostDecimals = 18
usdDecimals = 6
This conversion results in a significant difference between the expected boost amount and the actual USD output, further compounding the issue.
Internal pre-conditions
External pre-conditions
Attack Path
Impact
Due to the faulty output condition, users will experience continuous transaction failures when attempting to perform swaps. This can result in a negative user experience and potential loss of trust in the
SolidlyV3AMO
contract.PoC
To demonstrate the issue, consider the following scenario:
Inputs:
boostAmount
: 1,000,000,000,000,000,000 (1 BOOST token)minUsdAmountOut
: 100 (expected USD after swap)Execution:
usdAmountOut
is 90 USD.toBoostAmount(90)
yields 900,000,000,000,000,000 (0.9 BOOST).if (0.9 <= 1)
evaluates to true, triggering the revert.Mitigation
To mitigate this issue, the following adjustments are recommended:
Adjust the Condition: Modify the condition to account for the fees by introducing a threshold for acceptable fees or adjusting the expected output based on historical data.
Accurate Fee Calculation: Implement a more precise calculation method for
minUsdAmountOut
that factors in the fees expected during the swap.Error Handling: Provide a mechanism to report the actual USD amount received and give insights into why a revert may occur, rather than simply reverting the transaction.
The text was updated successfully, but these errors were encountered: