The bug in the primitiveOutputAmount function can lead to incorrect decimal conversions when calculating the rawInputAmount. The rawInputAmount is calculated using the _convertDecimals function, but the decimals parameter passed to _convertDecimals is decimals[inputToken], which retrieves the decimals of the input token. This is incorrect, as it should be decimals[outputToken] to retrieve the decimals of the output token. As a result, the calculated rawInputAmount may be based on the wrong decimal precision, leading to inaccurate calculations and potential loss of funds.
Proof of Concept
The bug can be observed in the following code snippet from the primitiveOutputAmount function:
Lines of code
https://github.com/code-423n4/2023-11-shellprotocol/blob/main/src/adapters/Curve2PoolAdapter.sol#L152
Vulnerability details
Impact
The bug in the primitiveOutputAmount function can lead to incorrect decimal conversions when calculating the rawInputAmount. The rawInputAmount is calculated using the _convertDecimals function, but the decimals parameter passed to _convertDecimals is decimals[inputToken], which retrieves the decimals of the input token. This is incorrect, as it should be decimals[outputToken] to retrieve the decimals of the output token. As a result, the calculated rawInputAmount may be based on the wrong decimal precision, leading to inaccurate calculations and potential loss of funds.
Proof of Concept
The bug can be observed in the following code snippet from the primitiveOutputAmount function:
https://github.com/code-423n4/2023-11-shellprotocol/blob/main/src/adapters/Curve2PoolAdapter.sol#L152
Here, decimals[inputToken] should be replaced with decimals[outputToken] to correctly convert the inputAmount to the desired decimal precision.
Tools Used
Manual Review
Recommended Mitigation Steps
This change ensures that the rawInputAmount is calculated using the correct decimal precision based on the output token.
Assessed type
Math