Skip to content

Commit

Permalink
Fix operation order in quorum / receiver update
Browse files Browse the repository at this point in the history
Fixes #93
  • Loading branch information
Dominator008 committed Oct 5, 2023
1 parent 16e7dcb commit 18c6fc1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -183,11 +183,13 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
address[] calldata _receiverAdapters,
bool[] calldata _operations
) external override onlyGlobalOwner {
/// @dev updates quorum here
_updateQuorum(_newQuorum);

/// @dev updates receiver adapter here
_updateReceiverAdapters(_receiverAdapters, _operations);
if (_newQuorum > quorum) {
_updateReceiverAdapters(_receiverAdapters, _operations);
_updateQuorum(_newQuorum);
} else {
_updateQuorum(_newQuorum);
_updateReceiverAdapters(_receiverAdapters, _operations);
}
}

/// @notice Update power quorum threshold of message execution.
Expand Down
47 changes: 47 additions & 0 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,53 @@ contract MultiBridgeMessageReceiverTest is Setup {
assertEq(receiver.isTrustedExecutor(adapters[0]), false);
}

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

// First, add one adapter
address[] memory addOneAdapter = new address[](1);
addOneAdapter[0] = address(42);
bool[] memory addOneOps = new bool[](1);
addOneOps[0] = true;

// Add two more and update quorum to 4
address[] memory addTwoAdapters = new address[](2);
addTwoAdapters[0] = address(420);
addTwoAdapters[1] = address(421);

bool[] memory addTwoOps = new bool[](2);
addTwoOps[0] = true;
addTwoOps[1] = true;

uint64 newQuorum = 4;

receiver.updateQuorumAndReceiverAdapter(newQuorum, addTwoAdapters, addTwoOps);

/// @dev asserts the quorum and adapter lengths
assertEq(receiver.quorum(), newQuorum);
assertEq(receiver.isTrustedExecutor(addTwoAdapters[0]), true);
assertEq(receiver.isTrustedExecutor(addTwoAdapters[1]), true);
}

/// @dev valid quorum and receiver updater in one single call, removing adapter and decreasing quorum
function test_quorum_and_receiver_updater_remove_decrease() public {
vm.startPrank(timelockAddr);

// Remove one adapter and update quorum to 1
address[] memory removeOneAdapter = new address[](1);
removeOneAdapter[0] = axelarAdapterAddr;

uint64 newQuorum = 1;

receiver.updateQuorumAndReceiverAdapter(newQuorum, removeOneAdapter, new bool[](1));

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

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

0 comments on commit 18c6fc1

Please sign in to comment.