Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERC20 TOKENS WITH DIFFERENT DECIMALS THAN 18 MAY BREAK THE LOGIC AND PROVIDE UNEXPECTED RESULTS #488

Closed
code423n4 opened this issue Dec 19, 2022 · 4 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-141 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-caviar/blob/main/src/LpToken.sol#L13
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L46
https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol#L20

Vulnerability details

Impact

Note: Though it is mentioned that Rebase/fee-on-transfer tokens are not expected, however there exist other ERC20 tokens having different decimals than 18

Contracts LpToken and Pair performs calculations by using hardcoded value of decimals 18 (1e18) for ERC20 tokens. This could break the logic and would provide unexpected results throughout the contract on using ERC20 tokens with different decimals than 18. Example of such a token is  Gemini USD only have 2 decimals, YAM-V2 has 24 decimals.

Hardcoded decimal value of 18 being used:

https://github.com/code-423n4/2022-12-caviar/blob/main/src/Pair.sol

20: uint256 public constant ONE = 1e18;
46: ERC20(string.concat(nftName, " fractional token"), string.concat("f", nftSymbol), 18)

https://github.com/code-423n4/2022-12-caviar/blob/main/src/LpToken.sol#L13

13: ERC20(string.concat(pairSymbol, " LP token"), string.concat("LP-", pairSymbol), 18)

Recommended Mitigation Steps

It is recommended to add support for different number of decimals than 18 by dynamically checking decimals() for the tokens that are part of the rewards calculations. Alternatively if such a support is not needed, new require statements should be added to addPool that will be checking that the number of decimals for all ERC20 tokens is 18.

@code423n4 code423n4 added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working labels Dec 19, 2022
code423n4 added a commit that referenced this issue Dec 19, 2022
@iFrostizz
Copy link

The 18 decimals token mentioned is the LP token.
There is no evidence of issues regarding tokens using another amount of decimals, as the LP tokens value is arbitrary.

@c4-judge
Copy link
Contributor

berndartmueller marked the issue as duplicate of #53

@c4-judge
Copy link
Contributor

berndartmueller marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 10, 2023
@C4-Staff
Copy link
Contributor

CloudEllie marked the issue as duplicate of #141

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working duplicate-141 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

4 participants