Skip to content

Commit a0bad59

Browse files
authored
evm: Change to use Modular Messaging (#4)
* EVM: Change to use Modular Messaging * Evm: More stuff * evm: Put back tests for NttManagerNoRateLimiting * evm: Put back tests for IntegrationStandalone * evm: Put back tests for RateLimit * evm: Put back tests for IntegrationWithoutRateLimiting * evm: Put back echidna * evm: Put back tests for IntegrationAdditionalTransfer * evm: Remove gmp-router module * forge install: example-messaging-endpoint * evm: Change from gmp-router to mm-endpoint * evm: Per-chain thresholds * evm: Add executor parameters to transfer * forge install: example-executor.git evm_add_functions_to_make_payloads * evm: Use executor * evm: Add per-chain gas limits * evm: Remove old executor submodule * forge install: example-messaging-executor * evm: Upgrade executor submodule * evm: Add relay instructions * evm: remove old endpoint * forge install: example-messaging-endpoint * evm: Use executor * Remove old executor and endpoint submodules * forge install: example-messaging-endpoint * forge install: example-messaging-executor * evm: Fix params to executor call
1 parent 092a8e7 commit a0bad59

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+3453
-6115
lines changed

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@
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-endpoint"]
14+
path = evm/lib/example-messaging-endpoint
15+
url = https://github.com/wormholelabs-xyz/example-messaging-endpoint
16+
[submodule "evm/lib/example-messaging-executor"]
17+
path = evm/lib/example-messaging-executor
18+
url = https://github.com/wormholelabs-xyz/example-messaging-executor

evm/echidna/FuzzNttManager.sol

+284-264
Large diffs are not rendered by default.

evm/lib/example-messaging-endpoint

evm/lib/example-messaging-executor

evm/script/ConfigureWormholeNtt.s.sol

+5-44
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ pragma solidity >=0.8.8 <0.9.0;
44
import {console2} from "forge-std/Script.sol";
55
import {stdJson} from "forge-std/StdJson.sol";
66

7+
import "example-messaging-endpoint/evm/src/interfaces/IAdapter.sol";
8+
79
import "../src/interfaces/INttManager.sol";
8-
import "../src/interfaces/IWormholeTransceiver.sol";
910
import "../src/interfaces/IOwnableUpgradeable.sol";
1011

1112
import {ParseNttConfig} from "./helpers/ParseNttConfig.sol";
12-
import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";
1313

1414
contract ConfigureWormholeNtt is ParseNttConfig {
1515
using stdJson for string;
@@ -24,42 +24,6 @@ contract ConfigureWormholeNtt is ParseNttConfig {
2424
require(params.wormholeChainId != 0, "Invalid chain ID");
2525
}
2626

27-
function configureWormholeTransceiver(
28-
IWormholeTransceiver wormholeTransceiver,
29-
ChainConfig[] memory config,
30-
ConfigParams memory params
31-
) internal {
32-
for (uint256 i = 0; i < config.length; i++) {
33-
ChainConfig memory targetConfig = config[i];
34-
if (targetConfig.chainId == params.wormholeChainId) {
35-
continue;
36-
} else {
37-
// Set relayer.
38-
if (targetConfig.isWormholeRelayingEnabled) {
39-
wormholeTransceiver.setIsWormholeRelayingEnabled(targetConfig.chainId, true);
40-
console2.log("Wormhole relaying enabled for chain", targetConfig.chainId);
41-
} else if (targetConfig.isSpecialRelayingEnabled) {
42-
wormholeTransceiver.setIsSpecialRelayingEnabled(targetConfig.chainId, true);
43-
console2.log("Special relaying enabled for chain", targetConfig.chainId);
44-
}
45-
46-
// Set peer.
47-
wormholeTransceiver.setWormholePeer(
48-
targetConfig.chainId, targetConfig.wormholeTransceiver
49-
);
50-
console2.log("Wormhole peer set for chain", targetConfig.chainId);
51-
52-
// Set EVM chain.
53-
if (targetConfig.isEvmChain) {
54-
wormholeTransceiver.setIsWormholeEvmChain(targetConfig.chainId, true);
55-
console2.log("EVM chain set for chain", targetConfig.chainId);
56-
} else {
57-
console2.log("This is not an EVM chain, doing nothing");
58-
}
59-
}
60-
}
61-
}
62-
6327
function configureNttManager(
6428
INttManager nttManager,
6529
ChainConfig[] memory config,
@@ -75,6 +39,7 @@ contract ConfigureWormholeNtt is ParseNttConfig {
7539
targetConfig.chainId,
7640
targetConfig.nttManager,
7741
targetConfig.decimals,
42+
targetConfig.gasLimit,
7843
targetConfig.inboundLimit
7944
);
8045
console2.log("Peer set for chain", targetConfig.chainId);
@@ -87,13 +52,9 @@ contract ConfigureWormholeNtt is ParseNttConfig {
8752

8853
// Sanity check deployment parameters.
8954
ConfigParams memory params = _readEnvVariables();
90-
(
91-
ChainConfig[] memory config,
92-
INttManager nttManager,
93-
IWormholeTransceiver wormholeTransceiver
94-
) = _parseAndValidateConfigFile(params.wormholeChainId);
55+
(ChainConfig[] memory config, INttManager nttManager,) =
56+
_parseAndValidateConfigFile(params.wormholeChainId);
9557

96-
configureWormholeTransceiver(wormholeTransceiver, config, params);
9758
configureNttManager(nttManager, config, params);
9859

9960
vm.stopBroadcast();

evm/script/DeployWormholeNtt.s.sol

+65-55
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ pragma solidity >=0.8.8 <0.9.0;
44
import {Script, console} from "forge-std/Script.sol";
55
import {DeployWormholeNttBase} from "./helpers/DeployWormholeNttBase.sol";
66
import {INttManager} from "../src/interfaces/INttManager.sol";
7-
import {IWormholeTransceiver} from "../src/interfaces/IWormholeTransceiver.sol";
87
import "../src/interfaces/IManagerBase.sol";
98
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
109
import {NttManager} from "../src/NttManager/NttManager.sol";
@@ -15,7 +14,10 @@ interface IWormhole {
1514

1615
contract DeployWormholeNtt is Script, DeployWormholeNttBase {
1716
function run(
17+
address endpoint,
18+
address executor,
1819
address wormhole,
20+
address transceiver,
1921
address token,
2022
address wormholeRelayer,
2123
address specialRelayer,
@@ -28,66 +30,72 @@ contract DeployWormholeNtt is Script, DeployWormholeNttBase {
2830
IWormhole wh = IWormhole(wormhole);
2931

3032
// sanity check decimals
31-
(bool success, bytes memory queriedDecimals) =
32-
token.staticcall(abi.encodeWithSignature("decimals()"));
33-
34-
if (success) {
35-
uint8 queriedDecimals = abi.decode(queriedDecimals, (uint8));
36-
if (queriedDecimals != decimals) {
37-
console.log("Decimals mismatch: ", queriedDecimals, " != ", decimals);
38-
vm.stopBroadcast();
39-
return;
33+
{
34+
(bool success, bytes memory queriedDecimals) =
35+
token.staticcall(abi.encodeWithSignature("decimals()"));
36+
37+
if (success) {
38+
uint8 queriedDec = abi.decode(queriedDecimals, (uint8));
39+
if (queriedDec != decimals) {
40+
console.log("Decimals mismatch: ", queriedDec, " != ", decimals);
41+
vm.stopBroadcast();
42+
return;
43+
}
44+
} else {
45+
// NOTE: this might not be a critical error. It could just mean that
46+
// the token contract was compiled against a different EVM version than what the forge script is running on.
47+
// In this case, it's the responsibility of the caller to ensure that the provided decimals are correct
48+
// and that the token contract is valid.
49+
// The best way to ensure that is by calling this script with the queried token decimals (which is what the NTT CLI does).
50+
console.log(
51+
"Failed to query token decimals. Proceeding with provided decimals.", decimals
52+
);
53+
// the NTT manager initialiser calls the token contract to get the
54+
// decimals as well. We're just going to mock that call to return the provided decimals.
55+
// This is a bit of a hack, but in the worst case (i.e. if the token contract is actually broken), the
56+
// NTT manager initialiser will fail anyway.
57+
vm.mockCall(
58+
token, abi.encodeWithSelector(ERC20.decimals.selector), abi.encode(decimals)
59+
);
4060
}
41-
} else {
42-
// NOTE: this might not be a critical error. It could just mean that
43-
// the token contract was compiled against a different EVM version than what the forge script is running on.
44-
// In this case, it's the responsibility of the caller to ensure that the provided decimals are correct
45-
// and that the token contract is valid.
46-
// The best way to ensure that is by calling this script with the queried token decimals (which is what the NTT CLI does).
47-
console.log(
48-
"Failed to query token decimals. Proceeding with provided decimals.", decimals
49-
);
50-
// the NTT manager initialiser calls the token contract to get the
51-
// decimals as well. We're just going to mock that call to return the provided decimals.
52-
// This is a bit of a hack, but in the worst case (i.e. if the token contract is actually broken), the
53-
// NTT manager initialiser will fail anyway.
54-
vm.mockCall(
55-
token, abi.encodeWithSelector(ERC20.decimals.selector), abi.encode(decimals)
56-
);
5761
}
5862

59-
uint16 chainId = wh.chainId();
60-
61-
console.log("Chain ID: ", chainId);
62-
63-
uint256 scale =
64-
decimals > TRIMMED_DECIMALS ? uint256(10 ** (decimals - TRIMMED_DECIMALS)) : 1;
65-
66-
DeploymentParams memory params = DeploymentParams({
67-
token: token,
68-
mode: mode,
69-
wormholeChainId: chainId,
70-
rateLimitDuration: 86400,
71-
shouldSkipRatelimiter: false,
72-
wormholeCoreBridge: wormhole,
73-
wormholeRelayerAddr: wormholeRelayer,
74-
specialRelayerAddr: specialRelayer,
75-
consistencyLevel: 202,
76-
gasLimit: 500000,
77-
// the trimming will trim this number to uint64.max
78-
outboundLimit: uint256(type(uint64).max) * scale
79-
});
63+
DeploymentParams memory params;
64+
{
65+
uint16 chainId = wh.chainId();
66+
67+
console.log("Chain ID: ", chainId);
68+
69+
uint256 scale =
70+
decimals > TRIMMED_DECIMALS ? uint256(10 ** (decimals - TRIMMED_DECIMALS)) : 1;
71+
72+
params = DeploymentParams({
73+
endpointAddr: endpoint,
74+
executorAddr: executor,
75+
token: token,
76+
mode: mode,
77+
wormholeChainId: chainId,
78+
rateLimitDuration: 86400,
79+
shouldSkipRatelimiter: false,
80+
wormholeCoreBridge: wormhole,
81+
wormholeRelayerAddr: wormholeRelayer,
82+
specialRelayerAddr: specialRelayer,
83+
consistencyLevel: 202,
84+
gasLimit: 500000,
85+
// the trimming will trim this number to uint64.max
86+
outboundLimit: uint256(type(uint64).max) * scale
87+
});
88+
}
8089

8190
// Deploy NttManager.
82-
address manager = deployNttManager(params);
83-
84-
// Deploy Wormhole Transceiver.
85-
address transceiver = deployWormholeTransceiver(params, manager);
91+
{
92+
address manager = deployNttManager(params);
8693

87-
// Configure NttManager.
88-
configureNttManager(
89-
manager, transceiver, params.outboundLimit, params.shouldSkipRatelimiter
90-
);
94+
// Configure NttManager.
95+
configureNttManager(
96+
manager, transceiver, params.outboundLimit, params.shouldSkipRatelimiter
97+
);
98+
}
9199

92100
vm.stopBroadcast();
93101
}
@@ -105,6 +113,8 @@ contract DeployWormholeNtt is Script, DeployWormholeNttBase {
105113
bool shouldSkipRatelimiter = rateLimitDuration == 0;
106114

107115
NttManager implementation = new NttManager(
116+
address(nttManager.endpoint()),
117+
address(nttManager.executor()),
108118
nttManager.token(),
109119
nttManager.mode(),
110120
nttManager.chainId(),

evm/script/UpgradeNttManager.s.sol

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {ParseNttConfig} from "./helpers/ParseNttConfig.sol";
1313

1414
contract UpgradeNttManager is ParseNttConfig {
1515
struct DeploymentParams {
16+
address endpoint;
17+
address executor;
1618
address token;
1719
INttManager.Mode mode;
1820
uint16 wormholeChainId;
@@ -26,6 +28,8 @@ contract UpgradeNttManager is ParseNttConfig {
2628
) internal {
2729
// Deploy the Manager Implementation.
2830
NttManager implementation = new NttManager(
31+
params.endpoint,
32+
params.executor,
2933
params.token,
3034
params.mode,
3135
params.wormholeChainId,

evm/script/UpgradeWormholeTransceiver.s.sol

-85
This file was deleted.

0 commit comments

Comments
 (0)