Skip to content

Commit

Permalink
Revert if updating receiver fails
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Oct 8, 2023
1 parent 77680b9 commit dc6c65c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
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

0 comments on commit dc6c65c

Please sign in to comment.