Open c4-bot-3 opened 9 months ago
raymondfam marked the issue as insufficient quality report
raymondfam marked the issue as duplicate of #684
alcueca changed the severity to 3 (High Risk)
alcueca changed the severity to 2 (Med Risk)
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/FeeSplitter.sol#L99
Vulnerability details
Impact
There's an issue with the
FeeSplitter::onBalanceChange
function of theFeeSplitter.sol
contract which is called after each trade that can lead to gas issues and DOS. If the same token subject is traded over and over again it will be pushed each time into storage which can lead to gas issues in the future.Likelihood: low Impact: High
Details
As long as the
balanceOf(token, account) > 0
, the function updates/doesuserTokens[account].push(token)
without checking if there are duplicate entries of the token for the specified account and pushing such entries into the array making it bigger. This can easily add up to a point where the array would have millions of entries, keeping in mind bot trades that may amass several thousands of trades per week.Let's imagine that Alice's bot has a balance of 2 curve token buys for the same subject. Subject in this example means the token
sellCurvesToken
passing the curve subject and 2 as the argumentsuserTokens[aliceBot]
contains 1 entry because it bought all 2 curve tokens in one transaction.userTokens[aliceBot]
now has 2 entries of the same token because it just sold all 2 curve tokens in one transaction.userTokens[aliceBot]
will have 1 entry each for the first 10 buysThis will easily compound to a ton of duplicate token addresses existing in the
userTokens[account]
arrays for accounts with consistent trading activity.This issue of duplicates will also make the
getUserTokensAndClaimable
function return a faultyUserClaimData
.Proof of Concept
This section provides a coded PoC.
Here's a link to the GitHub Gist setup for this issue: https://gist.github.com/Maroutis/37b1d67df90912f33cd059eadf58c9b9
Curves.t.sol
from gist in the repotest/foundry
testDupsInUserTokens()
test below in thetest/foundry/Curves.t.sol
file and run it using the commandforge test --mt testDupsInUserTokens -vv
. Here's the POC test:This test shows that same token can be stored after each trade. Over time this can create a huge mapping with duplicates.
Tools Used
Manual review + foundry
Recommended Mitigation Steps
Our recommendation is to check for duplicate entries before pushing new data.
Assessed type
Other