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

Revert if updating receiver fails #102

Merged
merged 1 commit into from
Oct 8, 2023
Merged
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
10 changes: 6 additions & 4 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,13 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
if (_receiverAdapter == address(0)) {
revert Error.ZERO_ADDRESS_INPUT();
}
if (_add) {
_addTrustedExecutor(_receiverAdapter);
} else {
_removeTrustedExecutor(_receiverAdapter);
bool success = _add ? _addTrustedExecutor(_receiverAdapter) : _removeTrustedExecutor(_receiverAdapter);

if (!success) {
// only fails because we are either attempting to add an existing adapter, or remove a non-existing adapter
revert Error.UPDATE_RECEIVER_ADAPTER_FAILED(_add ? "adapter already added" : "adapter not found");
}

emit BridgeReceiverAdapterUpdated(_receiverAdapter, _add);
}

Expand Down
4 changes: 4 additions & 0 deletions src/libraries/Error.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ library Error {
/// @dev is thrown if caller is invalid receiver adapter
error INVALID_RECEIVER_ADAPTER();

/// @dev is thrown if updating a receiver adapter fails
/// @param reason is the reason for failure
error UPDATE_RECEIVER_ADAPTER_FAILED(string reason);

/// @dev is thrown if caller is not self
error INVALID_SELF_CALLER();

Expand Down
28 changes: 28 additions & 0 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,19 @@ contract MultiBridgeMessageReceiverTest is Setup {
assertTrue(receiver.isTrustedExecutor(address(42)));
}

/// @dev adding a receiver adapter that already exists should fail
function test_update_receiver_adapter_add_existing() public {
vm.startPrank(timelockAddr);

address[] memory updatedAdapters = new address[](1);
updatedAdapters[0] = wormholeAdapterAddr;
bool[] memory operations = new bool[](1);
operations[0] = true;

vm.expectRevert(abi.encodeWithSelector(Error.UPDATE_RECEIVER_ADAPTER_FAILED.selector, "adapter already added"));
receiver.updateReceiverAdapters(updatedAdapters, operations);
}

/// @dev removes one receiver adapter
function test_update_receiver_adapter_remove() public {
vm.startPrank(timelockAddr);
Expand All @@ -420,6 +433,21 @@ contract MultiBridgeMessageReceiverTest is Setup {
assertTrue(receiver.isTrustedExecutor(axelarAdapterAddr));
}

/// @dev removing a receiver adapter that does not exist should fail
function test_update_receiver_adapter_remove_non_existing() public {
vm.startPrank(timelockAddr);

address[] memory updatedAdapters = new address[](1);
updatedAdapters[0] = address(42);
bool[] memory operations = new bool[](1);
operations[0] = false;

assertFalse(receiver.isTrustedExecutor(address(42)));

vm.expectRevert(abi.encodeWithSelector(Error.UPDATE_RECEIVER_ADAPTER_FAILED.selector, "adapter not found"));
receiver.updateReceiverAdapters(updatedAdapters, operations);
}

/// @dev only governance timelock can call
function test_update_receiver_adapter_only_governance_timelock() public {
vm.startPrank(caller);
Expand Down
Loading