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

Lack of WETH Fallback in redeemAtom Function for Failed ETH Transfers #73

Open
hats-bug-reporter bot opened this issue Jun 29, 2024 · 1 comment
Labels
bug Something isn't working invalid This doesn't seem right

Comments

@hats-bug-reporter
Copy link

Github username: --
Twitter username: --
Submission hash (on-chain): 0xfe48c86ee5fde1eaae0770dab56021baee6c579c2aa94c61a309134d82982c86
Severity: medium

Description:
Description
The redeemAtom function in the EthMultiVault contract attempts to transfer ETH directly to the receiver. If this transfer fails, the function simply reverts instead of attempting a fallback method using WETH. This approach can lead to unnecessary transaction failures and a poor user experience, especially when interacting with contracts that can't receive ETH directly but can handle WETH.

Attack Scenario
While not a direct security vulnerability, this issue can lead to the following problems:

  1. A user attempts to redeem their shares to a contract address that doesn't have a payable fallback function but can handle WETH.
  2. The ETH transfer fails, causing the entire transaction to revert.
  3. The user is unable to redeem their shares, despite the receiving contract being capable of handling the assets in WETH form.
  4. This limits the contract's interoperability with other DeFi protocols and smart contracts.

Attachments

  1. Proof of Concept (PoC) File

    (bool success,) = payable(receiver).call{value: assets}("");
    if (!success) {
    revert Errors.MultiVault_TransferFailed();
    }

  2. Revised Code File (Optional)

   function redeemAtom(uint256 shares, address receiver, uint256 id) external nonReentrant returns (uint256) {
        if (id == 0 || id > count) {
            revert Errors.MultiVault_VaultDoesNotExist();
        }

        if (isTripleId(id)) {
            revert Errors.MultiVault_VaultNotAtom();
        }

        (uint256 assets, uint256 protocolFee) = _redeem(id, msg.sender, shares);

        // Try to transfer ETH first
        (bool success,) = payable(receiver).call{value: assets}("");
        if (!success) {
            // If ETH transfer fails, fallback to WETH
            WETH.deposit{value: assets}();
            require(WETH.transfer(receiver, assets), "WETH transfer failed");
        }

        _transferFeesToProtocolVault(protocolFee);

        return assets;
    }
@hats-bug-reporter hats-bug-reporter bot added the bug Something isn't working label Jun 29, 2024
@mihailo-maksa mihailo-maksa added the invalid This doesn't seem right label Jul 1, 2024
@mihailo-maksa
Copy link
Collaborator

The report suggests adding a WETH fallback mechanism in the redeemAtom function to handle failed ETH transfers.

Label: invalid

Comment:
We designed the contract to only handle ETH in V1. The suggested WETH fallback is more gas-intensive and unnecessary as the number of users redeeming shares to a contract without a payable fallback or receive function is negligible. Moreover, the lack of this fix can be considered a security measure, preventing potential loss of funds if the receiver address cannot handle ETH.

Comment on the issue:
We designed the contract to handle only ETH in V1, making the suggested WETH fallback unnecessary and more gas-intensive. The current implementation prevents potential loss of funds, making this suggestion invalid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

1 participant