Skip to content

Commit

Permalink
use checksumed addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx committed Oct 1, 2024
1 parent 3f3d6b6 commit 336a56b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 19 deletions.
9 changes: 4 additions & 5 deletions contracts/crosschain/axelar/AxelarGatewayDestination.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.27;

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

abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, AxelarGatewayBase, AxelarExecutable {
using Strings for address;
using Strings for string;
using StringsUnreleased for address;
using StringsUnreleased for string;

/// @dev Passive mode
function validateReceivedMessage(
Expand All @@ -29,7 +28,7 @@ abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, Axelar
// Rebuild expected package
bytes memory adapterPayload = abi.encode(
sender,
msg.sender.toHexString(), // receiver
msg.sender.toChecksumHexString(), // receiver
payload,
attributes
);
Expand Down Expand Up @@ -71,7 +70,7 @@ abstract contract AxelarGatewayDestination is IGatewayDestinationPassive, Axelar
require(getRemoteGateway(source).equal(remoteAccount), "Invalid origin gateway");

// Active mode
IGatewayReceiver(StringsUnreleased.parseAddress(receiver)).receiveMessage(
IGatewayReceiver(receiver.parseAddress()).receiveMessage(
address(0), // not needed in active mode
new bytes(0), // not needed in active mode
source,
Expand Down
6 changes: 3 additions & 3 deletions contracts/crosschain/axelar/AxelarGatewaySource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pragma solidity ^0.8.27;

import {AxelarGatewayBase} from "./AxelarGatewayBase.sol";
import {IGatewaySource} from "../interfaces/IGatewaySource.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {StringsUnreleased} from "../../utils/Strings.sol";
import {CAIP2} from "../../utils/CAIP-2.sol";
import {CAIP10} from "../../utils/CAIP-10.sol";

abstract contract AxelarGatewaySource is IGatewaySource, AxelarGatewayBase {
using Strings for address;
using StringsUnreleased for address;

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

// Create the package
string memory sender = msg.sender.toHexString();
string memory sender = msg.sender.toChecksumHexString();
bytes memory adapterPayload = abi.encode(sender, receiver, payload, attributes);

// Emit event
Expand Down
18 changes: 12 additions & 6 deletions contracts/crosschain/mocks/AxelarGatewayMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pragma solidity ^0.8.27;
import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGateway.sol";
import {IAxelarExecutable} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarExecutable.sol";
import {BitMaps} from "@openzeppelin/contracts/utils/structs/BitMaps.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {StringsUnreleased} from "../../utils/Strings.sol";

contract AxelarGatewayMock {
using Strings for address;
using StringsUnreleased for address;
using StringsUnreleased for string;
using BitMaps for BitMaps.BitMap;

bool private activeMode;
Expand Down Expand Up @@ -42,7 +42,12 @@ contract AxelarGatewayMock {
);

bytes32 commandId = keccak256(
abi.encode(destinationChain, msg.sender.toHexString(), destinationContractAddress, keccak256(payload))
abi.encode(
destinationChain,
msg.sender.toChecksumHexString(),
destinationContractAddress,
keccak256(payload)
)
);

require(!pendingCommandIds.get(uint256(commandId)));
Expand All @@ -53,8 +58,8 @@ contract AxelarGatewayMock {
if (activeMode) {
// NOTE:
// - source chain and destination chain are the same in this mock
address target = StringsUnreleased.parseAddress(destinationContractAddress);
IAxelarExecutable(target).execute(commandId, destinationChain, msg.sender.toHexString(), payload);
address target = destinationContractAddress.parseAddress();
IAxelarExecutable(target).execute(commandId, destinationChain, msg.sender.toChecksumHexString(), payload);
}
}

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

return
commandId == keccak256(abi.encode(sourceChain, sourceAddress, msg.sender.toHexString(), payloadHash));
commandId ==
keccak256(abi.encode(sourceChain, sourceAddress, msg.sender.toChecksumHexString(), payloadHash));
} else return false;
}
}
6 changes: 3 additions & 3 deletions contracts/utils/CAIP-10.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
pragma solidity ^0.8.0;

import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import {Strings} from "@openzeppelin/contracts/utils/Strings.sol";
import {StringsUnreleased} from "./Strings.sol";
import {Bytes} from "./Bytes.sol";
import {CAIP2} from "./CAIP-2.sol";

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

function local(address account) internal view returns (string memory) {
return format(CAIP2.local(), account.toHexString());
return format(CAIP2.local(), account.toChecksumHexString());
}

function format(string memory caip2, string memory account) internal pure returns (string memory) {
Expand Down
2 changes: 1 addition & 1 deletion test/crosschain/axelar/AxelarGateway.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { expect } = require('chai');
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { anyValue } = require('@nomicfoundation/hardhat-chai-matchers/withArgs');

const getAddress = account => (account.target ?? account.address ?? account).toLowerCase();
const getAddress = account => ethers.getAddress(account.target ?? account.address ?? account);

async function fixture() {
const [owner, sender, ...accounts] = await ethers.getSigners();
Expand Down
2 changes: 1 addition & 1 deletion test/crosschain/utils/CAIP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('CAIP utilities', function () {

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

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

0 comments on commit 336a56b

Please sign in to comment.