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.
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;
}
Duplicate of Issue #53 (H-06)
Alex the Entreprenerd (judge) commented:
In contrast to #53 -> Revert of
initializeThis finding shows how, based on
constructorarguments, the function_mint_to_accountantcan 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_accountantmints the maximum value representable, deploying Note with a non-zeroinitialSupplywill cause a revert.Because this is contingent on a misconfiguration, I agree with Med Severity.
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.