Skip to content
Business logic Audit finding Intermediate

Unlisting a vesting after seller has claimed additional steps locks tokens which should have been claimable already

When a seller unlists a vesting after claiming some steps, the refunded tokens are spread over the remaining unclaimed steps, which lowers the amount that should already be claimable. This locks tokens that should have been available to the seller.

BenRai Follow

Originally disclosed on Code4rena

Submitted by BenRai

https://github.com/code-423n4/2024-12-secondswap/blob/b9497bcf5100046a169276cb6b351ebc0eddc2cc/contracts/SecondSwap_VestingManager.sol#L149-L152

Because unlisted vestings are equally distributed to the unclaimed steps of the seller, if a seller unlists a vesting after he claimed additional steps, tokens which should have been claimable already are locked again and the unlocking schedule is disrupted.

Proof of Concept

The core functionality of the SecondSwap protocol is the option to sell tokens which are currently still locked in the vesting schedule. A user which has a vesting allocation of a token can sell tokens which are currently still locked/unvested to other users by listing them for sale. The tokens are transferred to the VestingManager and the users releaseRate is adjusted accordingly.

E.g. if the user has a vesting of 1,000 tokens where the vesting has 10 steps, the user will have a releaseRate of 1000 tokens /10 steps = 100 tokens / step

The issue arises if a seller unlists a vesting and since the time he listed the vesting a new step was unlocked which he claimed. Because the tokens he gets back by unlisting his vesting are distributed equally by increasing his releaseRate for his unclaimed steps, tokens which should be unlocked will be locked again.

_vestings[_beneficiary].releaseRate =
                (_vestings[_beneficiary].totalAmount - _vestings[_beneficiary].amountClaimed) /
                (numOfSteps - _vestings[_beneficiary].stepsClaimed);

Scenario Illustration

  1. A vesting has 1000 tokens and 10 steps, meaning that at each step 100 tokens should become claimable.
  2. Alice has an allocation of 100 tokens and therefore a releaseRate of 10 tokens / step. She lists 50 of her tokens for sale. 50 tokens are transferred to the VestingManager and her release rate is adjusted to (100 - 50) tokens / 10 steps = 50/10 = 5 tokens/step
  3. The first 5 steps are unlocked and Alice claims her 5 tokens/ step * 5 steps = 25 tokens which leaves her with 25 tokens to claim.
  4. Since no one has bought her vesting, she decides to unlist it. The 50 tokens which are refunded are distributed to her unclaimed steps by increasing the release rate to (25 + 50)/(10-5) = 75 / 5 = 15 tokens / step
  5. Alice has all her initial allocation back but she can not claim any additional tokens at the moment, even though according to the initial allocation, once step 5 is unlocked a total of 5 * 10 = 50 tokens of her inital vesting should be claimable.

Recommended Mitigation Steps

To prevent locking tokens which should be claimable when a vesting is unlisted, consider adding the lastStepsClaimedSeller variable listing info indicating the last step the seller has claimed when creating the listing:

    struct Listing {
        address seller;
        uint256 total;
        uint256 balance;
        uint256 pricePerUnit;
        ListingType listingType;
        DiscountType discountType;
        uint256 discountPct;
        uint256 listTime;
+      uint256 lastStepsClaimedSeller;
        address whitelist;
        uint256 minPurchaseAmt;
        Status status;
        address currency;
        address vestingPlan;
    }

Also, an additional info about claimable tokens should be added to the vesting information:

struct Vesting {
        uint256 stepsClaimed;
        uint256 amountClaimed;
        uint256 releaseRate;
        uint256 totalAmount;
+      uint256 claimableAmount;
    }

When the seller unlists a vesting, his last stepsClaimed is compared to lastStepsClaimedSeller of the listing. If they differ, they are handled like this:

An amount of refunded tokens proportional to the steps claimed since the vesting was listed are allocated to claimableAmount of the seller and can be claimed immediately since they have been unlocked already:

claimableAmount = refundedTokens * (stepsClaimed-lastStepsClaimedSeller) / numOfSteps

releaseRate of the seller is adjusted using the remaining refunded tokens.

calvinx (SecondSwap) commented:

The token’s should be claimable and not locked. This is a valid issue.

Koolex (judge) commented:

Based on above, a valid Med.


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

Impact

The seller cannot claim tokens that should already be unlocked, disrupting the vesting schedule.

What the attacker needed

A vesting allocation; seller lists tokens for sale; seller claims some steps; seller unlists the vesting

The fix

The unlist logic should track the steps claimed at listing time and allocate a proportional part of the refunded tokens to an immediately claimable amount, adjusting the release rate only for the rest.

How it was found

  1. Alice has a vesting allocation and lists part of her tokens for sale, which adjusts her release rate.
  2. Some steps unlock and Alice claims the tokens for those steps.
  3. No one buys the listing, so Alice unlists it and the tokens are refunded.
  4. The refunded tokens are spread over the remaining steps, so Alice cannot claim tokens that should already be unlocked.

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 vesting schedule releases tokens in steps over time. If you sell some of your locked tokens and later cancel the sale, the returned tokens are mixed back into your future steps instead of being available now, so you cannot claim tokens that should already be unlocked.

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 BenRai

View all

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