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

Fix operation order in quorum / receiver update #99

Merged
merged 6 commits into from
Oct 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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);
ermyas marked this conversation as resolved.
Show resolved Hide resolved
_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);
}

ermyas marked this conversation as resolved.
Show resolved Hide resolved
/// @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
Loading