Skip to content

Commit eae15a0

Browse files
Foivosdjb15milapsheth
authored
fix: address axelar transceiver audit comments (wormhole-foundation#22)
* Squashed commit of the following: commit 0e817ae Merge: 8e24478 4c4b3f0 Author: Foivos <[email protected]> Date: Fri Jun 28 17:20:07 2024 +0300 Merge remote-tracking branch 'origin/feat/address-audit-comments' into feat/address-audit-comments commit 8e24478 Author: Foivos <[email protected]> Date: Fri Jun 28 17:19:29 2024 +0300 sqush commits commit 4c4b3f0 Author: Foivos <[email protected]> Date: Fri Jun 28 13:29:45 2024 +0300 fix error commit c167b14 Author: Foivos <[email protected]> Date: Fri Jun 28 13:09:16 2024 +0300 add tests for checks commit 92465cf Author: Foivos <[email protected]> Date: Fri Jun 28 13:06:37 2024 +0300 added additional check for setAxelarChainId commit 6ff7928 Author: Foivos <[email protected]> Date: Thu Jun 27 17:57:29 2024 +0300 forge fmt commit c639f11 Author: Foivos <[email protected]> Date: Thu Jun 27 16:53:02 2024 +0300 fix end to end tests commit ad272af Author: Foivos <[email protected]> Date: Thu Jun 27 16:31:47 2024 +0300 fix more capitaliaztion commit c45a2de Author: Foivos <[email protected]> Date: Thu Jun 27 16:14:01 2024 +0300 differnet import again commit 8273c1a Merge: 6eac1b9 1c0f731 Author: Foivos <[email protected]> Date: Thu Jun 27 16:13:06 2024 +0300 Merge remote-tracking branch 'origin/main' into feat/address-audit-comments commit 6eac1b9 Author: Foivos <[email protected]> Date: Thu Jun 27 16:11:50 2024 +0300 try different import commit 6aaf137 Author: Foivos <[email protected]> Date: Thu Jun 27 16:07:57 2024 +0300 trying more stuff commit 7bd8932 Author: Foivos <[email protected]> Date: Thu Jun 27 16:05:02 2024 +0300 trying to fix CLI commit f6e60a2 Author: Foivos <[email protected]> Date: Thu Jun 27 16:04:22 2024 +0300 try a different import commit 53b0e53 Author: Foivos <[email protected]> Date: Thu Jun 27 15:53:22 2024 +0300 revert change commit 4e576be Author: Foivos <[email protected]> Date: Thu Jun 27 15:46:19 2024 +0300 forge fmt commit 2d6af58 Author: Foivos <[email protected]> Date: Thu Jun 27 15:44:06 2024 +0300 fix import in test commit 7eb17a4 Author: Foivos <[email protected]> Date: Wed Jun 26 20:39:14 2024 +0300 remove confusing comment commit 2c000b2 Author: Foivos <[email protected]> Date: Tue Jun 25 11:14:28 2024 +0300 restrict use of setAxelarChainId commit 56ff882 Author: Canh Trinh <[email protected]> Date: Mon Jun 24 15:17:03 2024 -0400 Update test/axelar/AxelarTransceiver.t.sol Co-authored-by: Milap Sheth <[email protected]> commit be34917 Author: Canh Trinh <[email protected]> Date: Mon Jun 24 15:15:19 2024 -0400 Update test/axelar/AxelarTransceiver.t.sol Co-authored-by: Milap Sheth <[email protected]> commit dd1288c Author: Canh Trinh <[email protected]> Date: Mon Jun 24 15:14:47 2024 -0400 Update src/axelar/AxelarTransceiver.sol Co-authored-by: Milap Sheth <[email protected]> commit 2fa5cde Author: Foivos <[email protected]> Date: Wed Jun 19 14:29:49 2024 +0300 run fmt commit d5159a5 Author: Foivos <[email protected]> Date: Wed Jun 19 14:16:09 2024 +0300 Added better tests commit f03f0eb Author: Foivos <[email protected]> Date: Wed Jun 19 13:23:07 2024 +0300 Add validation for setAxelarChainId commit f4c441a Author: Foivos <[email protected]> Date: Wed Jun 19 13:16:48 2024 +0300 Add event to setAxelarChainId commit 02eaea5 Merge: 43e425c d7a07d9 Author: Foivos <[email protected]> Date: Wed Jun 19 13:16:21 2024 +0300 Merge branch 'feat/update-wormhole-examples-version' into feat/address-audit-comments commit d7a07d9 Author: Foivos <[email protected]> Date: Thu Jun 13 14:55:07 2024 +0300 forge fmt commit 1ed9e1d Author: Foivos <[email protected]> Date: Thu Jun 13 14:46:17 2024 +0300 Fix axelar transceiver to include version commit e642d8d Author: Foivos <[email protected]> Date: Thu Jun 13 14:29:58 2024 +0300 update wormhole-examples to new main commit 1b6520a Author: Foivos <[email protected]> Date: Tue Jun 11 18:19:43 2024 +0300 added more destriptive error message commit ef0dc87 Author: Foivos <[email protected]> Date: Tue Jun 11 16:21:12 2024 +0300 forge fmt commit 5b66ae8 Author: Foivos <[email protected]> Date: Tue Jun 11 16:20:53 2024 +0300 added a constant for easy identification commit 4c3e078 Author: Foivos <[email protected]> Date: Tue Jun 11 13:47:16 2024 +0300 tests now prperly check for reverts commit b8b2bb3 Author: Foivos <[email protected]> Date: Mon Jun 10 15:12:06 2024 +0300 run forge fmt again commit fc2dfea Author: Foivos <[email protected]> Date: Mon Jun 10 15:02:58 2024 +0300 run forge fmt commit d8e46e4 Author: Foivos <[email protected]> Date: Mon Jun 10 15:01:57 2024 +0300 remove unused var commit 30c5c6d Author: Foivos <[email protected]> Date: Mon Jun 10 14:58:57 2024 +0300 try to fix CI again commit 4b76355 Author: Foivos <[email protected]> Date: Mon Jun 10 14:56:57 2024 +0300 try to fix CI commit 69e5f40 Author: Foivos <[email protected]> Date: Sun Jun 9 22:57:40 2024 +0300 update readme commit fe2b441 Author: Foivos <[email protected]> Date: Sat Jun 8 20:59:02 2024 +0300 added a fail test if the address is not trusted. commit d07ebe0 Author: Foivos <[email protected]> Date: Sat Jun 8 20:54:16 2024 +0300 Added a receiving token test commit c1041cb Author: Foivos <[email protected]> Date: Fri Jun 7 12:00:44 2024 +0300 added a script to set remote siblings commit ad9e213 Author: Milap Sheth <[email protected]> Date: Thu Jun 6 13:16:22 2024 -0400 Update script/README.md commit eebec31 Author: Milap Sheth <[email protected]> Date: Thu Jun 6 13:16:14 2024 -0400 Update script/README.md commit d839bd4 Author: Milap Sheth <[email protected]> Date: Thu Jun 6 13:06:25 2024 -0400 Update src/axelar/AxelarTransceiver.sol commit c482fcb Author: Foivos <[email protected]> Date: Thu Jun 6 19:18:21 2024 +0300 correct decoding of message commit 6cda8f9 Author: Foivos <[email protected]> Date: Thu Jun 6 19:14:50 2024 +0300 checking for immutable immutables commit 985b915 Author: Foivos <[email protected]> Date: Thu Jun 6 19:10:30 2024 +0300 remove unecesairy modifier commit d9b4f6c Author: Foivos <[email protected]> Date: Thu Jun 6 19:09:24 2024 +0300 added some natspec commit 709ff54 Author: Foivos <[email protected]> Date: Thu Jun 6 18:25:20 2024 +0300 moved some errors commit 4d98b15 Author: Foivos <[email protected]> Date: Thu Jun 6 14:07:38 2024 +0300 add readme and rename dir commit ac40e0d Author: Foivos <[email protected]> Date: Thu Jun 6 14:03:48 2024 +0300 update deployment script commit f4fb0cb Author: Foivos <[email protected]> Date: Wed Jun 5 18:04:51 2024 +0300 added a deployment script commit b446382 Author: Nikhil Suri <[email protected]> Date: Mon Jun 3 17:41:53 2024 -0700 Fix CI and format commit ca08e99 Author: Nikhil Suri <[email protected]> Date: Mon Jun 3 17:37:04 2024 -0700 Fix OZ contracts issue commit 01edb75 Author: Foivos <[email protected]> Date: Fri May 31 15:42:53 2024 +0300 update tests a bit commit ac31c4d Author: Foivos <[email protected]> Date: Fri May 31 15:29:10 2024 +0300 change some names commit 1f25b44 Author: Foivos <[email protected]> Date: Fri May 31 15:28:39 2024 +0300 Update src/axelar/AxelarTransceiver.sol Co-authored-by: Milap Sheth <[email protected]> commit 9f42e32 Author: Foivos <[email protected]> Date: Fri May 31 15:28:16 2024 +0300 Update src/axelar/AxelarTransceiver.sol Co-authored-by: Milap Sheth <[email protected]> commit 9f2cd61 Author: Foivos <[email protected]> Date: Thu May 30 21:46:18 2024 +0300 using payGas instead of payNativeGasForContractCall commit a6d5211 Author: Foivos <[email protected]> Date: Thu May 30 21:37:53 2024 +0300 using the gas service estimateGasFee commit f3b02fe Author: Foivos <[email protected]> Date: Thu May 30 21:26:00 2024 +0300 fixed a naminginconsistency commit 71f586f Author: Foivos <[email protected]> Date: Thu May 30 21:23:57 2024 +0300 some more comments addressed commit 89ffcb6 Author: Foivos <[email protected]> Date: Thu May 30 21:01:00 2024 +0300 remove cgp-solidity as it is unused commit 72e05aa Author: Foivos <[email protected]> Date: Thu May 30 20:59:33 2024 +0300 address some comments commit 5f75247 Author: Foivos <[email protected]> Date: Thu May 30 20:27:56 2024 +0300 using axelar gmp executable commit 23640f4 Author: Foivos <[email protected]> Date: Thu May 30 18:39:24 2024 +0300 remove the proxy commit 053d9fb Merge: e4cbb67 c4361e7 Author: Foivos <[email protected]> Date: Thu May 30 18:35:57 2024 +0300 Merge remote-tracking branch 'origin/main' into feat/axelar-transceiver commit e4cbb67 Author: Foivos <[email protected]> Date: Thu May 30 18:27:22 2024 +0300 Tests work commit da28026 Author: Foivos <[email protected]> Date: Thu May 30 16:24:44 2024 +0300 change oz to an older version commit 356d603 Author: Foivos <[email protected]> Date: Wed May 29 18:16:28 2024 +0300 rename storage_ to slot commit 748b989 Author: Nikhil Suri <[email protected]> Date: Tue May 28 17:18:18 2024 -0700 downgrade to oz v4.8.1 commit 32f2600 Author: Foivos <[email protected]> Date: Mon May 27 20:28:39 2024 +0300 using Transceiver abstract contract commit 490202f Author: Foivos <[email protected]> Date: Fri May 24 16:51:52 2024 +0300 fix the test commit a228d68 Author: Foivos <[email protected]> Date: Fri May 24 16:02:45 2024 +0300 added some tests commit 96c4258 Author: Foivos <[email protected]> Date: Thu May 23 17:57:58 2024 +0300 forge install: axelar-cgp-solidity v6.3.1 commit b31cda4 Author: Foivos <[email protected]> Date: Thu May 23 17:57:54 2024 +0300 trying to add some tests commit 62edca4 Author: Foivos <[email protected]> Date: Thu May 23 17:42:29 2024 +0300 added a proxy as well commit 06ed4c4 Author: Foivos <[email protected]> Date: Fri May 17 13:21:27 2024 +0300 Added the rest of the files commit cacecd0 Author: Foivos <[email protected]> Date: Fri May 17 13:16:19 2024 +0300 add axelar tranceiver * Fix submodule commit hash * Update src/axelar/AxelarTransceiver.sol * fix: there can be multiple tranceivers on the same address on different chains. (wormhole-foundation#23) * fix it so that there can be multiple tranceivers on the same address on different chains. * fix spelling error * add token back * add cast to bytes * run forge fmt * update examples-native-token-transfers * try to revert to older package --------- Co-authored-by: Dirk Brink <[email protected]> Co-authored-by: Milap Sheth <[email protected]>
1 parent dbcd534 commit eae15a0

File tree

5 files changed

+337
-23
lines changed

5 files changed

+337
-23
lines changed

src/axelar/AxelarTransceiver.sol

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ contract AxelarTransceiver is IAxelarTransceiver, AxelarGMPExecutable, Transceiv
3030
mapping(uint16 => string) idToAxelarChainId;
3131
mapping(string => uint16) axelarChainIdToId;
3232
mapping(uint16 => string) idToTransceiverAddress;
33-
mapping(string => uint16) transceiverAddressToId;
33+
mapping(uint16 => bytes32) idToTransceiverAddressHash;
3434
}
3535
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AxelarTransceiver")) - 1)) & ~bytes32(uint256(0xff))
3636

@@ -79,11 +79,22 @@ contract AxelarTransceiver is IAxelarTransceiver, AxelarGMPExecutable, Transceiv
7979
string calldata chainName,
8080
string calldata transceiverAddress
8181
) external virtual onlyOwner {
82+
if (chainId == 0 || bytes(chainName).length == 0 || bytes(transceiverAddress).length == 0) {
83+
revert InvalidChainIdParams();
84+
}
85+
8286
AxelarTransceiverStorage storage slot = _storage();
87+
88+
if (bytes(slot.idToAxelarChainId[chainId]).length != 0) revert ChainIdAlreadySet(chainId);
89+
90+
if (slot.axelarChainIdToId[chainName] != 0) revert AxelarChainIdAlreadySet(chainName);
91+
8392
slot.idToAxelarChainId[chainId] = chainName;
8493
slot.axelarChainIdToId[chainName] = chainId;
8594
slot.idToTransceiverAddress[chainId] = transceiverAddress;
86-
slot.transceiverAddressToId[transceiverAddress] = chainId;
95+
slot.idToTransceiverAddressHash[chainId] = keccak256(bytes(transceiverAddress));
96+
97+
emit AxelarChainIdSet(chainId, chainName, transceiverAddress);
8798
}
8899

