Skip to content

Commit 70653e2

Browse files
Amxxernestognw
andauthored
Update ERC7786Receiver (#198)
Co-authored-by: ernestognw <[email protected]>
1 parent 8f26d9f commit 70653e2

14 files changed

+44
-63
lines changed

contracts/crosschain/ERC7786OpenBridge.sol

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,16 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
173173
* not revert. Any value accrued that way can be recovered by the admin using the {sweep} function.
174174
*/
175175
// slither-disable-next-line reentrancy-no-eth
176-
function executeMessage(
176+
function receiveMessage(
177177
bytes32 /*receiveId*/,
178178
bytes calldata sender, // Binary Interoperable Address
179-
bytes calldata payload,
180-
bytes[] calldata attributes
179+
bytes calldata payload
181180
) public payable virtual whenNotPaused returns (bytes4) {
182181
// Check sender is a trusted bridge
183182
require(keccak256(getRemoteBridge(sender)) == keccak256(sender), ERC7786OpenBridgeInvalidCrosschainSender());
184183

185184
// Message reception tracker
186-
bytes32 id = keccak256(abi.encode(sender, payload, attributes));
185+
bytes32 id = keccak256(abi.encode(sender, payload));
187186
Tracker storage tracker = _trackers[id];
188187

189188
// If call is first from a trusted gateway
@@ -194,7 +193,7 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
194193
emit Received(id, msg.sender);
195194

196195
// if already executed, leave gracefully
197-
if (tracker.executed) return IERC7786Receiver.executeMessage.selector;
196+
if (tracker.executed) return IERC7786Receiver.receiveMessage.selector;
198197
} else if (tracker.executed) {
199198
revert ERC7786OpenBridgeAlreadyExecuted();
200199
}
@@ -210,10 +209,7 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
210209
// prevent re-entry
211210
tracker.executed = true;
212211

213-
bytes memory call = abi.encodeCall(
214-
IERC7786Receiver.executeMessage,
215-
(id, originalSender, unwrappedPayload, attributes)
216-
);
212+
bytes memory call = abi.encodeCall(IERC7786Receiver.receiveMessage, (id, originalSender, unwrappedPayload));
217213
// slither-disable-next-line reentrancy-no-eth
218214
(, address target) = recipient.parseEvmV1();
219215
(bool success, bytes memory returndata) = target.call(call);
@@ -222,7 +218,7 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
222218
// rollback to enable retry
223219
tracker.executed = false;
224220
emit ExecutionFailed(id);
225-
} else if (bytes32(returndata) == bytes32(IERC7786Receiver.executeMessage.selector)) {
221+
} else if (bytes32(returndata) == bytes32(IERC7786Receiver.receiveMessage.selector)) {
226222
// call successful and correct value returned
227223
emit ExecutionSuccess(id);
228224
} else {
@@ -231,7 +227,7 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
231227
}
232228
}
233229

234-
return IERC7786Receiver.executeMessage.selector;
230+
return IERC7786Receiver.receiveMessage.selector;
235231
}
236232

237233
// =================================================== Getters ===================================================
@@ -281,7 +277,7 @@ contract ERC7786OpenBridge is IERC7786GatewaySource, IERC7786Receiver, Ownable,
281277
_unpause();
282278
}
283279

284-
/// @dev Recovery method in case value is ever received through {executeMessage}
280+
/// @dev Recovery method in case value is ever received through {receiveMessage}
285281
function sweep(address payable to) public virtual onlyOwner {
286282
Address.sendValue(to, address(this).balance);
287283
}

contracts/crosschain/axelar/AxelarGatewayDestination.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ abstract contract AxelarGatewayDestination is AxelarGatewayBase, AxelarExecutabl
3939
bytes calldata adapterPayload
4040
) internal override {
4141
// Parse the package
42-
(bytes memory sender, bytes memory recipient, bytes memory payload, bytes[] memory attributes) = abi.decode(
42+
(bytes memory sender, bytes memory recipient, bytes memory payload) = abi.decode(
4343
adapterPayload,
44-
(bytes, bytes, bytes, bytes[])
44+
(bytes, bytes, bytes)
4545
);
4646

4747
// Axelar to ERC-7930 translation
@@ -55,7 +55,7 @@ abstract contract AxelarGatewayDestination is AxelarGatewayBase, AxelarExecutabl
5555
);
5656

5757
(, address target) = recipient.parseEvmV1();
58-
bytes4 result = IERC7786Receiver(target).executeMessage(commandId, sender, payload, attributes);
59-
require(result == IERC7786Receiver.executeMessage.selector, ReceiverExecutionFailed());
58+
bytes4 result = IERC7786Receiver(target).receiveMessage(commandId, sender, payload);
59+
require(result == IERC7786Receiver.receiveMessage.selector, ReceiverExecutionFailed());
6060
}
6161
}

contracts/crosschain/axelar/AxelarGatewaySource.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ abstract contract AxelarGatewaySource is IERC7786GatewaySource, AxelarGatewayBas
3737

3838
// Create the package
3939
bytes memory sender = InteroperableAddress.formatEvmV1(block.chainid, msg.sender);
40-
bytes memory adapterPayload = abi.encode(sender, recipient, payload, attributes);
40+
bytes memory adapterPayload = abi.encode(sender, recipient, payload);
4141

4242
// Emit event
4343
sendId = bytes32(0); // Explicitly set to 0

