Skip to content

Commit c02fb27

Browse files
authored
evm: Use chain list from AdapterRegistry (#17)
* evm: Use chain list from AdapterRegistry * Tilt: Update endpoint commit
1 parent b0954f4 commit c02fb27

8 files changed

+16
-164
lines changed

evm/src/NttManager/ManagerBase.sol

+5-54
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity >=0.8.8 <0.9.0;
44
import "wormhole-solidity-sdk/Utils.sol";
55
import "wormhole-solidity-sdk/libraries/BytesParsing.sol";
66

7+
import "example-messaging-endpoint/evm/src/interfaces/IAdapterRegistry.sol";
78
import "example-messaging-endpoint/evm/src/interfaces/IEndpointAdmin.sol";
89
import "example-messaging-endpoint/evm/src/interfaces/IEndpointIntegrator.sol";
910
import "example-messaging-executor/evm/src/interfaces/IExecutor.sol";
@@ -70,9 +71,6 @@ abstract contract ManagerBase is
7071

7172
bytes32 private constant THRESHOLD_SLOT = bytes32(uint256(keccak256("ntt.threshold")) - 1);
7273

73-
bytes32 private constant RECV_ENABLED_CHAINS_SLOT =
74-
bytes32(uint256(keccak256("ntt.recvEnabledChains")) - 1);
75-
7674
// =============== Storage Getters/Setters ==============================================
7775

7876
function _getThresholdStorage()
@@ -93,13 +91,6 @@ abstract contract ManagerBase is
9391
}
9492
}
9593

96-
function _getChainsEnabledForReceiveStorage() internal pure returns (uint16[] storage $) {
97-
uint256 slot = uint256(RECV_ENABLED_CHAINS_SLOT);
98-
assembly ("memory-safe") {
99-
$.slot := slot
100-
}
101-
}
102-
10394
// =============== External Logic =============================================================
10495

10596
/// @inheritdoc IManagerBase
@@ -257,7 +248,6 @@ abstract contract ManagerBase is
257248
// However if the threshold is 0 (the initial case) we do increment to 1.
258249
if (_threshold.num == 0) {
259250
_threshold.num = 1;
260-
_addChainEnabledForReceive(chain);
261251
}
262252

263253
_checkThresholdInvariantsForChain(chain);
@@ -273,7 +263,7 @@ abstract contract ManagerBase is
273263
IEndpointAdmin(address(endpoint)).disableRecvAdapter(address(this), chain, transceiver);
274264

275265
_Threshold storage _threshold = _getThresholdStorage()[chain];
276-
uint8 numEnabled = IEndpointAdmin(address(endpoint)).getNumEnabledRecvAdaptersForChain(
266+
uint8 numEnabled = IAdapterRegistry(address(endpoint)).getNumEnabledRecvAdaptersForChain(
277267
address(this), chain
278268
);
279269

@@ -284,10 +274,6 @@ abstract contract ManagerBase is
284274
emit ThresholdChanged(chainId, oldThreshold, numEnabled);
285275
}
286276

287-
if (numEnabled == 0) {
288-
_removeChainEnabledForReceive(chain);
289-
}
290-
291277
_checkThresholdInvariantsForChain(chain);
292278
}
293279

@@ -301,7 +287,6 @@ abstract contract ManagerBase is
301287
uint8 oldThreshold = _threshold.num;
302288

303289
_threshold.num = threshold;
304-
_addChainEnabledForReceive(chain);
305290
_checkThresholdInvariantsForChain(chain);
306291
emit ThresholdChanged(chainId, oldThreshold, threshold);
307292
}
@@ -313,41 +298,6 @@ abstract contract ManagerBase is
313298
_getMessageSequenceStorage().num++;
314299
}
315300

