Wrong price calculation in DnGmxJuniorVaultManager.sol
The price calculation in DnGmxJuniorVaultManager.sol incorrectly places usdcPrice in the numerator and MAX_PRECISION in the denominator, causing the minimum expected amount to be too high when USDC price exceeds $1. This leads to rebalance calls reverting under 0% slippage, delaying rebalances and potentially causing protocol losses.
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2022-10-rage-trade-judging/issues/61
Found by
clems4ever
Summary
in DnGmxJuniorVaultManager.sol at line:647:
usdcPrice should be on denominator and MAX_PRECISION on numerator
(cf pricing in Vault: uint256 redemptionAmount = _usdgAmount.mul(PRICE_PRECISION).div(price);)
Vulnerability Detail
Impact
In the case usdcPrice is higher than 1$ (which already happened in reasonable market circumstances). Min amount expected will be higher than swap result under 0% slippage conditions. The call will revert, which will delay rebalances until usdcPrice comes back to 1$, and causing potential loss to the protocol.
Code Snippet
Tool used
Manual Review
Recommendation
Recommendation in summary
Discussion
0xDosa
The suggested fix seems to be incorrect. Since we already are passing the value in usdc amount hence neither multiplication nor division with usdcPrice should be required.
0x00052
Agreed, suggested fix is incorrect. It should only adjust for slippage
0xDosa
Fix PR: https://github.com/RageTrade/delta-neutral-gmx-vaults/pull/37
0x00052
Fix looks good. Value is now only adjusted to account for slippage
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
Impact
When USDC price is above $1, rebalances revert, delaying them until the price returns to $1 and potentially causing loss to the protocol.
What the attacker needed
USDC price above $1; rebalance transaction executed
The fix
The suggested fix was incorrect; the actual fix removed the multiplication and division by usdcPrice entirely, only adjusting for slippage.
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.
This report is about a smart contract that calculates prices incorrectly. When the price of USDC (a stablecoin) goes above $1, the contract expects a higher minimum amount than it actually gets, so the transaction fails. This means the protocol cannot rebalance its funds until the price returns to $1, which could cost it money.
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.