contracts/crosschain/utils/ERC7786Receiver.sol

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {IERC7786Receiver} from "../../interfaces/IERC7786.sol";
77
/**
88
* @dev Base implementation of an ERC-7786 compliant cross-chain message receiver.
99
*
10-
* This abstract contract exposes the `executeMessage` function that is used for communication with (one or multiple)
10+
* This abstract contract exposes the `receiveMessage` function that is used for communication with (one or multiple)
1111
* destination gateways. This contract leaves two functions unimplemented:
1212
*
1313
* {_isKnownGateway}, an internal getter used to verify whether an address is recognised by the contract as a valid
@@ -21,15 +21,14 @@ abstract contract ERC7786Receiver is IERC7786Receiver {
2121
error ERC7786ReceivePassiveModeValue();
2222

2323
/// @inheritdoc IERC7786Receiver
24-
function executeMessage(
24+
function receiveMessage(
2525
bytes32 receiveId,
2626
bytes calldata sender, // Binary Interoperable Address
27-
bytes calldata payload,
28-
bytes[] calldata attributes
27+
bytes calldata payload
2928
) public payable virtual returns (bytes4) {
3029
require(_isKnownGateway(msg.sender), ERC7786ReceiverInvalidGateway(msg.sender));
31-
_processMessage(msg.sender, receiveId, sender, payload, attributes);
32-
return IERC7786Receiver.executeMessage.selector;
30+
_processMessage(msg.sender, receiveId, sender, payload);
31+
return IERC7786Receiver.receiveMessage.selector;
3332
}
3433

3534
/// @dev Virtual getter that returns whether an address is a valid ERC-7786 gateway.
@@ -40,7 +39,6 @@ abstract contract ERC7786Receiver is IERC7786Receiver {
4039
address gateway,
4140
bytes32 receiveId,
4241
bytes calldata sender,
43-
bytes calldata payload,
44-
bytes[] calldata attributes
42+
bytes calldata payload
4543
) internal virtual;
4644
}

contracts/interfaces/IERC7786.sol

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ interface IERC7786Receiver {
5555
*
5656
* This function may be called directly by the gateway.
5757
*/
58-
function executeMessage(
58+
function receiveMessage(
5959
bytes32 receiveId,
6060
bytes calldata sender, // Binary Interoperable Address
61-
bytes calldata payload,
62-
bytes[] calldata attributes
61+
bytes calldata payload
6362
) external payable returns (bytes4);
6463
}

contracts/mocks/crosschain/ERC7786GatewayMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ contract ERC7786GatewayMock is IERC7786GatewaySource {
2828

2929
bytes memory sender = InteroperableAddress.formatEvmV1(block.chainid, msg.sender);
3030
require(
31-
IERC7786Receiver(target).executeMessage(bytes32(0), sender, payload, attributes) ==
32-
IERC7786Receiver.executeMessage.selector,
31+
IERC7786Receiver(target).receiveMessage(bytes32(0), sender, payload) ==
32+
IERC7786Receiver.receiveMessage.selector,
3333
"Receiver error"
3434
);
3535

contracts/mocks/crosschain/ERC7786ReceiverInvalidMock.sol

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ pragma solidity ^0.8.0;
55
import {IERC7786Receiver} from "../../interfaces/IERC7786.sol";
66

77
contract ERC7786ReceiverInvalidMock is IERC7786Receiver {
8-
function executeMessage(
9-
bytes32,
10-
bytes calldata,
11-
bytes calldata,
12-
bytes[] calldata
13-
) public payable virtual returns (bytes4) {
8+
function receiveMessage(bytes32, bytes calldata, bytes calldata) public payable virtual returns (bytes4) {
149
return 0xffffffff;
1510
}
1611
}

contracts/mocks/crosschain/ERC7786ReceiverMock.sol

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

10-
event MessageReceived(address gateway, bytes32 receiveId, bytes sender, bytes payload, bytes[] attributes);
10+
event MessageReceived(address gateway, bytes32 receiveId, bytes sender, bytes payload);
1111

1212
constructor(address gateway_) {
1313
_gateway = gateway_;
@@ -21,9 +21,8 @@ contract ERC7786ReceiverMock is ERC7786Receiver {
2121
address gateway,
2222
bytes32 receiveId,
2323
bytes calldata sender,
24-
bytes calldata payload,
25-
bytes[] calldata attributes
24+
bytes calldata payload
2625
) internal virtual override {
27-
emit MessageReceived(gateway, receiveId, sender, payload, attributes);
26+
emit MessageReceived(gateway, receiveId, sender, payload);
2827
}
2928
}

contracts/mocks/crosschain/ERC7786ReceiverRevertMock.sol

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,7 @@ pragma solidity ^0.8.0;
55
import {IERC7786Receiver} from "../../interfaces/IERC7786.sol";
66

77
contract ERC7786ReceiverRevertMock is IERC7786Receiver {
8-
function executeMessage(
9-
bytes32,
10-
bytes calldata,
11-
bytes calldata,
12-
bytes[] calldata
13-
) public payable virtual returns (bytes4) {
8+
function receiveMessage(bytes32, bytes calldata, bytes calldata) public payable virtual returns (bytes4) {
149
revert();
1510
}
1611
}

contracts/mocks/docs/crosschain/MyERC7786ReceiverContract.sol

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ contract MyERC7786ReceiverContract is ERC7786Receiver, AccessManaged {
1818
address gateway,
1919
bytes32 receiveId,
2020
bytes calldata sender,
21-
bytes calldata payload,
22-
bytes[] calldata attributes
21+
bytes calldata payload
2322
) internal virtual override restricted {
2423
// Process the message here
2524
}

0 commit comments

Comments
 (0)