Skip to content

Commit f86e69b

Browse files
committed
forge install: example-messaging-executor
1 parent 228e8b0 commit f86e69b

File tree

8 files changed

+807
-64
lines changed

8 files changed

+807
-64
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@
1010
[submodule "evm/lib/solidity-bytes-utils"]
1111
path = evm/lib/solidity-bytes-utils
1212
url = https://github.com/GNSPS/solidity-bytes-utils
13+
[submodule "evm/lib/example-messaging-executor"]
14+
path = evm/lib/example-messaging-executor
15+
url = https://github.com/wormholelabs-xyz/example-messaging-executor

evm/NOTES.md

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,11 @@
1-
# Notes on splitting token from base
1+
# Notes on changes made in this integration branch
22

3-
## MangerBase
3+
## Change that wasn't made
44

5-
### Implements (Should it implement all these?)
5+
It is unfortunate that `token` and `mode` exist in `ManagerBase` rather than `NttManager`.
6+
I tried moving them, but that increases
67

7-
- IManagerBase,
8-
- TransceiverRegistry,
9-
- PausableOwnable,
10-
- ReentrancyGuardUpgradeable,
11-
- Implementation
12-
13-
### Functionality Provided
14-
15-
- Stores the following:
16-
- Transceiver registry
17-
- Thresholds
18-
- Attestations
19-
- Message sequence number
20-
- Has the following functionality:
21-
- `quoteDeliveryPrice`
22-
- Record attestation
23-
- Send message
24-
25-
### Simple Changes Made
26-
27-
- Moved the following from `ManagerBase` to `NttManager:
28-
29-
- Token
30-
- Mode
31-
- `_prepareForTransfer`
32-
33-
### Possible Ideas
34-
35-
- Maybe we could [like an external library](https://book.getfoundry.sh/reference/forge/forge-create#linker-options) for admin functionality.
36-
37-
### Contract Sizes
38-
39-
#### Before we started
8+
### Before we started
409

4110
```bash
4211
evm (main)$ forge build --sizes --via-ir --skip test
@@ -49,14 +18,10 @@ evm (main)$ forge build --sizes --via-ir --skip test
4918
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
5019
| NttManagerNoRateLimiting | 17,141 | 18,557 | 7,435 | 30,595 |
5120
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
52-
| TestManager | 8,981 | 10,259 | 15,595 | 38,893 |
53-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
5421

5522
```
5623

57-
- Note the `TestManager` just instantiates `ManagerBase.sol`.
58-
59-
#### After simple changes
24+
### After moving token and mode
6025

6126
```bash
6227
evm (main)$ forge build --sizes --via-ir --skip test
@@ -66,26 +31,14 @@ evm (main)$ forge build --sizes --via-ir --skip test
6631
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
6732
| NttManagerNoRateLimiting | 18,788 | 20,281 | 5,788 | 28,871 |
6833
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
69-
| TestManager | 8,368 | 9,511 | 16,208 | 39,641 |
70-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
7134

7235
```
7336

74-
```
75-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
76-
| NttManager | 23,907 | 25,510 | 669 | 23,642 |
77-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
78-
| NttManagerHelpersLib | 58 | 87 | 24,518 | 49,065 |
79-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
80-
| NttManagerNoRateLimiting | 18,644 | 20,130 | 5,932 | 29,022 |
81-
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
82-
```
83-
84-
- Question: Why did `NttManagerNoRateLimiting` grow so much??
37+
Question: Why did `NttManagerNoRateLimiting` grow so much?? Because of this, I am not pursuing moving these fields at this time.
8538

86-
#### Creating TransceiverRegistryAdmin
39+
## Creating TransceiverRegistryAdmin
8740

88-
#### Before
41+
### Before
8942

9043
```bash
9144
evm (main)$ forge build --sizes --via-ir --skip test
@@ -101,7 +54,7 @@ evm (main)$ forge build --sizes --via-ir --skip test
10154

10255
```
10356

104-
#### After
57+
### After
10558

10659
```bash
10760
evm (main)$ forge build --sizes --via-ir --skip test
@@ -114,9 +67,11 @@ evm (main)$ forge build --sizes --via-ir --skip test
11467

