Skip to content
Smart contracts Audit finding Intermediate

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.

Picodes Follow

Originally disclosed on Code4rena

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 totalSupply function returns an incorrect value.

Picodes (warden) commented:

@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 totalSupply is a parameter passed in to the contract, and the ERC20 contract will not mint that amount, the totalSupply will 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.


The original report as published on Code4rena, by Picodes. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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

  1. Deploy the ERC20 contract with an initial supply of 1000.
  2. Observe that the totalSupply function returns 1000, which is incorrect.
  3. Mint 1000 more tokens.
  4. 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.

More by Picodes

View all

17 more disclosed reports, best first.

More from Canto

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.