Contract will reach a point where users will not be able to call `deposit`
The contract tracks total collateral per token by only increasing it on deposits and never decreasing it on withdrawals, so the tracked total eventually exceeds the collateral cap and blocks further deposits of that token. An attacker could not directly exploit this, but normal usage would cause a denial of service for deposits.
Source: https://github.com/sherlock-audit/2024-05-elfi-protocol-judging/issues/113
Found by
0x486776, Cosine, KupiaSec, jennifer37, mstpr-brainbot, tedox, whitehair0330
Summary
With the contract working as intended, after a long enough period of time the perceived amount of collateral for a specific point will cross collateralTotalCap resulting in the fact that users will not be able to deposit more tokens of that type.
Vulnerability Detail
When deposit is called, after the necessary checks the method commonData.addTradeTokenCollateral is called which increases the total amount of collateral for a specific token in order to track how much collateral of this type of token exists and so that it does not cross the collateralTotalCap.
On the other hand, the function subTradeTokenCollateral which is used to reduce the amount of total collateral per token is never called anywhere in the project resulting in an inaccurate value for self.tradeCollateralTokenDatas[token].totalCollateral as it tracks the amount of tokens that have entered the contract and not how many tokens are currently present inside the vault of the contract. And because there is a check weather the calling deposit would pass this cap it will eventually make it so that calling deposit with specific tokens would revert every time.
Impact
Eventual denial of service for deposit
Code Snippet
Tool used
Manual Review
Recommendation
Call subTradeTokenCollateral when the amount of collateral is being reduced (e.g. calling withdraw)
Discussion
sherlock-admin2
The protocol team fixed this issue in the following PRs/commits: https://github.com/0xCedar/elfi-perp-contracts/pull/55
sherlock-admin2
The Lead Senior Watson signed off on the fix.
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
The contract only increments the total collateral counter on deposits and never decrements it on withdrawals, so the counter does not reflect the actual collateral held.
Impact
Eventually, deposits of a specific token will always revert, causing a denial of service for that token.
What the attacker needed
Normal contract usage over time
The fix
The fix was to call `subTradeTokenCollateral` when collateral is reduced, such as during withdrawals.
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.
The contract keeps a running total of how much of each token has been deposited, but it never reduces that total when tokens are withdrawn. Over time, this total grows past a limit, and the contract then refuses any new deposits of that token, even though the actual vault may have plenty of room.
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.