Skip to content

Commit

Permalink
fix: conflicts with main
Browse files Browse the repository at this point in the history
  • Loading branch information
sujithsomraaj committed Oct 6, 2023
2 parents 6cedaa5 + e614b4c commit 8e63a80
Show file tree
Hide file tree
Showing 32 changed files with 241 additions and 206 deletions.
44 changes: 26 additions & 18 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pragma solidity >=0.8.9;
import "./interfaces/controllers/IGAC.sol";
import "./interfaces/adapters/IMessageReceiverAdapter.sol";
import "./interfaces/IMultiBridgeMessageReceiver.sol";
import "./interfaces/EIP5164/ExecutorAware.sol";
import "./libraries/EIP5164/ExecutorAware.sol";
import "./interfaces/controllers/IGovernanceTimelock.sol";

/// libraries
Expand Down Expand Up @@ -60,8 +60,8 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
_;
}

/// @notice A modifier used for restricting the caller to just the governance timelock contract
modifier onlyOwner() {
/// @notice Restricts the caller to the owner configured in GAC.
modifier onlyGlobalOwner() {
if (!gac.isGlobalOwner(msg.sender)) {
revert Error.CALLER_NOT_OWNER();
}
Expand All @@ -74,8 +74,16 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar

/// @notice sets the initial parameters
constructor(uint256 _srcChainId, address _gac) {
srcChainId = _srcChainId;
if (_gac == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

if (_srcChainId == 0) {
revert Error.INVALID_SENDER_CHAIN_ID();
}

gac = IGAC(_gac);
srcChainId = _srcChainId;
}

/*/////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -129,23 +137,23 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
}

/// @inheritdoc IMultiBridgeMessageReceiver
function executeMessage(bytes32 msgId) external override {
ExecutionData memory _execData = msgExecData[msgId];
function executeMessage(bytes32 _msgId) external override {
ExecutionData memory _execData = msgExecData[_msgId];

/// @dev validates if msg execution is not beyond expiration
if (block.timestamp > _execData.expiration) {
revert Error.MSG_EXECUTION_PASSED_DEADLINE();
}

/// @dev validates if msgId is already executed
if (isExecuted[msgId]) {
if (isExecuted[_msgId]) {
revert Error.MSG_ID_ALREADY_EXECUTED();
}

isExecuted[msgId] = true;
isExecuted[_msgId] = true;

/// @dev validates message quorum
if (msgDeliveryCount[msgId] < quorum) {
if (msgDeliveryCount[_msgId] < quorum) {
revert Error.QUORUM_NOT_ACHIEVED();
}

Expand All @@ -154,12 +162,12 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
_execData.target, _execData.value, _execData.callData
);

emit MessageExecuted(msgId, _execData.target, _execData.value, _execData.nonce, _execData.callData);
emit MessageExecuted(_msgId, _execData.target, _execData.value, _execData.nonce, _execData.callData);
}

/// @notice update the governance timelock contract.
/// @dev called by admin to update the timelock contract
function updateGovernanceTimelock(address _governanceTimelock) external onlyOwner {
function updateGovernanceTimelock(address _governanceTimelock) external onlyGlobalOwner {
if (_governanceTimelock == address(0)) {
revert Error.ZERO_GOVERNANCE_TIMELOCK();
}
Expand All @@ -171,7 +179,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
function updateReceiverAdapters(address[] calldata _receiverAdapters, bool[] calldata _operations)
external
override
onlyOwner
onlyGlobalOwner
{
_updateReceiverAdapters(_receiverAdapters, _operations);
}
Expand All @@ -182,7 +190,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
uint64 _newQuorum,
address[] calldata _receiverAdapters,
bool[] calldata _operations
) external override onlyOwner {
) external override onlyGlobalOwner {
/// @dev updates quorum here
_updateQuorum(_newQuorum);

Expand All @@ -191,7 +199,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
}

/// @notice Update power quorum threshold of message execution.
function updateQuorum(uint64 _quorum) external override onlyOwner {
function updateQuorum(uint64 _quorum) external override onlyGlobalOwner {
_updateQuorum(_quorum);
}

Expand All @@ -200,15 +208,15 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
////////////////////////////////////////////////////////////////*/

/// @notice view message info, return (executed, msgPower, delivered adapters)
function getMessageInfo(bytes32 msgId) public view returns (bool, uint256, string[] memory) {
uint256 msgCurrentVotes = msgDeliveryCount[msgId];
function getMessageInfo(bytes32 _msgId) public view returns (bool, uint256, string[] memory) {
uint256 msgCurrentVotes = msgDeliveryCount[_msgId];
string[] memory successfulBridge = new string[](msgCurrentVotes);

if (msgCurrentVotes != 0) {
uint256 currIndex;
address[] memory executors = getTrustedExecutors();
for (uint256 i; i < executors.length;) {
if (msgDeliveries[msgId][executors[i]]) {
if (msgDeliveries[_msgId][executors[i]]) {
successfulBridge[currIndex] = IMessageReceiverAdapter(executors[i]).name();
++currIndex;
}
Expand All @@ -219,7 +227,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
}
}

return (isExecuted[msgId], msgCurrentVotes, successfulBridge);
return (isExecuted[_msgId], msgCurrentVotes, successfulBridge);
}

/*/////////////////////////////////////////////////////////////////
Expand Down
12 changes: 6 additions & 6 deletions src/MultiBridgeMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ contract MultiBridgeMessageSender {
MODIFIERS
////////////////////////////////////////////////////////////////*/

/// @dev checks if msg.sender is the owner configured in GAC
modifier onlyOwner() {
/// @notice Restricts the caller to the owner configured in GAC.
modifier onlyGlobalOwner() {
if (msg.sender != senderGAC.getGlobalOwner()) {
revert Error.CALLER_NOT_OWNER();
}
Expand All @@ -106,7 +106,7 @@ contract MultiBridgeMessageSender {

/// @dev checks if msg.sender is the authorised caller configured in GAC
modifier onlyCaller() {
if (msg.sender != senderGAC.getAuthorisedCaller()) {
if (msg.sender != senderGAC.authorisedCaller()) {
revert Error.INVALID_PRIVILEGED_CALLER();
}
_;
Expand Down Expand Up @@ -214,7 +214,7 @@ contract MultiBridgeMessageSender {

/// @notice Add bridge sender adapters
/// @param _additions are the adapter address to add, in ascending order with no duplicates
function addSenderAdapters(address[] calldata _additions) external onlyOwner {
function addSenderAdapters(address[] calldata _additions) external onlyGlobalOwner {
_checkAdaptersOrder(_additions);

address[] memory existings = senderAdapters;
Expand Down Expand Up @@ -270,7 +270,7 @@ contract MultiBridgeMessageSender {

/// @notice Remove bridge sender adapters
/// @param _removals are the adapter addresses to remove
function removeSenderAdapters(address[] calldata _removals) external onlyOwner {
function removeSenderAdapters(address[] calldata _removals) external onlyGlobalOwner {
_checkAdaptersOrder(_removals);

address[] memory existings = senderAdapters;
Expand Down Expand Up @@ -350,7 +350,7 @@ contract MultiBridgeMessageSender {
revert Error.INVALID_REFUND_ADDRESS();
}

mmaReceiver = senderGAC.getRemoteMultiBridgeMessageReceiver(_dstChainId);
mmaReceiver = senderGAC.remoteMultiBridgeMessageReceiver(_dstChainId);

if (mmaReceiver == address(0)) {
revert Error.ZERO_RECEIVER_ADAPTER();
Expand Down
13 changes: 4 additions & 9 deletions src/adapters/BaseSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter {
MODIFIER
////////////////////////////////////////////////////////////////*/
modifier onlyMultiBridgeMessageSender() {
if (msg.sender != senderGAC.getMultiBridgeMessageSender()) {
if (msg.sender != senderGAC.multiBridgeMessageSender()) {
revert Error.CALLER_NOT_MULTI_MESSAGE_SENDER();
}
_;
Expand Down Expand Up @@ -72,20 +72,15 @@ abstract contract BaseSenderAdapter is IMessageSenderAdapter {
}
}

/// @inheritdoc IMessageSenderAdapter
function getReceiverAdapter(uint256 _dstChainId) external view override returns (address) {
return receiverAdapters[_dstChainId];
}

/*/////////////////////////////////////////////////////////////////
HELPER FUNCTIONS
////////////////////////////////////////////////////////////////*/

/// @notice generates a new message id by incrementing nonce
/// @param _toChainId is the destination chainId.
/// @param _receiverChainId is the destination chainId.
/// @param _to is the contract address on the destination chain.
function _getNewMessageId(uint256 _toChainId, address _to) internal returns (bytes32 messageId) {
messageId = keccak256(abi.encodePacked(block.chainid, _toChainId, nonce, address(this), _to));
function _getNewMessageId(uint256 _receiverChainId, address _to) internal returns (bytes32 messageId) {
messageId = keccak256(abi.encodePacked(block.chainid, _receiverChainId, nonce, address(this), _to));
++nonce;
}
}
34 changes: 18 additions & 16 deletions src/adapters/axelar/AxelarReceiverAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable {
/*/////////////////////////////////////////////////////////////////
STATE VARIABLES
////////////////////////////////////////////////////////////////*/
string public senderChain;
string public senderChainId;

mapping(bytes32 => bool) public isMessageExecuted;
mapping(bytes32 => bool) public commandIdStatus;
Expand All @@ -36,19 +36,21 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable {
CONSTRUCTOR
////////////////////////////////////////////////////////////////*/
/// @param _gateway is axelar gateway contract address.
/// @param _senderChain is the chain id of the sender chain.
/// @param _senderChainId is the chain id of the sender chain.
/// @param _receiverGAC is global access controller.
constructor(address _gateway, string memory _senderChain, address _receiverGAC) BaseReceiverAdapter(_receiverGAC) {
constructor(address _gateway, string memory _senderChainId, address _receiverGAC)
BaseReceiverAdapter(_receiverGAC)
{
if (_gateway == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}

if (bytes(_senderChain).length == 0) {
if (bytes(_senderChainId).length == 0) {
revert Error.INVALID_SENDER_CHAIN_ID();
}

gateway = IAxelarGateway(_gateway);
senderChain = _senderChain;
senderChainId = _senderChainId;
}

/*/////////////////////////////////////////////////////////////////
Expand All @@ -58,32 +60,32 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable {
/// @dev accepts new cross-chain messages from axelar gateway
/// @inheritdoc IAxelarExecutable
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
bytes32 _commandId,
string calldata _sourceChainId,
string calldata _sourceAddress,
bytes calldata _payload
) external override {
/// @dev step-1: validate incoming chain id
if (keccak256(bytes(sourceChain)) != keccak256(bytes(senderChain))) {
if (keccak256(bytes(_sourceChainId)) != keccak256(bytes(senderChainId))) {
revert Error.INVALID_SENDER_CHAIN_ID();
}

/// @dev step-2: validate the source address
if (sourceAddress.toAddress() != senderAdapter) {
if (_sourceAddress.toAddress() != senderAdapter) {
revert Error.INVALID_SENDER_ADAPTER();
}

/// @dev step-3: validate the contract call
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, keccak256(payload))) {
if (!gateway.validateContractCall(_commandId, _sourceChainId, _sourceAddress, keccak256(_payload))) {
revert Error.NOT_APPROVED_BY_GATEWAY();
}

/// decode the cross-chain payload
AdapterPayload memory decodedPayload = abi.decode(payload, (AdapterPayload));
AdapterPayload memory decodedPayload = abi.decode(_payload, (AdapterPayload));
bytes32 msgId = decodedPayload.msgId;

/// @dev step-4: check for duplicate message
if (commandIdStatus[commandId] || isMessageExecuted[msgId]) {
if (commandIdStatus[_commandId] || isMessageExecuted[msgId]) {
revert MessageIdAlreadyExecuted(msgId);
}

Expand All @@ -93,12 +95,12 @@ contract AxelarReceiverAdapter is BaseReceiverAdapter, IAxelarExecutable {
}

/// @dev step-6: validate the destination
if (decodedPayload.finalDestination != receiverGAC.getMultiBridgeMessageReceiver()) {
if (decodedPayload.finalDestination != receiverGAC.multiBridgeMsgReceiver()) {
revert Error.INVALID_FINAL_DESTINATION();
}

isMessageExecuted[msgId] = true;
commandIdStatus[commandId] = true;
commandIdStatus[_commandId] = true;

MessageLibrary.Message memory _data = abi.decode(decodedPayload.data, (MessageLibrary.Message));

Expand Down
Loading

0 comments on commit 8e63a80

Please sign in to comment.