89100
/// @notice Fetch the delivery price for a given recipient chain transfer.
@@ -174,7 +185,10 @@ contract AxelarTransceiver is IAxelarTransceiver, AxelarGMPExecutable, Transceiv
174185
) internal virtual override {
175186
AxelarTransceiverStorage storage slot = _storage();
176187
uint16 sourceChainId = slot.axelarChainIdToId[sourceChain];
177-
if (sourceChainId == 0 || slot.transceiverAddressToId[sourceAddress] != sourceChainId) {
188+
if (
189+
sourceChainId == 0
190+
|| slot.idToTransceiverAddressHash[sourceChainId] != keccak256(bytes(sourceAddress))
191+
) {
178192
revert InvalidSibling(sourceChainId, sourceChain, sourceAddress);
179193
}
180194

src/axelar/interfaces/IAxelarTransceiver.sol

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,18 @@ interface IAxelarTransceiver is ITransceiver {
1212

1313
/// @notice Chain Id passed is not valid.
1414
/// @param chainId The wormhole chainId.
15-
error InvalidChainId(uint16 chainId, string chainName, string destinationContract);
15+
/// @param chainName The axelar chainName.
16+
/// @param transceiverAddress The address of the Transceiver as a string.
17+
error InvalidChainId(uint16 chainId, string chainName, string transceiverAddress);
18+
19+
/// @notice Chain Id passed is zero, or Axelar Chain Id or Transceiver Address were empty.
20+
error InvalidChainIdParams();
21+
22+
/// @notice Chain Id is already being used.
23+
error ChainIdAlreadySet(uint16 chainId);
24+
25+
/// @notice Axelar chain Id is already being used.
26+
error AxelarChainIdAlreadySet(string axelarChainId);
1627

1728
/// @notice Emmited when a transceiver message is sent.
1829
/// @param recipientChainId The wormhole chainId of the destination chain.
@@ -26,6 +37,12 @@ interface IAxelarTransceiver is ITransceiver {
2637
bytes32 indexed refundAddress
2738
);
2839

40+
/// @notice Emmited when the chain id is set.
41+
/// @param chainId The wormhole chainId of the destination chain.
42+
/// @param chainName The axelar chain name.
43+
/// @param transceiverAddress The transceiver address as a string.
44+
event AxelarChainIdSet(uint16 chainId, string chainName, string transceiverAddress);
45+
2946
/**
3047
* Set the bridge manager contract address
3148
* @param chainId The chainId of the chain. This is used to identify the chain in the EndpointManager.

test/axelar/AxelarTransceiver.t.sol

Lines changed: 53 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,16 @@ import "forge-std/Test.sol";
1919
import "openzeppelin-contracts/contracts/access/Ownable.sol";
2020

2121
contract AxelarTransceiverTest is Test {
22+
event ContractCall(
23+
address indexed sender,
24+
string destinationChain,
25+
string destinationContractAddress,
26+
bytes32 indexed payloadHash,
27+
bytes payload
28+
);
29+
30+
event AxelarChainIdSet(uint16 chainId, string chainName, string transceiverAddress);
31+
2232
address constant OWNER = address(1004);
2333

2434
uint64 constant RATE_LIMIT_DURATION = 0;
@@ -34,9 +44,6 @@ contract AxelarTransceiverTest is Test {
3444
WstEthL2TokenHarness token;
3545

3646
function setUp() public {
37-
string memory url = "https://ethereum-sepolia-rpc.publicnode.com";
38-
vm.createSelectFork(url);
39-
4047
gateway = IAxelarGateway(new MockAxelarGateway());
4148
gasService = IAxelarGasService(address(new MockAxelarGasService()));
4249

@@ -75,12 +82,31 @@ contract AxelarTransceiverTest is Test {
7582
string memory chainName = "chainName";
7683
string memory axelarAddress = "axelarAddress";
7784

85+
vm.expectEmit(address(transceiver));
86+
emit AxelarChainIdSet(chainId, chainName, axelarAddress);
87+
7888
vm.prank(OWNER);
7989
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);
80-
/*assertEq(transceiver.idToAxelarChainIds(chainId), chainName);
81-
assertEq(transceiver.axelarChainIdToId(chainName),chainId);
82-
assertEq(transceiver.idToAxelarAddress(chainId), axelarAddress);
83-
assertEq(transceiver.axelarAddressToId(axelarAddress), chainId);*/
90+
}
91+
92+
function test_setAxelarChainIdDuplicateChainId() public {
93+
uint16 chainId = 1;
94+
string memory chainName = "chainName";
95+
string memory axelarAddress = "axelarAddress";
96+
97+
vm.expectEmit(address(transceiver));
98+
emit AxelarChainIdSet(chainId, chainName, axelarAddress);
99+
100+
vm.prank(OWNER);
101+
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);
102+
103+
vm.prank(OWNER);
104+
vm.expectRevert(abi.encodeWithSignature("ChainIdAlreadySet(uint16)", chainId));
105+
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);
106+
107+
vm.prank(OWNER);
108+
vm.expectRevert(abi.encodeWithSignature("AxelarChainIdAlreadySet(string)", chainName));
109+
transceiver.setAxelarChainId(chainId + 1, chainName, axelarAddress);
84110
}
85111

