Skip to content
Smart contracts Audit finding Intermediate

Two different transactions can result in the same txnHash value, thus breaking the approval process of transaction minting

The destination bridge computes a transaction hash from a payload that omits the source chain and source address, so two different transactions from different sources can produce the same hash. The later transaction overwrites the approval threshold state of the earlier one, breaking the approval process for minting.

Udsen Follow with adriro, pep7siup and 8 others

Originally disclosed on Code4rena

Submitted by Udsen, also found by adriro, pep7siup, kutugu, ast3ros, bin2chen, 0xDING99YA, SpicyMeatball, 0xpiken (1, 2), bowtiedvirus, Inspecktor, and seerether

The DestinationBridge._execute is an internal function that is executed when contract is called by Axelar Gateway. The _execute function stores the Transaction struct in the txnHashToTransaction mapping as shown below:

bytes32 txnHash = keccak256(payload);
txnHashToTransaction[txnHash] = Transaction(srcSender, amt);

The transaction hash txnHash is calculated by keccak256(payload) and the payload is an abi encoded value consisting of following variables.

bytes32 version, address srcSender, uint256 amt, uint256 nonce

The issue here is that the two different srcChains with two different srcAddr contracts can end up providing the same txnHash if the above mentioned version, srcSender, amt and nonce are the same. The _execute function only restricts the same srcAddr to not to use the same nonce as shown below:

if (isSpentNonce[chainToApprovedSender[srcChain]][nonce]) {
  revert NonceSpent();
}

But the problem is if there are different srcAddrs providing the same payload it will result into the same txnHash.

Hence, there could be two transactions with the same transaction hash (txnHash). The later transaction will override the txnToThresholdSet[txnHash] of the former transaction. As a result, the approval process for transaction minting will be broken.

Proof of Concept

    bytes32 txnHash = keccak256(payload);
    txnHashToTransaction[txnHash] = Transaction(srcSender, amt);

https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/DestinationBridge.sol#L108-L109

        txnToThresholdSet[txnHash] = TxnThreshold(
          t.numberOfApprovalsNeeded,
          new address[](0)
        );

https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/DestinationBridge.sol#L137-L140

    (bytes32 version, address srcSender, uint256 amt, uint256 nonce) = abi
      .decode(payload, (bytes32, address, uint256, uint256));

https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/DestinationBridge.sol#L90-L91

Tools Used

VSCode

Recommended Mitigation Steps

It is recommended to include the srcChain and the srcAddr in the payload as well, which is getting hashed to calculate the txnHash. By doing so, different transactions coming from different srcChains and srcAddr will not result into the same txnHash. The approval process for the transaction minting via the bridge will successfully execute.

kirk-baird (judge) decreased severity to Medium

ali2251 (Ondo) confirmed


The original report as published on Code4rena, by Udsen. 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

Likely the transaction hash is computed over a payload that does not include the source chain and source address, so distinct cross-chain transactions can collide.

Impact

Two transactions can share a hash, and the later one overwrites the earlier transaction's approval threshold set, breaking the approval process for minting; the judge rated this Medium.

What the attacker needed

Bridge accepts messages from multiple source chains; two sources send matching version, sender, amount and nonce

The fix

The payload that is hashed should also include the source chain and source address so that transactions from different sources cannot collide.

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 receives messages from other blockchains and uses a hash (a short fingerprint) to identify each one. Here the fingerprint was built only from the amount, a counter and a sender address, not from which chain or contract sent it, so two different messages could share one fingerprint and confuse the approval tracking.

What is Smart contracts?

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.

More by Udsen

View all

6 more disclosed reports, best first.

More from Ondo Finance

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Smart contract vulnerabilities

The lesson behind this report.

Flaws in on-chain code that let an attacker drain funds, freeze them or break the protocol's accounting.