sherlock-audit / 2023-01-uxd-judging

3 stars 1 forks source link

duc - Deposit and withdraw wrong decimals of amount in contract `PerpDepository` #398

Closed github-actions[bot] closed 1 year ago

github-actions[bot] commented 1 year ago

duc

high

Deposit and withdraw wrong decimals of amount in contract PerpDepository

Summary

Function vault.deposit and vault.withdraw of vault in contract PerpDepository need to be passed with 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

(uint256 baseAmount, uint256 quoteAmount) = _placePerpOrder( normalizedAmount, isShort, amountIsInput, sqrtPriceLimitX96 ); vault.withdraw(assetToken, baseAmount);

...


## Impact
Because of calling `vault.deposit` and `vault.withdraw` with wrong decimal of the param amount, the protocol can lose a lot of funds. And some functionalities of the protocol can be broken cause it might revert by not enough allowance when calling these functions.
## Code Snippet
https://github.com/sherlock-audit/2023-01-uxd/blob/main/contracts/integrations/perp/PerpDepository.sol#L498
https://github.com/sherlock-audit/2023-01-uxd/blob/main/contracts/integrations/perp/PerpDepository.sol#L524
https://github.com/sherlock-audit/2023-01-uxd/blob/main/contracts/integrations/perp/PerpDepository.sol#L638
## Tools used
Manual review
## Recommendation
Should convert the param `amount` from decimal 18 to token's decimal before `vault.deposit` and `vault.withdraw`.