Skip to content

Commit 336a56b

Browse files
committed
use checksumed addresses
1 parent 3f3d6b6 commit 336a56b

File tree

6 files changed

+24
-19
lines changed

6 files changed

+24
-19
lines changed

contracts/crosschain/axelar/AxelarGatewayDestination.sol

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
pragma solidity ^0.8.27;
44

55
import {AxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
6-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
76
import {StringsUnreleased} from "../../utils/Strings.sol";
87
import {CAIP2} from "../../utils/CAIP-2.sol";
98
import {CAIP10} from "../../utils/CAIP-10.sol";
@@ -12,8 +11,8 @@ import {IGatewayDestinationPassive} from "../interfaces/IGatewayDestinationPassi
1211
import {IGatewayReceiver} from "../interfaces/IGatewayReceiver.sol";
1312

1413
abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, AxelarGatewayBase, AxelarExecutable {
15-
using Strings for address;
16-
using Strings for string;
14+
using StringsUnreleased for address;
15+
using StringsUnreleased for string;
1716

1817
/// @dev Passive mode
1918
function validateReceivedMessage(
@@ -29,7 +28,7 @@ abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, Axelar
2928
// Rebuild expected package
3029
bytes memory adapterPayload = abi.encode(
3130
sender,
32-
msg.sender.toHexString(), // receiver
31+
msg.sender.toChecksumHexString(), // receiver
3332
payload,
3433
attributes
3534
);
@@ -71,7 +70,7 @@ abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, Axelar
7170
require(getRemoteGateway(source).equal(remoteAccount), "Invalid origin gateway");
7271

7372
// Active mode
74-
IGatewayReceiver(StringsUnreleased.parseAddress(receiver)).receiveMessage(
73+
IGatewayReceiver(receiver.parseAddress()).receiveMessage(
7574
address(0), // not needed in active mode
7675
new bytes(0), // not needed in active mode
7776
source,

contracts/crosschain/axelar/AxelarGatewaySource.sol

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

55
import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
66
import {IGatewaySource} from "../interfaces/IGatewaySource.sol";
7-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
7+
import {StringsUnreleased} from "../../utils/Strings.sol";
88
import {CAIP2} from "../../utils/CAIP-2.sol";
99
import {CAIP10} from "../../utils/CAIP-10.sol";
1010

1111
abstract contract AxelarGatewaySource is IGatewaySource, AxelarGatewayBase {
12-
using Strings for address;
12+
using StringsUnreleased for address;
1313

1414
function supportsAttribute(bytes4 /*selector*/) public view virtual returns (bool) {
1515
return false;
@@ -29,7 +29,7 @@ abstract contract AxelarGatewaySource is IGatewaySource, AxelarGatewayBase {
2929
}
3030

3131
// Create the package
32-
string memory sender = msg.sender.toHexString();
32+
string memory sender = msg.sender.toChecksumHexString();
3333
bytes memory adapterPayload = abi.encode(sender, receiver, payload, attributes);
3434

3535
// Emit event

contracts/crosschain/mocks/AxelarGatewayMock.sol

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ pragma solidity ^0.8.27;
55
import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol";
66
import {IAxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol";
77
import {BitMaps} from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
8-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
98
import {StringsUnreleased} from "../../utils/Strings.sol";
109

1110
contract AxelarGatewayMock {
12-
using Strings for address;
11+
using StringsUnreleased for address;
12+
using StringsUnreleased for string;
1313
using BitMaps for BitMaps.BitMap;
1414

1515
bool private activeMode;
@@ -42,7 +42,12 @@ contract AxelarGatewayMock {
4242
);
4343

4444
bytes32 commandId = keccak256(
45-
abi.encode(destinationChain, msg.sender.toHexString(), destinationContractAddress, keccak256(payload))
45+
abi.encode(
46+
destinationChain,
47+
msg.sender.toChecksumHexString(),
48+
destinationContractAddress,
49+
keccak256(payload)
50+
)
4651
);
4752

4853
require(!pendingCommandIds.get(uint256(commandId)));
@@ -53,8 +58,8 @@ contract AxelarGatewayMock {
5358
if (activeMode) {
5459
// NOTE:
5560
// - source chain and destination chain are the same in this mock
56-
address target = StringsUnreleased.parseAddress(destinationContractAddress);
57-
IAxelarExecutable(target).execute(commandId, destinationChain, msg.sender.toHexString(), payload);
61+
address target = destinationContractAddress.parseAddress();
62+
IAxelarExecutable(target).execute(commandId, destinationChain, msg.sender.toChecksumHexString(), payload);
5863
}
5964
}
6065

@@ -70,7 +75,8 @@ contract AxelarGatewayMock {
7075
emit IAxelarGateway.ContractCallExecuted(commandId);
7176

7277
return
73-
commandId == keccak256(abi.encode(sourceChain, sourceAddress, msg.sender.toHexString(), payloadHash));
78+
commandId ==
79+
keccak256(abi.encode(sourceChain, sourceAddress, msg.sender.toChecksumHexString(), payloadHash));
7480
} else return false;
7581
}
7682
}

contracts/utils/CAIP-10.sol

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

55
import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
6-
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
6+
import {StringsUnreleased} from "./Strings.sol";
77
import {Bytes} from "./Bytes.sol";
88
import {CAIP2} from "./CAIP-2.sol";
99

@@ -12,11 +12,11 @@ import {CAIP2} from "./CAIP-2.sol";
1212
// account_address: [-.%a-zA-Z0-9]{1,128}
1313
library CAIP10 {
1414
using SafeCast for uint256;
15-
using Strings for address;
15+
using StringsUnreleased for address;
1616
using Bytes for bytes;
1717

1818
function local(address account) internal view returns (string memory) {
19-
return format(CAIP2.local(), account.toHexString());
19+
return format(CAIP2.local(), account.toChecksumHexString());
2020
}
2121

2222
function format(string memory caip2, string memory account) internal pure returns (string memory) {

test/crosschain/axelar/AxelarGateway.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { expect } = require('chai');
33
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
44
const { anyValue } = require('@nomicfoundation/hardhat-chai-matchers/withArgs');
55

6-
const getAddress = account => (account.target ?? account.address ?? account).toLowerCase();
6+
const getAddress = account => ethers.getAddress(account.target ?? account.address ?? account);
77

88
async function fixture() {
99
const [owner, sender, ...accounts] = await ethers.getSigners();

test/crosschain/utils/CAIP.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ describe('CAIP utilities', function () {
3737

3838
it(`local(${account})`, async function () {
3939
// lowercase encoding for now
40-
expect(await this.caip10.$local(ethers.Typed.address(account))).to.equal(format('eip155', this.chainId, account.toLowerCase()));
40+
expect(await this.caip10.$local(ethers.Typed.address(account))).to.equal(format('eip155', this.chainId, account));
4141
});
4242

4343
for (const { account, caip2, caip10 } of Object.values(CHAINS))

0 commit comments

Comments
 (0)