Open c4-bot-5 opened 10 months ago
raymondfam marked the issue as insufficient quality report
raymondfam marked the issue as primary issue
raymondfam marked the issue as duplicate of #22
alcueca changed the severity to QA (Quality Assurance)
Very limited impact, they can sell their holdings minus one wei.
alcueca marked the issue as grade-a
This previously downgraded issue has been upgraded by alcueca
alcueca marked the issue as satisfactory
alcueca changed the severity to QA (Quality Assurance)
alcueca marked the issue as grade-b
Lines of code
https://github.com/code-423n4/2024-01-curves/blob/main/contracts/Curves.sol#L284
Vulnerability details
Impact
The issue in the
sellCurvesToken()
function arises from a constraint that prevents the sale of the last remaining token in the total supply of a given subject token. The intention behind this constraint is likely to maintain the existence of the token and prevent the subject from selling a token that was originally obtained for free, as per the bonding curve pricing mechanism. However, the current implementation of this constraint is overly restrictive and does not differentiate between tokens owned by the subject itself and those owned by other users.The problematic code is as follows:
This line of code prevents any sale transaction that would result in the total supply of the subject token being reduced to zero. The issue is that it indiscriminately applies to all users, including those who did not receive any free tokens and bought their shares at a price set by the bonding curve.
The unintended consequence is that regular users who have purchased tokens are unable to sell their entire holdings if their holdings match the total remaining supply, even though they should logically be able to liquidate their investment.
Proof of Concept
The POC shows that normal users cannot sell all purchased tokens as expected.
Code
Result
Tools Used
Foundry
Recommended Mitigation Steps
Enforce the constraint that the subject cannot sell its initial free token while allowing other users to sell all their purchased tokens. This would likely involve additional state tracking within the contract to differentiate between free and purchased tokens.
A potential implementation for the second solution could be:
This revised condition checks if the caller (
msg.sender
) is the subject itself and if the transaction would result in the total supply reaching zero, which would only revert if the subject is trying to sell their last token (presumably the one they received for free).Assessed type
Invalid Validation