Skip to content
Business logic Audit finding Intermediate

Chain support cannot be removed or cleared in bridge contracts

The bridge contracts store chain support as strings or hashes, so setting the address to zero does not clear the support. An attacker could not directly exploit this, but the owner cannot remove chain support, potentially causing tokens to be burned without being minted on the destination.

adriro Follow with gkrastenov and lsaudit

Originally disclosed on Code4rena

Submitted by adriro, also found by gkrastenov and lsaudit

Due to how addresses are handled and stored in the configuration settings, it is not possible to remove chain support in both source and destination bridge contracts.

The Axelar bridge service uses strings to represent addresses: messages sent to another chain need to specify its destination contract as a string. The protocol decided to follow the same representation and contract store addresses as strings as part of their configuration.

Chain support in the bridge contracts is then represented by associating the chain name with the address of the contract, stored as a string. This can be seen in the implementation of setDestinationChainContractAddress() for the SourceBridge contract, which stores the string, and the implementation of addChainSupport() in the DestinationBridge contract, which stores the hash of the string:

https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/SourceBridge.sol#L121-L129

121:   function setDestinationChainContractAddress(
122:     string memory destinationChain,
123:     address contractAddress
124:   ) external onlyOwner {
125:     destChainToContractAddr[destinationChain] = AddressToString.toString(
126:       contractAddress
127:     );
128:     emit DestinationChainContractAddressSet(destinationChain, contractAddress);
129:   }

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

234:   function addChainSupport(
235:     string calldata srcChain,
236:     string calldata srcContractAddress
237:   ) external onlyOwner {
238:     chainToApprovedSender[srcChain] = keccak256(abi.encode(srcContractAddress));
239:     emit ChainIdSupported(srcChain, srcContractAddress);
240:   }

This also means that checks need to be done based on the stored representation. SourceBridge checks the length of the string, while DestinationBridge checks for a bytes32(0) value:

https://github.com/code-423n4/2023-09-ondo/blob/main/contracts/bridge/SourceBridge.sol#L68-L71

68:     if (bytes(destContract).length == 0) {
69:       revert DestinationNotSupported();
70:     }
71:

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

96:     if (chainToApprovedSender[srcChain] == bytes32(0)) {
97:       revert ChainNotSupported();
98:     }

Note that this implies that there is no way to clear these settings and remove chain support. In the case of SourceBridge, any address sent to setDestinationChainContractAddress() will be converted to their string representation, which will always have a length greater than zero. For the DestinationBridge, addChainSupport() will hash the address parameter and it will be impossible for that hash value to be zero (since it will imply knowing the preimage of zero).

Proof of Concept

  1. Admin configs the destination address in SourceBridge by calling setDestinationChainContractAddress("optimism", destinationAddress).
  2. Admin decides to remove support for Optimism.
  3. Admin calls setDestinationChainContractAddress("optimism", address(0)), but this will actually store the string for the zero address 0x0000....000.
  4. The check bytes(destContract).length == 0 will fail and messages will still be routed.

Recommended Mitigation Steps

Provide functions in both contracts to allow the owner to clear the settings by resetting their configuration to the default value.

function removeDestinationChainContractAddress(
  string memory destinationChain
) external onlyOwner {
  delete destChainToContractAddr[destinationChain];
  emit DestinationChainContractAddressRemoved(destinationChain);
}
function removeChainSupport(
  string calldata srcChain
) external onlyOwner {
  delete chainToApprovedSender[srcChain];
  emit ChainIdRemoved(srcChain);
}

tom2o17 (Ondo) commented:

@kirk-baird - Can I not set acceptable srcAddr to address(0) and then, given address(0) cannot have a contract deployed to it, this value should not be within the possible ranges of srcAddr within the _execute function?

Granted not super ideal given it will hit a different error message, but functionally, the result is the same.

kirk-baird (judge) commented:

@tom2o17 - My concern here is that there’s no way to stop calling burnAndCallAxelar(), which would burn tokens on the source chain. These would not be minted on the destination chain and are essentially lost.

E.g. If you call setDestinationChainContractAddress(dstChain, address(0)), then Address.toString(address(0)) will encode that to 42 hex characters.

So this check in burnAndCallAxelar() will always pass, since bytes(destContract).length is 42 bytes.

tom2o17 (Ondo) commented:

@kirk-baird - Ah I see. I am inclined to accept this issue. Apologies, I thought this was referencing the dstBridge not the srcBridge. As mitigation we would be able to pause the contract, and prevent this functionality, but agree with the auditor that this is not ideal.

tom2o17 (Ondo) acknowledged


The original report as published on Code4rena, by adriro. 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 contracts store chain support as non-empty strings or hashes, so there is no way to set them to a value that the checks treat as 'not supported'.

Impact

The owner cannot remove chain support, so tokens could be burned on the source chain without being minted on the destination, leading to lost funds; pausing the contract is a workaround but not ideal.

What the attacker needed

Owner privileges

The fix

The contracts should be fixed by adding functions that allow the owner to delete the stored chain support settings.

How it was found

  1. Admin configs the destination address in SourceBridge by calling setDestinationChainContractAddress with a chain name and a destination address.
  2. Admin decides to remove support for that chain.
  3. Admin calls setDestinationChainContractAddress with the same chain name and the zero address.
  4. The zero address is converted to a non-empty string, so the length check passes and messages are still routed.

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.

In a blockchain bridge, the owner can add or remove which chains are supported. Here, the way addresses are saved means that even if the owner tries to remove a chain by setting its address to zero, the system still thinks the chain is supported. This could lead to tokens being sent to a chain that is no longer supported, and those tokens might be lost.

What is Business logic?

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.

More by adriro

View all

57 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.

Business logic flaws

The lesson behind this report.

The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.