Skip to content

Commit 18db32c

Browse files
Amxxfrangio
andauthored
Add messageId in IERC7786Receiver.executeMessage (#88)
Co-authored-by: Francisco Giordano <[email protected]>
1 parent 3342e64 commit 18db32c

16 files changed

+40
-22
lines changed

contracts/crosschain/ERC7786Aggregator.sol

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
180180
* not revert. Any value accrued that way can be recovered by the admin using the {sweep} function.
181181
*/
182182
function executeMessage(
183+
string calldata /*messageId*/, // gateway specific, empty or unique
183184
string calldata sourceChain, // CAIP-2 chain identifier
184185
string calldata sender, // CAIP-10 account address (does not include the chain identifier)
185186
bytes calldata payload,
@@ -218,7 +219,7 @@ contract ERC7786Aggregator is IERC7786GatewaySource, IERC7786Receiver, Ownable,
218219

219220
bytes memory call = abi.encodeCall(
220221
IERC7786Receiver.executeMessage,
221-
(sourceChain, originalSender, unwrappedPayload, attributes)
222+
(uint256(id).toHexString(32), sourceChain, originalSender, unwrappedPayload, attributes)
222223
);
223224
// slither-disable-next-line reentrancy-no-eth
224225
(bool success, bytes memory returndata) = receiver.parseAddress().call(call);

contracts/crosschain/axelar/AxelarGatewayBase.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ abstract contract AxelarGatewayBase is Ownable {
2626
error RemoteGatewayAlreadyRegistered(string caip2);
2727

2828
/// @dev Axelar's official gateway for the current chain.
29-
IAxelarGateway public immutable localGateway;
29+
IAxelarGateway internal immutable _axelarGateway;
3030

3131
mapping(string caip2 => string remoteGateway) private _remoteGateways;
3232
mapping(string caip2OrAxelar => string axelarOrCaip2) private _chainEquivalence;
3333

3434
/// @dev Sets the local gateway address (i.e. Axelar's official gateway for the current chain).
3535
constructor(IAxelarGateway _gateway) {
36-
localGateway = _gateway;
36+
_axelarGateway = _gateway;
3737
}
3838

3939
/// @dev Returns the equivalent chain given an id that can be either CAIP-2 or an Axelar network identifier.

contracts/crosschain/axelar/AxelarGatewayDestination.sol

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
1414
* workflow into the standard ERC-7786.
1515
*/
1616
abstract contract AxelarGatewayDestination is AxelarGatewayBase, AxelarExecutable {
17-
using Strings for address;
18-
using Strings for string;
17+
using Strings for *;
1918

2019
error InvalidOriginGateway(string sourceChain, string axelarSourceAddress);
2120
error ReceiverExecutionFailed();
@@ -33,10 +32,13 @@ abstract contract AxelarGatewayDestination is AxelarGatewayBase, AxelarExecutabl
3332
* the message)
3433
*/
3534
function _execute(
35+
bytes32 commandId,
3636
string calldata axelarSourceChain, // chain of the remote gateway - axelar format
3737
string calldata axelarSourceAddress, // address of the remote gateway
3838
bytes calldata adapterPayload
3939
) internal override {
40+
string memory messageId = uint256(commandId).toHexString(32);
41+
4042
// Parse the package
4143
(string memory sender, string memory receiver, bytes memory payload, bytes[] memory attributes) = abi.decode(
4244
adapterPayload,
@@ -53,6 +55,7 @@ abstract contract AxelarGatewayDestination is AxelarGatewayBase, AxelarExecutabl
5355
);
5456

5557
bytes4 result = IERC7786Receiver(receiver.parseAddress()).executeMessage(
58+
messageId,
5659
sourceChain,
5760
sender,
5861
payload,

contracts/crosschain/axelar/AxelarGatewaySource.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ abstract contract AxelarGatewaySource is IERC7786GatewaySource, AxelarGatewayBas
5353
// Send the message
5454
string memory axelarDestination = getEquivalentChain(destinationChain);
5555
string memory remoteGateway = getRemoteGateway(destinationChain);
56-
localGateway.callContract(axelarDestination, remoteGateway, adapterPayload);
56+
_axelarGateway.callContract(axelarDestination, remoteGateway, adapterPayload);
5757

5858
return outboxId;
5959
}

contracts/crosschain/utils/ERC7786Receiver.sol

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ abstract contract ERC7786Receiver is IERC7786Receiver {
2222

2323
/// @inheritdoc IERC7786Receiver
2424
function executeMessage(
25+
string calldata messageId,
2526
string calldata source,
2627
string calldata sender,
2728
bytes calldata payload,
2829
bytes[] calldata attributes
2930
) public payable virtual returns (bytes4) {
3031
require(_isKnownGateway(msg.sender), ERC7786ReceiverInvalidGateway(msg.sender));
31-
_processMessage(msg.sender, source, sender, payload, attributes);
32+
_processMessage(msg.sender, messageId, source, sender, payload, attributes);
3233
return IERC7786Receiver.executeMessage.selector;
3334
}
3435

@@ -38,6 +39,7 @@ abstract contract ERC7786Receiver is IERC7786Receiver {
3839
/// @dev Virtual function that should contain the logic to execute when a cross-chain message is received.
3940
function _processMessage(
4041
address gateway,
42+
string calldata messageId,
4143
string calldata sourceChain,
4244
string calldata sender,
4345
bytes calldata payload,

contracts/interfaces/IERC7786.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ interface IERC7786Receiver {
6060
* This function may be called directly by the gateway.
6161
*/
6262
function executeMessage(
63+
string calldata messageId, // gateway specific, empty or unique
6364
string calldata sourceChain, // CAIP-2 chain identifier
6465
string calldata sender, // CAIP-10 account address (does not include the chain identifier)
6566
bytes calldata payload,

contracts/mocks/crosschain/ERC7786GatewayMock.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ contract ERC7786GatewayMock is IERC7786GatewaySource {
3232

3333
address target = Strings.parseAddress(receiver);
3434
require(
35-
IERC7786Receiver(target).executeMessage(source, sender, payload, attributes) ==
35+
IERC7786Receiver(target).executeMessage("", source, sender, payload, attributes) ==
3636
IERC7786Receiver.executeMessage.selector,
3737
"Receiver error"
3838
);

contracts/mocks/crosschain/ERC7786ReceiverInvalidMock.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {IERC7786Receiver} from "../../interfaces/IERC7786.sol";
66

77
contract ERC7786ReceiverInvalidMock is IERC7786Receiver {
88
function executeMessage(
9+
string calldata,
910
string calldata,
1011
string calldata,
1112
bytes calldata,

contracts/mocks/crosschain/ERC7786ReceiverMock.sol

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ import {ERC7786Receiver} from "../../crosschain/utils/ERC7786Receiver.sol";
77
contract ERC7786ReceiverMock is ERC7786Receiver {
88
address private immutable _gateway;
99

10-
event MessageReceived(address gateway, string source, string sender, bytes payload, bytes[] attributes);
10+
event MessageReceived(
11+
address gateway,
12+
string messageId,
13+
string source,
14+
string sender,
15+
bytes payload,
16+
bytes[] attributes
17+
);
1118

1219
constructor(address gateway_) {
1320
_gateway = gateway_;
@@ -19,11 +26,12 @@ contract ERC7786ReceiverMock is ERC7786Receiver {
1926

2027
function _processMessage(
2128
address gateway,
29+
string calldata messageId,
2230
string calldata source,
2331
string calldata sender,
2432
bytes calldata payload,
2533
bytes[] calldata attributes
2634
) internal virtual override {
27-
emit MessageReceived(gateway, source, sender, payload, attributes);
35+
emit MessageReceived(gateway, messageId, source, sender, payload, attributes);
2836
}
2937
}

contracts/mocks/crosschain/ERC7786ReceiverRevertMock.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {IERC7786Receiver} from "../../interfaces/IERC7786.sol";
66

77
contract ERC7786ReceiverRevertMock is IERC7786Receiver {
88
function executeMessage(
9+
string calldata,
910
string calldata,
1011
string calldata,
1112
bytes calldata,

0 commit comments

Comments
 (0)