diff --git a/src/adapters/BaseSenderAdapter.sol b/src/adapters/BaseSenderAdapter.sol index 6e1435b..66b26b7 100644 --- a/src/adapters/BaseSenderAdapter.sol +++ b/src/adapters/BaseSenderAdapter.sol @@ -77,10 +77,10 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter { ////////////////////////////////////////////////////////////////*/ /// @notice generates a new message id by incrementing nonce - /// @param _toChainId is the destination chainId. + /// @param _receiverChainId is the destination chainId. /// @param _to is the contract address on the destination chain. - function _getNewMessageId(uint256 _toChainId, address _to) internal returns (bytes32 messageId) { - messageId = keccak256(abi.encodePacked(block.chainid, _toChainId, nonce, address(this), _to)); + function _getNewMessageId(uint256 _receiverChainId, address _to) internal returns (bytes32 messageId) { + messageId = keccak256(abi.encodePacked(block.chainid, _receiverChainId, nonce, address(this), _to)); ++nonce; } } diff --git a/src/adapters/axelar/AxelarReceiverAdapter.sol b/src/adapters/axelar/AxelarReceiverAdapter.sol index 68cc8f9..3ba60d2 100644 --- a/src/adapters/axelar/AxelarReceiverAdapter.sol +++ b/src/adapters/axelar/AxelarReceiverAdapter.sol @@ -27,7 +27,7 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable { /*///////////////////////////////////////////////////////////////// STATE VARIABLES ////////////////////////////////////////////////////////////////*/ - string public senderChain; + string public senderChainId; mapping(bytes32 => bool) public isMessageExecuted; mapping(bytes32 => bool) public commandIdStatus; @@ -36,19 +36,21 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable { CONSTRUCTOR ////////////////////////////////////////////////////////////////*/ /// @param _gateway is axelar gateway contract address. - /// @param _senderChain is the chain id of the sender chain. + /// @param _senderChainId is the chain id of the sender chain. /// @param _receiverGAC is global access controller. - constructor(address _gateway, string memory _senderChain, address _receiverGAC) BaseReceiverAdapter(_receiverGAC) { + constructor(address _gateway, string memory _senderChainId, address _receiverGAC) + BaseReceiverAdapter(_receiverGAC) + { if (_gateway == address(0)) { revert Error.ZERO_ADDRESS_INPUT(); } - if (bytes(_senderChain).length == 0) { + if (bytes(_senderChainId).length == 0) { revert Error.INVALID_SENDER_CHAIN_ID(); } gateway = IAxelarGateway(_gateway); - senderChain = _senderChain; + senderChainId = _senderChainId; } /*///////////////////////////////////////////////////////////////// @@ -58,32 +60,32 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable { /// @dev accepts new cross-chain messages from axelar gateway /// @inheritdoc IAxelarExecutable function execute( - bytes32 commandId, - string calldata sourceChain, - string calldata sourceAddress, - bytes calldata payload + bytes32 _commandId, + string calldata _sourceChainId, + string calldata _sourceAddress, + bytes calldata _payload ) external override { /// @dev step-1: validate incoming chain id - if (keccak256(bytes(sourceChain)) != keccak256(bytes(senderChain))) { + if (keccak256(bytes(_sourceChainId)) != keccak256(bytes(senderChainId))) { revert Error.INVALID_SENDER_CHAIN_ID(); } /// @dev step-2: validate the source address - if (sourceAddress.toAddress() != senderAdapter) { + if (_sourceAddress.toAddress() != senderAdapter) { revert Error.INVALID_SENDER_ADAPTER(); } /// @dev step-3: validate the contract call - if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, keccak256(payload))) { + if (!gateway.validateContractCall(_commandId, _sourceChainId, _sourceAddress, keccak256(_payload))) { revert Error.NOT_APPROVED_BY_GATEWAY(); } /// decode the cross-chain payload - AdapterPayload memory decodedPayload = abi.decode(payload, (AdapterPayload)); + AdapterPayload memory decodedPayload = abi.decode(_payload, (AdapterPayload)); bytes32 msgId = decodedPayload.msgId; /// @dev step-4: check for duplicate message - if (commandIdStatus[commandId] || isMessageExecuted[msgId]) { + if (commandIdStatus[_commandId] || isMessageExecuted[msgId]) { revert MessageIdAlreadyExecuted(msgId); } @@ -98,7 +100,7 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable { } isMessageExecuted[msgId] = true; - commandIdStatus[commandId] = true; + commandIdStatus[_commandId] = true; MessageLibrary.Message memory _data = abi.decode(decodedPayload.data, (MessageLibrary.Message)); diff --git a/src/adapters/axelar/AxelarSenderAdapter.sol b/src/adapters/axelar/AxelarSenderAdapter.sol index f98e801..b383abb 100644 --- a/src/adapters/axelar/AxelarSenderAdapter.sol +++ b/src/adapters/axelar/AxelarSenderAdapter.sol @@ -35,32 +35,32 @@ contract AxelarSenderAdapter is BaseSenderAdapter { ////////////////////////////////////////////////////////////////*/ /// @dev sendMessage sends a message to Axelar. - /// @param _toChainId The ID of the destination chain. + /// @param _receiverChainId The ID of the destination chain. /// @param _to The address of the contract on the destination chain that will receive the message. /// @param _data The data to be included in the message. - function dispatchMessage(uint256 _toChainId, address _to, bytes calldata _data) + function dispatchMessage(uint256 _receiverChainId, address _to, bytes calldata _data) external payable override onlyMultiBridgeMessageSender returns (bytes32 msgId) { - address receiverAdapter = receiverAdapters[_toChainId]; + address receiverAdapter = receiverAdapters[_receiverChainId]; if (receiverAdapter == address(0)) { revert Error.ZERO_RECEIVER_ADAPTER(); } - string memory destinationChain = chainIdMap[_toChainId]; + string memory destinationChain = chainIdMap[_receiverChainId]; if (bytes(destinationChain).length == 0) { revert Error.INVALID_DST_CHAIN(); } - msgId = _getNewMessageId(_toChainId, _to); + msgId = _getNewMessageId(_receiverChainId, _to); _callContract(destinationChain, receiverAdapter, msgId, _to, _data); - emit MessageDispatched(msgId, msg.sender, _toChainId, _to, _data); + emit MessageDispatched(msgId, msg.sender, _receiverChainId, _to, _data); } /// @dev maps the MMA chain id to bridge specific chain id @@ -87,26 +87,26 @@ contract AxelarSenderAdapter is BaseSenderAdapter { ////////////////////////////////////////////////////////////////*/ /// @dev Sends a message to the IAxelarRelayer contract for relaying to the Axelar Network. - /// @param destinationChain The name of the destination chain. - /// @param receiverAdapter The address of the adapter on the destination chain that will receive the message. - /// @param msgId The ID of the message to be relayed. - /// @param multibridgeReceiver The address of the MultibridgeReceiver contract on the destination chain that will receive the message. - /// @param data The bytes data to pass to the contract on the destination chain. + /// @param _destinationChain The name of the destination chain. + /// @param _receiverAdapter The address of the adapter on the destination chain that will receive the message. + /// @param _msgId The ID of the message to be relayed. + /// @param _multibridgeReceiver The address of the MultibridgeReceiver contract on the destination chain that will receive the message. + /// @param _data The bytes data to pass to the contract on the destination chain. function _callContract( - string memory destinationChain, - address receiverAdapter, - bytes32 msgId, - address multibridgeReceiver, - bytes calldata data + string memory _destinationChain, + address _receiverAdapter, + bytes32 _msgId, + address _multibridgeReceiver, + bytes calldata _data ) internal { - string memory receiverAdapterInString = StringAddressConversion.toString(receiverAdapter); + string memory receiverAdapterInString = StringAddressConversion.toString(_receiverAdapter); bytes memory payload = - abi.encode(AdapterPayload(msgId, address(msg.sender), receiverAdapter, multibridgeReceiver, data)); + abi.encode(AdapterPayload(_msgId, address(msg.sender), _receiverAdapter, _multibridgeReceiver, _data)); gasService.payNativeGasForContractCall{value: msg.value}( - msg.sender, destinationChain, receiverAdapterInString, payload, msg.sender + msg.sender, _destinationChain, receiverAdapterInString, payload, msg.sender ); - gateway.callContract(destinationChain, receiverAdapterInString, payload); + gateway.callContract(_destinationChain, receiverAdapterInString, payload); } } diff --git a/src/adapters/axelar/interfaces/IAxelarExecutable.sol b/src/adapters/axelar/interfaces/IAxelarExecutable.sol index d7e2499..a73743d 100644 --- a/src/adapters/axelar/interfaces/IAxelarExecutable.sol +++ b/src/adapters/axelar/interfaces/IAxelarExecutable.sol @@ -2,14 +2,14 @@ pragma solidity >=0.8.9; interface IAxelarExecutable { - /// @param commandId is axelar specific message identifier - /// @param sourceChain is the identifier for source chain - /// @param sourceAddress is the message sender address on source chain - /// @param payload is the cross-chain message sent + /// @param _commandId is axelar specific message identifier + /// @param _sourceChainId is the identifier for source chain + /// @param _sourceAddress is the message sender address on source chain + /// @param _payload is the cross-chain message sent function execute( - bytes32 commandId, - string calldata sourceChain, - string calldata sourceAddress, - bytes calldata payload + bytes32 _commandId, + string calldata _sourceChainId, + string calldata _sourceAddress, + bytes calldata _payload ) external; } diff --git a/src/adapters/axelar/interfaces/IAxelarGasService.sol b/src/adapters/axelar/interfaces/IAxelarGasService.sol index f3b1142..c440c3a 100644 --- a/src/adapters/axelar/interfaces/IAxelarGasService.sol +++ b/src/adapters/axelar/interfaces/IAxelarGasService.sol @@ -5,10 +5,10 @@ pragma solidity >=0.8.9; interface IAxelarGasService { // This is called on the source chain before calling the gateway to execute a remote contract. function payNativeGasForContractCall( - address sender, - string calldata destinationChain, - string calldata destinationAddress, - bytes calldata payload, - address refundAddress + address _sender, + string calldata _destinationChain, + string calldata _destinationAddress, + bytes calldata _payload, + address _refundAddress ) external payable; } diff --git a/src/adapters/axelar/interfaces/IAxelarGateway.sol b/src/adapters/axelar/interfaces/IAxelarGateway.sol index d395f09..02e5bd0 100644 --- a/src/adapters/axelar/interfaces/IAxelarGateway.sol +++ b/src/adapters/axelar/interfaces/IAxelarGateway.sol @@ -2,21 +2,21 @@ pragma solidity >=0.8.9; interface IAxelarGateway { - function callContract(string calldata destinationChain, string calldata contractAddress, bytes calldata payload) + function callContract(string calldata _destinationChain, string calldata _contractAddress, bytes calldata _payload) external; function isContractCallApproved( - bytes32 commandId, - string calldata sourceChain, - string calldata sourceAddress, - address contractAddress, - bytes32 payloadHash + bytes32 _commandId, + string calldata _sourceChain, + string calldata _sourceAddress, + address _contractAddress, + bytes32 _payloadHash ) external view returns (bool); function validateContractCall( - bytes32 commandId, - string calldata sourceChain, - string calldata sourceAddress, - bytes32 payloadHash + bytes32 _commandId, + string calldata _sourceChain, + string calldata _sourceAddress, + bytes32 _payloadHash ) external returns (bool); } diff --git a/src/adapters/wormhole/WormholeReceiverAdapter.sol b/src/adapters/wormhole/WormholeReceiverAdapter.sol index 1560815..309ded3 100644 --- a/src/adapters/wormhole/WormholeReceiverAdapter.sol +++ b/src/adapters/wormhole/WormholeReceiverAdapter.sol @@ -21,7 +21,7 @@ import "../BaseReceiverAdapter.sol"; contract WormholeReceiverAdapter is BaseReceiverAdapter, IWormholeReceiver { string public constant name = "WORMHOLE"; address public immutable relayer; - uint16 public immutable senderChain; + uint16 public immutable senderChainId; /*///////////////////////////////////////////////////////////////// STATE VARIABLES @@ -46,20 +46,20 @@ contract WormholeReceiverAdapter is BaseReceiverAdapter, IWormholeReceiver { ////////////////////////////////////////////////////////////////*/ /// @param _relayer is wormhole relayer. - /// @param _senderChain is the chain id of the sender chain. + /// @param _senderChainId is the chain id of the sender chain. /// @param _receiverGAC is global access controller. /// note: https://docs.wormhole.com/wormhole/quick-start/cross-chain-dev/automatic-relayer - constructor(address _relayer, uint16 _senderChain, address _receiverGAC) BaseReceiverAdapter(_receiverGAC) { + constructor(address _relayer, uint16 _senderChainId, address _receiverGAC) BaseReceiverAdapter(_receiverGAC) { if (_relayer == address(0)) { revert Error.ZERO_ADDRESS_INPUT(); } - if (_senderChain == uint16(0)) { + if (_senderChainId == uint16(0)) { revert Error.INVALID_SENDER_CHAIN_ID(); } relayer = _relayer; - senderChain = _senderChain; + senderChainId = _senderChainId; } /*///////////////////////////////////////////////////////////////// @@ -68,34 +68,34 @@ contract WormholeReceiverAdapter is BaseReceiverAdapter, IWormholeReceiver { /// @inheritdoc IWormholeReceiver function receiveWormholeMessages( - bytes memory payload, + bytes memory _payload, bytes[] memory, - bytes32 sourceAddress, - uint16 sourceChain, - bytes32 deliveryHash + bytes32 _sourceAddress, + uint16 _sourceChainId, + bytes32 _deliveryHash ) public payable override onlyRelayerContract { /// @dev validate the caller (done in modifier) /// @dev step-1: validate incoming chain id - if (sourceChain != senderChain) { + if (_sourceChainId != senderChainId) { revert Error.INVALID_SENDER_CHAIN_ID(); } /// @dev step-2: validate the source address - if (TypeCasts.bytes32ToAddress(sourceAddress) != senderAdapter) { + if (TypeCasts.bytes32ToAddress(_sourceAddress) != senderAdapter) { revert Error.INVALID_SENDER_ADAPTER(); } /// decode the cross-chain payload - AdapterPayload memory decodedPayload = abi.decode(payload, (AdapterPayload)); + AdapterPayload memory decodedPayload = abi.decode(_payload, (AdapterPayload)); bytes32 msgId = decodedPayload.msgId; /// @dev step-3: check for duplicate message - if (isMessageExecuted[msgId] || deliveryHashStatus[deliveryHash]) { + if (isMessageExecuted[msgId] || deliveryHashStatus[_deliveryHash]) { revert MessageIdAlreadyExecuted(msgId); } isMessageExecuted[decodedPayload.msgId] = true; - deliveryHashStatus[deliveryHash] = true; + deliveryHashStatus[_deliveryHash] = true; /// @dev step-4: validate the receive adapter if (decodedPayload.receiverAdapter != address(this)) { diff --git a/src/adapters/wormhole/WormholeSenderAdapter.sol b/src/adapters/wormhole/WormholeSenderAdapter.sol index ea3cb61..38504cf 100644 --- a/src/adapters/wormhole/WormholeSenderAdapter.sol +++ b/src/adapters/wormhole/WormholeSenderAdapter.sol @@ -32,26 +32,26 @@ contract WormholeSenderAdapter is BaseSenderAdapter { ////////////////////////////////////////////////////////////////*/ /// @notice sends a message via wormhole relayer - function dispatchMessage(uint256 _toChainId, address _to, bytes calldata _data) + function dispatchMessage(uint256 _receiverChainId, address _to, bytes calldata _data) external payable override onlyMultiBridgeMessageSender returns (bytes32 msgId) { - address receiverAdapter = receiverAdapters[_toChainId]; + address receiverAdapter = receiverAdapters[_receiverChainId]; if (receiverAdapter == address(0)) { revert Error.ZERO_RECEIVER_ADAPTER(); } - uint16 wormChainId = chainIdMap[_toChainId]; + uint16 wormChainId = chainIdMap[_receiverChainId]; if (wormChainId == 0) { revert Error.INVALID_DST_CHAIN(); } - msgId = _getNewMessageId(_toChainId, _to); + msgId = _getNewMessageId(_receiverChainId, _to); bytes memory payload = abi.encode(AdapterPayload(msgId, msg.sender, receiverAdapter, _to, _data)); relayer.sendPayloadToEvm{value: msg.value}( @@ -63,7 +63,7 @@ contract WormholeSenderAdapter is BaseSenderAdapter { senderGAC.msgDeliveryGasLimit() ); - emit MessageDispatched(msgId, msg.sender, _toChainId, _to, _data); + emit MessageDispatched(msgId, msg.sender, _receiverChainId, _to, _data); } /// @dev maps the MMA chain id to bridge specific chain id diff --git a/src/interfaces/EIP5164/MessageDispatcher.sol b/src/interfaces/EIP5164/MessageDispatcher.sol index fce2a26..5e2c15b 100644 --- a/src/interfaces/EIP5164/MessageDispatcher.sol +++ b/src/interfaces/EIP5164/MessageDispatcher.sol @@ -11,6 +11,6 @@ interface MessageDispatcher { * @dev The MessageDispatched event MUST be emitted by the MessageDispatcher when an individual message is dispatched. */ event MessageDispatched( - bytes32 indexed messageId, address indexed from, uint256 indexed toChainId, address to, bytes data + bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data ); } diff --git a/src/interfaces/EIP5164/SingleMessageDispatcher.sol b/src/interfaces/EIP5164/SingleMessageDispatcher.sol index f910b79..22deabd 100644 --- a/src/interfaces/EIP5164/SingleMessageDispatcher.sol +++ b/src/interfaces/EIP5164/SingleMessageDispatcher.sol @@ -6,14 +6,14 @@ import "./MessageDispatcher.sol"; /** * @dev The SingleMessageDispatcher is an extension of MessageDispatcher that defines a method, dispatchMessage, - * for dispatching an individual message to be executed on the toChainId. + * for dispatching an individual message to be executed on the receiverChainId. * More about SingleMessageDispatcher of EIP5164, see https://eips.ethereum.org/EIPS/eip-5164#singlemessagedispatcher. */ interface SingleMessageDispatcher is MessageDispatcher { /** - * @dev A method for dispatching an individual message to be executed on the toChainId. + * @dev A method for dispatching an individual message to be executed on the receiver chain. */ - function dispatchMessage(uint256 toChainId, address to, bytes calldata data) + function dispatchMessage(uint256 _receiverChainId, address _to, bytes calldata _data) external payable returns (bytes32 messageId); diff --git a/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol b/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol index d9dd95c..96e6d35 100644 --- a/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol +++ b/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol @@ -38,7 +38,7 @@ contract AxelarReceiverAdapterTest is Setup { // checks existing setup assertEq(address(adapter.gateway()), POLYGON_GATEWAY); assertEq(address(adapter.receiverGAC()), contractAddress[DST_CHAIN_ID]["GAC"]); - assertEq(adapter.senderChain(), "ethereum"); + assertEq(adapter.senderChainId(), "ethereum"); } /// @dev constructor with invalid parameters should fail diff --git a/test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol b/test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol index 07bbb7f..7e817ac 100644 --- a/test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol +++ b/test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol @@ -11,7 +11,7 @@ import {AxelarSenderAdapter} from "src/adapters/axelar/AxelarSenderAdapter.sol"; contract AxelarSenderAdapterTest is Setup { event MessageDispatched( - bytes32 indexed messageId, address indexed from, uint256 indexed toChainId, address to, bytes data + bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data ); address senderAddr; diff --git a/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol b/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol index f9175e5..6ac06b8 100644 --- a/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol +++ b/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol @@ -70,7 +70,7 @@ contract WormholeReceiverAdapterTest is Setup { adapter.updateSenderAdapter(address(42)); assertEq(adapter.senderAdapter(), address(42)); - assertEq(adapter.senderChain(), uint16(2)); + assertEq(adapter.senderChainId(), uint16(2)); } /// @dev only global owner can update sender adapter diff --git a/test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol b/test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol index a96f037..58ad9b5 100644 --- a/test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol +++ b/test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol @@ -12,7 +12,7 @@ import {IWormholeRelayer} from "lib/wormhole-solidity-sdk/src/interfaces/IWormho contract WormholeSenderAdapterTest is Setup { event MessageDispatched( - bytes32 indexed messageId, address indexed from, uint256 indexed toChainId, address to, bytes data + bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data ); address senderAddr;