Open github-actions[bot] opened 1 year ago
amount
is always in the unit of the token being deposited so no normalization required.
@WarTech9 just confirming that your comment is applicable to all the duplicates tagged here. Right?
After further review this issue is valid. quoteAmount
should be converted to quoteDecimals
before vault.deposit()
in _rebalanceNegativePnlWithSwap()
Issue exists in _rebalanceNegativePnlWithSwap()
before vault.deposit()
. Need to convert from 18 decimals to 6 for USDC.
Issue does not exist in _rebalanceNegativePnlLite
where amount returned by _placePerpOrder()
is already in 18 decimals. So no conversion required before vault.withdraw()
.
Fixed here: https://github.com/UXDProtocol/uxd-evm/pull/27
Fix looks good. Decimals are now correctly adjusted for quote deposits
duc
high
Deposit and withdraw to the vault with the wrong decimals of amount in contract
PerpDepository
Summary
Function
vault.deposit
andvault.withdraw
of vault in contractPerpDepository
need to be passed with the amount in raw decimal of tokens (is different from 18 in case using USDC, WBTC, ... as base and quote tokens). But some calls miss the conversion of decimals from 18 to token's decimal, and pass wrong decimals into them.Vulnerability Detail
Function
vault.deposit
need to be passed the param amount in token's decimal (as same asvault.withdraw
). You can see at function_depositAsset
in contract PerpDepository.But there are some calls of
vault.deposit
andvault.withdraw
that passed the amount in the wrong decimal (18 decimal). Let's see function_rebalanceNegativePnlWithSwap
in contract PerpDepository:Because function
_placePerpOrder
returns in decimal 18 (confirmed with sponsor WarTech), this calls passbaseAmount
andquoteAmount
in decimal 18, inconsistent with the above call. It leads to vault using the wrong decimal when depositing and withdrawing tokens.vault.withdraw
with the wrong decimal (same as this case) in function_rebalanceNegativePnlLite
:(uint256 baseAmount, uint256 quoteAmount) = _placePerpOrder( normalizedAmount, isShort, amountIsInput, sqrtPriceLimitX96 ); vault.withdraw(assetToken, baseAmount);
...