PerpDepository#_rebalanceNegativePnlWithSwap fails to approve vault for quote deposit
The PerpDepository contract's _rebalanceNegativePnlWithSwap function does not approve the vault to spend the quote token before calling deposit, causing the deposit to fail and the function to always revert. An attacker could not exploit this directly, but the function is unusable, disrupting the protocol's rebalancing mechanism.
HonorLt Follow with rvierdiiev, 0x52 and 3 others
Originally disclosed on Sherlock
Source: https://github.com/sherlock-audit/2023-01-uxd-judging/issues/372
Found by
HonorLt, rvierdiiev, 0x52, GimelSec, yixxas, Bahurum
Summary
Throughout the entirety of the contract it grants approval to the vault before depositing either quote or asset. In this case there is no approval which means that the deposit call will fail causing PerpDepository#_rebalanceNegativePnlWithSwap to always revert.
Vulnerability Detail
See summary.
Impact
PerpDepository#_rebalanceNegativePnlWithSwap won't function
Code Snippet
Tool used
Manual Review
Recommendation
Add the missing approve call:
} else if (shortFall < 0) {
// we got excess tokens in the spot swap. Send them to the account paying for rebalance
IERC20(quoteToken).transfer(
account,
_abs(shortFall)
);
}
+ IERC20(quoteToken).approve(address(vault), quoteAmount);
vault.deposit(quoteToken, quoteAmount);
emit Rebalanced(baseAmount, quoteAmount, shortFall);
return (baseAmount, quoteAmount);
Discussion
WarTech9
This is a duplicate of #339
IAm0x52
Two separate issues here. #339 is pointing out it's not approved for the swapper. This one is pointing out it's not approved for the vault. It should be approved for both
WarTech9
@0x00052 good catch. You're right. This is a separate issue from #339
WarTech9
This was fixed here: https://github.com/UXDProtocol/uxd-evm/commit/8d76f0cedc3dfc83c775ae461613c71ba5dcf1e7 As part of the fix for #339
IAm0x52
Fix looks good. Vault is now approved for quoteToken before deposit
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
Likely the missing approval call for the quote token to the vault before depositing.
Impact
PerpDepository#_rebalanceNegativePnlWithSwap won't function, potentially preventing the protocol from rebalancing negative PnL.
What the attacker needed
None
The fix
The missing approval was added, and the issue was fixed.
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 Ethereum smart contracts, before one contract can take tokens from another, the token owner must approve the spender. Here, the contract forgot to approve the vault to take the quote token, so the deposit always fails. This means a key rebalancing function never works.
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.