maxSellPercent will be broken when a vesting is delisted after a seller has claimed additional steps
When a seller unlists a vesting after claiming additional steps, the full listed amount is deducted from their sold value, allowing them to sell more tokens than the maxSellPercent limit permits. This breaks the protocol's sell limit, enabling the seller to sell tokens that should already be unlocked and claimable.
Submitted by BenRai
When a listed vesting is delisted after the seller has claimed additional steps, the full listed amount is deducted from the sold value of the seller’s Allocation data. This allows him to sell tokens which should have already been unlocked and claimable which breaks a core functionality of the protocol, namely the sell limit intended by the value set for maxSellPercent.
Proof of Concept
The SecondSwap_VestingManager contract manages the vesting and selling of tokens through the listVesting() function. This function checks if the vesting plan is sellable and verifies the user’s available tokens before allowing a sale. To determine how many tokens a user is allowed to sell, the users current allocation as well as the amounts he has sold and bought until now are taken into account. Each vesting has its own maxSellPercent value to limit the amount of unvested tokens that can be sold at any point in time. This value indicates how many percent of the currently locked tokens should be sellable. E.g. if the total amount of tokens for a vesting is 1000, there are 10 steps and the maxSellPercent is set to 50%, this mean that in the beginning, when all tokens are still locked, a max of 1000 * 50% = 500 tokens should be sellable. At step 5 when only 500 tokens are locked, only 500 * 50% = 250 tokens should be sellable.
However, this invariant is broken if a seller unlist a listed vesting after he has claimed additional steps compared to when he created the listing. This is because the total refunded amount of tokens is deducted from the sold value without regard to the already unlocked and claimed steps of the seller.
function unlistVesting(address seller, address plan, uint256 amount) external onlyMarketplace {
@> allocations[seller][plan].sold -= amount;
SecondSwap_Vesting(plan).transferVesting(address(this), seller, amount);
}
Scenario Illustration
The vesting has 1000 tokens, 10 steps and 50% maxSellPercent
- Alice has an allocation of 100 tokens and therefore a releaseRate of 100 / 10 = 10 tokens / step. She creates a listing for 50 tokens. The tokens are transferred to the
VestingManagerand herreleaseRateis decreased to (100-50)/10 = 50/10 = 5 tokens per step. Her value forsoldis set to 50. - Time passes and the first 5 steps are unlocked allowing Alice to claim 5 * 5 = 25 tokens leaving her with a remaining allocation of 50 - 25 = 25 tokens.
- Since no one bought the tokens she put for sale she unlist them. She gets refunded 50 tokens and her
soldvalue is reduced by 50 making it 0 again. She now has her initial vesting back with 25 tokens claimed and 75 tokens unclaimed. - For Alice’s initial vesting, after 5 unlocked steps half of her vesting should still be locked and according to the
maxSellPercentshe should be able to sell 50% of the tokens still locked. ( 100/2 * 50% = 25 tokens). - But since her sold value is 0 and her current allocation is used as a basis to calculate her
sellLimit, she is able to sell 100 * 50% = 50 tokens which is all her locked allocation.
Recommended Mitigation Steps
To prevent sellers being able to sell more tokens than specified in ´maxSellPercent´ after unlisting a vesting, consider adding a stepsClaimedSeller vriable to the Listing struct indicating the last step the seller has claimed when he created the listing:
struct Listing {
address seller;
+ uint256 stepsClaimedSeller;
uint256 total;
uint256 balance;
uint256 pricePerUnit;
ListingType listingType;
DiscountType discountType;
uint256 discountPct;
uint256 listTime;
address whitelist;
uint256 minPurchaseAmt;
Status status;
address currency;
address vestingPlan;
}
In addition, the variable amountClaimable needs to be added to the Vesting struct:
struct Vesting {
uint256 stepsClaimed;
uint256 amountClaimed;
+ uint256 amountClaimable;
uint256 releaseRate;
uint256 totalAmount;
}
Once the seller unlists a listing, the value of stepsClaimedSeller is compared to the seller’s current stepsClaimed. If the seller has claimed additional steps since he initially listed the vesting, the number of steps is calculated and a proportional amount of the refunded tokens is added to amountClaimable making them claimable instantly:
amountToAdd = refundedAmount * (stepsClaimed – stepsClaimedSeller) / totalSteps
To ensure the calculation of available tokens stays accurate, the same amount needs to be added to amountClaimed.
The remaining amount of refunded tokens is deducted from the sold amount and is available for sale again.
When claiming tokens the amount saved in amountClaimable is added to the amount transfered to the user and amountClaimable is set to 0.
I’m sorry for the late comment, but I think both this issue and S-140 are more fit for the medium severity, as assets are not at risk/no loss of funds (which is a criteria for medium severity in C4 docs), the only impact is user being able to sell more tokens.
calvinx (SecondSwap) commented:
This looks like a medium issue, please include this. We will explore for ways to do 1 fix for both issues.
Considering the input above from the wardens and the sponsor, this is a valid Medium.
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 unlist function subtracts the full listed amount from the seller's sold value without accounting for steps claimed since listing, so the sold value no longer reflects the true proportion of tokens sold.
Impact
A seller could sell more tokens than the maxSellPercent limit allows, breaking the intended sell limit; no loss of funds is reported, and the issue was rated Medium.
What the attacker needed
Seller has a vesting with maxSellPercent set; seller lists tokens and later claims steps; seller unlists the listing
The fix
The fix should track the steps claimed at listing time and adjust the refunded amount so that tokens corresponding to steps claimed since listing become immediately claimable, with the remainder deducted from sold.
How it was found
- Alice creates a listing for 50 tokens from her 100-token vesting, reducing her release rate and setting her sold value to 50.
- After 5 steps, Alice claims 25 tokens, leaving her with 25 tokens from the listing and 75 unclaimed tokens overall.
- Alice unlists the remaining 50 tokens, receiving a refund and her sold value is reduced to 0.
- Alice can now sell 50 tokens (100 * 50%), which is all her locked allocation, exceeding the intended limit of 25 tokens.
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 over time, and a sell limit caps how many locked tokens can be sold. The bug lets a seller reset their sold count by unlisting after claiming some steps, so they can sell more than the cap allows.
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.