Skip to content

Commit

Permalink
evm: Change to use Modular Messaging (#4)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
bruce-riley authored Dec 23, 2024
1 parent 092a8e7 commit a0bad59
Show file tree
Hide file tree
Showing 47 changed files with 3,453 additions and 6,115 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "evm/lib/solidity-bytes-utils"]
path = evm/lib/solidity-bytes-utils
url = https://github.com/GNSPS/solidity-bytes-utils
[submodule "evm/lib/example-messaging-endpoint"]
path = evm/lib/example-messaging-endpoint
url = https://github.com/wormholelabs-xyz/example-messaging-endpoint
[submodule "evm/lib/example-messaging-executor"]
path = evm/lib/example-messaging-executor
url = https://github.com/wormholelabs-xyz/example-messaging-executor
548 changes: 284 additions & 264 deletions evm/echidna/FuzzNttManager.sol

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions evm/lib/example-messaging-endpoint
1 change: 1 addition & 0 deletions evm/lib/example-messaging-executor
49 changes: 5 additions & 44 deletions evm/script/ConfigureWormholeNtt.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ pragma solidity >=0.8.8 <0.9.0;
import {console2} from "forge-std/Script.sol";
import {stdJson} from "forge-std/StdJson.sol";

import "example-messaging-endpoint/evm/src/interfaces/IAdapter.sol";

import "../src/interfaces/INttManager.sol";
import "../src/interfaces/IWormholeTransceiver.sol";
import "../src/interfaces/IOwnableUpgradeable.sol";

import {ParseNttConfig} from "./helpers/ParseNttConfig.sol";
import {WormholeTransceiver} from "../src/Transceiver/WormholeTransceiver/WormholeTransceiver.sol";

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

function configureWormholeTransceiver(
IWormholeTransceiver wormholeTransceiver,
ChainConfig[] memory config,
ConfigParams memory params
) internal {
for (uint256 i = 0; i < config.length; i++) {
ChainConfig memory targetConfig = config[i];
if (targetConfig.chainId == params.wormholeChainId) {
continue;
} else {
// Set relayer.
if (targetConfig.isWormholeRelayingEnabled) {
wormholeTransceiver.setIsWormholeRelayingEnabled(targetConfig.chainId, true);
console2.log("Wormhole relaying enabled for chain", targetConfig.chainId);
} else if (targetConfig.isSpecialRelayingEnabled) {
wormholeTransceiver.setIsSpecialRelayingEnabled(targetConfig.chainId, true);
console2.log("Special relaying enabled for chain", targetConfig.chainId);
}

// Set peer.
wormholeTransceiver.setWormholePeer(
targetConfig.chainId, targetConfig.wormholeTransceiver
);
console2.log("Wormhole peer set for chain", targetConfig.chainId);

// Set EVM chain.
if (targetConfig.isEvmChain) {
wormholeTransceiver.setIsWormholeEvmChain(targetConfig.chainId, true);
console2.log("EVM chain set for chain", targetConfig.chainId);
} else {
console2.log("This is not an EVM chain, doing nothing");
}
}
}
}

