USDC deposited to PerpDepository.sol are irretrievable and effectively causes UDX to become undercollateralized
USDC deposited into the PerpDepository contract through several functions cannot be withdrawn because the only withdrawal function is limited by an internal counter that prevents redeeming more than was originally deposited. This causes the system's collateral to become inaccessible, effectively making UDX undercollateralized over time.
0x52 Follow with csanuragjain
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-uxd-judging/issues/250
Found by
0x52, csanuragjain
Summary
PerpDepository rebalances negative PNL into USDC holdings. This preserves the delta neutrality of the system by exchanging base to quote. This is problematic though as once it is in the vault as USDC it can never be withdrawn. The effect is that the delta neutral position can never be liquidated but the USDC is inaccessible so UDX is effectively undercollateralized.
Vulnerability Detail
_processQuoteMint, _rebalanceNegativePnlWithSwap and _rebalanceNegativePnlLite all add USDC collateral to the system. There were originally two ways in which USDC could be removed from the system. The first was positive PNL rebalancing, which has now been deactivated. The second is for the owner to remove the USDC via withdrawInsurance.
function withdrawInsurance(uint256 amount, address to)
external
nonReentrant
onlyOwner
{
if (amount == 0) {
revert ZeroAmount();
}
insuranceDeposited -= amount;
vault.withdraw(insuranceToken(), amount);
IERC20(insuranceToken()).transfer(to, amount);
emit InsuranceWithdrawn(msg.sender, to, amount);
}
The issue is that withdrawInsurance cannot actually redeem any USDC. Since insuranceDeposited is a uint256 and is decremented by the withdraw, it is impossible for more USDC to be withdrawn then was originally deposited.
The result is that there is no way for the USDC to ever be redeemed and therefore over time will lead to the system becoming undercollateralized due to its inaccessibility.
Impact
UDX will become undercollateralized and the ecosystem will spiral out of control
Code Snippet
Tool used
Manual Review
Recommendation
Allow all USDC now deposited into the insurance fund to be redeemed 1:1
Discussion
hrishibhat
Fix: https://github.com/UXDProtocol/uxd-evm/pull/32
IAm0x52
Fix looks good. Quote redeeming has been enabled. I would recommend removing redundant onlyController modifier on _processQuoteRedeem
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 withdrawal function uses a counter (insuranceDeposited) that is decremented on withdrawal, preventing redemption of USDC that was added outside of the insurance deposit tracking.
Impact
Over time, the inaccessible USDC will cause UDX to become undercollateralized, potentially destabilizing the ecosystem.
What the attacker needed
USDC deposited via normal operations; no direct user action required
The fix
The fix enables redeeming quote (USDC) by allowing all deposited USDC to be redeemed 1:1, as confirmed by the discussion.
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.
In this system, users deposit USDC (a stablecoin) as collateral to back another token called UDX. The contract adds USDC to its holdings in several places, but the only way to take USDC out is through a function that is capped by a counter, so it can never release more than was originally recorded. As a result, the USDC gets stuck, and the system may not have enough accessible collateral to back UDX.
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.