Problem:
Decimals are set in the constructor and can be any value, but the contract does not enforce a reasonable range (e.g., 0–18).
Protocols may assume 6 or 18 decimals, leading to calculation errors or overflows.
Risk:
Protocols interacting with this token may miscalculate values, leading to overflows, underflows, or loss of funds.
Attacker can deploy a token with extreme decimals (e.g., 255), breaking integrations.
constructor(uint8 _tokenDecimals) ERC20("MockUSDC", "mUSDC") {
tokenDecimals = _tokenDecimals;
}
Proof of Concept
function testExtremeDecimals() public {
MockUSDC token = new MockUSDC(255);
token.mint(address(this), 1);
}
Recommended Mitigation
constructor(uint8 _tokenDecimals) ERC20("MockUSDC", "mUSDC") {
- tokenDecimals = _tokenDecimals;
+ require(_tokenDecimals <= 18, "Decimals too high");
+ tokenDecimals = _tokenDecimals;
}