11568
```
11669

117-
#### Creating MsgManagerBase
70+
## Creating MsgManagerBase
71+
72+
Note that this change is not dependent on `TransceiverRegistryAdmin`.
11873

119-
#### Before
74+
### Before
12075

12176
```bash
12277
evm (main)$ forge build --sizes --via-ir --skip test
@@ -132,7 +87,7 @@ evm (main)$ forge build --sizes --via-ir --skip test
13287

13388
```
13489

135-
#### After
90+
### After
13691

13792
```bash
13893
evm (main)$ forge build --sizes --via-ir --skip test
@@ -142,5 +97,9 @@ evm (main)$ forge build --sizes --via-ir --skip test
14297
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
14398
| NttManagerNoRateLimiting | 18,496 | 19,949 | 6,080 | 29,203 |
14499
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
100+
| MsgManager | 12,540 | 13,745 | 12,036 | 35,407 |
101+
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
102+
| MsgManagerWithExecutor | 13,145 | 14,400 | 11,431 | 34,752 |
103+
|-----------------------------------------+------------------+-------------------+--------------------+---------------------|
145104

146105
```

evm/lib/example-messaging-executor

evm/src/NttManager/MsgManagerBase.sol

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,7 @@ abstract contract MsgManagerBase is ManagerBase, IMsgReceiver {
7777
// construct the NttManagerMessage payload
7878
encodedNttManagerPayload = TransceiverStructs.encodeNttManagerMessage(
7979
TransceiverStructs.NttManagerMessage(
80-
// TODO: Should we use `address(this)` instead of `msg.sender`?
81-
bytes32(uint256(sequence)),
82-
toWormholeFormat(msg.sender),
83-
payload
80+
bytes32(uint256(sequence)), toWormholeFormat(msg.sender), payload
8481
)
8582
);
8683

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
// SPDX-License-Identifier: Apache 2
2+
pragma solidity >=0.8.8 <0.9.0;
3+
4+
import "example-messaging-executor/evm/src/interfaces/IExecutor.sol";
5+
import "example-messaging-executor/evm/src/libraries/ExecutorMessages.sol";
6+
import "wormhole-solidity-sdk/Utils.sol";
7+
import "wormhole-solidity-sdk/libraries/BytesParsing.sol";
8+
9+
import "../interfaces/IMsgManagerWithExecutor.sol";
10+
import "../interfaces/ITransceiver.sol";
11+
import "../libraries/TransceiverHelpers.sol";
12+
13+
import {MsgManagerBase} from "./MsgManagerBase.sol";
14+
15+
contract MsgManagerWithExecutor is IMsgManagerWithExecutor, MsgManagerBase {
16+
string public constant MSG_MANAGER_VERSION = "1.0.0";
17+
18+
IExecutor public immutable executor;
19+
20+
// =============== Setup =================================================================
21+
22+
constructor(
23+
uint16 _chainId,
24+
address _executor
25+
) MsgManagerBase(address(0), Mode.LOCKING, _chainId) {
26+
assert(_executor != address(0));
27+
executor = IExecutor(_executor);
28+
}
29+
30+
function _initialize() internal virtual override {
31+
_init();
32+
_checkThresholdInvariants();
33+
_checkTransceiversInvariants();
34+
}
35+
36+
function _init() internal onlyInitializing {
37+
// check if the owner is the deployer of this contract
38+
if (msg.sender != deployer) {
39+
revert UnexpectedDeployer(deployer, msg.sender);
40+
}
41+
if (msg.value != 0) {
42+
revert UnexpectedMsgValue();
43+
}
44+
__PausedOwnable_init(msg.sender, msg.sender);
45+
__ReentrancyGuard_init();
46+
}
47+
48+
// =============== Storage ==============================================================
49+
50+
bytes32 private constant PEERS_SLOT = bytes32(uint256(keccak256("mmgr.peers")) - 1);
51+
52+
// =============== Storage Getters/Setters ==============================================
53+
54+
function _getPeersStorage()
55+
internal
56+
pure
57+
returns (mapping(uint16 => MsgManagerPeer) storage $)
58+
{
59+
uint256 slot = uint256(PEERS_SLOT);
60+
assembly ("memory-safe") {
61+
$.slot := slot
62+
}
63+
}
64+
65+
// =============== Public Getters ========================================================
66+
67+
/// @inheritdoc IMsgManagerWithExecutor
68+
function getPeer(
69+
uint16 chainId_
70+
) external view returns (MsgManagerPeer memory) {
71+
return _getPeersStorage()[chainId_];
72+
}
73+
74+
// =============== Admin ==============================================================
75+
76+
/// @inheritdoc IMsgManagerWithExecutor
77+
function setPeer(uint16 peerChainId, bytes32 peerAddress) public onlyOwner {
78+
if (peerChainId == 0) {
79+
revert InvalidPeerChainIdZero();
80+
}
81+
if (peerAddress == bytes32(0)) {
82+
revert InvalidPeerZeroAddress();
83+
}
84+
if (peerChainId == chainId) {
85+
revert InvalidPeerSameChainId();
86+
}
87+
88+
MsgManagerPeer memory oldPeer = _getPeersStorage()[peerChainId];
89+
90+
_getPeersStorage()[peerChainId].peerAddress = peerAddress;
91+
92+
emit PeerUpdated(peerChainId, oldPeer.peerAddress, peerAddress);
93+
}
94+
95+
/// ============== Invariants =============================================
96+
97+
/// @dev When we add new immutables, this function should be updated
98+
function _checkImmutables() internal view virtual override {
99+
super._checkImmutables();
100+
}
101+
102+
// ==================== External Interface ===============================================
103+
104+
/// @inheritdoc IMsgManagerWithExecutor
105+
function sendMessage(
106+
uint16 recipientChain,
107+
bytes calldata payload,
108+
bytes memory transceiverInstructions,
109+
ExecutorArgs calldata executorArgs
110+
) external payable nonReentrant whenNotPaused returns (uint64 sequence) {
111+
sequence = _useMessageSequence();
112+
113+
bytes32 recipientAddress = _getPeersStorage()[recipientChain].peerAddress;
114+
115+
(uint256 totalPriceQuote,) = _sendMessage(
116+
recipientChain, recipientAddress, sequence, payload, transceiverInstructions
117+
);
118+
119+
if (totalPriceQuote + executorArgs.value > msg.value) {
120+
revert InsufficientMsgValue(msg.value, totalPriceQuote, executorArgs.value);
121+
}
122+
123+
// emit MessageSent(recipientChain, recipientAddress, sequence, totalPriceQuote);
124+
125+
// Generate the executor event.
126+
// TODO: Not sure we want to use `makeNTTv1Request` since it doesn't have the payload.
127+
executor.requestExecution{value: executorArgs.value}(
128+
recipientChain,
129+
recipientAddress,
130+
executorArgs.refundAddress,
131+
executorArgs.signedQuote,
132+
ExecutorMessages.makeNTTv1Request(
133+
chainId, bytes32(uint256(uint160(address(this)))), bytes32(uint256(sequence))
134+
),
135+
executorArgs.instructions
136+
);
137+
}
138+
139+
/// @dev Override this function to handle your messages.
140+
function _handleMsg(
141+
uint16 sourceChainId,
142+
bytes32 sourceManagerAddress,
143+
TransceiverStructs.NttManagerMessage memory message,
144+
bytes32 digest
145+
) internal virtual override {}
146+
147+
// ==================== Internal Helpers ===============================================
148+
149+
/// @dev Verify that the peer address saved for `sourceChainId` matches the `peerAddress`.
150+
function _verifyPeer(uint16 sourceChainId, bytes32 peerAddress) internal view override {
151+
if (_getPeersStorage()[sourceChainId].peerAddress != peerAddress) {
152+
revert InvalidPeer(sourceChainId, peerAddress);
153+
}
154+
}
155+
}

0 commit comments

Comments
 (0)