Skip to content
Smart contracts Audit finding Intermediate

Note: When _initialSupply ! = 0 , the _mint_to_Accountant function will fail

The Note contract's constructor sets _totalSupply to the initial supply, and the _mint_to_Accountant function later mints the maximum uint256 value, causing an overflow and revert if the initial supply is non-zero. An attacker could not exploit this directly, but a misconfiguration would prevent the contract from functioning as intended.

cccz Follow

Originally disclosed on Code4rena

Submitted by cccz, also found by Picodes

In Note contract, if _initialSupply ! = 0, _totalSupply will overflow when the _mint_to_Accountant function executes _mint(msg.sender, type(uint).max)

    constructor(string memory name_, string memory symbol_, uint256 totalSupply_) public {
        _name = name_;
        _symbol = symbol_;
	    _initialSupply = totalSupply_;
	    _totalSupply = totalSupply_;
    }
...
    function _mint(address account, uint256 amount) internal   {
        require(account != address(0), "ERC20: mint to the zero address");

        _beforeTokenTransfer(address(0), account, amount);

        _totalSupply += amount;
        _balances[account] += amount;
        emit Transfer(address(0), account, amount);

        _afterTokenTransfer(address(0), account, amount);
    }

Proof of Concept

https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/Note.sol#L13-L19 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/ERC20.sol#L29-L34 https://github.com/Plex-Engineer/lending-market/blob/ab31a612be354e252d72faead63d86b844172761/contracts/ERC20.sol#L237-L247

Recommended Mitigation Steps

ERC20.sol

    constructor(string memory name_, string memory symbol_) public {
        _name = name_;
        _symbol = symbol_;
    }

note.sol

    constructor() ERC20("Note", "NOTE") {
        admin = msg.sender;
    }

nivasan1 (Canto) commented:

Duplicate of Issue #53 (H-06)

Alex the Entreprenerd (judge) commented:

In contrast to #53 -> Revert of initialize

This finding shows how, based on constructor arguments, the function _mint_to_accountant can fail.

Am not convinced on the impact as I believe in the worst case the Sponsor would just be forced to re-deploy

Alex the Entreprenerd (judge) commented:

The warden has shown how, because the function _mint_to_accountant mints the maximum value representable, deploying Note with a non-zero initialSupply will cause a revert.

Because this is contingent on a misconfiguration, I agree with Med Severity.

abhipingle (Canto) confirmed


The original report as published on Code4rena, by cccz. 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 mints the maximum possible integer value without checking if the total supply is already non-zero, leading to an arithmetic overflow.

Impact

The contract's _mint_to_Accountant function would revert, potentially forcing a redeployment if the initial supply is non-zero.

What the attacker needed

Non-zero initial supply

The fix

The constructor should not set _totalSupply to the initial supply, or the minting function should not mint the maximum value.

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.

This is a smart contract bug where a function tries to add a huge number to a total that already has some value, causing the total to exceed the maximum allowed and the transaction to fail. It means the contract would be unusable if deployed with a non-zero initial supply.

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 cccz

View all

104 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.