function configureNttManager(
INttManager nttManager,
ChainConfig[] memory config,
Expand All @@ -75,6 +39,7 @@ contract ConfigureWormholeNtt is ParseNttConfig {
targetConfig.chainId,
targetConfig.nttManager,
targetConfig.decimals,
targetConfig.gasLimit,
targetConfig.inboundLimit
);
console2.log("Peer set for chain", targetConfig.chainId);
Expand All @@ -87,13 +52,9 @@ contract ConfigureWormholeNtt is ParseNttConfig {

// Sanity check deployment parameters.
ConfigParams memory params = _readEnvVariables();
(
ChainConfig[] memory config,
INttManager nttManager,
IWormholeTransceiver wormholeTransceiver
) = _parseAndValidateConfigFile(params.wormholeChainId);
(ChainConfig[] memory config, INttManager nttManager,) =
_parseAndValidateConfigFile(params.wormholeChainId);

configureWormholeTransceiver(wormholeTransceiver, config, params);
configureNttManager(nttManager, config, params);

vm.stopBroadcast();
Expand Down
120 changes: 65 additions & 55 deletions evm/script/DeployWormholeNtt.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ pragma solidity >=0.8.8 <0.9.0;
import {Script, console} from "forge-std/Script.sol";
import {DeployWormholeNttBase} from "./helpers/DeployWormholeNttBase.sol";
import {INttManager} from "../src/interfaces/INttManager.sol";
import {IWormholeTransceiver} from "../src/interfaces/IWormholeTransceiver.sol";
import "../src/interfaces/IManagerBase.sol";
import "openzeppelin-contracts/contracts/token/ERC20/ERC20.sol";
import {NttManager} from "../src/NttManager/NttManager.sol";
Expand All @@ -15,7 +14,10 @@ interface IWormhole {

contract DeployWormholeNtt is Script, DeployWormholeNttBase {
function run(
address endpoint,
address executor,
address wormhole,
address transceiver,
address token,
address wormholeRelayer,
address specialRelayer,
Expand All @@ -28,66 +30,72 @@ contract DeployWormholeNtt is Script, DeployWormholeNttBase {
IWormhole wh = IWormhole(wormhole);

// sanity check decimals
(bool success, bytes memory queriedDecimals) =
token.staticcall(abi.encodeWithSignature("decimals()"));

if (success) {
uint8 queriedDecimals = abi.decode(queriedDecimals, (uint8));
if (queriedDecimals != decimals) {
console.log("Decimals mismatch: ", queriedDecimals, " != ", decimals);
vm.stopBroadcast();
return;
{
(bool success, bytes memory queriedDecimals) =
token.staticcall(abi.encodeWithSignature("decimals()"));

if (success) {
uint8 queriedDec = abi.decode(queriedDecimals, (uint8));
if (queriedDec != decimals) {
console.log("Decimals mismatch: ", queriedDec, " != ", decimals);
vm.stopBroadcast();
return;
}
} else {
// NOTE: this might not be a critical error. It could just mean that
// the token contract was compiled against a different EVM version than what the forge script is running on.
// In this case, it's the responsibility of the caller to ensure that the provided decimals are correct
// and that the token contract is valid.
// The best way to ensure that is by calling this script with the queried token decimals (which is what the NTT CLI does).
console.log(
"Failed to query token decimals. Proceeding with provided decimals.", decimals
);
// the NTT manager initialiser calls the token contract to get the
// decimals as well. We're just going to mock that call to return the provided decimals.
// This is a bit of a hack, but in the worst case (i.e. if the token contract is actually broken), the
// NTT manager initialiser will fail anyway.
vm.mockCall(
token, abi.encodeWithSelector(ERC20.decimals.selector), abi.encode(decimals)
);
}
} else {
// NOTE: this might not be a critical error. It could just mean that
// the token contract was compiled against a different EVM version than what the forge script is running on.
// In this case, it's the responsibility of the caller to ensure that the provided decimals are correct
// and that the token contract is valid.
// The best way to ensure that is by calling this script with the queried token decimals (which is what the NTT CLI does).
console.log(
"Failed to query token decimals. Proceeding with provided decimals.", decimals
);
// the NTT manager initialiser calls the token contract to get the
// decimals as well. We're just going to mock that call to return the provided decimals.
// This is a bit of a hack, but in the worst case (i.e. if the token contract is actually broken), the
// NTT manager initialiser will fail anyway.
vm.mockCall(
token, abi.encodeWithSelector(ERC20.decimals.selector), abi.encode(decimals)
);
}

uint16 chainId = wh.chainId();

console.log("Chain ID: ", chainId);

uint256 scale =
decimals > TRIMMED_DECIMALS ? uint256(10 ** (decimals - TRIMMED_DECIMALS)) : 1;

DeploymentParams memory params = DeploymentParams({
token: token,
mode: mode,
wormholeChainId: chainId,
rateLimitDuration: 86400,
shouldSkipRatelimiter: false,
wormholeCoreBridge: wormhole,
wormholeRelayerAddr: wormholeRelayer,
specialRelayerAddr: specialRelayer,
consistencyLevel: 202,
gasLimit: 500000,
// the trimming will trim this number to uint64.max
outboundLimit: uint256(type(uint64).max) * scale
});
DeploymentParams memory params;
{
uint16 chainId = wh.chainId();

console.log("Chain ID: ", chainId);

uint256 scale =
decimals > TRIMMED_DECIMALS ? uint256(10 ** (decimals - TRIMMED_DECIMALS)) : 1;

params = DeploymentParams({
endpointAddr: endpoint,
executorAddr: executor,
token: token,
mode: mode,
wormholeChainId: chainId,
rateLimitDuration: 86400,
shouldSkipRatelimiter: false,
wormholeCoreBridge: wormhole,
wormholeRelayerAddr: wormholeRelayer,
specialRelayerAddr: specialRelayer,
consistencyLevel: 202,
gasLimit: 500000,
// the trimming will trim this number to uint64.max
outboundLimit: uint256(type(uint64).max) * scale
});
}

// Deploy NttManager.
address manager = deployNttManager(params);

// Deploy Wormhole Transceiver.
address transceiver = deployWormholeTransceiver(params, manager);
{
address manager = deployNttManager(params);

// Configure NttManager.
configureNttManager(
manager, transceiver, params.outboundLimit, params.shouldSkipRatelimiter
);
// Configure NttManager.
configureNttManager(
manager, transceiver, params.outboundLimit, params.shouldSkipRatelimiter
);
}

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

NttManager implementation = new NttManager(
address(nttManager.endpoint()),
address(nttManager.executor()),
nttManager.token(),
nttManager.mode(),
nttManager.chainId(),
Expand Down
4 changes: 4 additions & 0 deletions evm/script/UpgradeNttManager.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import {ParseNttConfig} from "./helpers/ParseNttConfig.sol";

contract UpgradeNttManager is ParseNttConfig {
struct DeploymentParams {
address endpoint;
address executor;
address token;
INttManager.Mode mode;
uint16 wormholeChainId;
Expand All @@ -26,6 +28,8 @@ contract UpgradeNttManager is ParseNttConfig {
) internal {
// Deploy the Manager Implementation.
NttManager implementation = new NttManager(
params.endpoint,
params.executor,
params.token,
params.mode,
params.wormholeChainId,
Expand Down
85 changes: 0 additions & 85 deletions evm/script/UpgradeWormholeTransceiver.s.sol

This file was deleted.

Loading

0 comments on commit a0bad59

Please sign in to comment.