From 69cc47e69869b1ca793b66aeb719dca9dfe470bc Mon Sep 17 00:00:00 2001 From: Foivos Date: Mon, 9 Oct 2023 11:54:31 +0300 Subject: [PATCH] feat: using a custom implementation of AxelarExecutable (#114) * using a custom implementation of AxelarExecutable * Fixed an import bug. --------- Co-authored-by: Milap Sheth --- .../InterchainTokenService.sol | 40 ++++++++++++------- .../interfaces/IInterchainTokenService.sol | 1 + 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/contracts/interchain-token-service/InterchainTokenService.sol b/contracts/interchain-token-service/InterchainTokenService.sol index 4ba539c6..6c3392eb 100644 --- a/contracts/interchain-token-service/InterchainTokenService.sol +++ b/contracts/interchain-token-service/InterchainTokenService.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import { IAxelarGasService } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol'; -import { AxelarExecutable } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol'; +import { IAxelarGateway } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol'; import { SafeTokenTransferFrom } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/SafeTransfer.sol'; import { IERC20 } from '@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IERC20.sol'; @@ -33,15 +33,7 @@ import { Multicall } from '../utils/Multicall.sol'; * It (mostly) does not handle tokens, but is responsible for the messaging that needs to occur for cross chain transfers to happen. * @dev The only storage used here is for ExpressCalls */ -contract InterchainTokenService is - IInterchainTokenService, - AxelarExecutable, - Upgradable, - Operatable, - ExpressCallHandler, - Pausable, - Multicall -{ +contract InterchainTokenService is IInterchainTokenService, Upgradable, Operatable, ExpressCallHandler, Pausable, Multicall { using StringToBytes32 for string; using Bytes32ToString for bytes32; using AddressBytesUtils for bytes; @@ -51,6 +43,7 @@ contract InterchainTokenService is address internal immutable implementationMintBurn; address internal immutable implementationLockUnlockFee; address internal immutable implementationLiquidityPool; + IAxelarGateway public immutable gateway; IAxelarGasService public immutable gasService; IRemoteAddressValidator public immutable remoteAddressValidator; address public immutable tokenManagerDeployer; @@ -84,13 +77,16 @@ contract InterchainTokenService is address gasService_, address remoteAddressValidator_, address[] memory tokenManagerImplementations - ) AxelarExecutable(gateway_) { + ) { if ( remoteAddressValidator_ == address(0) || gasService_ == address(0) || tokenManagerDeployer_ == address(0) || - standardizedTokenDeployer_ == address(0) + standardizedTokenDeployer_ == address(0) || + gateway_ == address(0) ) revert ZeroAddress(); + + gateway = IAxelarGateway(gateway_); remoteAddressValidator = IRemoteAddressValidator(remoteAddressValidator_); gasService = IAxelarGasService(gasService_); tokenManagerDeployer = tokenManagerDeployer_; @@ -530,11 +526,16 @@ contract InterchainTokenService is * @param sourceAddress The address where the transaction originates from * @param payload The encoded data payload for the transaction */ - function _execute( + function execute( + bytes32 commandId, string calldata sourceChain, string calldata sourceAddress, bytes calldata payload - ) internal override onlyRemoteService(sourceChain, sourceAddress) notPaused { + ) external onlyRemoteService(sourceChain, sourceAddress) notPaused { + bytes32 payloadHash = keccak256(payload); + + if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, payloadHash)) revert NotApprovedByGateway(); + uint256 selector = abi.decode(payload, (uint256)); if (selector == SELECTOR_SEND_TOKEN || selector == SELECTOR_SEND_TOKEN_WITH_DATA) { _processSendTokenPayload(sourceChain, payload, selector); @@ -547,6 +548,17 @@ contract InterchainTokenService is } } + function executeWithToken( + bytes32 /*commandId*/, + string calldata /*sourceChain*/, + string calldata /*sourceAddress*/, + bytes calldata /*payload*/, + string calldata /*tokenSymbol*/, + uint256 /*amount*/ + ) external pure { + revert ExecuteWithTokenNotSupported(); + } + /** * @notice Processes the payload data for a send token call * @param sourceChain The chain where the transaction originates from diff --git a/contracts/interfaces/IInterchainTokenService.sol b/contracts/interfaces/IInterchainTokenService.sol index a46bcfd2..a9325220 100644 --- a/contracts/interfaces/IInterchainTokenService.sol +++ b/contracts/interfaces/IInterchainTokenService.sol @@ -26,6 +26,7 @@ interface IInterchainTokenService is ITokenManagerType, IExpressCallHandler, IAx error SelectorUnknown(); error InvalidMetadataVersion(uint32 version); error AlreadyExecuted(bytes32 commandId); + error ExecuteWithTokenNotSupported(); error InvalidExpressSelector(); event TokenSent(bytes32 indexed tokenId, string destinationChain, bytes destinationAddress, uint256 indexed amount);