In ERC20 , TotalSupply is broken
The ERC20 contract's total supply is not initialised to zero, so when the constructor mints the initial supply the total supply becomes double the intended amount. This inaccurate total supply could break integrations and market cap calculations.
Submitted by Picodes, also found by cccz
https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/ERC20.sol#L33 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/ERC20.sol#L95
For an obscure reason as it’s not commented, _totalSupply is not initialized to 0, leading to an inaccurate total supply, which could easily break integrations, computations of market cap, etc.
Proof of Concept
If the constructor is called with _initialSupply = 1000, then 1000 tokens are minted. The total supply will be 2000.
Recommended Mitigation Steps
Remove _initialSupply.
tkkwon1998 (Canto) disputed and commented:
The explanation is not clear. We can’t seem to reproduce this issue as we can’t find a scenario where the
totalSupplyfunction returns an incorrect value.
@tkkwon1998 to clarify:
Deploy the ERC20 with
totalSupply_ = 1000.Then
totalSupply()returns 1000, which is incorrect.Then if someone mints 1000 tokens, there is 1000 tokens in the market but due to
_totalSupply += amount;, totalSupply = 2000 which is still incorrect
Alex the Entreprenerd (judge) commented:
I believe the submission could have benefitted by:
- A coded POC
- Recognizing a revert due to the finding
However the finding is ultimately true in that, because
totalSupplyis a parameter passed in to the contract, and the ERC20 contract will not mint that amount, thetotalSupplywill end up not reflecting the total amounts of tokens minted.For this reason, I believe the finding to be valid and High Severity to be appropriate.
I recommend the warden to err on the side of giving too much information to avoid getting their finding invalidated incorrectly.
Alex the Entreprenerd (judge) commented:
After further thinking, I still believe the finding is of high severity as the ERC20 standard is also broken. I do believe the submission could have been better developed, however, I think High is in place here.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the contract's internal total supply variable is not initialised to zero before the constructor mints the initial supply, causing it to be added twice.
Impact
The incorrect total supply could break integrations and market cap calculations, and the ERC20 standard is broken.
What the attacker needed
Deploy the ERC20 contract
The fix
The initial supply parameter should be removed so that the total supply is not double-counted.
How it was found
- Deploy the ERC20 contract with an initial supply of 1000.
- Observe that the totalSupply function returns 1000, which is incorrect.
- Mint 1000 more tokens.
- Observe that totalSupply now returns 2000, still incorrect.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In a cryptocurrency token, the total supply is the number of tokens that exist. This contract mistakenly starts counting from a non-zero number, so after creating the first tokens the reported total is twice what it should be. That wrong number can confuse other programs that rely on it.
What is Smart contracts?
Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.