Skip to content
Business logic Audit finding Beginner

Total supply can be incorrect in ERC20

The ERC20 token contract allowed the total supply to be initialised to a non-zero value without updating any user's balance, creating a permanent discrepancy between the reported total supply and the actual sum of balances. This could break integrations and market cap calculations.

Picodes Follow

Originally disclosed on Code4rena

Submitted by Picodes

https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/ERC20.sol#L33 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/ERC20.sol#L95

_totalSupply can be initialized to something different than 0, which would lead to an inaccurate total supply, and could easily break integrations, computations of market cap, etc.

Proof of Concept

If the constructor is called with _initialSupply = 1000, the totalSupply will be initialized to 1000.

As all the others computations are correct, there will be for ever a discrepancy of 1000 between the real total supply and the one of the contract.

Recommended Mitigation Steps

Remove _initialSupply.

nivasan1 (Canto) acknowledged

Alex the Entreprenerd (judge) commented:

Same bug as from Canto V1. Recommend the sponsor to just set to 0 and remove the assignment from the constructor

See: https://github.com/code-423n4/2022-06-canto-findings/issues/108

Please note: the following additional discussions took place after judging and awarding were finalized. As such, this report will leave this finding in its originally assessed risk category as it simply reflects a snapshot in time.

shung (warden) commented:

In the provided contracts, v2 repo is included: https://github.com/code-423n4/2022-06-canto-v2

However, in this submission, the second line of code provided links to the v1 repo. The described issue only exists in v1 version. In v2 version the issue does not exist because msg.sender balance is updated along with the total supply: https://github.com/Plex-Engineer/lending-market-v2/blob/ea5840de72eab58bec837bb51986ac73712fcfde/contracts/ERC20.sol#L34

Therefore this finding seems invalid.

Alex the Entreprenerd (judge) commented:

@shung - You’re right, I must have missed the line with the mitigation.

The current code will update the _totalSupply and will give the balance to the deployer.

This is a mistake on my part and the finding should have been closed as invalid as it was mitigated in the V2 code in scope.

Alex the Entreprenerd (judge) commented:

While a nitpick I’d recommend changing the code to use _mint as it the code in scope will not emit an event which may cause issues if you’re tracking via theGraph or similar.

Either way I made a mistake here, sorry about that.


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

The constructor set the total supply to an initial value without minting corresponding tokens to any address, so the total supply did not match the sum of balances.

Impact

The incorrect total supply could break integrations and market cap computations, but the issue was later found to be mitigated in the in-scope version because the deployer's balance was updated along with the total supply.

What the attacker needed

None

The fix

The issue was mitigated in the in-scope version by updating the deployer's balance along with the total supply, and the judge recommended using `_mint` to also emit an event.

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 an ERC20 token, the total supply should equal the sum of all balances. If the contract starts with a total supply that isn't zero but doesn't give those tokens to anyone, the numbers won't add up. This can confuse other contracts and tools that rely on the total supply.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by Picodes

View all

17 more disclosed reports, best first.

More from Canto v2 contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.