Skip to content

Commit

Permalink
Fix missing events in three state update functions (#101)
Browse files Browse the repository at this point in the history
* Fix missing event on timelock address update

* Fix missing event in Axelar adapter during id map change

* Fix missing event in Wormhole chain id map update

* Add missing validation in chain id mapping updates

* Improve chain id mapping update events
  • Loading branch information
ermyas authored Oct 8, 2023
1 parent 77680b9 commit 9d56d5f
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,9 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar
if (_governanceTimelock == address(0)) {
revert Error.ZERO_GOVERNANCE_TIMELOCK();
}
address oldGovernanceTimelock = governanceTimelock;
governanceTimelock = _governanceTimelock;
emit GovernanceTimelockUpdated(oldGovernanceTimelock, _governanceTimelock);
}

/// @notice Update bridge receiver adapters.
Expand Down
10 changes: 10 additions & 0 deletions src/adapters/axelar/AxelarSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import "./interfaces/IAxelarGasService.sol";
import "./libraries/StringAddressConversion.sol";

contract AxelarSenderAdapter is BaseSenderAdapter {
/// @notice event emitted when a chain id mapping is updated
event ChainIDMappingUpdated(uint256 indexed origId, string oldAxlId, string newAxlId);

string public constant name = "AXELAR";

IAxelarGateway public immutable gateway;
Expand Down Expand Up @@ -78,8 +81,15 @@ contract AxelarSenderAdapter is BaseSenderAdapter {
}

for (uint256 i; i < arrLength;) {
if (_origIds[i] == 0) {
revert Error.ZERO_CHAIN_ID();
}

string memory oldAxlId = chainIdMap[_origIds[i]];
chainIdMap[_origIds[i]] = _axlIds[i];

emit ChainIDMappingUpdated(_origIds[i], oldAxlId, _axlIds[i]);

unchecked {
++i;
}
Expand Down
10 changes: 10 additions & 0 deletions src/adapters/wormhole/WormholeSenderAdapter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import "../../libraries/Types.sol";

/// @notice sender adapter for wormhole bridge
contract WormholeSenderAdapter is BaseSenderAdapter {
/// @notice event emitted when a chain id mapping is updated
event ChainIDMappingUpdated(uint256 indexed origId, uint16 oldWhId, uint16 newWhId);

string public constant name = "WORMHOLE";
IWormholeRelayer public immutable relayer;

Expand Down Expand Up @@ -80,8 +83,15 @@ contract WormholeSenderAdapter is BaseSenderAdapter {
}

for (uint256 i; i < arrLength;) {
if (_origIds[i] == 0) {
revert Error.ZERO_CHAIN_ID();
}

uint16 oldWhId = chainIdMap[_origIds[i]];
chainIdMap[_origIds[i]] = _whIds[i];

emit ChainIDMappingUpdated(_origIds[i], oldWhId, _whIds[i]);

unchecked {
++i;
}
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/IMultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ interface IMultiBridgeMessageReceiver {
/// @param newQuorum is the new quorum value
event QuorumUpdated(uint64 oldQuorum, uint64 newQuorum);

/// @notice emitted when the governance timelock address is updated.
/// @param oldTimelock is the previous governance timelock contract address
/// @param newTimelock is the new governance timelock contract address
event GovernanceTimelockUpdated(address oldTimelock, address newTimelock);

/// @notice Receive messages from allowed bridge receiver adapters.
/// @dev Every receiver adapter should call this function with decoded MessageLibrary.Message
/// @param _message is the message to be received
Expand Down Expand Up @@ -75,4 +80,8 @@ interface IMultiBridgeMessageReceiver {
bool[] calldata _operations,
uint64 _newQuorum
) external;

/// @notice updates the governance timelock address, which is the contract that ultimately executes valid messages.
/// @param _newGovernanceTimelock is the new governance timelock contract address
function updateGovernanceTimelock(address _newGovernanceTimelock) external;
}
4 changes: 4 additions & 0 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {MultiBridgeMessageReceiver} from "src/MultiBridgeMessageReceiver.sol";
contract MultiBridgeMessageReceiverTest is Setup {
event BridgeReceiverAdapterUpdated(address indexed receiverAdapter, bool add);
event QuorumUpdated(uint64 oldValue, uint64 newValue);
event GovernanceTimelockUpdated(address oldTimelock, address newTimelock);
event BridgeMessageReceived(
bytes32 indexed msgId, string indexed bridgeName, uint256 nonce, address receiverAdapter
);
Expand Down Expand Up @@ -368,6 +369,9 @@ contract MultiBridgeMessageReceiverTest is Setup {
function test_update_governance_timelock() public {
vm.startPrank(timelockAddr);

vm.expectEmit(true, true, true, true, address(receiver));
emit GovernanceTimelockUpdated(receiver.governanceTimelock(), address(42));

receiver.updateGovernanceTimelock(address(42));
assertEq(receiver.governanceTimelock(), address(42));
}
Expand Down
13 changes: 13 additions & 0 deletions test/unit-tests/adapters/axelar/AxelarSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contract AxelarSenderAdapterTest is Setup {
event MessageDispatched(
bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data
);
event ChainIDMappingUpdated(uint256 indexed origId, string oldAxlId, string newAxlId);

address senderAddr;
AxelarSenderAdapter adapter;
Expand Down Expand Up @@ -108,6 +109,10 @@ contract AxelarSenderAdapterTest is Setup {
origIds[0] = DST_CHAIN_ID;
string[] memory axlIds = new string[](1);
axlIds[0] = "42";

vm.expectEmit(true, true, true, true, address(adapter));
emit ChainIDMappingUpdated(origIds[0], adapter.chainIdMap(DST_CHAIN_ID), axlIds[0]);

adapter.setChainIdMap(origIds, axlIds);

assertEq(adapter.chainIdMap(DST_CHAIN_ID), "42");
Expand All @@ -128,4 +133,12 @@ contract AxelarSenderAdapterTest is Setup {
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCHED.selector);
adapter.setChainIdMap(new uint256[](0), new string[](1));
}

/// @dev cannot set chain ID map with invalid chain ID
function test_set_chain_id_map_zero_chain_id() public {
vm.startPrank(owner);

vm.expectRevert(Error.ZERO_CHAIN_ID.selector);
adapter.setChainIdMap(new uint256[](1), new string[](1));
}
}
13 changes: 13 additions & 0 deletions test/unit-tests/adapters/wormhole/WormholeSenderAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ contract WormholeSenderAdapterTest is Setup {
event MessageDispatched(
bytes32 indexed messageId, address indexed from, uint256 indexed receiverChainId, address to, bytes data
);
event ChainIDMappingUpdated(uint256 indexed origId, uint16 oldWhId, uint16 newWhId);

address senderAddr;
WormholeSenderAdapter adapter;
Expand Down Expand Up @@ -105,6 +106,10 @@ contract WormholeSenderAdapterTest is Setup {
origIds[0] = DST_CHAIN_ID;
uint16[] memory whIds = new uint16[](1);
whIds[0] = 42;

vm.expectEmit(true, true, true, true, address(adapter));
emit ChainIDMappingUpdated(origIds[0], adapter.chainIdMap(DST_CHAIN_ID), whIds[0]);

adapter.setChainIdMap(origIds, whIds);

assertEq(adapter.chainIdMap(DST_CHAIN_ID), 42);
Expand All @@ -125,4 +130,12 @@ contract WormholeSenderAdapterTest is Setup {
vm.expectRevert(Error.ARRAY_LENGTH_MISMATCHED.selector);
adapter.setChainIdMap(new uint256[](0), new uint16[](1));
}

/// @dev cannot set chain ID map with invalid chain ID
function test_set_chain_id_map_zero_chain_id() public {
vm.startPrank(owner);

vm.expectRevert(Error.ZERO_CHAIN_ID.selector);
adapter.setChainIdMap(new uint256[](1), new uint16[](1));
}
}

0 comments on commit 9d56d5f

Please sign in to comment.