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

Risk of Unhandled Failures #416

Closed
c4-bot-4 opened this issue Jan 22, 2024 · 6 comments
Closed

Risk of Unhandled Failures #416

c4-bot-4 opened this issue Jan 22, 2024 · 6 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 insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-4
Copy link
Contributor

Lines of code

https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L285
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L302

Vulnerability details

In the DecentEthRouter contract, there are several instances where external calls are made to other contracts, such as weth.transfer, weth.withdraw, weth.deposit, and dcntEth contract calls. These calls are potentially unsafe as they don't handle the possibility of these calls failing or reverting:

function redeemEth(uint256 amount) public onlyIfWeHaveEnoughReserves(amount) {
    // ...
    weth.withdraw(amount);
    payable(msg.sender).transfer(amount);
}

function addLiquidityEth() public payable onlyEthChain userDepositing(msg.value) {
    weth.deposit{value: msg.value}();
    // ...
}

function removeLiquidityWeth(uint256 amount) public userIsWithdrawing(amount) {
    dcntEth.burn(address(this), amount);
    weth.transfer(msg.sender, amount);
}

Impact

If external calls to WETH or other contracts fail, the current implementation does not handle these failures, which can lead to transaction reversion and inconsistent contract states.

Mitigation

To address these risks, handle the possibility of failures in external calls:

  • Implement checks for the return value or use try-catch blocks for external calls.
     function safeWethWithdraw(IWETH wethToken, uint256 amount) private {
         bool success = wethToken.withdraw(amount);
         require(success, "WETH withdrawal failed");
     }

     function safeEthTransfer(address payable recipient, uint256 amount) private {
         (bool success, ) = recipient.call{value: amount}("");
         require(success, "ETH transfer failed");
     }

     function redeemEth(uint256 amount) public onlyIfWeHaveEnoughReserves(amount) {
         // ...
         safeWethWithdraw(weth, amount);
         safeEthTransfer(payable(msg.sender), amount);
     }

Assessed type

Error

@c4-bot-4 c4-bot-4 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 22, 2024
c4-bot-4 added a commit that referenced this issue Jan 22, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as insufficient quality report

@c4-pre-sort c4-pre-sort added the insufficient quality report This report is not of sufficient quality label Jan 24, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as duplicate of #25

@raymondfam
Copy link

weth and dcntEth are ERC20 tokens not to be mixed up with native coin using call().

@c4-judge
Copy link

c4-judge commented Feb 2, 2024

alex-ppg marked the issue as not a duplicate

@c4-judge c4-judge reopened this Feb 2, 2024
@alex-ppg
Copy link

alex-ppg commented Feb 2, 2024

The Warden has confused low-level calls (that always yield a bool and a bytes memory variable) with interface based interactions that may yield nothing or yield different variables and whose execution is guaranteed to either succeed or revert the whole transaction.

@c4-judge
Copy link

c4-judge commented Feb 2, 2024

alex-ppg marked the issue as unsatisfactory:
Invalid

@c4-judge c4-judge closed this as completed Feb 2, 2024
@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Feb 2, 2024
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 insufficient quality report This report is not of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

5 participants