Broken batch minting feature
The batch minting function forwards the entire msg.value to the fee manager in each loop iteration, so the first iteration spends all the ETH and subsequent iterations revert due to insufficient balance. This breaks the core batch minting feature, preventing users from minting multiple tokens in one transaction.
Source: https://github.com/sherlock-audit/2024-04-titles-judging/issues/280
Found by
0x486776, 0xShiki, 0xlucky, AgileJune, ArsenLupin, BiasedMerc, ComposableSecurity, Dots, FastTiger, IllIllI, Kalogerone, KupiaSec, Shaheen, Varun_05, ZdravkoHr., alexzoid, ast3ros, azanux, cducrest-brainbot, cu5t0mPe0, ff, fugazzi, funkornaut, jennifer37, joicygiore, juan, kennedy1030, kn0t, mt030d, sammy, smbv-1923, trachev, xiaoming90, y4y, ydlee, zigtur
Summary
The core minting feature of the protocol is broken due to the mishandling of msg.value within the for-loop.
Vulnerability Detail
Assume that the total fee for each token is 0.001 ETH, and Bob wants to mint four tokens. The total fee will be 0.004 ETH, so he will send 0.004 ETH when calling the above mintBatch function.
An important point to note is that the msg.value will always remain at 0.004 ETH throughout the entire execution of the mintBatch function. The msg.value will not automatically be reduced regardless of how many ETH has been transferred out or "spent".
In the first for-loop, the msg.value will be 0.004 ETH, and all 0.004 ETH will be routed to the fee manager and subsequently routed to the fee recipient address/0xSplit wallet.
In the second for-loop, since all the ETH (0.004 ETH) was sent to the fee manager earlier, the amount of ETH left on the Edition contract is zero. When the second for-loop attempts to send msg.value (0.004 ETH) to the fee manager again, it will revert due to insufficient ETH, and the transaction will fail and revert. Thus, this batch minting feature is broken.
File: Edition.sol
277: function mintBatch(
278: address to_,
279: uint256[] calldata tokenIds_,
280: uint256[] calldata amounts_,
281: bytes calldata data_
282: ) external payable {
283: for (uint256 i = 0; i < tokenIds_.length; i++) {
284: Work storage work = works[tokenIds_[i]];
285:
286: // wake-disable-next-line reentrancy
287: FEE_MANAGER.collectMintFee{value: msg.value}(
288: this, tokenIds_[i], amounts_[i], msg.sender, address(0), work.strategy
289: );
290:
291: _checkTime(work.opensAt, work.closesAt);
292: _updateSupply(work, amounts_[i]);
293: }
294:
295: _batchMint(to_, tokenIds_, amounts_, data_);
296: _refundExcess();
297: }
Impact
Breaks core contract functionality. The batch minting feature, a core feature of the protocol, is broken.
Code Snippet
Tool used
Manual Review
Recommendation
For each loop, consider only forwarding/transferring the minting fee for the current token ID instead of the entire ETH (msg.value).
function mintBatch(
address to_,
uint256[] calldata tokenIds_,
uint256[] calldata amounts_,
bytes calldata data_
) external payable {
for (uint256 i = 0; i < tokenIds_.length; i++) {
Work storage work = works[tokenIds_[i]];
+ uint256 mintFee = FEE_MANAGER.getMintFee(work.strategy, amounts_[i])
// wake-disable-next-line reentrancy
+ FEE_MANAGER.collectMintFee{value: mintFee}(
- FEE_MANAGER.collectMintFee{value: msg.value}(
this, tokenIds_[i], amounts_[i], msg.sender, address(0), work.strategy
);
Discussion
pqseags
I don't think the duplicates on this issue are actually duplicates of this issue. @Hash01011122
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/titlesnyc/wallflower-contract-v2/pull/1
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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 code uses msg.value inside a loop instead of calculating and forwarding only the fee for each individual token.
Impact
The batch minting feature is completely broken, preventing any user from minting multiple tokens in a single transaction.
What the attacker needed
User calls mintBatch with multiple tokens; User sends enough ETH to cover all fees
The fix
The fix was to calculate the mint fee for each token and forward only that amount in each loop iteration, rather than the entire msg.value.
How it was found
- Bob calls mintBatch with four token IDs and sends 0.004 ETH as msg.value.
- In the first loop iteration, the contract forwards the entire 0.004 ETH to the fee manager.
- In the second loop iteration, the contract tries to forward 0.004 ETH again but has no ETH left, so the transaction reverts.
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.
When you call a function that accepts cryptocurrency, the total amount you sent is available as msg.value throughout the function. If you send that same total amount multiple times in a loop, the contract will run out of money after the first payment and the transaction will fail. Here, the batch mint function tried to pay the full fee for each token, so it always failed after the first token.
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.