Skip to content

Commit 80b0a59

Browse files
committed
update
1 parent 91cb0ac commit 80b0a59

9 files changed

+89
-90
lines changed

contracts/crosschain/ICAIP2Equivalence.sol

Lines changed: 0 additions & 13 deletions
This file was deleted.

contracts/crosschain/IGatewaySource.sol

Lines changed: 0 additions & 22 deletions
This file was deleted.

contracts/crosschain/axelar/AxelarGatewayBase.sol

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,40 @@ pragma solidity ^0.8.0;
44

55
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
66
import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol";
7-
import {ICAIP2Equivalence} from "../ICAIP2Equivalence.sol";
87

9-
abstract contract AxelarGatewayBase is ICAIP2Equivalence, Ownable {
8+
abstract contract AxelarGatewayBase is Ownable {
109
event RegisteredRemoteGateway(string caip2, string gatewayAddress);
1110
event RegisteredCAIP2Equivalence(string caip2, string destinationChain);
1211

12+
error UnsupportedChain(string caip2);
13+
1314
IAxelarGateway public immutable localGateway;
1415

16+
// TODO: merge these two (and the corresponding setters?)
1517
mapping(string caip2 => string remoteGateway) private _remoteGateways;
1618
mapping(string caip2 => string destinationChain) private _equivalence;
1719

1820
constructor(IAxelarGateway _gateway) {
1921
localGateway = _gateway;
2022
}
2123

22-
function fromCAIP2(string memory caip2) public view returns (string memory) {
23-
return _equivalence[caip2];
24+
function fromCAIP2(string memory caip2) public view virtual returns (string memory axelarName) {
25+
axelarName = _equivalence[caip2];
26+
require(bytes(axelarName).length > 0, UnsupportedChain(caip2));
2427
}
2528

26-
function getRemoteGateway(string memory caip2) public view returns (string memory remoteGateway) {
27-
return _remoteGateways[caip2];
29+
function getRemoteGateway(string memory caip2) public view virtual returns (string memory remoteGateway) {
30+
remoteGateway = _remoteGateways[caip2];
31+
require(bytes(remoteGateway).length > 0, UnsupportedChain(caip2));
2832
}
2933

30-
function registerCAIP2Equivalence(string calldata caip2, string calldata axelarSupported) public onlyOwner {
34+
function registerCAIP2Equivalence(string calldata caip2, string calldata axelarSupported) public virtual onlyOwner {
3135
require(bytes(_equivalence[caip2]).length == 0);
3236
_equivalence[caip2] = axelarSupported;
3337
emit RegisteredCAIP2Equivalence(caip2, axelarSupported);
3438
}
3539

36-
function registerRemoteGateway(string calldata caip2, string calldata remoteGateway) public onlyOwner {
40+
function registerRemoteGateway(string calldata caip2, string calldata remoteGateway) public virtual onlyOwner {
3741
require(bytes(_remoteGateways[caip2]).length == 0);
3842
_remoteGateways[caip2] = remoteGateway;
3943
emit RegisteredRemoteGateway(caip2, remoteGateway);

contracts/crosschain/axelar/AxelarGatewayDestination.sol

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,37 @@ pragma solidity ^0.8.27;
55
import {AxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
66
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
77
import {StringsUnreleased} from "../../utils/Strings.sol";
8-
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
9-
import {IGatewayDestinationPassive} from "../IGatewayDestinationPassive.sol";
10-
import {IGatewayReceiver} from "../IGatewayReceiver.sol";
118
import {CAIP2} from "../../utils/CAIP-2.sol";
129
import {CAIP10} from "../../utils/CAIP-10.sol";
10+
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
11+
import {IGatewayDestinationPassive} from "../interfaces/IGatewayDestinationPassive.sol";
12+
import {IGatewayReceiver} from "../interfaces/IGatewayReceiver.sol";
1313

1414
abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, AxelarGatewayBase, AxelarExecutable {
1515
using Strings for string;
1616

1717
/// @dev Passive mode
1818
function validateReceivedMessage(
19-
bytes calldata gatewayData,
20-
string calldata srcChain, // CAIP-2
21-
string calldata srcAccount, // CAIP-10
19+
bytes calldata messageKey,
20+
string calldata source, // CAIP-2
21+
string calldata sender, // CAIP-10
2222
bytes calldata payload,
2323
bytes[] calldata attributes
24-
) external virtual override {
24+
) external virtual {
2525
// Extract Axelar commandId
26-
bytes32 commandId = abi.decode(gatewayData, (bytes32));
26+
bytes32 commandId = abi.decode(messageKey, (bytes32));
2727

2828
// Rebuild expected package
2929
bytes memory package = abi.encode(
30-
CAIP10.format(srcChain, srcAccount),
30+
CAIP10.format(source, sender),
3131
CAIP10.format(msg.sender),
3232
payload,
3333
attributes
3434
);
3535

3636
// Check package was received from remote gateway on src chain
3737
require(
38-
gateway.validateContractCall(
39-
commandId,
40-
fromCAIP2(srcChain),
41-
getRemoteGateway(srcChain),
42-
keccak256(package)
43-
),
38+
gateway.validateContractCall(commandId, fromCAIP2(source), getRemoteGateway(source), keccak256(package)),
4439
NotApprovedByGateway()
4540
);
4641
}
@@ -59,27 +54,28 @@ abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, Axelar
5954
bytes calldata package
6055
) internal virtual override {
6156
// Parse the package
62-
(string memory srcCAIP10, string memory dstCAIP10, bytes memory payload, bytes[] memory attributes) = abi
63-
.decode(package, (string, string, bytes, bytes[]));
57+
(string memory from, string memory to, bytes memory payload, bytes[] memory attributes) = abi.decode(
58+
package,
59+
(string, string, bytes, bytes[])
60+
);
6461

65-
(string memory srcChain, string memory srcAccount) = CAIP10.parse(srcCAIP10);
66-
(string memory dstChain, string memory dstAccount) = CAIP10.parse(dstCAIP10);
62+
(string memory source, string memory sender) = CAIP10.parse(from);
63+
(string memory destination, string memory receiver) = CAIP10.parse(to);
6764

6865
// check message validity
6966
// - `remoteChain` matches origin chain in the message (in caip2)
7067
// - `remoteAccount` is the remote gateway on the origin chain.
71-
require(remoteChain.equal(fromCAIP2(srcChain)), "Invalid origin chain");
72-
require(remoteAccount.equal(getRemoteGateway(srcChain)), "Invalid origin gateway");
68+
require(remoteChain.equal(fromCAIP2(source)), "Invalid origin chain");
69+
require(remoteAccount.equal(getRemoteGateway(source)), "Invalid origin gateway");
7370
// This check is not required for security. That is enforced by axelar (+ source gateway)
74-
require(dstChain.equal(CAIP2.format()), "Invalid tardet chain");
71+
require(destination.equal(CAIP2.format()), "Invalid tardet chain");
7572

7673
// Active mode
77-
address destination = StringsUnreleased.parseAddress(dstAccount);
78-
IGatewayReceiver(destination).receiveMessage(
74+
IGatewayReceiver(StringsUnreleased.parseAddress(receiver)).receiveMessage(
7975
address(0), // not needed in active mode
8076
new bytes(0), // not needed in active mode
81-
srcChain,
82-
srcAccount,
77+
source,
78+
sender,
8379
payload,
8480
attributes
8581
);

contracts/crosschain/axelar/AxelarGatewaySource.sol

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,38 @@
33
pragma solidity ^0.8.27;
44

55
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
6-
import {IGatewaySource} from "../IGatewaySource.sol";
6+
import {IGatewaySource} from "../interfaces/IGatewaySource.sol";
77
import {CAIP10} from "../../utils/CAIP-10.sol";
88

99
abstract contract AxelarGatewaySource is IGatewaySource, AxelarGatewayBase {
10+
function supportsAttribute(bytes4 /*signature*/) public view virtual returns (bool) {
11+
return false;
12+
}
13+
1014
function sendMessage(
11-
string calldata dstChain, // CAIP-2 chain ID
12-
string calldata dstAccount, // i.e. address
15+
string calldata destination, // CAIP-2 chain ID
16+
string calldata receiver, // i.e. address
1317
bytes calldata payload,
1418
bytes[] calldata attributes
15-
) external payable override returns (bytes32) {
16-
// TODO: Handle ether (payable)
17-
// TODO: Validate attributes
19+
) external payable virtual returns (bytes32) {
20+
// TODO: add support for value and attributes ?
21+
require(msg.value == 0, "Value not supported");
22+
for (uint256 i = 0; i < attributes.length; ++i) {
23+
bytes4 signature = bytes4(attributes[i][0:4]);
24+
require(supportsAttribute(signature), UnsuportedAttribute(signature));
25+
}
1826

19-
string memory srcCAIP10 = CAIP10.format(msg.sender);
20-
string memory dstCAIP10 = CAIP10.format(dstChain, dstAccount);
27+
string memory from = CAIP10.format(msg.sender);
28+
string memory to = CAIP10.format(destination, receiver);
2129

2230
// Create the package
23-
bytes memory package = abi.encode(srcCAIP10, dstCAIP10, payload, attributes);
31+
bytes memory package = abi.encode(from, to, payload, attributes);
2432

2533
// Emit event
26-
emit MessageCreated(0, srcCAIP10, dstCAIP10, payload, attributes);
34+
emit MessageCreated(0, from, to, payload, attributes);
2735

2836
// Send the message
29-
localGateway.callContract(fromCAIP2(dstChain), getRemoteGateway(dstChain), package);
37+
localGateway.callContract(fromCAIP2(destination), getRemoteGateway(destination), package);
3038

3139
return 0;
3240
}

contracts/crosschain/IGatewayDestinationPassive.sol renamed to contracts/crosschain/interfaces/IGatewayDestinationPassive.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
pragma solidity ^0.8.0;
44

55
interface IGatewayDestinationPassive {
6-
error GatewayDestinationPassiveInvalidMessage(bytes gatewayData);
6+
error InvalidMessageKey(bytes messageKey);
77

88
function validateReceivedMessage(
9-
bytes calldata gatewayData,
10-
string calldata srcChain,
11-
string calldata srcAccount,
9+
bytes calldata messageKey,
10+
string calldata source,
11+
string calldata sender,
1212
bytes calldata payload,
1313
bytes[] calldata attributes
1414
) external;

contracts/crosschain/IGatewayReceiver.sol renamed to contracts/crosschain/interfaces/IGatewayReceiver.sol

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ pragma solidity ^0.8.0;
44

55
interface IGatewayReceiver {
66
function receiveMessage(
7-
address gatewayAddr,
8-
bytes calldata gatewayData,
9-
string calldata srcChain,
10-
string calldata srcAccount,
7+
address gateway,
8+
bytes calldata gatewayMessageKey,
9+
string calldata source,
10+
string calldata sender,
1111
bytes calldata payload,
1212
bytes[] calldata attributes
1313
) external payable;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
interface IGatewaySource {
6+
event MessageCreated(
7+
bytes32 outboxId,
8+
string from, // CAIP-10 account ID
9+
string to, // CAIP-10 account ID
10+
bytes payload,
11+
bytes[] attributes
12+
);
13+
14+
event MessageSent(bytes32 indexed outboxId);
15+
16+
error UnsuportedAttribute(bytes4 signature);
17+
18+
function supportsAttribute(bytes4 signature) external view returns (bool);
19+
20+
function sendMessage(
21+
string calldata destination, // CAIP-2 chain ID
22+
string calldata receiver, // CAIP-10 account ID
23+
bytes calldata payload,
24+
bytes[] calldata attributes
25+
) external payable returns (bytes32 outboxId);
26+
}

contracts/crosschain/mocks/GatewayReceiverMock.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
pragma solidity ^0.8.27;
44

5-
import {IGatewayDestinationPassive} from "../IGatewayDestinationPassive.sol";
6-
import {IGatewayReceiver} from "../IGatewayReceiver.sol";
5+
import {IGatewayDestinationPassive} from "../interfaces/IGatewayDestinationPassive.sol";
6+
import {IGatewayReceiver} from "../interfaces/IGatewayReceiver.sol";
77

88
contract GatewayReceiverMock is IGatewayReceiver {
99
address public immutable GATEWAY;

0 commit comments

Comments
 (0)