316-
/// @dev It's not an error if the chain is not in the list.
317-
function _removeChainEnabledForReceive(
318-
uint16 chain
319-
) internal {
320-
uint16[] storage chains = _getChainsEnabledForReceiveStorage();
321-
uint256 len = chains.length;
322-
for (uint256 idx = 0; (idx < len);) {
323-
if (chains[idx] == chain) {
324-
chains[idx] = chains[len - 1];
325-
chains.pop();
326-
return;
327-
}
328-
unchecked {
329-
++idx;
330-
}
331-
}
332-
}
333-
334-
/// @dev It's not an error if the chain is already in the list.
335-
function _addChainEnabledForReceive(
336-
uint16 chain
337-
) internal {
338-
uint16[] storage chains = _getChainsEnabledForReceiveStorage();
339-
uint256 len = chains.length;
340-
for (uint256 idx = 0; (idx < len);) {
341-
if (chains[idx] == chain) {
342-
return;
343-
}
344-
unchecked {
345-
++idx;
346-
}
347-
}
348-
chains.push(chain);
349-
}
350-
351301
/// ============== Invariants =============================================
352302

353303
/// @dev When we add new immutables, this function should be updated
@@ -360,7 +310,8 @@ abstract contract ManagerBase is
360310
}
361311

362312
function _checkThresholdInvariants() internal view {
363-
uint16[] storage chains = _getChainsEnabledForReceiveStorage();
313+
uint16[] memory chains =
314+
IAdapterRegistry(address(endpoint)).getChainsEnabledForRecv(address(this));
364315
uint256 len = chains.length;
365316
for (uint256 idx = 0; (idx < len);) {
366317
_checkThresholdInvariantsForChain(chains[idx]);
@@ -375,7 +326,7 @@ abstract contract ManagerBase is
375326
uint16 chain
376327
) internal view {
377328
uint8 threshold = _getThresholdStorage()[chain].num;
378-
uint8 numEnabled = IEndpointAdmin(address(endpoint)).getNumEnabledRecvAdaptersForChain(
329+
uint8 numEnabled = IAdapterRegistry(address(endpoint)).getNumEnabledRecvAdaptersForChain(
379330
address(this), chain
380331
);
381332

evm/test/NttManager.t.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
1919
import "wormhole-solidity-sdk/interfaces/IWormhole.sol";
2020
import "wormhole-solidity-sdk/testing/helpers/WormholeSimulator.sol";
2121
import "wormhole-solidity-sdk/Utils.sol";
22-
import "example-messaging-endpoint/evm/src/AdapterRegistry.sol";
22+
import "example-messaging-endpoint/evm/src/interfaces/IAdapterRegistry.sol";
2323
import "./libraries/TransceiverHelpers.sol";
2424
import "./libraries/NttManagerHelpers.sol";
2525
import "./mocks/DummyTransceiver.sol";
@@ -412,7 +412,7 @@ contract TestNttManager is Test, IRateLimiterEvents {
412412
nttManager.setTransceiver(address(e));
413413

414414
vm.expectRevert(
415-
abi.encodeWithSelector(AdapterRegistry.AdapterAlreadyRegistered.selector, address(e))
415+
abi.encodeWithSelector(IAdapterRegistry.AdapterAlreadyRegistered.selector, address(e))
416416
);
417417
nttManager.setTransceiver(address(e));
418418
}
@@ -512,7 +512,7 @@ contract TestNttManager is Test, IRateLimiterEvents {
512512

513513
// Registering a new transceiver should fail as we've hit the cap
514514
DummyTransceiver c = new DummyTransceiver(chainId, address(endpoint));
515-
vm.expectRevert(AdapterRegistry.TooManyAdapters.selector);
515+
vm.expectRevert(IAdapterRegistry.TooManyAdapters.selector);
516516
nttManager.setTransceiver(address(c));
517517
}
518518

evm/test/NttManagerNoRateLimiting.t.sol

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import "openzeppelin-contracts/contracts/proxy/ERC1967/ERC1967Proxy.sol";
1919
import "wormhole-solidity-sdk/interfaces/IWormhole.sol";
2020
import "wormhole-solidity-sdk/testing/helpers/WormholeSimulator.sol";
2121
import "wormhole-solidity-sdk/Utils.sol";
22-
import "example-messaging-endpoint/evm/src/AdapterRegistry.sol";
22+
import "example-messaging-endpoint/evm/src/interfaces/IAdapterRegistry.sol";
2323
import "./libraries/TransceiverHelpers.sol";
2424
import "./libraries/NttManagerHelpers.sol";
2525
import "./mocks/DummyTransceiver.sol";
@@ -264,7 +264,7 @@ contract TestNoRateLimitingNttManager is Test, IRateLimiterEvents {
264264
nttManager.setTransceiver(address(e));
265265

266266
vm.expectRevert(
267-
abi.encodeWithSelector(AdapterRegistry.AdapterAlreadyRegistered.selector, address(e))
267+
abi.encodeWithSelector(IAdapterRegistry.AdapterAlreadyRegistered.selector, address(e))
268268
);
269269
nttManager.setTransceiver(address(e));
270270
}

evm/test/Threshold.t.sol

-83
Original file line numberDiff line numberDiff line change
@@ -154,87 +154,4 @@ contract TestThreshold is Test {
154154
assertEq(0, nttManager.getThreshold(chainId2));
155155
assertEq(2, nttManager.getThreshold(chainId3));
156156
}
157-
158-
function test_chainsEnabledForReceive() public {
159-
uint16[] memory chains = nttManager.getChainsEnabledForReceive();
160-
assertEq(0, chains.length);
161-
162-
nttManager.addChainEnabledForReceive(42);
163-
chains = nttManager.getChainsEnabledForReceive();
164-
assertEq(1, chains.length);
165-
assertEq(42, chains[0]);
166-
167-
nttManager.addChainEnabledForReceive(41);
168-
chains = nttManager.getChainsEnabledForReceive();
169-
assertEq(2, chains.length);
170-
assertEq(42, chains[0]);
171-
assertEq(41, chains[1]);
172-
173-
nttManager.addChainEnabledForReceive(43);
174-
chains = nttManager.getChainsEnabledForReceive();
175-
assertEq(3, chains.length);
176-
assertEq(42, chains[0]);
177-
assertEq(41, chains[1]);
178-
assertEq(43, chains[2]);
179-
180-
// Adding the same thing again shouldn't do anything.
181-
nttManager.addChainEnabledForReceive(43);
182-
chains = nttManager.getChainsEnabledForReceive();
183-
assertEq(3, chains.length);
184-
assertEq(42, chains[0]);
185-
assertEq(41, chains[1]);
186-
assertEq(43, chains[2]);
187-
188-
nttManager.addChainEnabledForReceive(41);
189-
chains = nttManager.getChainsEnabledForReceive();
190-
assertEq(3, chains.length);
191-
assertEq(42, chains[0]);
192-
assertEq(41, chains[1]);
193-
assertEq(43, chains[2]);
194-
195-
// Add one more.
196-
nttManager.addChainEnabledForReceive(44);
197-
chains = nttManager.getChainsEnabledForReceive();
198-
assertEq(4, chains.length);
199-
assertEq(42, chains[0]);
200-
assertEq(41, chains[1]);
201-
assertEq(43, chains[2]);
202-
assertEq(44, chains[3]);
203-
204-
// Now test removing.
205-
206-
// Remove one from the middle. The last one should get moved into its slot.
207-
nttManager.removeChainEnabledForReceive(41);
208-
chains = nttManager.getChainsEnabledForReceive();
209-
assertEq(3, chains.length);
210-
assertEq(42, chains[0]);
211-
assertEq(44, chains[1]);
212-
assertEq(43, chains[2]);
213-
214-
// Removing something not in the list shouldn't do anything.
215-
nttManager.removeChainEnabledForReceive(410);
216-
chains = nttManager.getChainsEnabledForReceive();
217-
assertEq(3, chains.length);
218-
assertEq(42, chains[0]);
219-
assertEq(44, chains[1]);
220-
assertEq(43, chains[2]);
221-
222-
// Remove the first one. The last one should get moved into its slot.
223-
nttManager.removeChainEnabledForReceive(42);
224-
chains = nttManager.getChainsEnabledForReceive();
225-
assertEq(2, chains.length);
226-
assertEq(43, chains[0]);
227-
assertEq(44, chains[1]);
228-
229-
// Remove the last one.
230-
nttManager.removeChainEnabledForReceive(44);
231-
chains = nttManager.getChainsEnabledForReceive();
232-
assertEq(1, chains.length);
233-
assertEq(43, chains[0]);
234-
235-
// Remove the only one.
236-
nttManager.removeChainEnabledForReceive(43);
237-
chains = nttManager.getChainsEnabledForReceive();
238-
assertEq(0, chains.length);
239-
}
240157
}

evm/test/mocks/MockNttManager.sol

-16
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,6 @@ contract MockNttManagerContract is NttManager {
2828
}
2929
}
3030

31-
function removeChainEnabledForReceive(
32-
uint16 chain
33-
) public {
34-
_removeChainEnabledForReceive(chain);
35-
}
36-
37-
function addChainEnabledForReceive(
38-
uint16 chain
39-
) public {
40-
_addChainEnabledForReceive(chain);
41-
}
42-
43-
function getChainsEnabledForReceive() public pure returns (uint16[] memory result) {
44-
result = _getChainsEnabledForReceiveStorage();
45-
}
46-
4731
function setGasLimitToZero(
4832
uint16 peerChainId
4933
) external onlyOwner {

sdk/__tests__/utils.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,16 @@ import axios from "axios";
4848

4949
export const NETWORK: "Devnet" = "Devnet";
5050
export const ENDPOINTS: { [chainId in ChainId]?: `0x${string}` } = {
51-
2: "0xF9f67913ba058BD29E699BfcD0eb0ec878555226",
52-
4: "0x86ee2Ad4bca65764928680812A6C5315eDA9EEfd",
51+
2: "0x9259cB76111dD04b06f3a514B4a70Dc7e704d450",
52+
4: "0xee54955A543e1FC45fb8b3BdC89C72881bc1b8C2",
5353
};
5454
export const EXECUTORS: { [chainId in ChainId]?: `0x${string}` } = {
5555
2: "0x0a65677098872f870224F6E9533734F4a4B0eBAB",
5656
4: "0xB67841A38bF16EB9999dC7B6015746506e20F0aA",
5757
};
5858
export const WHG_ADAPTERS: { [chainId in ChainId]?: `0x${string}` } = {
59-
2: "0x47A17F7E84Fb16c752352325F854A5358b4461d0",
60-
4: "0x9683b5Cb8F274510782183CB20E76c3F7C1c884b",
59+
2: "0x9Ee7A4e1DC11226d90db33f326168cf33B2456cC",
60+
4: "0x3Cc81b56192c66968Df4D0E9D23c46Fa6ce42628",
6161
};
6262

6363
type NativeSdkSigner<P extends Platform> = P extends "Evm"

tilt/Dockerfile.deploy

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ WORKDIR /app/example-messaging-endpoint
66

77
RUN git init && \
88
git remote add origin https://github.com/wormholelabs-xyz/example-messaging-endpoint && \
9-
git fetch --depth 1 origin 0f853ea0335937d611217f5048d677a4f46249fd && \
9+
git fetch --depth 1 origin 026d20c6a276a3ee2e02c9f785df9c5279522566 && \
1010
git checkout FETCH_HEAD
1111

1212
WORKDIR /app/example-messaging-endpoint/evm

0 commit comments

Comments
 (0)