Submitted by BenRai, also found by ABAIKUNANBAEV, Agontuk, AshishLach, attentioniayn, chupinexx, EaglesSecurity, escrow, franfran20, gesha17, itsabinashb, jsonDoge, NexusAudits, nikhil840096, nitinaimshigh, parishill24, Rhaydden, Samueltroydomi, Saurabh_Singh, typicalHuman, typicalHuman, wickie0x, and zzebra83
https://github.com/code-423n4/2024-12-secondswap/blob/b9497bcf5100046a169276cb6b351ebc0eddc2cc/contracts/SecondSwap_VestingManager.sol#L127-L134
Because the maxSellPercent can be bypassed by selling previously bought vestings at a later time, the core functionality to limit the amount of unvested tokens which can be sold is broken.
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 users available tokens before allowing a sale.
However, the logic for calculating the sellLimit is flawed.
The relevant code snippet is as follows:
The sellLimit is calculated for the case a maxSellPercent is set for the vesting. The maxSellPercent should limit the amount of unvested tokens that can be sold. E.g. if maxSellPercent is set to 20%, only 20% of the unvested tokens should be sellable. So if we have vesting with a total of 1000 tokens and 10 steps and the maxSellPercent is set to 20%, in the beginning of the vesting when all tokens are still locked only 20% of the max tokens (200 tokens) should be sellable. When 5 steps are unlocked, only 20% of the remaining locked tokens (500 tokens * 20% = 100 tokens) should be sellable. 
The issue arises from the fact that all previously bought tokens can be sold at a later point in time:
uint256 sellLimit = userAllocation.bought;
This can result in more tokens than intended to be sellable.
Scenario Illustration
Vesting has 1000 tokens and 10 steps, maxSellPercent is set to 20%:
To prevent more locked tokens to be sellable than specified in maxSellPercent consider adding a stepsBought to the Allocation struct to be able to adjust the bought value according to the steps already claimed by the user:
The stepsBought value would be adjusted each time a user buys or sells a vesting and would be set to the current stepsClaimed value of the buyer. In addition, for sells, the bought amount would also need to be reduced by the already claimed amount.
Buy a vesting: 
Sell a vesting:
For this to work:
The result would be that the sold amount represents only the amount a user sold of his initial allocation.
In addition the Allocation struct also needs a stepsSold variable which can be used to adjust/reduce the sold amount according to the claimed steps of the seller/buyer.
TechticalRAM (SecondSwap) confirmed
