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

BranchBridgeAgent:lzReceive() should check if _srcChainId is rootChainId #706

Open
c4-submissions opened this issue Oct 6, 2023 · 4 comments
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-855 grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sufficient quality report This report is of sufficient quality

Comments

@c4-submissions
Copy link
Contributor

Lines of code

https://github.com/code-423n4/2023-09-maia/blob/main/src/BranchBridgeAgent.sol#L578

Vulnerability details

Impact

Attackers can replay calls from the old root chain to branch chains if the root chain is forked.

Proof of Concept

In BranchBridgeAgent:lzReceive(), we ignore the _srcChainId parameter passed from the endpoint, only check the msg.sender is the endpoint, and the message sender is the root bridge agent in requiresEndpoint modifier.

    function lzReceive(uint16, bytes calldata _srcAddress, uint64, bytes calldata _payload) public override {
        address(this).excessivelySafeCall(
            gasleft(),
            150,
            abi.encodeWithSelector(this.lzReceiveNonBlocking.selector, msg.sender, _srcAddress, _payload)
        );
    }

However, this can lead to a replay problem when the root chain forked and added to the LayerZero as a new chain:

  1. Alice triggers a message from the root chain R1 to branch chain A. This is a swap call with slippage protection, and the call reverts on the branch router.
  2. The root chain R1 is forked with R1 and R2.
  3. Alice retried the settlement on R1 and reverted again.
  4. Time passed, the slippage protection set in 1 is unpractical. Bob replayed the retrySettlement tx in step 3 on R2, and the bridge agent on chain A received the message from R2. Since the msg.sender is the endpoint and _srcAddress is the root bridge agent address, the call is executed on Chain A and success, which is unexpected by Alice.

Tools Used

Recommended Mitigation Steps

We should make sure BranchBridgeAgent can only get call from the root chain when it's deployed:

    function lzReceive(uint16 _srcChainId, bytes calldata _srcAddress, uint64, bytes calldata _payload) public override {
    require(_srcChainId == rootChainId, "Only accept message from the root chain");

Assessed type

Invalid Validation

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

0xA5DF marked the issue as duplicate of #855

@c4-pre-sort
Copy link

0xA5DF marked the issue as sufficient quality report

@c4-pre-sort c4-pre-sort added the sufficient quality report This report is of sufficient quality label Oct 12, 2023
@c4-judge
Copy link
Contributor

alcueca changed the severity to QA (Quality Assurance)

@c4-judge c4-judge added downgraded by judge Judge downgraded the risk level of this issue QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax grade-a and removed 2 (Med Risk) Assets not at direct risk, but function/availability of the protocol could be impacted or leak value labels Oct 25, 2023
@c4-judge
Copy link
Contributor

alcueca marked the issue as grade-a

@C4-Staff C4-Staff reopened this Nov 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working downgraded by judge Judge downgraded the risk level of this issue duplicate-855 grade-a QA (Quality Assurance) Assets are not at risk. State handling, function incorrect as to spec, issues with clarity, syntax sufficient quality report This report is of sufficient quality
Projects
None yet
Development

No branches or pull requests

4 participants