-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
User who buys X tokens from 1 account overpays in comparison to a user who buys 1 token from X accounts #292
Comments
minhquanym marked the issue as sufficient quality report |
I think dup of #9 |
OpenCoreCH (sponsor) confirmed |
Core issue is timing of reward computation, duplicating to #9 |
MarioPoneder marked the issue as duplicate of #9 |
MarioPoneder marked the issue as satisfactory |
Agree with the previous comment. User acts as multiple users by using multiple accounts. See also my comment in #498. |
MarioPoneder marked the issue as not a duplicate |
MarioPoneder changed the severity to QA (Quality Assurance) |
MarioPoneder marked the issue as grade-b |
I believe this is the root cause of #9, isn't it? |
Lines of code
https://github.com/code-423n4/2023-11-canto/blob/335930cd53cf9a137504a57f1215be52c6d67cb3/1155tech-contracts/src/Market.sol#L150-L169
Vulnerability details
Impact
Market#buy does the following:
Calculates the price the buyer should pay
Retrieves previously earned rewards for the buyer (if he already owes a token; 0 otherwise)
Distributes the fees from the current purchase
Sets the buyer's lastClaimedRewards to the shareHolderRewardsPerTokenScaled
Transfers rewards to the buyer
Note that the distribution of fees from the current purchase happens after the fee for the buyer is calculated, so the buyer does not get any fees from his own purchase. Whether he tries to buy 10 shares at once, or one share 10 times, he will not receive any fees, because on each iteration his shareHolderRewardsPerTokenScaled will be updated without transferring him any fees.
However, if he instead uses 10 different accounts, starting from the second one, his purchases will generate fees to all of the previous accounts. Essentially, he loses funds by using batch buys directly, in comparison to this strategy.
This behaviour creates an incentive to split buys into several accounts, because in that case users would pay less for the same tokens.
Proof of Concept
Add to Market.t.sol
Run the test:
forge test --match-test testBuyV -vv
Test Output:
Tools Used
Foundry
Assessed type
Math
The text was updated successfully, but these errors were encountered: