Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Ownable dependency in AxelarGatewayBase #64

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions contracts/crosschain/axelar/AxelarGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

pragma solidity ^0.8.27;

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

/**
Expand All @@ -12,7 +11,7 @@ import {IAxelarGateway} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/
* to Axelar chain identifiers) and remote gateways (i.e. gateways on other chains) to
* facilitate cross-chain communication.
*/
abstract contract AxelarGatewayBase is Ownable {
abstract contract AxelarGatewayBase {
/// @dev A remote gateway has been registered for a chain.
event RegisteredRemoteGateway(string caip2, string gatewayAddress);

Expand All @@ -31,6 +30,12 @@ abstract contract AxelarGatewayBase is Ownable {
mapping(string caip2 => string remoteGateway) private _remoteGateways;
mapping(string caip2OrAxelar => string axelarOrCaip2) private _chainEquivalence;

/// @dev Only allows an authorized registrant to call the function. See {_checkRegistrant}.
modifier onlyRegistrant() {
_checkRegistrant();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern usually goes like this:

Suggested change
_checkRegistrant();
_checkRegistrant(msg.sender);

_;
}

/// @dev Sets the local gateway address (i.e. Axelar's official gateway for the current chain).
constructor(IAxelarGateway _gateway) {
localGateway = _gateway;
Expand All @@ -49,17 +54,23 @@ abstract contract AxelarGatewayBase is Ownable {
}

/// @dev Registers a chain equivalence between a CAIP-2 chain identifier and an Axelar network identifier.
function registerChainEquivalence(string calldata caip2, string calldata axelarSupported) public virtual onlyOwner {
function registerChainEquivalence(
string calldata caip2,
string calldata axelarSupported
) public virtual onlyRegistrant {
require(bytes(_chainEquivalence[caip2]).length == 0, ChainEquivalenceAlreadyRegistered(caip2));
_chainEquivalence[caip2] = axelarSupported;
_chainEquivalence[axelarSupported] = caip2;
emit RegisteredChainEquivalence(caip2, axelarSupported);
}

/// @dev Registers the address string of the remote gateway for a given CAIP-2 chain identifier.
function registerRemoteGateway(string calldata caip2, string calldata remoteGateway) public virtual onlyOwner {
function registerRemoteGateway(string calldata caip2, string calldata remoteGateway) public virtual onlyRegistrant {
require(bytes(_remoteGateways[caip2]).length == 0, RemoteGatewayAlreadyRegistered(caip2));
_remoteGateways[caip2] = remoteGateway;
emit RegisteredRemoteGateway(caip2, remoteGateway);
}

/// @dev Modifier to check if the caller is allowed to register remote gateways and chain equivalences.
function _checkRegistrant() internal virtual;
}
7 changes: 2 additions & 5 deletions contracts/crosschain/axelar/AxelarGatewayDuplex.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import {AxelarGatewaySource} from "./AxelarGatewaySource.sol";
* adapters for the Axelar Network. Allowing to either send or receive messages across chains.
*/
// slither-disable-next-line locked-ether
contract AxelarGatewayDuplex is AxelarGatewaySource, AxelarGatewayDestination {
abstract contract AxelarGatewayDuplex is AxelarGatewaySource, AxelarGatewayDestination {
/// @dev Initializes the contract with the Axelar gateway and the initial owner.
constructor(
IAxelarGateway gateway,
address initialOwner
) Ownable(initialOwner) AxelarGatewayBase(gateway) AxelarExecutable(address(gateway)) {}
constructor(IAxelarGateway gateway) AxelarGatewayBase(gateway) AxelarExecutable(address(gateway)) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.27;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {AxelarGatewayDestination} from "../../../crosschain/axelar/AxelarGatewayDestination.sol";

abstract contract AxelarGatewayDestinationOwnableMock is AxelarGatewayDestination, Ownable {
function _checkRegistrant() internal override onlyOwner {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.27;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {AxelarGatewaySource} from "../../../crosschain/axelar/AxelarGatewaySource.sol";

abstract contract AxelarGatewaySourceOwnableMock is AxelarGatewaySource, Ownable {
function _checkRegistrant() internal override onlyOwner {}
}
4 changes: 2 additions & 2 deletions test/crosschain/axelar/AxelarGateway.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ async function fixture() {
const asCAIP10 = account => `eip155:${chainId}:${getAddress(account)}`;

const axelar = await ethers.deployContract('$AxelarGatewayMock');
const srcGateway = await ethers.deployContract('$AxelarGatewaySource', [owner, axelar]);
const dstGateway = await ethers.deployContract('$AxelarGatewayDestination', [owner, axelar, axelar]);
const srcGateway = await ethers.deployContract('$AxelarGatewaySourceOwnableMock', [axelar, owner]);
const dstGateway = await ethers.deployContract('$AxelarGatewayDestinationOwnableMock', [axelar, axelar, owner]);
const receiver = await ethers.deployContract('$ERC7786ReceiverMock', [dstGateway]);
const invalidReceiver = await ethers.deployContract('$ERC7786ReceiverInvalidMock');

Expand Down
Loading