sherlock-audit / 2023-05-dodo-judging

6 stars 2 forks source link

J4de - Some token do not support approve `type(uint256).max` #185

Closed sherlock-admin closed 1 year ago

sherlock-admin commented 1 year ago

J4de

medium

Some token do not support approve type(uint256).max

Summary

Some token do not support approve type(uint256).max

Vulnerability Detail

File: MarginTrading.sol
392     function _approveToken(address _address, address _tokenAddress, uint256 _tokenAmount) internal {
393         if (IERC20(_tokenAddress).allowance(address(this), _address) < _tokenAmount) {
394             IERC20(_tokenAddress).approve(_address, type(uint256).max);
395         }
396     }

MarginTrading.sol contract defaults to approve type(uint256).max, but some tokens (such as UNI) do not support approve type(uint256).max

Impact

Cause protocol not applicable to some tokens

Code Snippet

https://github.com/sherlock-audit/2023-05-dodo/blob/main/dodo-margin-trading-contracts/contracts/marginTrading/MarginTrading.sol#L267

https://github.com/sherlock-audit/2023-05-dodo/blob/main/dodo-margin-trading-contracts/contracts/marginTrading/MarginTrading.sol#L309

https://github.com/sherlock-audit/2023-05-dodo/blob/main/dodo-margin-trading-contracts/contracts/marginTrading/MarginTrading.sol#L394

Tool used

Manual Review

Recommendation

do not approve type(uint256).max