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

yixxas - Adversary can prevent withdrawal of assets if token used has multiple addresses #369

Closed
sherlock-admin opened this issue Apr 22, 2023 · 6 comments
Labels
Disagree With Severity The sponsor disputed the severity of this issue 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

yixxas

high

Adversary can prevent withdrawal of assets if token used has multiple addresses

Summary

Some tokens have multiple addresses. If such tokens are used as collatearl, an adversary can cause unknown users from having their collateral stuck in the contract permanently.

Vulnerability Detail

commitCollateral() has no access control. It checks the balance of borrower to ensure that they have enough balance. If a check is successful, the address is added to the collateralAddresses enumerableSet via collateral.collateralAddresses.add(_collateralInfo._collateralAddress).

The issue here is that, for a token with multiple addresses, an adversary can call this function to add the same token of its different addresses to collateral.collateralAddresses. This call will succeed as commitCollateral() only checks balances of the token, and both addresses will map to the same balances of the token.

When withdrawing, it loops through all collateralAddresses of thebidId. It then withdraws the token based on collateralInfo._amount.

For example, if a user has balanceOf(tokenId) = 500, and collateralInfo._amount = 500, after the first withdrawal, balanceOf == 0, but it will attempt to withdraw again on this 0 balance as the 2 different addresses maps to the same token. This will revert hence preventing any withdrawal from happening permanently.

    function _withdraw(uint256 _bidId, address _receiver) internal virtual {
        for (
            uint256 i;
            i < _bidCollaterals[_bidId].collateralAddresses.length();
            i++
        ) {
            // Get collateral info
            Collateral storage collateralInfo = _bidCollaterals[_bidId]
                .collateralInfo[
                    _bidCollaterals[_bidId].collateralAddresses.at(i)
                ];
            // Withdraw collateral from escrow and send it to bid lender
            ICollateralEscrowV1(_escrows[_bidId]).withdraw(
                collateralInfo._collateralAddress,
                collateralInfo._amount,
                _receiver
            );
            emit CollateralWithdrawn(
                _bidId,
                collateralInfo._collateralType,
                collateralInfo._collateralAddress,
                collateralInfo._amount,
                collateralInfo._tokenId,
                _receiver
            );
        }
    }

Impact

Assets with multiple addresses can be forced trapped in contract permanently.

Code Snippet

https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/CollateralManager.sol#L431
https://github.com/sherlock-audit/2023-03-teller/blob/main/teller-protocol-v2/packages/contracts/contracts/CollateralManager.sol#L393-L419

Tool used

Manual Review

Recommendation

Consider using a whitelist to prevent such tokens from being used.

@github-actions github-actions bot added the Medium A valid Medium severity issue label May 1, 2023
@ethereumdegen
Copy link

ethereumdegen commented May 5, 2023

'Some tokens have multiple addresses' I have never heard of a token having multiple assets. This does not make sense. A token is created by the deployment of a smart contract and that smart contract address is the token address. I do not see any issue here.

@ethereumdegen ethereumdegen added the Disagree With Severity The sponsor disputed the severity of this issue label May 5, 2023
@Trumpero Trumpero closed this as completed May 8, 2023
@sherlock-admin sherlock-admin added Non-Reward This issue will not receive a payout and removed Medium A valid Medium severity issue labels May 20, 2023
@yixxas
Copy link

yixxas commented May 20, 2023

Escalate for 10 USDC

To respond to the sponsor @ethereumdegen, tokens with multiple addresses do exist though they are rare. A similar issue has been reported and accepted in a previous contest sherlock-audit/2023-03-taurus-judging#31

It is explicitly mentioned by the protocol that it aims to support all ERC20 tokens, hence they should be prepared to handle such tokens. Therefore, this issue should be considered a valid medium.

@sherlock-admin
Copy link
Contributor Author

Escalate for 10 USDC

To respond to the sponsor @ethereumdegen, tokens with multiple addresses do exist though they are rare. A similar issue has been reported and accepted in a previous contest sherlock-audit/2023-03-taurus-judging#31

It is explicitly mentioned by the protocol that it aims to support all ERC20 tokens, hence they should be prepared to handle such tokens. Therefore, this issue should be considered a valid medium.

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 May 20, 2023
@Trumpero
Copy link
Collaborator

Trumpero commented Jun 3, 2023

Disagree with the escalation, I believe this issue is invalid. In the scenario where borrowers commit the same token with two different addresses, they are required to deposit this token twice (refer to deployAndDeposit function). Therefore, when it comes to withdrawing, no issue arises as the token amount is insufficient to withdraw twice.

@hrishibhat
Copy link

Escalation rejected

Invalid issue
As pointed out by the lead judge in order to withdraw through two different addresses, they need to deposit twice in order to withdraw twice.

@sherlock-admin sherlock-admin removed the Escalated This issue contains a pending escalation label Jun 6, 2023
@sherlock-admin
Copy link
Contributor Author

Escalation rejected

Invalid issue
As pointed out by the lead judge in order to withdraw through two different addresses, they need to deposit twice in order to withdraw twice.

This issue's escalations have been rejected!

Watsons who escalated this issue will have their escalation amount deducted from their next payout.

@sherlock-admin sherlock-admin added the Escalation Resolved This issue's escalations have been approved/rejected label Jun 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Disagree With Severity The sponsor disputed the severity of this issue 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

5 participants