86112
function test_setAxelarChainIdNotOwner() public {
@@ -101,11 +127,18 @@ contract AxelarTransceiverTest is Test {
101127
bytes32 recipientNttManagerAddress = bytes32(uint256(1010));
102128
bytes memory nttManagerMessage = bytes("nttManagerMessage");
103129
bytes32 refundAddress = bytes32(uint256(1011));
130+
bytes memory payload = abi.encode(manager, nttManagerMessage, recipientNttManagerAddress);
104131
TransceiverStructs.TransceiverInstruction memory instruction =
105132
TransceiverStructs.TransceiverInstruction(0, bytes(""));
106133

107134
vm.prank(OWNER);
108135
transceiver.setAxelarChainId(chainId, chainName, axelarAddress);
136+
137+
vm.expectEmit(address(gateway));
138+
emit ContractCall(
139+
address(transceiver), chainName, axelarAddress, keccak256(payload), payload
140+
);
141+
109142
vm.prank(address(manager));
110143
transceiver.sendMessage(
111144
chainId, instruction, nttManagerMessage, recipientNttManagerAddress, refundAddress
@@ -167,6 +200,7 @@ contract AxelarTransceiverTest is Test {
167200
uint16 chainId = 2;
168201
string memory chainName = "chainName";
169202
string memory axelarAddress = "axelarAddress";
203+
bytes32 messageId = bytes32(uint256(25));
170204
bytes32 recipientNttManagerAddress = bytes32(uint256(uint160(address(manager))));
171205

172206
bytes32 to = bytes32(uint256(1234));
@@ -184,9 +218,9 @@ contract AxelarTransceiverTest is Test {
184218
bytes memory nttManagerMessage;
185219
{
186220
uint16 length = uint16(nttPayload.length);
187-
bytes32 messageId = bytes32(uint256(0));
221+
bytes32 nttMessageId = bytes32(uint256(0));
188222
bytes32 sender = bytes32(uint256(1));
189-
nttManagerMessage = abi.encodePacked(messageId, sender, length, nttPayload);
223+
nttManagerMessage = abi.encodePacked(nttMessageId, sender, length, nttPayload);
190224
}
191225

192226
bytes32 sourceNttManagerAddress = bytes32(uint256(1012));
@@ -201,21 +235,29 @@ contract AxelarTransceiverTest is Test {
201235
token.setMinter(OWNER);
202236
vm.prank(OWNER);
203237
token.mint(address(manager), amount);
238+
gateway.approveContractCall(messageId, chainName, axelarAddress, keccak256(payload));
204239

205-
transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
240+
transceiver.execute(messageId, chainName, axelarAddress, payload);
206241

207242
if (token.balanceOf(fromWormholeFormat(to)) != amount) revert("Amount Incorrect");
243+
244+
vm.prank(OWNER);
245+
token.mint(address(manager), amount);
246+
vm.expectRevert(abi.encodeWithSignature("NotApprovedByGateway()"));
247+
transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
208248
}
209249

210250
function test_executeNotTrustedAddress() public {
211251
string memory chainName = "chainName";
212252
string memory axelarAddress = "axelarAddress";
213253
bytes memory payload = bytes("");
254+
bytes32 messageId = keccak256(bytes("message Id"));
255+
gateway.approveContractCall(messageId, chainName, axelarAddress, keccak256(payload));
214256
vm.expectRevert(
215257
abi.encodeWithSignature(
216258
"InvalidSibling(uint16,string,string)", 0, chainName, axelarAddress
217259
)
218260
);
219-
transceiver.execute(bytes32(0), chainName, axelarAddress, payload);
261+
transceiver.execute(messageId, chainName, axelarAddress, payload);
220262
}
221263
}

0 commit comments

Comments
 (0)