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

Deecnt contracts are using same WETH interface across different chains which can disable some critical features #333

Closed
c4-bot-10 opened this issue Jan 22, 2024 · 8 comments
Labels
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) primary issue Highest quality submission among a set of duplicates sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-bot-10
Copy link
Contributor

Lines of code

https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentBridgeExecutor.sol#L60
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L178
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L275

Vulnerability details

Vulnerability Details

WETH implementation is different in some chains but DecentEthRouter and DecentBridgeExecutor and several other contracts are using same interface for all different chains

Proof of Concept

WETH contract is implemented differently in some chains.

polygon mainnet:
https://polygonscan.com/address/0x7ceB23fD6bC0adD59E62ac25578270cFf1b9f619#code
deposit function of WETH has 2 parameters:

function deposit(address user, bytes calldata depositData)
    external
    override
    only(DEPOSITOR_ROLE)
{
    uint256 amount = abi.decode(depositData, (uint256));
    _mint(user, amount);
}

and all calls to this function are restricted to DEPOSITOR_ROLE, meaning that DecentEthRouter or DecentBridgeExecutor or other contracts wont be able to call this function.

Avalanche C-Chain:
https://avascan.info/blockchain/c/address/0x49D5c2BdFfac6CE2BFdB6640F4F80f226bc10bAB/contract
WETH implementation in Avalanche does not have a deposit function at all, instead it has a mint function

function mint(
    address to,
    uint256 amount,
    address feeAddress,
    uint256 feeAmount,
    bytes32 originTxId
) public {
    require(bridgeRoles.has(msg.sender), "Unauthorized.");
    _mint(to, amount);
    if (feeAmount > 0) {
        _mint(feeAddress, feeAmount);
    }
    emit Mint(to, amount, feeAddress, feeAmount, originTxId);
}

All calls to this function are also limited to bridgeRoles which means that Decent system contracts wont be able to call this function
It also does not support a withdraw function, instead it has an unwrap function:

function unwrap(uint256 amount, uint256 chainId) public {
    require(tx.origin == msg.sender, "Contract calls not supported.");
    require(chainIds[chainId] == true, "Chain ID not supported.");
    _burn(msg.sender, amount);
    emit Unwrap(amount, chainId);
}

Impact

WETH.deposit or WETH.withdraw are used in different parts of the codebase, any action that involves making a call to WETH using an incorrect interface is disabled.
Example (not limited to):
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentBridgeExecutor.sol#L60
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L178
https://github.com/decentxyz/decent-bridge/blob/7f90fd4489551b69c20d11eeecb17a3f564afb18/src/DecentEthRouter.sol#L275

Tools Used

Manual review

Recommended Mitigation Steps

use a compatible interface for interacting with WETH in different chain.

Assessed type

Other

@c4-bot-10 c4-bot-10 added 3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working labels Jan 22, 2024
c4-bot-10 added a commit that referenced this issue Jan 22, 2024
@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Jan 24, 2024
@c4-pre-sort
Copy link

raymondfam marked the issue as sufficient quality report

@c4-pre-sort
Copy link

raymondfam marked the issue as primary issue

@c4-pre-sort c4-pre-sort added the primary issue Highest quality submission among a set of duplicates label Jan 24, 2024
@raymondfam
Copy link

Function call disruptions due to varied WETH interfaces cross-chain.

@c4-sponsor
Copy link

wkantaros marked the issue as disagree with severity

@c4-sponsor c4-sponsor added the disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) label Jan 30, 2024
@c4-sponsor
Copy link

wkantaros (sponsor) confirmed

@c4-sponsor c4-sponsor added the sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") label Jan 30, 2024
@alex-ppg
Copy link

alex-ppg commented Feb 1, 2024

Related to #505, an interesting problem here is that the withdraw signature does not exist on all chains but balanceOf does. As such, some permanent DoS attack could manifest although none of the submissions describe it. I will re-evaluate once I acquire Sponsor feedback on the aforementioned submission.

As-is, I definitely consider it a valid QA issue given that it is a real inconsistency that should be avoided in more explicit ways.

@alex-ppg
Copy link

alex-ppg commented Feb 2, 2024

Submission #429 details the discrepancies between WETH implementations greatly and I thank the Warden for their effort in detailing them.

Inspecting #505 will highlight that the WETH asset will not really be transferred in an L2 solution and can be "maliciously" forced to be transferred but would yield no exploitation vector.

This and its duplicate submissions differ in that they detail how a transaction may fail by assuming the WETH token is conformant with its Ethereum main-net interface which is incorrect.

Inspecting the codebase, we have the following invocations of non-EIP-20 functions that are "safe":

  • DecentEthRouter::_bridgeWithPayload: The WETH::deposit function call is protected by the gasCurrencyIsEth flag, meaning it won't be executed in non-Ethereum chains.
  • DecentEthRouter::onOFTReceived: The WETH::withdraw function call will only occur if !gasCurrencyIsEth, meaning that it won't be executed in non-Ethereum chains.
  • DecentEthRouter::redeemEth: Failure of this function is desirable on non-Ethereum chains and it is not meant to be invoked normally. See Loss of funds when redeeming Decent tokens on chains that dont support ETH as gas token #505.
  • DecentEthRouter::addLiquidityEth: This function is protected by the DecentEthRouter::onlyEthChain modifier and thus will not be executable in non-Ethereum chains.
  • DecentEthRouter::removeLiquidityEth: This function is protected by the DecentEthRouter::onlyEthChain modifier and thus will not be executable in non-Ethereum chains.
  • DecentBridgeExecutor::_executeEth: This function is invoked by DecentBridgeExecutor::execute solely when !gasCurrencyIsEth, meaning that it won't be executed in non-Ethereum chains.

Based on the above, the DecentEthRouter and DecentBridgeExecutor are "safe" and will never fail due to the non-conformity of the interfaces. I fully agree with the Wardens that this is a discrepancy that should be rectified in different, more explicit ways (i.e. different router for L2 and different for main-net) that will also save gas, however, it does not presently constitute a high or medium risk vulnerability.

@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
3 (High Risk) Assets can be stolen/lost/compromised directly bug Something isn't working disagree with severity Sponsor confirms validity, but disagrees with warden’s risk assessment (sponsor explain in comments) primary issue Highest quality submission among a set of duplicates sponsor confirmed Sponsor agrees this is a problem and intends to fix it (OK to use w/ "disagree with severity") sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards
Projects
None yet
Development

No branches or pull requests

6 participants