Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

shealtielanz - Must Approve Zero First #136

Closed
sherlock-admin opened this issue Jun 11, 2023 · 5 comments
Closed

shealtielanz - Must Approve Zero First #136

sherlock-admin opened this issue Jun 11, 2023 · 5 comments
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout

Comments

@sherlock-admin
Copy link
Contributor

sherlock-admin commented Jun 11, 2023

shealtielanz

medium

Must Approve Zero First

Line of Issue

Summary

In the flashloan contract, if a certain condition is true, it approves the ironBank contract to an unlimited amount of tokens, without considering that the input token could revert if it isn't approved to zero first.

Vulnerability Detail

Take a look at the _loan function in the flashloan contract. Link here

        if (allowance < amount) {
            IERC20(token).safeApprove(ironbank, type(uint256).max);
        }

Here it just approves the IronBank to the desired amount, without considering tokens that revert with approving to zero first, and also safeApprove function is depreciated in real time, safeIncreaseAllowance or safeDecreaseAllowance should be used, due to race conditions and more.

Impact

Some tokens (like USDT) do not work when changing the allowance from an existing non-zero allowance value. They must first be approved by zero and then the actual allowance must be approved, meaning if called with such token the _loan function will always revert.

Code Snippet

Tool used

Manual Review, A Little Research

Recommendation

While approving to zero is the most used and standard way, it has been depreciated so I would advise the developers to use the safeIncreaseAllowance or safeDecreaseAllowance function as it mitigates this issue.
A better way would be:

        if (allowance < amount) {
            IERC20(token). safeIncreaseAllowance(ironbank, type(uint256).max);
        }

But the more standard way would be:

        if (allowance < amount) {
            IERC20(token).safeApprove(ironbank, 0);
            IERC20(token).safeApprove(ironbank, type(uint256).max);
        }

Duplicate of #420

@github-actions github-actions bot added Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jun 19, 2023
@sherlock-admin sherlock-admin added Non-Reward This issue will not receive a payout and removed Medium A valid Medium severity issue Duplicate A valid issue that is a duplicate of an issue with `Has Duplicates` label labels Jun 25, 2023
@shealtielanz
Copy link

Escalate for 10 USDC
This is a well know issue, tokens like usdt or usdc have to be first approved to zero, before being approved to the desired amount, the flashloan will be DOSed with tokens like that limiting its use, I request that the Sponsors do more research on this matter to verify.

@sherlock-admin
Copy link
Contributor Author

Escalate for 10 USDC
This is a well know issue, tokens like usdt or usdc have to be first approved to zero, before being approved to the desired amount, the flashloan will be DOSed with tokens like that limiting its use, I request that the Sponsors do more research on this matter to verify.

You've created a valid escalation for 10 USDC!

To remove the escalation from consideration: Delete your comment.

You may delete or edit your escalation comment anytime before the 48-hour escalation window closes. After that, the escalation becomes final.

@sherlock-admin sherlock-admin added the Escalated This issue contains a pending escalation label Jun 26, 2023
@0xffff11
Copy link
Collaborator

0xffff11 commented Jul 3, 2023

The if statement will only be entered 1 time. Therefore it won't happen the approval from non-zero to x value. Invalid

@hrishibhat
Copy link

hrishibhat commented Jul 4, 2023

Result:
Invalid
Duplicate of #420
This is not a valid issue as pointed out by the Lead Judge as well and the Sponsor in #420

@sherlock-admin
Copy link
Contributor Author

sherlock-admin commented Jul 4, 2023

Escalations have been resolved successfully!

Escalation status:

@sherlock-admin sherlock-admin added Escalation Resolved This issue's escalations have been approved/rejected and removed Escalated This issue contains a pending escalation labels Jul 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Escalation Resolved This issue's escalations have been approved/rejected Non-Reward This issue will not receive a payout
Projects
None yet
Development

No branches or pull requests

4 participants