The Users who voted for collection shutdown will lose their collection tokens by cancelling the shutdown
The CollectionShutdown contract takes voters' collection tokens when they vote for a shutdown, but the cancel function does not return those tokens. As a result, voters permanently lose their tokens if the shutdown is cancelled.
Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/261
Found by
0xAlix2, 0xHappy, 0xc0ffEE, Audinarey, Aymen0909, BADROBINX, BugPull, Hearmen, Limbooo, McToady, Ragnarok, almantare, araj, asui, blockchain555, cawfree, ctf_sec, dany.armstrong90, g, merlinboii, onthehunt, steadyman, stuart_the_minion, utsav, ydlee, zzykxx
Summary
When a user votes for collection shutdown, the CollectionShutdown contract gathers the whole balance from the user. However, when cancelling the shutdown process, the contract doesn't refund the user's votes.
Vulnerability Detail
The CollectionShutdown::_vote() function gathers the whole balance of the collection token from a voter.
function _vote(address _collection, CollectionShutdownParams memory params) internal returns (CollectionShutdownParams memory) {
uint userVotes = params.collectionToken.balanceOf(msg.sender);
if (userVotes == 0) revert UserHoldsNoTokens();
// Pull our tokens in from the user
params.collectionToken.transferFrom(msg.sender, address(this), userVotes);
... ...
}
But in the CollectionShutdown::cancel() function, it does not refund the voters tokens.
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()) {
revert InsufficientTotalSupplyToCancel();
}
// Remove our execution flag
delete _collectionParams[_collection];
emit CollectionShutdownCancelled(_collection);
}
Proof-Of-Concept
Here is the testcase of the POC:
To bypass the total supply vs shutdown votes restriction, added the following line to the test case:
collectionToken.mint(address(10), _additionalAmount);
The whole test case is:
function test_CancelShutdownNotRefund() public withQuorumCollection {
uint256 _additionalAmount = 1 ether;
// Confirm that we can execute with our quorum-ed collection
assertCanExecute(address(erc721b), true);
vm.prank(address(locker));
collectionToken.mint(address(10), _additionalAmount);
// Cancel our shutdown
collectionShutdown.cancel(address(erc721b));
// Now that we have cancelled the shutdown process, we should no longer
// be able to execute the shutdown.
assertCanExecute(address(erc721b), false);
console.log("Address 1 balance after:", collectionToken.balanceOf(address(1)));
console.log("Address 2 balance after:", collectionToken.balanceOf(address(2)));
}
Here are the logs after running the test:
$ forge test --match-test test_CancelShutdownNotRefund -vv
[⠒] Compiling...
[⠃] Compiling 1 files with Solc 0.8.26
[⠊] Solc 0.8.26 finished in 8.81s
Compiler run successful!
Ran 1 test for test/utils/CollectionShutdown.t.sol:CollectionShutdownTest
[PASS] test_CancelShutdownNotRefund() (gas: 390566)
Logs:
Address 1 balance after: 0
Address 2 balance after: 0
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 8.29s (454.80µs CPU time)
Ran 1 test suite in 8.29s (8.29s CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
As can be seen from the logs, the voters(1, 2) were not refunded their tokens.
Impact
Shutdown Voters will be ended up losing their whole collection tokens by cancelling the shutdown.
Code Snippet
utils/CollectionShutdown.sol#L390-L405
Tool used
Manual Review
Recommendation
The problem can be fixed by implementing following:
- Add new state variable to the contract that records all voters
address[] public votersList;
- Update the
_vote()function like below:
function _vote(address _collection, CollectionShutdownParams memory params) internal returns (CollectionShutdownParams memory) {
... ...
// Register the amount of votes sent as a whole, and store them against the user
params.shutdownVotes += uint96(userVotes);
// Register the amount of votes for the collection against the user
+ if (shutdownVoters[_collection][msg.sender] == 0)
+ votersList.push(msg.sender);
unchecked { shutdownVoters[_collection][msg.sender] += userVotes; }
... ...
}
-
Add the new code section to the
reclaimVote()function, that removes the sender from thevotersList. -
Update the
cancel()function like below:
function cancel(address _collection) public whenNotPaused {
... ...
if (params.collectionToken.totalSupply() <= MAX_SHUTDOWN_TOKENS * 10 ** locker.collectionToken(_collection).denomination()) {
revert InsufficientTotalSupplyToCancel();
}
+ uint256 i;
+ uint256 votersLength = votersList.length;
+ for (; i < votersLength; i ++) {
+ params.collectionToken.transfer(
+ votersList[i],
+ shutdownVoters[_collection][votersList[i]]
+ );
+ }
// Remove our execution flag
delete _collectionParams[_collection];
+ delete votersList;
emit CollectionShutdownCancelled(_collection);
}
After running the testcase on the above update, the user voters are able to get their own votes:
$ forge test --match-test test_CancelShutdownNotRefund -vv
[⠒] Compiling...
[⠘] Compiling 3 files with Solc 0.8.26
[⠃] Solc 0.8.26 finished in 8.70s
Compiler run successful!
Ran 1 test for test/utils/CollectionShutdown.t.sol:CollectionShutdownTest
[PASS] test_CancelShutdownNotRefund() (gas: 486318)
Logs:
Address 1 balance after: 1000000000000000000
Address 2 balance after: 1000000000000000000
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 3.46s (526.80µs CPU time)
Ran 1 test suite in 3.46s (3.46s CPU time): 1 tests passed, 0 failed, 0 skipped (1 total tests)
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
Impact
Voters who participated in a shutdown that is later cancelled will lose their entire collection token balance.
What the attacker needed
A collection with enough tokens to vote; Shutdown reaches quorum; Total supply increases to allow cancellation
The fix
The cancel function should refund each voter's contributed tokens, for example by tracking voters and their amounts and transferring tokens back before deleting the shutdown parameters.
How it was found
- Vote for collection shutdown by calling the vote function, which transfers the voter's entire collection token balance to the contract.
- Ensure the total supply condition for cancellation is met (e.g., by minting additional tokens).
- Call the cancel function to cancel the shutdown.
- Observe that the voters' token balances remain zero and are not refunded.
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 people vote to shut down a collection, the contract takes their tokens as votes. If the shutdown is later cancelled, those tokens are not given back, so the voters lose them. This is a bug because the tokens should be returned when the vote is cancelled.
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.