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

feat: refactor gac into two #77

Closed
wants to merge 1 commit into from
Closed
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
6 changes: 3 additions & 3 deletions src/MultiMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity >=0.8.9;
/// interfaces
import "./interfaces/IMessageSenderAdapter.sol";
import "./interfaces/IMultiMessageReceiver.sol";
import "./interfaces/IGAC.sol";
import "./interfaces/ISenderGAC.sol";

/// libraries
import "./libraries/Message.sol";
Expand All @@ -22,7 +22,7 @@ contract MultiMessageSender {
//////////////////////////////////////////////////////////////*/

/// @dev Global Access Controller (GAC) contract
IGAC public immutable gac;
ISenderGAC public immutable gac;

/// @dev the minimum and maximum duration that a message's expiration parameter can be set to
uint256 public constant MIN_EXPIRATION = 2 days;
Expand Down Expand Up @@ -115,7 +115,7 @@ contract MultiMessageSender {
revert Error.ZERO_ADDRESS_INPUT();
}

gac = IGAC(_gac);
gac = ISenderGAC(_gac);
}

/*/////////////////////////////////////////////////////////////////
Expand Down
6 changes: 3 additions & 3 deletions src/adapters/BaseSenderAdapter.sol
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: GPL-3.0-only
pragma solidity >=0.8.9;

import "../interfaces/IGAC.sol";
import "../libraries/Error.sol";
import "../interfaces/IMessageSenderAdapter.sol";
import "../interfaces/ISenderGAC.sol";

abstract contract BaseSenderAdapter is IMessageSenderAdapter {
IGAC public immutable gac;
ISenderGAC public immutable gac;

/*/////////////////////////////////////////////////////////////////
STATE VARIABLES
Expand Down Expand Up @@ -42,7 +42,7 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter {
revert Error.ZERO_ADDRESS_INPUT();
}

gac = IGAC(_gac);
gac = ISenderGAC(_gac);
}

/*/////////////////////////////////////////////////////////////////
Expand Down
62 changes: 0 additions & 62 deletions src/controllers/GAC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,9 @@ import {Error} from "../libraries/Error.sol";

/// @dev is the global access control contract for bridge adapters
contract GAC is IGAC, Ownable {
/*///////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
uint256 public constant MINIMUM_DST_GAS_LIMIT = 50000;

/*///////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
uint256 public dstGasLimit;

/// @notice is the MMA Core Contracts on the chain
/// @dev leveraged by bridge adapters for authentication
address public multiMessageSender;

/// @dev is the allowed caller for the multi-message sender
address public allowedCaller;

mapping(uint256 chainId => address mmaReceiver) public multiMessageReceiver;

Expand All @@ -39,28 +26,6 @@ contract GAC is IGAC, Ownable {
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @inheritdoc IGAC
function setMultiMessageSender(address _mmaSender) external override onlyOwner {
if (_mmaSender == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

multiMessageSender = _mmaSender;

emit MultiMessageSenderUpdated(_mmaSender);
}

/// @inheritdoc IGAC
function setMultiMessageCaller(address _mmaCaller) external override onlyOwner {
if (_mmaCaller == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

allowedCaller = _mmaCaller;

emit MultiMessageCallerUpdated(_mmaCaller);
}

/// @inheritdoc IGAC
function setMultiMessageReceiver(uint256 _chainId, address _mmaReceiver) external override onlyOwner {
if (_mmaReceiver == address(0)) {
Expand All @@ -76,18 +41,6 @@ contract GAC is IGAC, Ownable {
emit MultiMessageReceiverUpdated(_chainId, _mmaReceiver);
}

/// @inheritdoc IGAC
function setGlobalMsgDeliveryGasLimit(uint256 _gasLimit) external override onlyOwner {
if (_gasLimit < MINIMUM_DST_GAS_LIMIT) {
revert Error.INVALID_DST_GAS_LIMIT_MIN();
}

uint256 oldLimit = dstGasLimit;
dstGasLimit = _gasLimit;

emit DstGasLimitUpdated(oldLimit, _gasLimit);
}

/*///////////////////////////////////////////////////////////////
EXTERNAL VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand All @@ -106,23 +59,8 @@ contract GAC is IGAC, Ownable {
_owner = owner();
}

/// @inheritdoc IGAC
function getGlobalMsgDeliveryGasLimit() external view override returns (uint256 _gasLimit) {
_gasLimit = dstGasLimit;
}

/// @inheritdoc IGAC
function getMultiMessageSender() external view returns (address _mmaSender) {
_mmaSender = multiMessageSender;
}

/// @inheritdoc IGAC
function getMultiMessageReceiver(uint256 _chainId) external view returns (address _mmaReceiver) {
_mmaReceiver = multiMessageReceiver[_chainId];
}

/// @inheritdoc IGAC
function getMultiMessageCaller() external view returns (address _mmaCaller) {
_mmaCaller = allowedCaller;
}
}
83 changes: 83 additions & 0 deletions src/controllers/SenderGAC.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.9;

import {GAC} from "./GAC.sol";
import {Error} from "../libraries/Error.sol";
import {ISenderGAC} from "../interfaces/ISenderGAC.sol";

/// @dev is extension of GAC containing sender only functions
contract SenderGAC is GAC, ISenderGAC {
/*///////////////////////////////////////////////////////////////
CONSTANTS
//////////////////////////////////////////////////////////////*/
uint256 public constant MINIMUM_DST_GAS_LIMIT = 50000;

/*///////////////////////////////////////////////////////////////
STATE VARIABLES
//////////////////////////////////////////////////////////////*/
uint256 public dstGasLimit;

/// @notice is the MMA Core Contracts on the chain
/// @dev leveraged by bridge adapters for authentication
address public multiMessageSender;

/// @dev is the allowed caller for the multi-message sender
address public allowedCaller;

/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @inheritdoc ISenderGAC
function setMultiMessageSender(address _mmaSender) external override onlyOwner {
if (_mmaSender == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

multiMessageSender = _mmaSender;

emit MultiMessageSenderUpdated(_mmaSender);
}

/// @inheritdoc ISenderGAC
function setMultiMessageCaller(address _mmaCaller) external override onlyOwner {
if (_mmaCaller == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

allowedCaller = _mmaCaller;

emit MultiMessageCallerUpdated(_mmaCaller);
}

/// @inheritdoc ISenderGAC
function setGlobalMsgDeliveryGasLimit(uint256 _gasLimit) external override onlyOwner {
if (_gasLimit < MINIMUM_DST_GAS_LIMIT) {
revert Error.INVALID_DST_GAS_LIMIT_MIN();
}

uint256 oldLimit = dstGasLimit;
dstGasLimit = _gasLimit;

emit DstGasLimitUpdated(oldLimit, _gasLimit);
}
/*///////////////////////////////////////////////////////////////
EXTERNAL VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @inheritdoc ISenderGAC
function getMultiMessageCaller() external view returns (address _mmaCaller) {
_mmaCaller = allowedCaller;
}

/// @inheritdoc ISenderGAC
function getMultiMessageSender() external view returns (address _mmaSender) {
_mmaSender = multiMessageSender;
}

/// @inheritdoc ISenderGAC
function getGlobalMsgDeliveryGasLimit() external view override returns (uint256 _gasLimit) {
_gasLimit = dstGasLimit;
}
}
28 changes: 0 additions & 28 deletions src/interfaces/IGAC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,17 @@ interface IGAC {
/*///////////////////////////////////////////////////////////////
EVENT
//////////////////////////////////////////////////////////////*/
event DstGasLimitUpdated(uint256 oldLimit, uint256 newLimit);

event MultiMessageCallerUpdated(address indexed mmaCaller);

event MultiMessageSenderUpdated(address indexed mmaSender);

event MultiMessageReceiverUpdated(uint256 chainId, address indexed mmaReceiver);

/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @dev sets the multi message sender caller
/// @param _mmaCaller is the multi message caller
function setMultiMessageCaller(address _mmaCaller) external;

/// @dev sets the multi message sender on same chain
/// @param _mmaSender is the multi message sender contracts
function setMultiMessageSender(address _mmaSender) external;

/// @dev sets the multi message contracts
/// @param _chainId is the unique chain identifier of the receiver address
/// @param _mmaReceiver is the multi message receiver contracts
function setMultiMessageReceiver(uint256 _chainId, address _mmaReceiver) external;

/// @dev sets the global message gas limits
/// @param _gasLimit is the limit to be set
function setGlobalMsgDeliveryGasLimit(uint256 _gasLimit) external;

/*///////////////////////////////////////////////////////////////
EXTERNAL VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand All @@ -49,16 +31,6 @@ interface IGAC {
/// @return _owner is the global owner address
function getGlobalOwner() external view returns (address _owner);

/// @dev returns the global message delivery gas limit configured
/// @return _gasLimit is the configured gas limit on dst
function getGlobalMsgDeliveryGasLimit() external view returns (uint256 _gasLimit);

/// @dev returns the multi message sender on the chain
function getMultiMessageSender() external view returns (address _mmaSender);

/// @dev returns the multi message caller that can only call the multi message sender contract
function getMultiMessageCaller() external view returns (address _mmaCaller);

/// @dev returns the multi message receiver on the chain
function getMultiMessageReceiver(uint256 _chainId) external view returns (address _mmaReceiver);
}
47 changes: 47 additions & 0 deletions src/interfaces/ISenderGAC.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// SPDX-License-Identifier: GPL-3.0-only

pragma solidity >=0.8.9;

import {IGAC} from "./IGAC.sol";

/// @notice interface for GAC (Global Access Controller) on sender chain
interface ISenderGAC is IGAC {
/*///////////////////////////////////////////////////////////////
EVENT
//////////////////////////////////////////////////////////////*/
event DstGasLimitUpdated(uint256 oldLimit, uint256 newLimit);

event MultiMessageCallerUpdated(address indexed mmaCaller);

event MultiMessageSenderUpdated(address indexed mmaSender);

/*///////////////////////////////////////////////////////////////
EXTERNAL FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @dev sets the multi message sender caller
/// @param _mmaCaller is the multi message caller
function setMultiMessageCaller(address _mmaCaller) external;

/// @dev sets the multi message sender on same chain
/// @param _mmaSender is the multi message sender contracts
function setMultiMessageSender(address _mmaSender) external;

/// @dev sets the global message gas limits
/// @param _gasLimit is the limit to be set
function setGlobalMsgDeliveryGasLimit(uint256 _gasLimit) external;

/*///////////////////////////////////////////////////////////////
EXTERNAL VIEW FUNCTIONS
//////////////////////////////////////////////////////////////*/

/// @dev returns the global message delivery gas limit configured
/// @return _gasLimit is the configured gas limit on dst
function getGlobalMsgDeliveryGasLimit() external view returns (uint256 _gasLimit);

/// @dev returns the multi message sender on the chain
function getMultiMessageSender() external view returns (address _mmaSender);

/// @dev returns the multi message caller that can only call the multi message sender contract
function getMultiMessageCaller() external view returns (address _mmaCaller);
}
15 changes: 10 additions & 5 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {AxelarSenderAdapter} from "src/adapters/axelar/AxelarSenderAdapter.sol";
import {AxelarReceiverAdapter} from "src/adapters/axelar/AxelarReceiverAdapter.sol";

import {GAC} from "src/controllers/GAC.sol";
import {SenderGAC} from "src/controllers/SenderGAC.sol";
import {GovernanceTimelock} from "src/controllers/GovernanceTimelock.sol";

import {MultiMessageSender} from "src/MultiMessageSender.sol";
Expand Down Expand Up @@ -133,10 +134,14 @@ abstract contract Setup is Test {
uint256 chainId = ALL_CHAINS[i];
vm.selectFork(fork[chainId]);

GAC gac = new GAC{salt: _salt}();
gac.setMultiMessageCaller(caller);
contractAddress[chainId][bytes("GAC")] = address(gac);

if (chainId == SRC_CHAIN_ID) {
SenderGAC gac = new SenderGAC{salt: _salt}();
gac.setMultiMessageCaller(caller);
contractAddress[chainId][bytes("GAC")] = address(gac);
} else {
GAC gac = new GAC{salt: _salt}();
contractAddress[chainId][bytes("GAC")] = address(gac);
}
unchecked {
++i;
}
Expand Down Expand Up @@ -313,7 +318,7 @@ abstract contract Setup is Test {

/// @dev mma sender is only available on chain id 1
if (chainId == 1) {
GAC(contractAddress[chainId][bytes("GAC")]).setMultiMessageSender(
SenderGAC(contractAddress[chainId][bytes("GAC")]).setMultiMessageSender(
contractAddress[chainId][bytes("MMA_SENDER")]
);
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit-tests/GAC.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "../contracts-mock/FailingSenderAdapter.sol";
import "../contracts-mock/ZeroAddressReceiverGac.sol";
import "src/interfaces/IMessageSenderAdapter.sol";
import "src/interfaces/IMultiMessageReceiver.sol";
import "src/interfaces/IGAC.sol";
import "src/interfaces/ISenderGAC.sol";
import "src/libraries/Error.sol";
import "src/libraries/Message.sol";
import {MultiMessageSender} from "src/MultiMessageSender.sol";
Expand All @@ -25,7 +25,7 @@ contract GACTest is Setup {

address senderAddr;
address receiverAddr;
IGAC gac;
ISenderGAC gac;

/// @dev initializes the setup
function setUp() public override {
Expand All @@ -34,7 +34,7 @@ contract GACTest is Setup {
vm.selectFork(fork[SRC_CHAIN_ID]);
senderAddr = contractAddress[SRC_CHAIN_ID]["MMA_SENDER"];
receiverAddr = contractAddress[DST_CHAIN_ID]["MMA_RECEIVER"];
gac = IGAC(contractAddress[SRC_CHAIN_ID]["GAC"]);
gac = ISenderGAC(contractAddress[SRC_CHAIN_ID]["GAC"]);
}

/// @dev constructor
Expand Down
Loading