Skip to content

Commit

Permalink
Merge pull request #70 from immutable/SMR-2127/adaptor/disable_execut…
Browse files Browse the repository at this point in the history
…eWithToken

Audit: Disable call to executeWithToken on adaptors
  • Loading branch information
ermyas authored Dec 12, 2023
2 parents 23e13f7 + 8ed3ec7 commit 1923f80
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/child/ChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,19 @@ contract ChildAxelarBridgeAdaptor is
childBridge.onMessageReceive(_payload);
}

/**
* @inheritdoc AxelarExecutable
* @dev This function is called by the parent `AxelarExecutable` contract's `executeWithToken()` function.
* However, this function is not required for the bridge, and thus reverts with an `UnsupportedOperation` error.
*/
function _executeWithToken(string calldata, string calldata, bytes calldata, string calldata, uint256)
internal
pure
override
{
revert UnsupportedOperation();
}

// slither-disable-next-line unused-state,naming-convention
uint256[50] private __gapChildAxelarBridgeAdaptor;
}
2 changes: 2 additions & 0 deletions src/interfaces/child/IChildAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ interface IChildAxelarBridgeAdaptorErrors {
error InvalidSourceChain();
/// @notice Error when the source chain's message sender is not a recognised address.
error InvalidSourceAddress();
/// @notice Error when a function that isn't supported by the adaptor is called.
error UnsupportedOperation();
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/interfaces/root/IRootAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ interface IRootAxelarBridgeAdaptorErrors {
error InvalidSourceAddress();
/// @notice Error when a message received has invalid source chain.
error InvalidSourceChain();
/// @notice Error when a function that isn't supported by the adaptor is called.
error UnsupportedOperation();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/root/RootAxelarBridgeAdaptor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ contract RootAxelarBridgeAdaptor is
rootBridge.onMessageReceive(_payload);
}

/**
* @inheritdoc AxelarExecutable
* @dev This function is called by the parent `AxelarExecutable` contract's `executeWithToken()` function.
* However, this function is not required for the bridge, and thus reverts with an `UnsupportedOperation` error.
*/
function _executeWithToken(string calldata, string calldata, bytes calldata, string calldata, uint256)
internal
pure
override
{
revert UnsupportedOperation();
}

// slither-disable-next-line unused-state,naming-convention
uint256[50] private __gapRootAxelarBridgeAdaptor;
}
8 changes: 8 additions & 0 deletions test/mocks/child/MockChildAxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,13 @@ contract MockChildAxelarGateway {
return true;
}

function validateContractCallAndMint(bytes32, string calldata, string calldata, bytes32, string calldata, uint256)
external
pure
returns (bool)
{
return true;
}

function callContract(string memory childChain, string memory childBridgeAdaptor, bytes memory payload) external {}
}
8 changes: 8 additions & 0 deletions test/mocks/root/MockAxelarGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,12 @@ contract MockAxelarGateway {
function validateContractCall(bytes32, string calldata, string calldata, bytes32) external pure returns (bool) {
return true;
}

function validateContractCallAndMint(bytes32, string calldata, string calldata, bytes32, string calldata, uint256)
external
pure
returns (bool)
{
return true;
}
}
15 changes: 15 additions & 0 deletions test/unit/child/ChildAxelarBridgeAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -489,4 +489,19 @@ contract ChildAxelarBridgeAdaptorUnitTest is Test, IChildAxelarBridgeAdaptorErro
axelarAdaptor.updateGasService(address(0));
vm.stopPrank();
}

/**
* UNSUPPORTED OPERATION
*/

/// Check that executeWithToken function in AxelarExecutable cannot be called
function test_RevertIf_executeWithTokenCalled() public {
bytes32 commandId = bytes32("testCommandId");
bytes memory payload = abi.encodePacked("payload");
string memory tokenSymbol = "TST";
uint256 amount = 100;

vm.expectRevert(UnsupportedOperation.selector);
axelarAdaptor.executeWithToken(commandId, ROOT_CHAIN_NAME, ROOT_BRIDGE_ADAPTOR, payload, tokenSymbol, amount);
}
}
17 changes: 17 additions & 0 deletions test/unit/root/RootAxelarBridgeAdaptor.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -450,4 +450,21 @@ contract RootAxelarBridgeAdaptorTest is Test, IRootAxelarBridgeAdaptorEvents, IR
vm.expectRevert(ZeroAddresses.selector);
axelarAdaptor.updateGasService(address(0));
}

/**
* UNSUPPORTED OPERATION
*/

/// Check that executeWithToken function in AxelarExecutable cannot be called
function test_RevertIf_executeWithTokenCalled() public {
bytes32 commandId = bytes32("testCommandId");
bytes memory payload = abi.encodePacked("payload");
string memory tokenSymbol = "TST";
uint256 amount = 100;

vm.expectRevert(UnsupportedOperation.selector);
axelarAdaptor.executeWithToken(
commandId, CHILD_CHAIN_NAME, CHILD_BRIDGE_ADAPTOR_STRING, payload, tokenSymbol, amount
);
}
}

0 comments on commit 1923f80

Please sign in to comment.