Skip to content

Commit

Permalink
Cleanup update receiver adapter / quorum logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominator008 committed Oct 5, 2023
1 parent 18c6fc1 commit 6b25342
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
28 changes: 12 additions & 16 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
onlyGlobalOwner
{
_updateReceiverAdapters(_receiverAdapters, _operations);
_validateQuorum(quorum);
}

/// @notice Update bridge receiver adapters after quorum update
Expand All @@ -183,18 +184,13 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
address[] calldata _receiverAdapters,
bool[] calldata _operations
) external override onlyGlobalOwner {
if (_newQuorum > quorum) {
_updateReceiverAdapters(_receiverAdapters, _operations);
_updateQuorum(_newQuorum);
} else {
_updateQuorum(_newQuorum);
_updateReceiverAdapters(_receiverAdapters, _operations);
}
_updateReceiverAdapters(_receiverAdapters, _operations);
_validateAndUpdateQuorum(_newQuorum);
}

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

/*/////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -228,10 +224,8 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
PRIVATE/INTERNAL FUNCTIONS
////////////////////////////////////////////////////////////////*/

function _updateQuorum(uint64 _quorum) internal {
if (_quorum > trustedExecutorsCount() || _quorum == 0) {
revert Error.INVALID_QUORUM_THRESHOLD();
}
function _validateAndUpdateQuorum(uint64 _quorum) internal {
_validateQuorum(_quorum);

uint64 oldValue = quorum;

Expand Down Expand Up @@ -268,11 +262,13 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
_addTrustedExecutor(_receiverAdapter);
} else {
_removeTrustedExecutor(_receiverAdapter);

if (quorum > trustedExecutorsCount()) {
revert Error.INVALID_QUORUM_THRESHOLD();
}
}
emit BridgeReceiverAdapterUpdated(_receiverAdapter, _add);
}

function _validateQuorum(uint256 _quorum) private view {
if (_quorum > trustedExecutorsCount() || _quorum == 0) {
revert Error.INVALID_QUORUM_THRESHOLD();
}
}
}
3 changes: 1 addition & 2 deletions test/Setup.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ abstract contract Setup is Test {

MultiBridgeMessageReceiver dstMMReceiver =
MultiBridgeMessageReceiver(contractAddress[chainId][bytes("MMA_RECEIVER")]);
dstMMReceiver.updateReceiverAdapters(_receiverAdapters, _operations);
dstMMReceiver.updateQuorumAndReceiverAdapter(2, _receiverAdapters, _operations);
dstMMReceiver.updateGovernanceTimelock(contractAddress[chainId]["TIMELOCK"]);
dstMMReceiver.updateQuorum(2);

MessageReceiverGAC receiverGAC = MessageReceiverGAC(contractAddress[chainId][bytes("GAC")]);
receiverGAC.setMultiBridgeMessageReceiver(address(dstMMReceiver));
Expand Down
26 changes: 26 additions & 0 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,32 @@ contract MultiBridgeMessageReceiverTest is Setup {
assertEq(receiver.isTrustedExecutor(axelarAdapterAddr), false);
}

/// @dev valid quorum and receiver updater in one single call, removing one, adding two and increasing quorum
function test_quorum_and_receiver_updater_remove_add_increase() public {
vm.startPrank(timelockAddr);

// Remove one adapter and update quorum to 1
address[] memory removeAddAdapters = new address[](3);
removeAddAdapters[0] = axelarAdapterAddr;
removeAddAdapters[1] = address(42);
removeAddAdapters[2] = address(43);
bool[] memory removeAddOps = new bool[](3);
removeAddOps[0] = false;
removeAddOps[1] = true;
removeAddOps[2] = true;

uint64 newQuorum = 3;

receiver.updateQuorumAndReceiverAdapter(newQuorum, removeAddAdapters, removeAddOps);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
assertEq(receiver.isTrustedExecutor(wormholeAdapterAddr), true);
assertEq(receiver.isTrustedExecutor(axelarAdapterAddr), false);
assertEq(receiver.isTrustedExecutor(removeAddAdapters[1]), true);
assertEq(receiver.isTrustedExecutor(removeAddAdapters[2]), true);
}

/// @dev should get message info
function test_get_message_info() public {
vm.startPrank(wormholeAdapterAddr);
Expand Down

0 comments on commit 6b25342

Please sign in to comment.