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

Fee-on-transfer check can be avoided #119

Open
code423n4 opened this issue Jan 26, 2022 · 2 comments
Open

Fee-on-transfer check can be avoided #119

code423n4 opened this issue Jan 26, 2022 · 2 comments
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists

Comments

@code423n4
Copy link
Contributor

Handle

harleythedog

Vulnerability details

Impact

In Exchange.sol, there is a check in addLiquidity to see if the base token is a fee-on-transfer token (and it reverts if it is, since this is not supported and would break a lot of the internal accounting):

bool isExchangeEmpty = IERC20(baseToken).balanceOf(address(this)) == 0;
...
if (isExchangeEmpty) {
    require(
        IERC20(baseToken).balanceOf(address(this)) ==
            tokenQtys.baseTokenQty,
         "Exchange: FEE_ON_TRANSFER_NOT_SUPPORTED"
    );
}

This check can easily be avoided by transferring 1 wei of the base token to the contract before supplying the initial liquidity. This would create an exchange with a fee-on-transfer base token, which is not desirable and new users might interact with these exchanges, not knowing that the exchange logic will not work correctly and thus should not be interacted with.

Proof of Concept

See referenced code here.

Tools Used

Inspection.

Recommended Mitigation Steps

Instead of checking if balanceOf is 0, the contract should check that the internalBalance is 0. So I recommend changing line 123/124 to be:

bool isExchangeEmpty = internalBalances.baseTokenReserveQty == 0;

This way, there is no way of supplying initial liquidity an exchange that has fee-on-transfer tokens as the base token.

@code423n4 code423n4 added 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 labels Jan 26, 2022
code423n4 added a commit that referenced this issue Jan 26, 2022
@0xean 0xean added duplicate This issue or pull request already exists and removed duplicate This issue or pull request already exists labels Jan 27, 2022
@0xean
Copy link
Collaborator

0xean commented Jan 31, 2022

Fee on Transfer Tokens are NOT supported in our current implementation is stated in the readme of the contest.

Yes, the check could be gamed, but we are not trying to avoid people gaming the system, we are trying to simply add a check to help people making an honest mistake.

Would suggest a low severity on this given FOT are not supported and its called out as such in the README.

@0xean 0xean added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Jan 31, 2022
@GalloDaSballo
Copy link
Collaborator

I agree with both sides, the finding is valid and Low Severity is appropriate given that feeOnTransfer tokens are out of scope and explicitly not supported by the protocol

@GalloDaSballo GalloDaSballo added 1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Feb 5, 2022
@CloudEllie CloudEllie added the duplicate This issue or pull request already exists label Feb 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 (Low Risk) Assets are not at risk. State handling, function incorrect as to spec, issues with comments bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants