sherlock-audit / 2023-04-unitasprotocol-judging

4 stars 3 forks source link

PokemonAuditSimulator - Accounting for fee-on-transfer tokens like USDT, can mess up the internal balances #125

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

PokemonAuditSimulator

medium

Accounting for fee-on-transfer tokens like USDT, can mess up the internal balances

Summary

If USDT is upgraded to have a fee-on-transfer feature, it could potentially create significant issues in internal accounting. Currently, the swap() function assumes a 0% fee on transfers between USDT and USD1, where USD1 is pegged to USDT.

Vulnerability Detail

Let's consider the scenario of swapping USDT for USD1. The swap() function involves two steps:

For example:

Impact

Internal accounting is messed up

Code Snippet

https://github.com/sherlock-audit/2023-04-unitasprotocol/blob/main/Unitas-Protocol/src/Unitas.sol#L360-L371 https://github.com/sherlock-audit/2023-04-unitasprotocol/blob/main/Unitas-Protocol/src/Unitas.sol#L379-L400

Tool used

Manual Review

Recommendation

In order to address this issue, it is recommended to modify the _swapIn() function as follows:

        if (tokenType == ITokenManager.TokenType.Asset) {
             uint balanceBefore = getReserve(token)
             IERC20(token).safeTransferFrom(spender, address(this), amount);
             uint balanceAfter = getReserve(token);
            _setBalance(token, _getBalance(token) + balanceAfter-balanceBefore);
        } 

Also you will need to account how many tokens are minted with _swapOut()