Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protocol does not handle the tokens correctly that has decimal value more than 18 #536

Closed
code423n4 opened this issue Dec 16, 2022 · 3 comments
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-533 satisfactory satisfies C4 submission criteria; eligible for awards

Comments

@code423n4
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2022-12-tigris/blob/588c84b7bb354d20cbca6034544c4faa46e6a80e/contracts/StableVault.sol#L44-L71

Vulnerability details

Impact

StableVault.sol :
desposit , depositWithPermit and withdraw would revert.

TradingLibrary.sol : verifyPrice function would revert at line 115

Trading.sol : _handleDeposit function would revert at line 650, _handleWithdraw will fail at line 675.

Proof of Concept

From the listed pairs it is clear that the protocol is supporting the NEAR/USD - https://docs.tigris.trade/protocol/listed-pairs#:~:text=3-,NEAR/USD,-0.10%25

NEAR has decimal value of 24. https://etherscan.io/token/0x85f17cf997934a597031b2e18a9ab6ebd4b9f6a4

    function deposit(address _token, uint256 _amount) public {
    require(allowed[_token], "Token not listed");
    IERC20(_token).transferFrom(_msgSender(), address(this), _amount);
    IERC20Mintable(stable).mintFor(
        _msgSender(),
        _amount*(10**(18-IERC20Mintable(_token).decimals()))
    );
}


function depositWithPermit(address _token, uint256 _amount, uint256 _deadline, bool _permitMax, uint8 v, bytes32 r, bytes32 s) external {
    uint _toAllow = _amount;
    if (_permitMax) _toAllow = type(uint).max;
    ERC20Permit(_token).permit(_msgSender(), address(this), _toAllow, _deadline, v, r, s);
    deposit(_token, _amount);
}


/**
* @notice swap tigAsset to _token
* @param _token address of the token to receive
* @param _amount amount of _token
*/
function withdraw(address _token, uint256 _amount) external returns (uint256 _output) {
    IERC20Mintable(stable).burnFrom(_msgSender(), _amount);
    _output = _amount/10**(18-IERC20Mintable(_token).decimals());
    IERC20(_token).transfer(
        _msgSender(),
        _output
    );

StableVault.sol : both witdraw and deposit will revert due to the calculation at lines 49, 67

Tools Used

Manual review

Recommended Mitigation Steps

Kindly consider changing the subtraction from large to min instead of (18 - token decimal)

@code423n4 code423n4 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Dec 16, 2022
code423n4 added a commit that referenced this issue Dec 16, 2022
@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as duplicate of #533

@c4-judge
Copy link
Contributor

GalloDaSballo marked the issue as satisfactory

@c4-judge c4-judge added the satisfactory satisfies C4 submission criteria; eligible for awards label Jan 22, 2023
@c4-judge
Copy link
Contributor

GalloDaSballo changed the severity to 2 (Med Risk)

@c4-judge c4-judge added 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value downgraded by judge Judge downgraded the risk level of this issue and removed 3 (High Risk) Assets can be stolen/lost/compromised directly labels Jan 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-533 satisfactory satisfies C4 submission criteria; eligible for awards
Projects
None yet
Development

No branches or pull requests

2 participants