Skip to content

Commit

Permalink
Nit fixes to address comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominator008 committed Oct 11, 2023
1 parent 9377e1f commit f6f281e
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 36 deletions.
9 changes: 6 additions & 3 deletions src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
}

Expand Down
4 changes: 3 additions & 1 deletion src/MultiBridgeMessageSender.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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
////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 16 additions & 14 deletions test/unit-tests/MultiBridgeMessageReceiver.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand All @@ -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);

Expand All @@ -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));
}

Expand All @@ -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
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 5 additions & 3 deletions test/unit-tests/MultiBridgeMessageSender.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand Down
17 changes: 9 additions & 8 deletions test/unit-tests/adapters/axelar/AxelarReceiverAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
16 changes: 9 additions & 7 deletions test/unit-tests/adapters/wormhole/WormholeReceiverAdapter.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit f6f281e

Please sign in to comment.