This repository has been archived by the owner on Jan 7, 2024. It is now read-only.
xiaoming90 - Liquidation of PartyA will fail due to underflow errors #241
Labels
Has Duplicates
A valid issue with 1+ other issues describing the same vulnerability
High
A valid High severity issue
Reward
A payout will be made for this issue
Sponsor Confirmed
The sponsor acknowledged this issue is valid
Will Fix
The sponsor confirmed this issue will be fixed
xiaoming90
high
Liquidation of PartyA will fail due to underflow errors
Summary
Liquidation of PartyA will fail due to underflow errors. As a result, assets will be stuck, and there will be a loss of assets for the counterparty (the creditor) since they cannot receive the liquidated assets.
Vulnerability Detail
https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/liquidation/LiquidationFacetImpl.sol#L126
Assume that at this point, the allocated balance of PartyB (
accountLayout.partyBAllocatedBalances[quote.partyB][partyA]
) only has 1000 USD.In Line 152 above, the
getValueOfQuoteForPartyA
function is called to compute the PnL of a position. Assume the position has a huge profit of 3000 USD due to a sudden spike in price. For this particular position, PartyA will profit 3000 USD while PartyB will lose 3000 USD.In this case, 3000 USD needs to be deducted from PartyB's account. However, when the
accountLayout.partyBAllocatedBalances[quote.partyB][partyA] -= amount;
code at Line 170, 182, or 190 gets executed, an underflow error will occur, and the transaction will revert. This is becausepartyBAllocatedBalances
is an unsigned integer, and PartyB only has 1000 USD of allocated balance, but the code attempts to deduct 3000 USD.Impact
Liquidation of PartyA will fail. Since liquidation cannot be completed, the assets that are liable to be liquidated cannot be transferred from PartyA (the debtor) to the counterparty (the creditor). Assets will be stuck, and there will be a loss of assets for the counterparty (the creditor) since they cannot receive the liquidated assets.
Code Snippet
https://github.com/sherlock-audit/2023-06-symmetrical/blob/main/symmio-core/contracts/facets/liquidation/LiquidationFacetImpl.sol#L126
Tool used
Manual Review
Recommendation
Consider implementing the following fixes to ensure that the amount to be deducted will never exceed the allocated balance of PartyB to prevent underflow errors from occurring.
The text was updated successfully, but these errors were encountered: