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

[bridge] Replay protection on L1 #868

Open
apenzk opened this issue Nov 20, 2024 · 1 comment
Open

[bridge] Replay protection on L1 #868

apenzk opened this issue Nov 20, 2024 · 1 comment
Assignees
Labels
bridge Priority: High After critical issues are fixed, these should be dealt with before any further issues.

Comments

@apenzk
Copy link

apenzk commented Nov 20, 2024

Problem

This considers a transfer from L2 --> L1.

The relayer may (maliciously or by accident) complete a transfer on the target chain (L1) twice. This needs to be prevented, as it constitutes a double spend.

Background

MIP-58: Trusted-Relayer focused Bridge Design

Solution

Transfers are identified on the source chain (L2) by L2L1bridgeTransferId. The native bridge contract on the target chain (L1) MUST keep a list L2L1bridgeTransferIds in the solidity contract and the contract MUST check if the requested completion of a transfer by the relayer has been already previously completed.

Recommendations

DO NOT use bridgeTransferId. It should be crystal clear from the code that this is an L2-->L1 transfer.

@apenzk apenzk added Priority: High After critical issues are fixed, these should be dealt with before any further issues. bridge labels Nov 20, 2024
@Primata
Copy link
Contributor

Primata commented Nov 20, 2024

// Ensure the nonce is valid
        require(nonce > 0, InvalidNonce());

        // Ensure the incoming bridge transfer ID has not already been completed
        require(idsToIncomingNonces[bridgeTransferId] == 0, CompletedBridgeTransferId());
        // Ensure the bridge transfer ID is valid against the initiator, recipient, amount, and nonce
        require(
            bridgeTransferId == keccak256(abi.encodePacked(initiator, recipient, amount, nonce)),
            InvalidBridgeTransferId()
        );

        // Store the incoming nonce to incoming bridge transfer ID
        idsToIncomingNonces[bridgeTransferId] = nonce;
        ```
        
        does this suffices?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bridge Priority: High After critical issues are fixed, these should be dealt with before any further issues.
Projects
None yet
Development

No branches or pull requests

4 participants