You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Critical Position Size Inflation Due to Scaling Error in Liquidation Mechanism in BorrowingLiquidation::liquidationType2
Summary
A severe computational error has been discovered in the BorrowingLiquidation::liquidationType2 function's sizeDelta parameter calculation. This error results in grossly inflated position sizes being transmitted to the Synthetix PerpsV2 system, potentially destabilizing the entire liquidation process.
Root Cause
The sizeDelta calculation:
-int((uint(margin*1ether*1e16)/currentEthPrice))
incorrectly multiplies the margin by both 1 ether ((1e18)) and an additional scaling factor 1e16, leading to a drastically inflated result. This excessive scaling inflates the sizeDelta by a factor of (1e16).
A currentEthPrice value representing the ETH/USD price (e.g., (1000e2) for $1000 with 2 decimal places).
The synthetixPerpsV2 contract is deployed and accessible.
Sufficient funds are available in the system to process the margin transfer.
External pre-conditions
No response
Attack Path
Initial Trigger:
When liquidation is initiated, the function processes inputs through flawed calculation
The scaling error compounds through multiplication operations
System Response:
The contract forwards an extremely oversized position to Synthetix
No safeguards catch the mathematical error before execution
Cascading Effects:
Position sizes become unreasonably large
System parameters deviate from intended ranges
Impact
Protocol Stability:
Risk of system-wide imbalances
Potential cascade of failed liquidations
Economic Consequences:
Severe miscalculation of position values
Possible exploitation of price differences
Operational Risks:
Disruption of normal liquidation processes
Increased complexity in position management
PoC
functionliquidationType2(addressuser,uint64index,uint64currentEthPrice)internal{//...// Calculate the marginint256margin=int256((amount*currentEthPrice)/100);// Transfer the margin to synthetixsynthetixPerpsV2.transferMargin(margin);// Submit an offchain delayed order in synthetix for short position with 1X leveragesynthetixPerpsV2.submitOffchainDelayedOrder(-int((uint(margin*1ether*1e16)/currentEthPrice)),currentEthPrice*1e16);}
Given that the margin is 1000e18, the expected position size should be approximately -1e18, representing a short position of 1 ETH. However, the computed value -10^47 is astronomically large and incorrect.
Lone Fossilized Lemur
High
Critical Position Size Inflation Due to Scaling Error in Liquidation Mechanism in BorrowingLiquidation::liquidationType2
Summary
A severe computational error has been discovered in the
BorrowingLiquidation::liquidationType2
function'ssizeDelta
parameter calculation. This error results in grossly inflated position sizes being transmitted to the Synthetix PerpsV2 system, potentially destabilizing the entire liquidation process.Root Cause
The
sizeDelta
calculation:incorrectly multiplies the
margin
by both1 ether
((1e18)) and an additional scaling factor1e16
, leading to a drastically inflated result. This excessive scaling inflates the sizeDelta by a factor of (1e16).Internal pre-conditions
amount
(e.g., (1e18) for 1 Ether).currentEthPrice
value representing the ETH/USD price (e.g., (1000e2) for $1000 with 2 decimal places).synthetixPerpsV2
contract is deployed and accessible.External pre-conditions
No response
Attack Path
Initial Trigger:
System Response:
Cascading Effects:
Impact
PoC
Margin Calculation
The margin is calculated using the formula:
Substituting the given values:
amount
= 1e18currentEthPrice
= 1000e2We compute:
Thus,
Position Sizing with Leverage
For a 1x leverage short position, the
sizeDelta
is calculated as:Substituting the values:
margin
= 1000e18currentEthPrice
= 1000e2Numerator:
Denominator:
Final Calculation:
Thus,
Expected Value
Given that the
margin
is 1000e18, the expected position size should be approximately -1e18, representing a short position of 1 ETH. However, the computed value -10^47 is astronomically large and incorrect.Simply code to test the inflated value
Mitigation
sizeDelta
inBorrowingLiquidation::liquidationType2
the calculation to avoid unnecessary scalingThe text was updated successfully, but these errors were encountered: