diff --git a/src/MultiBridgeMessageReceiver.sol b/src/MultiBridgeMessageReceiver.sol index 966f078..e852e5d 100644 --- a/src/MultiBridgeMessageReceiver.sol +++ b/src/MultiBridgeMessageReceiver.sol @@ -21,6 +21,9 @@ import "./libraries/Message.sol"; /// @dev The contract only accepts messages from trusted bridge receiver adapters, each of which implements the /// IMessageReceiverAdapter interface. contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAware { + using MessageLibrary for MessageLibrary.Message; + using MessageLibrary for MessageLibrary.MessageExecutionParams; + /// @notice the id of the source chain that this contract can receive messages from uint256 public immutable srcChainId; /// @notice the global access control contract @@ -114,7 +117,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar /// this msgId is totally different with each adapters' internal msgId(which is their internal nonce essentially) /// although each adapters' internal msgId is attached at the end of calldata, it's not useful to MultiBridgeMessageReceiver.sol. - bytes32 msgId = MessageLibrary.computeMsgId(_message); + bytes32 msgId = _message.computeMsgId(); if (msgDeliveries[msgId][msg.sender]) { revert Error.DUPLICATE_MESSAGE_DELIVERY_BY_ADAPTER(); @@ -135,7 +138,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar /// stores the message if the amb is the first one delivering the message if (prevStoredHash == bytes32(0)) { - msgExecParamsHash[msgId] = MessageLibrary.computeExecutionParamsHash(_message); + msgExecParamsHash[msgId] = _message.computeExecutionParamsHash(); } string memory bridgeName = IMessageReceiverAdapter(msg.sender).name(); @@ -148,7 +151,7 @@ contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAwar override { bytes32 execParamsHash = msgExecParamsHash[_msgId]; - if (MessageLibrary.computeExecutionParamsHash(_execParams) != execParamsHash) { + if (_execParams.computeExecutionParamsHash() != execParamsHash) { revert Error.EXEC_PARAMS_HASH_MISMATCH(); } diff --git a/src/MultiBridgeMessageSender.sol b/src/MultiBridgeMessageSender.sol index 6a3351c..f5bf467 100644 --- a/src/MultiBridgeMessageSender.sol +++ b/src/MultiBridgeMessageSender.sol @@ -17,6 +17,8 @@ import "./libraries/Error.sol"; /// Both of these are configured in the Global Access Control contract. In the case of Uniswap, both the authorised caller /// and owner should be set to the Uniswap V2 Timelock contract on Ethereum. contract MultiBridgeMessageSender { + using MessageLibrary for MessageLibrary.Message; + /*///////////////////////////////////////////////////////////////// STRUCTS ////////////////////////////////////////////////////////////////*/ @@ -268,7 +270,7 @@ contract MultiBridgeMessageSender { _args.nativeValue, block.timestamp + _args.expiration ); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); (bool[] memory adapterSuccess, uint256 successCount) = _dispatchMessages(adapters, mmaReceiver, _args.dstChainId, message, _args.fees); diff --git a/test/unit-tests/MultiBridgeMessageReceiver.t.sol b/test/unit-tests/MultiBridgeMessageReceiver.t.sol index 309b48e..184c5b4 100644 --- a/test/unit-tests/MultiBridgeMessageReceiver.t.sol +++ b/test/unit-tests/MultiBridgeMessageReceiver.t.sol @@ -13,6 +13,8 @@ import {MultiBridgeMessageReceiver} from "src/MultiBridgeMessageReceiver.sol"; import {IMultiBridgeMessageReceiver} from "src/interfaces/IMultiBridgeMessageReceiver.sol"; contract MultiBridgeMessageReceiverTest is Setup { + using MessageLibrary for MessageLibrary.Message; + event BridgeReceiverAdapterUpdated(address indexed receiverAdapter, bool add); event QuorumUpdated(uint64 oldValue, uint64 newValue); event GovernanceTimelockUpdated(address oldTimelock, address newTimelock); @@ -126,7 +128,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); vm.expectEmit(true, true, true, true, address(receiver)); emit BridgeMessageReceived(msgId, "WORMHOLE", 42, wormholeAdapterAddr); @@ -139,7 +141,7 @@ contract MultiBridgeMessageReceiverTest is Setup { assertEq(receiver.msgDeliveryCount(msgId), 1); - assertEq(receiver.msgExecParamsHash(msgId), MessageLibrary.computeExecutionParamsHash(message)); + assertEq(receiver.msgExecParamsHash(msgId), message.computeExecutionParamsHash()); } /// @dev receives message from two adapters @@ -155,7 +157,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); @@ -268,7 +270,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); // Reduce quorum first vm.startPrank(address(timelockAddr)); @@ -277,7 +279,7 @@ contract MultiBridgeMessageReceiverTest is Setup { vm.startPrank(wormholeAdapterAddr); receiver.receiveMessage(message); - receiver.scheduleMessageExecution(msgId, MessageLibrary.extractExecutionParams(message)); + receiver.scheduleMessageExecution(msgId, message.extractExecutionParams()); vm.startPrank(axelarAdapterAddr); vm.expectRevert(Error.MSG_ID_ALREADY_SCHEDULED.selector); @@ -297,7 +299,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); @@ -307,7 +309,7 @@ contract MultiBridgeMessageReceiverTest is Setup { vm.expectEmit(true, true, true, true, address(receiver)); emit MessageExecutionScheduled(msgId, address(42), 0, 42, bytes("42")); - receiver.scheduleMessageExecution(msgId, MessageLibrary.extractExecutionParams(message)); + receiver.scheduleMessageExecution(msgId, message.extractExecutionParams()); assertTrue(receiver.isExecutionScheduled(msgId)); } @@ -324,12 +326,12 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: 0 }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); vm.expectRevert(Error.MSG_EXECUTION_PASSED_DEADLINE.selector); - receiver.scheduleMessageExecution(msgId, MessageLibrary.extractExecutionParams(message)); + receiver.scheduleMessageExecution(msgId, message.extractExecutionParams()); } /// @dev cannot schedule execution of message that has already been scheduled @@ -345,7 +347,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); @@ -364,7 +366,7 @@ contract MultiBridgeMessageReceiverTest is Setup { ); vm.expectRevert(Error.MSG_ID_ALREADY_SCHEDULED.selector); - receiver.scheduleMessageExecution(msgId, MessageLibrary.extractExecutionParams(message)); + receiver.scheduleMessageExecution(msgId, message.extractExecutionParams()); } /// @dev cannot schedule message execution without quorum @@ -380,12 +382,12 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); vm.expectRevert(Error.QUORUM_NOT_ACHIEVED.selector); - receiver.scheduleMessageExecution(msgId, MessageLibrary.extractExecutionParams(message)); + receiver.scheduleMessageExecution(msgId, message.extractExecutionParams()); } /// @dev updates governance timelock @@ -689,7 +691,7 @@ contract MultiBridgeMessageReceiverTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); receiver.receiveMessage(message); diff --git a/test/unit-tests/MultiBridgeMessageSender.t.sol b/test/unit-tests/MultiBridgeMessageSender.t.sol index 5e4fa4e..a61f997 100644 --- a/test/unit-tests/MultiBridgeMessageSender.t.sol +++ b/test/unit-tests/MultiBridgeMessageSender.t.sol @@ -17,6 +17,8 @@ import "src/libraries/Message.sol"; import {MultiBridgeMessageSender} from "src/MultiBridgeMessageSender.sol"; contract MultiBridgeMessageSenderTest is Setup { + using MessageLibrary for MessageLibrary.Message; + event MultiBridgeMessageSent( bytes32 indexed msgId, uint256 nonce, @@ -86,7 +88,7 @@ contract MultiBridgeMessageSenderTest is Setup { nativeValue: 0, expiration: block.timestamp + expiration }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); vm.expectEmit(true, true, true, true, address(sender)); emit MultiBridgeMessageSent( @@ -161,7 +163,7 @@ contract MultiBridgeMessageSenderTest is Setup { nativeValue: 0, expiration: block.timestamp + EXPIRATION_CONSTANT }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); uint256[] memory fees = new uint256[](1); (uint256 wormholeFee,) = IWormholeRelayer(POLYGON_RELAYER).quoteEVMDeliveryPrice( @@ -539,7 +541,7 @@ contract MultiBridgeMessageSenderTest is Setup { nativeValue: 0, expiration: block.timestamp + expiration }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); vm.expectEmit(true, true, true, true, address(sender)); emit MessageSendFailed(failingAdapterAddr, message); diff --git a/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol b/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol index 96e6d35..b03c10f 100644 --- a/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol +++ b/test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol @@ -16,6 +16,7 @@ import "src/libraries/Types.sol"; import {AxelarReceiverAdapter} from "src/adapters/axelar/AxelarReceiverAdapter.sol"; contract AxelarReceiverAdapterTest is Setup { + using MessageLibrary for MessageLibrary.Message; using StringAddressConversion for address; event MessageIdExecuted(uint256 indexed fromChainId, bytes32 indexed messageId); @@ -105,7 +106,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -137,7 +138,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -164,7 +165,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -191,7 +192,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -218,7 +219,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -247,7 +248,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -274,7 +275,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -301,7 +302,7 @@ contract AxelarReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, diff --git a/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol b/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol index 6ac06b8..66da381 100644 --- a/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol +++ b/test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol @@ -15,6 +15,8 @@ import "src/libraries/TypeCasts.sol"; import {WormholeReceiverAdapter} from "src/adapters/wormhole/WormholeReceiverAdapter.sol"; contract WormholeReceiverAdapterTest is Setup { + using MessageLibrary for MessageLibrary.Message; + event MessageIdExecuted(uint256 indexed fromChainId, bytes32 indexed messageId); event SenderAdapterUpdated(address indexed oldSenderAdapter, address indexed newSenderAdapter); @@ -104,7 +106,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -140,7 +142,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -170,7 +172,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -201,7 +203,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -234,7 +236,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -264,7 +266,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId, @@ -295,7 +297,7 @@ contract WormholeReceiverAdapterTest is Setup { nativeValue: 0, expiration: type(uint256).max }); - bytes32 msgId = MessageLibrary.computeMsgId(message); + bytes32 msgId = message.computeMsgId(); AdapterPayload memory payload = AdapterPayload({ msgId: msgId,