code-423n4 / 2024-03-taiko-findings

3 stars 2 forks source link

Malicious exploitation allowed via self-referential hops, undermining bridge contract security, facilitating attacks. #125

Open c4-bot-1 opened 7 months ago

c4-bot-1 commented 7 months ago

Lines of code

https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/signal/SignalService.sol#L104-L118

Vulnerability details

Description

proveSignalReceived function in the SignalService contract is vulnerable to self-referential hops, allowing a malicious user to potentially manipulate the multi-hop bridging process and exploit vulnerabilities in the underlying bridge contracts.

Vulnerability Details

File: SignalService.sol:L104-L117

for (uint256 i; i < hopProofs.length; ++i) {
    hop = hopProofs[i];

    bytes32 signalRoot = _verifyHopProof(chainId, app, signal, value, hop, signalService);
    bool isLastHop = i == hopProofs.length - 1;

    if (isLastHop) {
        if (hop.chainId != block.chainid) revert SS_INVALID_LAST_HOP_CHAINID();
        signalService = address(this);
    } else {
        if (hop.chainId == 0 || hop.chainId == block.chainid) {
            revert SS_INVALID_MID_HOP_CHAINID();
        }
        signalService = resolve(hop.chainId, "signal_service", false);
    }

This lines checks for invalid last hop and intermediate hop chain IDs but does not prevent self-referential hops.

Expected Behavior

But the current Behavior

Impact

Malicious users can construct proofs with self-referential hops to bypass the loop detection mechanism and potentially exploit vulnerabilities in the bridge contracts.

Recommended Mitigation Steps

The function should maintain a mapping or array to keep track of the visited chain IDs and ensure that each hop's chain ID is unique and has not been encountered in any previous hops.

     mapping(uint256 => bool) private visitedChainIds;

     // Inside the proveSignalReceived function
     for (uint256 i = 0; i < hopProofs.length; ++i) {
         // ...

         if (visitedChainIds[hop.chainId]) {
             revert("Self-referential hop detected");
         }
         visitedChainIds[hop.chainId] = true;

         // ...
     }

Assessed type

Reentrancy

c4-pre-sort commented 7 months ago

minhquanym marked the issue as primary issue

minhquanym commented 7 months ago

Insufficient proof

c4-sponsor commented 7 months ago

dantaik (sponsor) confirmed

dantaik commented 7 months ago

This PR mitigates the concerns in this issue , but I'm having a hard time to construct an exploiting transaction with a bridge loop that has actual security impact.

c4-judge commented 7 months ago

0xean marked the issue as satisfactory

c4-judge commented 7 months ago

0xean marked the issue as selected for report

0xean commented 7 months ago

Welcome more comment from wardens and sponsors here during PJQA but perhaps this is better as QA since there is not enough proof to show the attack.

mcgrathcoutinho commented 7 months ago

Hi @0xean, I believe this issue should be of QA-severity.

I do not see a security risk entailed on how this could be misused or could impact the protocol. Additionally, I agree with the sponsor's comment on the fix regarding this issue: https://github.com/taikoxyz/taiko-mono/pull/16659#issuecomment-2039252060

Please consider re-evaluating this issue.

Thank you!

0xean commented 7 months ago

After thinking about this more, marking down to QA, as I just don't think there is a sufficient proof to warrant M

c4-judge commented 7 months ago

0xean changed the severity to QA (Quality Assurance)

c4-judge commented 7 months ago

0xean marked the issue as grade-b

c4-judge commented 7 months ago

0xean marked the issue as not selected for report