Open c4-bot-7 opened 4 months ago
JustDravee marked the issue as duplicate of #906
JustDravee marked the issue as high quality report
koolexcrypto marked the issue as not a duplicate
koolexcrypto marked the issue as unsatisfactory: Invalid
koolexcrypto removed the grade
koolexcrypto marked the issue as duplicate of #75
koolexcrypto marked the issue as satisfactory
koolexcrypto changed the severity to 2 (Med Risk)
koolexcrypto marked the issue as not a duplicate
koolexcrypto marked the issue as primary issue
koolexcrypto marked the issue as selected for report
Lines of code
https://github.com/code-423n4/2024-04-dyad/blob/cd48c684a58158de444b24854ffd8f07d046c31b/src/core/VaultManagerV2.sol#L205-L228
Vulnerability details
Impact
When a liquidator liquidates a user, he will pay his debt and must receive the
debt + 20% bonus
in form of collateral (from the user). But now the20% bonus
is based on the user’s (collateral - debt), which removes the entire incentive for liquidation.Proof of Concept
From Docs:
liquidate()
will first check if the user with the suppliedid
is for liquidation, then take the user's debt to cover frommintedDyad
and burn it from the liquidator's balance. From there, the calculation of the liquidation bonus begins.Let's look at this example (same as in the test below):
But it will actually calculate 20% of (UserA collateral - UserA debt), which in this case would be 20% of $35 = $7
1.35e18
(1.35e18 - 1e18) * 0.2e18 / 1e18 = 0.35e18 * 0.2e18 / 1e18 = 0.07e18
This
0.79e18
or more precisely107/135
is how much of user’s collateral the liquidator will receive and that is$135 * (107/135) = $107
.As we can see for
$100 repaid
he will only get$7 collateral
bonus collateral, which confirms our state that the20%
bonus is based on(UserA collateral - UserA debt)
.Coded POC
The test will cover the same as case we explained above.
In order to execute the test:
virtual
to the setUp ofBaseTest
file.Tools Used
Manual Review
Recommended Mitigation Steps
The bonus should be based on the burned user debt and then must send the liquidator the percentage of liquidated user collateral equal to the burned debt + 20% bonus.
This is an example implementation, which gives the desired 20% bonus from the right amount, but need to be tested for further issues.
Assessed type
Math