Deployer wallet retains ability to spoof validated senders after ownership transfer
The deployer wallet that created the InterchainTokenService can deploy a malicious contract at the same address on a new EVM chain, and the RemoteAddressValidator on existing chains will treat that address as a trusted sender even after ownership has been transferred to a governance multisig. This lets the deployer spoof validated senders and perform arbitrary token transfers or deploy token managers.
pcarranzav Follow with immeas
Originally disclosed on Code4rena
Submitted by pcarranzav, also found by immeas
Lines of code
https://github.com/code-423n4/2023-07-axelar/blob/9f642fe854eb11ad9f18fe028e5a8353c258e926/contracts/its/remote-address-validator/RemoteAddressValidator.sol#L72-L74 https://github.com/code-423n4/2023-07-axelar/blob/9f642fe854eb11ad9f18fe028e5a8353c258e926/contracts/its/remote-address-validator/RemoteAddressValidator.sol#L83
Impact
The InterchainTokenService is deployed using create3. This means, that its address depends on the address of the deployer wallet, the address of the Create3Deployer contract, and the salt that is extracted from a deployment key.
It should be feasible for the same deployer wallet to deploy a Create3Deployer with the same address on a new chain and use the same deployment key to deploy a contract with the same address as the InterchainTokenService, but with arbitrary implementation. A team member has confirmed on Discord that “the address will be the interchainTokenServiceAddress which is constant across EVM chains.”. However, at deployment time, only a subset of all the possible EVM chains will be supported, and more may be added in the future. When that happens, it is possible that the original deployer wallet is compromised or no longer available.
On the other hand, the addTrustedAddress function validates that the sender is the owner of the RemoteAddressValidator contract. This owner is originally the deployer wallet, but ownership may be transferred (and it would be a good practice to transfer it to a more secure governance multisig immediately after deployment). After ownership transfer, the previous owner should not be allowed to add trusted addresses.
However, the validateSender function will treat any address that is the same as the current chain’s InterchainTokenService as valid. A malicious contract deployed by the deployer wallet after the ownership transfer could be treated as valid and would have the ability to deploy token managers and standardized tokens, or perform arbitrary token transfers. This is a form of centralization risk but is also a serious privilege escalation, as it should be possible to strip the deployer of the ability to perform these actions. This gives them virtually unlimited power even after an ownership transfer.
Proof of Concept
- A deployer account is used to deploy all contracts on chain A.
- Ownership of the
RemoteAddressValidatorand all other contracts is transferred to governance multisigs. After this point, the deployer should have no ability to add trusted addresses. - The deployer account is compromised (which is easier to do than compromising a governance multisig), or a team member with access to the deployer account becomes compromised or malicious.
- The deployer repeats the same steps used for the deployment, starting from the same wallet nonce on chain B, but replaces the
InterchainTokenServicecontract with a contract that allows arbitrary messages, e.g. by adding this function to a regularInterchainTokenService:
function callContract(
string calldata destinationChain,
bytes memory payload,
uint256 gasValue,
address refundTo
) external onlyOwner {
_callContract(destinationChain, payload, gasValue, refundTo);
}
- The deployer then uses this contract to send a payload with
SELECTOR_SEND_TOKENand using the deployer address as destination to theInterchainTokenServiceon chain A. - When running
validateSenderon theRemoteAddressValidatoron chain A, this check will pass and the address will be treated as valid:
if (sourceAddressHash == interchainTokenServiceAddressHash) {
return true;
}
Therefore, the tokens will be transferred to the deployer address on chain A.
Recommended Mitigation Steps
The assumption that the InterchainTokenService address is valid in any chain is dangerous because of how the contract is created and the possibility that new EVM chains may exist in the future. A deployer EOA should not have this amount of permission for an indefinite time. I would recommend breaking that assumption and requiring that all addresses are added as trusted addresses explicitly.
A check can therefore be added to only treat the interchain token service’s address as valid if the source chain is also the same chain where the RemoteAddressValidator is deployed. The following diff shows a way to do this:
diff --git a/contracts/its/remote-address-validator/RemoteAddressValidator.sol b/contracts/its/remote-address-validator/RemoteAddressValidator.sol
index bb101e5..c2e5382 100644
--- a/contracts/its/remote-address-validator/RemoteAddressValidator.sol
+++ b/contracts/its/remote-address-validator/RemoteAddressValidator.sol
@@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import { IRemoteAddressValidator } from '../interfaces/IRemoteAddressValidator.sol';
import { AddressToString } from '../../gmp-sdk/util/AddressString.sol';
import { Upgradable } from '../../gmp-sdk/upgradable/Upgradable.sol';
+import { StringToBytes32 } from '../../gmp-sdk/util/Bytes32String.sol';
/**
* @title RemoteAddressValidator
@@ -11,23 +12,25 @@ import { Upgradable } from '../../gmp-sdk/upgradable/Upgradable.sol';
*/
contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
using AddressToString for address;
+ using StringToBytes32 for string;
mapping(string => bytes32) public remoteAddressHashes;
mapping(string => string) public remoteAddresses;
address public immutable interchainTokenServiceAddress;
bytes32 public immutable interchainTokenServiceAddressHash;
mapping(string => bool) public supportedByGateway;
-
+ bytes32 public immutable currentChainName;
bytes32 private constant CONTRACT_ID = keccak256('remote-address-validator');
/**
* @dev Constructs the RemoteAddressValidator contract, both array parameters must be equal in length
* @param _interchainTokenServiceAddress Address of the interchain token service
*/
- constructor(address _interchainTokenServiceAddress) {
+ constructor(address _interchainTokenServiceAddress, string memory _chainName) {
if (_interchainTokenServiceAddress == address(0)) revert ZeroAddress();
interchainTokenServiceAddress = _interchainTokenServiceAddress;
interchainTokenServiceAddressHash = keccak256(bytes(_lowerCase(interchainTokenServiceAddress.toString())));
+ currentChainName = _chainName.toBytes32();
}
/**
@@ -69,7 +72,7 @@ contract RemoteAddressValidator is IRemoteAddressValidator, Upgradable {
function validateSender(string calldata sourceChain, string calldata sourceAddress) external view returns (bool) {
string memory sourceAddressLC = _lowerCase(sourceAddress);
bytes32 sourceAddressHash = keccak256(bytes(sourceAddressLC));
- if (sourceAddressHash == interchainTokenServiceAddressHash) {
+ if (sourceAddressHash == interchainTokenServiceAddressHash && sourceChain.toBytes32() == currentChainName) {
return true;
}
return sourceAddressHash == remoteAddressHashes[sourceChain];
Assessed type
Access Control
pcarranzav (warden) commented:
@berndartmueller - I’d like to point out this one, which was marked as duplicate of Issue 348 which is marked as invalid. The argumentation in my submission is different, as it is framed as a privilege escalation of the deployer wallet, which persists after ownership transfer and in the hypothetical of a new EVM chain being added to the Axelar network.
This modifies the trust assumptions of the protocol, as users can reasonably expect to trust the multisig Owner, but not a deployer EOA, for an indefinite time. In the closed issue, @deanamiel commented “It would be impossible to deploy a different contract at this address because the address will depend on the deployer address and salt.” However, there is a different level of “impossible” when comparing an EOA to a multisig and users now need to trust that nobody with access to that EOA is compromised or that it is disposed of properly.
The probability of this being exploited is low (requires deployer EOA compromise and new chain added to the network), but the impact would be huge, which is why I honestly believe it warrants a Medium severity and is a valid finding to surface in the report so that users are aware.
berndartmueller (judge) commented:
@pcarranzav - thanks for pointing this out! I’ve marked your submission as the primary report due to pointing out the deployer privilege escalation. But I also consider #348 a duplicate, as the recommended fix would also fix the underlying issue.
Overall, I agree with the outlined privilege escalation. Even though the likelihood of this to happen is low, the impact would be critical. Thus, I consider medium severity to be appropriate.
deanamiel (Axelar) acknowledged and commented:
We acknowledge the severity, and while we’ve considered using a deployer multisig contract which reduces this risk, our operations team is planning on whitelisting explicitly to minimize the impact of the deployer or a non-whitelisted chain being compromised. Note that
RemoteAddressValidatoris deployed on the destination chain, so the recommendation to compare the source chain to the chain in remote address validator won’t work.
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 validateSender function treats any source address equal to the InterchainTokenService address as valid without checking that the source chain is the same as the current chain, so a contract deployed at the same address on another chain is automatically trusted.
Impact
A compromised or malicious deployer could spoof validated senders and perform arbitrary token transfers or deploy token managers, though the likelihood is low because it requires deployer compromise and a new chain being added; the team plans to whitelist explicitly to reduce the risk.
What the attacker needed
Deployer account compromised or malicious; new EVM chain added to the network; same deployment key and nonce reused
The fix
The assumption that the InterchainTokenService address is valid on any chain should be broken by requiring all addresses to be added as trusted addresses explicitly, or by only treating the address as valid when the source chain matches the current chain, though the team notes the latter…
How it was found
- Deploy all contracts on chain A using a deployer account.
- Transfer ownership of RemoteAddressValidator and other contracts to governance multisigs.
- Compromise the deployer account or have a malicious team member with access to it.
- On chain B, repeat the same deployment steps from the same wallet nonce but replace InterchainTokenService with a contract that allows arbitrary messages.
- Use the malicious contract to send a payload with SELECTOR_SEND_TOKEN and the deployer address as destination to the InterchainTokenService on chain A.
- The validateSender check on chain A passes because the source address matches the InterchainTokenService address, so tokens are transferred to the deployer.
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 smart contract's address can be recreated on a different blockchain if the same wallet deploys it with the same setup. The system assumed that any contract at the known InterchainTokenService address is trustworthy, so the original deployer could later put a fake contract at that address on a new chain and the old chains would accept its messages. This means the deployer keeps a powerful backdoor even after handing over control to a safer multisig wallet.
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.