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.
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);
txnToThresholdSet[txnHash] = TxnThreshold(
t.numberOfApprovalsNeeded,
new address[](0)
);
(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
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.