ERC20 Tokens with more than 18 decimals are not compatible
Summary
Some token won't be compatible as used a hardcoded value of 18-decimals, if decimals is bigger than 18, it will revert due to an underflow, and therefore, not be compatible.
Impact
Some erc20 tokens not compatible as StableVault.sol functions withdraw, deposit will revert when used
Same happens on:
Trading.sol functions _handleDeposit and _handleWithdraw
Lines of code
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/utils/TradingLibrary.sol#L115 https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/Trading.sol#L675 https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/Trading.sol#L643-L659 https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/StableVault.sol#L65-L72 https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/StableVault.sol#L44-L51
Vulnerability details
ERC20 Tokens with more than 18
decimals
are not compatibleSummary
Some token won't be compatible as used a hardcoded value of
18-decimals
, if decimals is bigger than 18, it will revert due to an underflow, and therefore, not be compatible.Impact
Some erc20 tokens not compatible as
StableVault.sol
functionswithdraw
,deposit
will revert when used Same happens on:Trading.sol
functions_handleDeposit
and_handleWithdraw
TradingLibrary.sol#verifyPrice()
References
https://ethereum.stackexchange.com/questions/118896/can-an-erc-20-have-more-than-18-decimals
Proof of Concept
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/StableVault.sol#L44-L51
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/StableVault.sol#L65-L72
_handleDeposit
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/Trading.sol#L643-L659_handleWithdraw
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/Trading.sol#L675And in
TradingLibrary.sol#verifyPrice()
https://github.com/code-423n4/2022-12-tigris/blob/0cb05a462e78c4470662e9d9a4f9ab587f266bb5/contracts/utils/TradingLibrary.sol#L115Recommended Steps
Consider this edge case and don't use a hardcoded amount
18
in when usingdecimals()