Token:mint : infinite loop if the founders’ shares sum up to 100
The token minting function uses a loop that checks whether each new token ID belongs to a founder, but it incorrectly checks the token ID modulo 100. If founders collectively own 100% of the first 100 token IDs, the loop never finds a token that is not for a founder, causing an infinite loop and out-of-gas revert. An attacker could not directly exploit this, but the configuration bricks the token and auction contracts, preventing any auctions.
Submitted by zzzitron, also found by 0xSmartContract, ChristianKuri, davidbrai, elad, ElKu, hansfriese, immeas, ladboy233, Lambda, MiloTruck, scaraven, tonisives, and volky
The Token as well as Auction cannot be used if the sum of ownershipPct is 100
Proof of Concept
function test_poc_mintforever() public {
createUsers(2, 1 ether);
address[] memory wallets = new address[](2);
uint256[] memory percents = new uint256[](2);
uint256[] memory vestExpirys = new uint256[](2);
uint256 pct = 50;
uint256 end = 4 weeks;
unchecked {
for (uint256 i; i < 2; ++i) {
wallets[i] = otherUsers[i];
percents[i] = pct;
vestExpirys[i] = end;
}
}
deployWithCustomFounders(wallets, percents, vestExpirys);
assertEq(token.totalFounders(), 2);
assertEq(token.totalFounderOwnership(), 100);
Founder memory founder;
unchecked {
for (uint256 i; i < 100; ++i) {
founder = token.getScheduledRecipient(i);
if (i % 2 == 0) assertEq(founder.wallet, otherUsers[0]);
else assertEq(founder.wallet, otherUsers[1]);
}
}
// // commented out as it will not stop
// vm.prank(otherUsers[0]);
// auction.unpause();
}
In the proof of concept, there are two founders and they both share 50% of ownership. If the Auction should be unpaused, and therefore triggers to mint tokens, it will go into the infinite loop and eventually revert for out of gas.
// Token.sol
143 function mint() external nonReentrant returns (uint256 tokenId) {
144 // Cache the auction address
145 address minter = settings.auction;
146
147 // Ensure the caller is the auction
148 if (msg.sender != minter) revert ONLY_AUCTION();
149
150 // Cannot realistically overflow
151 unchecked {
152 do {
153 // Get the next token to mint
154 tokenId = settings.totalSupply++;
155
156 // Lookup whether the token is for a founder, and mint accordingly if so
157 } while (_isForFounder(tokenId));
158 }
159
160 // Mint the next available token to the auction house for bidding
161 _mint(minter, tokenId);
162 }
177 function _isForFounder(uint256 _tokenId) private returns (bool) {
178 // Get the base token id
179 uint256 baseTokenId = _tokenId % 100;
180
181 // If there is no scheduled recipient:
182 if (tokenRecipient[baseTokenId].wallet == address(0)) {
183 return false;
184
185 // Else if the founder is still vesting:
186 } else if (block.timestamp < tokenRecipient[baseTokenId].vestExpiry) {
187 // Mint the token to the founder
188 _mint(tokenRecipient[baseTokenId].wallet, _tokenId);
189
190 return true;
191
192 // Else the founder has finished vesting:
193 } else {
194 // Remove them from future lookups
195 delete tokenRecipient[baseTokenId];
196
197 return false;
198 }
199 }
In the Token::mint, there is a while loop which will keep looping as long as _isForFounder returns true. The _isForFounder function will return true is the given _tokenId’s recipient is still vesting. However, to check the recipient it is checking the baseTokenId which is _tokenId % 100 (in line 179 above snippet). Which means, if the tokenRecipient of 0 to 99 are currently vesting, it will keep returning true and the while loop in the mint function will not stop. The tokenRecipient was set in the _addFounders and if the sum of all founders’ ownership percent is 100, the tokenRecipient will be filled up to 100.
While a different typo may have allow to support more than 100 founders and shares setup, the following check: Token.sol#L179-L180
uint256 baseTokenId = _tokenId % 100;
Will cause each id to be check against the first 100, meaning that if the owners own 100% of all first 100 ids (e.g. the schedule value is 1, the code will loop forever in this while loop as no new ID is available
Because this is contingent on setting admin ownership to 100%, I think Medium Severity to be more appropriate. I wonder if 100% ownership for founders is rational in any case, as no auction would ever happen, however the configuration is allowed and it will brick the contracts.
The original report as published on Code4rena, by zzzitron. 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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
How it worked
Root cause
Likely the mint loop uses `_tokenId % 100` to look up founder ownership, so when all 100 possible remainders are assigned to vesting founders, the loop never finds a free token and runs indefinitely.
Impact
The token and auction contracts become unusable because minting always reverts, so no auctions can take place; the judge noted this is contingent on setting admin ownership to 100% and rated it Medium severity.
What the attacker needed
Founders' ownership percentages sum to 100%
The fix
The code should use `_tokenId` instead of `baseTokenId` when checking if a token is for a founder, so the loop can find a token not reserved for founders.
How it was found
Deploy the token with two founders each having 50% ownership, so total founder ownership is 100%.
Call `auction.unpause()` to start the auction, which triggers token minting.
Observe that the mint function enters an infinite loop and eventually reverts due to out-of-gas.
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.
Generating the AI write-up for this report.
This usually takes about 30 seconds. You can read the original meanwhile; this page updates itself.
Writing the technical write-up
Writing the version for beginners
Checking every passage against the original
This is a smart contract bug where a loop that is supposed to find a token not reserved for founders gets stuck. Because the code checks only the last two digits of each token number, if founders own all 100 possible last-two-digit combinations, the loop never exits. As a result, the contract runs out of gas and cannot mint any new tokens, so the auction cannot start.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.