Skip to content
Business logic Audit finding Intermediate

Users can prevent being reallocated by listing to marketplace

A vesting beneficiary can prevent the token issuer from reallocating their vesting by listing it on the marketplace, which moves the allocated amount to the VestingManager contract. The issuer's reallocation then fails due to an insufficient balance check, and reallocating from the manager could make the marketplace insolvent.

0xc0ffEE Follow with attentioniayn, ChainProof and 4 others

Originally disclosed on Code4rena

Submitted by 0xc0ffEE, also found by attentioniayn, ChainProof, falconhoof, rouhsamad, sl1, and TheKhans

https://github.com/code-423n4/2024-12-secondswap/blob/214849c3517eb26b31fe194bceae65cb0f52d2c0/contracts/SecondSwap_StepVesting.sol#L216-L235

https://github.com/code-423n4/2024-12-secondswap/blob/214849c3517eb26b31fe194bceae65cb0f52d2c0/contracts/SecondSwap_VestingManager.sol#L139

The token issuer has the ability to change vesting allocation. However, a user can prevent his vesting from being allocated by listing his vesting to the marketplace.

The function SecondSwap_StepVesting::transferVesting() can be used by token issuer to transfer vesting, effectively reallocating vestings. By listing the vesting to marketplace, seller’s allocated amount is sent to VestingManager contract, which can make the token issuer unable to reallocate his vesting directly (due to available amount check). Indeed, if the token issuer decides to reallocate that wanted amount from VestingManager, then this can cause the marketplace to be insolvent.

    function transferVesting(address _grantor, address _beneficiary, uint256 _amount) external {
        require(
            msg.sender == tokenIssuer || msg.sender == manager || msg.sender == vestingDeployer,
            "SS_StepVesting: unauthorized"
        );
        require(_beneficiary != address(0), "SS_StepVesting: beneficiary is zero");
        require(_amount > 0, "SS_StepVesting: amount is zero");
        Vesting storage grantorVesting = _vestings[_grantor];
@>        require(
            grantorVesting.totalAmount - grantorVesting.amountClaimed >= _amount,
            "SS_StepVesting: insufficient balance"
        ); // 3.8. Claimed amount not checked in transferVesting function

@>        grantorVesting.totalAmount -= _amount;
        grantorVesting.releaseRate = grantorVesting.totalAmount / numOfSteps;

        _createVesting(_beneficiary, _amount, grantorVesting.stepsClaimed, true);

        emit VestingTransferred(_grantor, _beneficiary, _amount);
    }
    function listVesting(address seller, address plan, uint256 amount) external onlyMarketplace {
        require(vestingSettings[plan].sellable, "vesting not sellable");
        require(SecondSwap_Vesting(plan).available(seller) >= amount, "SS_VestingManager: insufficient availablility");

        Allocation storage userAllocation = allocations[seller][plan];

        uint256 sellLimit = userAllocation.bought;
        uint256 currentAlloc = SecondSwap_Vesting(plan).total(seller);

        if (currentAlloc + userAllocation.sold > userAllocation.bought) {
            sellLimit +=
                ((currentAlloc + userAllocation.sold - userAllocation.bought) * vestingSettings[plan].maxSellPercent) /
                BASE;
        }

        userAllocation.sold += amount;

        require(userAllocation.sold <= sellLimit, "SS_VestingManager: cannot list more than max sell percent");
@>        SecondSwap_Vesting(plan).transferVesting(seller, address(this), amount);
    }

Note that: This attack vector can be done by front-running, since the codebase is deployed to Ethereum.

Impacts:

  • Token issuer can not reallocate as expected. At least, the total allocated amount can not be reallocated, depending on the max sell percent.

Proof of Concept

Add this test below to the file test/VestingManager.test.ts, under describe("List, Purchase and Transfer".

    describe("List, Purchase and Transfer", async function () {
    ...

        it.only("prevent allocation", async function () {
          // initial, alice has 1000
          const {vesting, alice, bob, manager, tokenOwner,owner, token, marketPlaceholder} = await loadFixture(deployStepVestingFixture);

          // token issuer wants to reallocate 1000 from alice
          // but alice front-runs to list to marketplace
          await manager.write.listVesting([alice.account.address, vesting.address, parseEther("200")], { account: marketPlaceholder.account });

          // can not reallocate 1000
          await expect(vesting.write.transferVesting([alice.account.address, bob.account.address, parseEther("1000")], { account: owner.account }))
          .to.rejectedWith("SS_StepVesting: insufficient balance");
        })

Run the test and it succeeds.

Recommended mitigation steps

Consider adding trusted role to unlist from marketplace, so that the reallocation can be handled completely.

bobwong (SecondSwap) acknowledged


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

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

Likely the transferVesting function checks only the grantor's remaining unclaimed amount, so once the amount is moved to the VestingManager via listVesting, the issuer cannot reallocate it from the original grantor.

Impact

The token issuer cannot reallocate the user's vesting as expected, and reallocating from the VestingManager could make the marketplace insolvent.

What the attacker needed

User has a vesting allocation; vesting is sellable on the marketplace; attacker can front-run the issuer's transaction

The fix

Consider adding a trusted role to unlist from the marketplace so that reallocation can be handled completely.

How it was found

  1. The token issuer intends to reallocate a user's vesting.
  2. The user front-runs by listing part of their vesting on the marketplace.
  3. The listing moves the allocated amount to the VestingManager contract.
  4. The issuer's attempt to reallocate the full amount from the user fails with an insufficient balance error.

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.

Vesting means tokens are locked up and released over time. The token issuer can normally move a user's locked tokens to someone else, but if the user first lists those tokens for sale on a marketplace, the tokens are held by the marketplace contract instead. The issuer then cannot move them because the user's own balance appears too low.

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 SecondSwap

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.