code-423n4 / 2022-09-vtvl-findings

0 stars 0 forks source link

`maxSupply_` fails to set a limit. #454

Closed code423n4 closed 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/code-423n4/2022-09-vtvl/blob/f68b7f3e61dad0d873b5b5a1e8126b839afeab5f/contracts/token/VariableSupplyERC20Token.sol#L36-L46

Vulnerability details

Impact

In VariableSupplyERC20Token.sol maxSupply_ is used to set a limit to the amount mintable, and a value of 0 is used to represent an infinite limit. 0 is indeed a nonsensical value for this variable, and as such would be suitable to represent infinity, but mintableSupply takes its value from maxSupply_, and here we have a clash as a mintableSupply of 0 simply means that nothing more should be minted.

Proof of Concept

Suppose a VariableSupplyERC20Token was created with a positive maxSupply_, which means that the supply should be limited. If mint is called with an amount equal to mintableSupply, then mintableSupply will be set to 0 at line 43. Now, mint will behave as if the supply is unlimited (contrary to our expectations and with unlimited possiblity of inflation).

Tools Used

Code inspection

Recommended Mitigation Steps

Use another representation for infinite supply, for example type(uint256).max.

0xean commented 2 years ago

dupe of #3