Skip to content

Commit

Permalink
Merge branch 'main' into remove-circular-timelock
Browse files Browse the repository at this point in the history
  • Loading branch information
ermyas committed Sep 24, 2023
2 parents b8b0b25 + af18f6d commit 5daab35
Show file tree
Hide file tree
Showing 45 changed files with 1,364 additions and 959 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ On the destination chain, if 2 of the 3 AMB agree with each other, we would cons
The flow of the message and how it is transformed and relayed is detailed below:

1. Uniswap Ethereum governance structure, `src`, approves to execute a message `msg` on destination chain `dst`.
2. Uniswap governance sends `msg` to `MultiMessageSender`.
3. `MultiMessageSender` relays `msg` to different adapters `adapter`.
2. Uniswap governance sends `msg` to `MultiBridgeMessageSender`.
3. `MultiBridgeMessageSender` relays `msg` to different adapters `adapter`.
4. `adapter` encodes `msg` into the corresponding formatted message, `formatted_msg`, and sends it to the hardcoded AMB contracts `AMB`.
5. Each `AMB` independently carries `formatted_msg` to `dst`.
6. On the destination chain, another set of `adapters` decodes `formatted_msgs` into the original `msg`.
7. `msg` is collected inside the `MultiMessageReceiver` contract.
7. `msg` is collected inside the `MultiBridgeMessageReceiver` contract.
8. If 2 out of 3 `msg` is the same, the `msg` will be executed on `dst`.

![Illustration of ](https://files.gitbook.com/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FyWOfgotvwuIBhzylK0ud%2Fuploads%2Fco073eKSrR7xUmhObi7v%2FMMA_Highlevel.png?alt=media&token=bff8ec55-c04f-4ab9-b362-caae601154db)
Expand Down Expand Up @@ -97,8 +97,8 @@ All code changes must be thoroughly tested. Please ensure that your tests cover
## Contracts
```
contracts
├── MultiMessageReceiver.sol
├── MultiMessageSender.sol
├── MultiBridgeMessageReceiver.sol
├── MultiBridgeMessageSender.sol
├── adapters
│   ├── BaseSenderAdapter.sol
│   ├── axelar
Expand Down Expand Up @@ -126,7 +126,7 @@ contracts
│   ├── IGovernanceTimelock.sol
│   ├── IMessageReceiverAdapter.sol
│   ├── IMessageSenderAdapter.sol
│   └── IMultiMessageReceiver.sol
│   └── IMultiBridgeMessageReceiver.sol
└── libraries
├── Error.sol
├── Message.sol
Expand Down
31 changes: 15 additions & 16 deletions src/MultiMessageReceiver.sol → src/MultiBridgeMessageReceiver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
pragma solidity >=0.8.9;

/// interfaces
import "./interfaces/IGAC.sol";
import "./interfaces/IMessageReceiverAdapter.sol";
import "./interfaces/IMultiMessageReceiver.sol";
import "./interfaces/controllers/IGAC.sol";
import "./interfaces/adapters/IMessageReceiverAdapter.sol";
import "./interfaces/IMultiBridgeMessageReceiver.sol";
import "./interfaces/EIP5164/ExecutorAware.sol";
import "./interfaces/IGovernanceTimelock.sol";
import "./interfaces/controllers/IGovernanceTimelock.sol";

/// libraries
import "./libraries/Error.sol";
import "./libraries/Message.sol";

/// @title Multi-bridge message receiver.
/// @notice This contract is deployed on each destination chain, and receives messages sent by the MultiMessageSender
/// @notice This contract is deployed on each destination chain, and receives messages sent by the MultiBridgeMessageSender
/// contract on the source chain, through multiple bridge adapters. A message is considered valid and can be executed
/// if it has been delivered by enough trusted bridge receiver adapters (i.e. has achieved a quorum threshold),
/// if it has been delivered by enough trusted bridge receiver adapters (i.e. has achieved a configured quorum threshold),
/// before the message's expiration. If a message is successfully validated in time, it is queued for execution on the
/// governance timelock contract.
/// @dev The contract only accepts messages from trusted bridge receiver adapters, each of which implements the
/// IMessageReceiverAdapter interface.
contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
contract MultiBridgeMessageReceiver is IMultiBridgeMessageReceiver, ExecutorAware {
/*/////////////////////////////////////////////////////////////////
STATE VARIABLES
////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -98,7 +98,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
}

/// 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 MultiMessageReceiver.
/// although each adapters' internal msgId is attached at the end of calldata, it's not useful to MultiBridgeMessageReceiver.sol.
bytes32 msgId = MessageLibrary.computeMsgId(_message);

if (msgDeliveries[msgId][msg.sender]) {
Expand All @@ -125,13 +125,11 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
}

string memory bridgeName = IMessageReceiverAdapter(msg.sender).name();
emit SingleBridgeMsgReceived(msgId, bridgeName, _message.nonce, msg.sender);
emit BridgeMessageReceived(msgId, bridgeName, _message.nonce, msg.sender);
}

/// @notice Execute the message (invoke external call according to the message content) if the message
/// @dev has reached the power threshold (the same message has been delivered by enough multiple bridges).
/// Param values can be found in the MultiMessageSent event from the source chain MultiMessageSender contract.
function executeMessage(bytes32 msgId) external {
/// @inheritdoc IMultiBridgeMessageReceiver
function executeMessage(bytes32 msgId) external override {
ExecutionData memory _execData = msgExecData[msgId];

/// @dev validates if msg execution is not beyond expiration
Expand Down Expand Up @@ -172,6 +170,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
/// @dev called by admin to update receiver bridge adapters on all other chains
function updateReceiverAdapters(address[] calldata _receiverAdapters, bool[] calldata _operations)
external
override
onlyOwner
{
_updateReceiverAdapters(_receiverAdapters, _operations);
Expand All @@ -183,7 +182,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
uint64 _newQuorum,
address[] calldata _receiverAdapters,
bool[] calldata _operations
) external onlyOwner {
) external override onlyOwner {
/// @dev updates quorum here
_updateQuorum(_newQuorum);

Expand All @@ -192,7 +191,7 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
}

/// @notice Update power quorum threshold of message execution.
function updateQuorum(uint64 _quorum) external onlyOwner {
function updateQuorum(uint64 _quorum) external override onlyOwner {
_updateQuorum(_quorum);
}

Expand Down Expand Up @@ -272,6 +271,6 @@ contract MultiMessageReceiver is IMultiMessageReceiver, ExecutorAware {
revert Error.INVALID_QUORUM_THRESHOLD();
}
}
emit ReceiverAdapterUpdated(_receiverAdapter, _add);
emit BridgeReceiverAdapterUpdated(_receiverAdapter, _add);
}
}
Loading

0 comments on commit 5daab35

Please sign in to comment.