Closed code423n4 closed 2 years ago
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L44 https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L239
The definition of tokenOutPrice is the amount of tokenIn per tokenOut
tokenOutPrice
/// tokenIn per tokenOut price /// eg. 1 WBTC (8 decimals) = 40,000 CTDL ==> price = 10^8 / 40,000 uint256 public tokenOutPrice;
In getAmountOut, _tokenInAmount is multiplied with tokenOutPrice but should be divided
_tokenInAmount
tokenOutAmount_ = (_tokenInAmount * tokenOutPrice) / tokenInNormalizationValue;
Which would lead to user receiving less token than expected and thus losing value.
eg. 1 WBTC (8 decimals) = 40,000 CTDL ==> price = 10^8 / 40,000 = 25000 getAmountOut(10e8) = (10e8 * 25000) / 10e8 = 25000 != 40000
tokenOutAmount_ = _tokenInAmount / tokenOutPrice;
Disputed per the same reasoning shown in #159
Lines of code
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L44 https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L239
Vulnerability details
Impact
The definition of
tokenOutPrice
is the amount of tokenIn per tokenOutIn getAmountOut,
_tokenInAmount
is multiplied with tokenOutPrice but should be dividedWhich would lead to user receiving less token than expected and thus losing value.
Proof of Concept
https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L44 https://github.com/code-423n4/2022-04-badger-citadel/blob/18f8c392b6fc303fe95602eba6303725023e53da/src/KnightingRound.sol#L239
eg. 1 WBTC (8 decimals) = 40,000 CTDL ==> price = 10^8 / 40,000 = 25000 getAmountOut(10e8) = (10e8 * 25000) / 10e8 = 25000 != 40000
Recommended Mitigation Steps