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

CoreBranchRouter.executeNoSettlement() fails to refund the unconsumed gas after completion of execution #345

Closed
c4-submissions opened this issue Oct 3, 2023 · 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 primary issue Highest quality submission among a set of duplicates sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue sufficient quality report This report is of sufficient quality unsatisfactory does not satisfy C4 submission criteria; not eligible for awards

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-09-maia/blob/main/src/CoreBranchRouter.sol#L86-L149
https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchBridgeAgentExecutor.sol#L53-L56
https://github.com/code-423n4/2023-09-maia/blob/main/src/MulticallRootRouter.sol#L142-L149
https://github.com/code-423n4/2023-09-maia/blob/main/src/RootBridgeAgentExecutor.sol#L72
https://github.com/code-423n4/2023-09-maia/blob/main/src/MulticallRootRouter.sol#L234-L241
https://github.com/code-423n4/2023-09-maia/blob/main/src/RootBridgeAgentExecutor.sol#L156

Vulnerability details

CoreBranchRouter.executeNoSettlement() is used to execute branch management functions such as addGlobalToken, addBridgeAgent, manageStrategyToken, etc. It receives native tokens from BranchBridgeAgentExecutor for gas to perform subsequent callout to root chain. In the case of addGlobalToken and addBridgeAgent, the callout to root chain will take care of the refund of native tokens as LayerZeroEndpoint(lzEndpointAddress).send() will refund the excess minus fees.

However, for management functions that does not have subsequent callout like manageStrategyToken, removeBranchBridgeAgent, the native tokens are not refunded by CoreBranchRouter after successful execution. The unconsumed native tokens will be left stuck in the CoreBranchRouter contract.

Note that the issue is possible as CoreRootRouter allows the passing in of GasParams to allow transfer of native tokens for remote execution gas. And this issue occurs in the test suite as shown in the POC below.

The issue is also present in ArbitrumCoreBranchRouter.executeNoSettlement(), MulticallRootRouter.execute(), MulticallRootRouter.executeSigned(). These functions accept native tokens for remote execution but has specific cases that does not perform subsequent callouts.

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchBridgeAgentExecutor.sol#L53-L56

contract BranchBridgeAgentExecutor is Ownable, BridgeAgentConstants {
    ...
    function executeNoSettlement(address _router, bytes calldata _payload) external payable onlyOwner {
        
        //@audit CoreBranchRouter will receive native tokens for gas to perform subsequent callout to root chain
        IRouter(_router).executeNoSettlement{value: msg.value}(_payload[PARAMS_TKN_START_SIGNED:]);
    }
}

Impact

The unconsumed gas will be left stuck within the router contracts without any mechanism to retrieve them.

Proof of Concept

Add the console.log as shown below to existing testAddStrategyToken() in RootTest.t.sol#L747. It will show that the CoreBranchRouter will be left with the unconsumed native tokens.

function testAddStrategyToken() public {
    // Get some gas
    hevm.deal(address(this), 1 ether);

    rootCoreRouter.manageStrategyToken{value: 0.05 ether}(
        address(102), 3000, address(this), ftmChainId, GasParams(0.05 ether, 0.05 ether)
    );

    require(ftmPort.isStrategyToken(address(102)), "Should be added");

    //@audit add the following console.log to see the unrefunded gas that is left in the destination branch router. 
    console.log("address(ftmCoreRouter).balance == %d", address(ftmCoreRouter).balance);
}

Recommended Mitigation Steps

Implement a refund by transfering the native tokens that was received from msg.value.

Assessed type

Token-Transfer

@c4-submissions c4-submissions 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 Oct 3, 2023
c4-submissions added a commit that referenced this issue Oct 3, 2023
@c4-pre-sort
Copy link

0xA5DF marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added sufficient quality report This report is of sufficient quality primary issue Highest quality submission among a set of duplicates labels Oct 14, 2023
@c4-pre-sort
Copy link

0xA5DF marked the issue as primary issue

@c4-sponsor
Copy link

0xLightt (sponsor) disputed

@c4-sponsor c4-sponsor added the sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue label Oct 16, 2023
@alcueca
Copy link

alcueca commented Oct 26, 2023

Disputed on what grounds, please?

@0xLightt
Copy link

This would require API misuse by governance. The governance contract would be sending extra native tokens to be used for further layerzero/cross-chain calls when there are none expected. The gas parameters passed should be something like this GasParams(0.05 ether, 0). Since the "airdrop" functionality of layerzero adapter params has no use here.

@c4-judge c4-judge added the unsatisfactory does not satisfy C4 submission criteria; not eligible for awards label Oct 27, 2023
@c4-judge
Copy link
Contributor

alcueca marked the issue as unsatisfactory:
Invalid

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 primary issue Highest quality submission among a set of duplicates sponsor disputed Sponsor cannot duplicate the issue, or otherwise disagrees this is an issue 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