Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 40 additions & 42 deletions scripts/DeployFraxOFTProtocol/inherited/SetDVNs.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { L0Config } from "scripts/L0Constants.sol";
import { Strings } from "@openzeppelin/contracts/utils/Strings.sol";
import { Arrays } from "@openzeppelin-5/contracts/utils/Arrays.sol";

import { SetConfigParam, IMessageLibManager} from "@fraxfinance/layerzero-v2-upgradeable/protocol/contracts/interfaces/IMessageLibManager.sol";
import { SetConfigParam, IMessageLibManager } from "@fraxfinance/layerzero-v2-upgradeable/protocol/contracts/interfaces/IMessageLibManager.sol";
import { Constant } from "@fraxfinance/layerzero-v2-upgradeable/messagelib/test/util/Constant.sol";
import { UlnConfig } from "@fraxfinance/layerzero-v2-upgradeable/messagelib/contracts/uln/UlnBase.sol";

Expand All @@ -19,6 +19,8 @@ contract SetDVNs is BaseInherited, Script {
using Strings for uint256;
using stdJson for string;

uint8 internal constant NIL_DVN_COUNT = type(uint8).max;

address[] public dvnStackTemp;

struct DvnStack {
Expand All @@ -41,8 +43,8 @@ contract SetDVNs is BaseInherited, Script {
address[] memory _connectedOfts,
L0Config[] memory _configs
) public virtual {
for (uint256 o=0; o<_connectedOfts.length; o++) {
for (uint256 c=0; c<_configs.length; c++) {
for (uint256 o = 0; o < _connectedOfts.length; o++) {
for (uint256 c = 0; c < _configs.length; c++) {
// Skip if setting config to self
if (_connectedConfig.chainid == _configs[c].chainid) continue;
setConfigs({
Expand Down Expand Up @@ -72,7 +74,7 @@ contract SetDVNs is BaseInherited, Script {
_oft: _connectedOft
});
}

function setConfig(
L0Config memory _srcConfig,
L0Config memory _dstConfig,
Expand All @@ -94,20 +96,24 @@ contract SetDVNs is BaseInherited, Script {
_dstChainId: _dstConfig.chainid
});

uint64 desiredConfirmations = getConfirmations({
_srcConfig: _srcConfig,
_dstConfig: _dstConfig,
_lib: _lib
});
uint64 desiredConfirmations = getConfirmations({ _srcConfig: _srcConfig, _dstConfig: _dstConfig, _lib: _lib });

// Determine if we are working with a different ULN config than what is currently configured
// Do nothing if the stack and confirmations are the same as before
if (currentUlnConfig.confirmations == desiredConfirmations && arraysAreEqual(currentUlnConfig.requiredDVNs, desiredDVNs)) return;
// Do nothing if the stack, confirmations, and disabled optional DVNs are the same as before
if (
currentUlnConfig.confirmations == desiredConfirmations &&
currentUlnConfig.optionalDVNCount == NIL_DVN_COUNT &&
currentUlnConfig.optionalDVNThreshold == 0 &&
currentUlnConfig.optionalDVNs.length == 0 &&
arraysAreEqual(currentUlnConfig.requiredDVNs, desiredDVNs)
) return;

// generate the config
UlnConfig memory desiredUlnConfig;
desiredUlnConfig.confirmations = desiredConfirmations;
desiredUlnConfig.requiredDVNCount = uint8(desiredDVNs.length);
desiredUlnConfig.optionalDVNCount = NIL_DVN_COUNT;
desiredUlnConfig.optionalDVNThreshold = 0;
desiredUlnConfig.requiredDVNs = desiredDVNs;

SetConfigParam[] memory setConfigParamArray = new SetConfigParam[](1);
Expand All @@ -118,22 +124,10 @@ contract SetDVNs is BaseInherited, Script {
});

// generate data and call
bytes memory data = abi.encodeCall(
IMessageLibManager.setConfig,
(
_oft,
_lib,
setConfigParamArray
)
);
bytes memory data = abi.encodeCall(IMessageLibManager.setConfig, (_oft, _lib, setConfigParamArray));
(bool success, ) = _srcConfig.endpoint.call(data);
require(success, "Unable to setConfig");
pushSerializedTx({
_name: "setConfig",
_to: _srcConfig.endpoint,
_value: 0,
_data: data
});
pushSerializedTx({ _name: "setConfig", _to: _srcConfig.endpoint, _value: 0, _data: data });
}

function getConfirmations(
Expand All @@ -155,11 +149,14 @@ contract SetDVNs is BaseInherited, Script {
revert("Unknown ULN lib");
}

function arraysAreEqual(address[] memory _dvnStackA, address[] memory _dvnStackB) public pure virtual returns (bool) {
function arraysAreEqual(
address[] memory _dvnStackA,
address[] memory _dvnStackB
) public pure virtual returns (bool) {
if (_dvnStackA.length != _dvnStackB.length) {
return false;
} else {
for (uint256 i=0; i<_dvnStackA.length; i++) {
for (uint256 i = 0; i < _dvnStackA.length; i++) {
if (_dvnStackA[i] != _dvnStackB[i]) {
return false;
}
Expand All @@ -168,19 +165,13 @@ contract SetDVNs is BaseInherited, Script {
return true;
}

// Returns the ascending-sorted DVN stack of the connected chain
// Returns the ascending-sorted DVN stack of the connected chain
function craftDvnStack(
uint256 _srcChainId,
uint256 _dstChainId
) public virtual returns (address[] memory desiredDVNs) {
DvnStack memory srcDVNs = getDvnStack({
_srcChainId: _srcChainId,
_dstChainId: _dstChainId
});
DvnStack memory dstDVNs = getDvnStack({
_srcChainId: _dstChainId,
_dstChainId: _srcChainId
});
DvnStack memory srcDVNs = getDvnStack({ _srcChainId: _srcChainId, _dstChainId: _dstChainId });
DvnStack memory dstDVNs = getDvnStack({ _srcChainId: _dstChainId, _dstChainId: _srcChainId });

// start with a fresh array
delete dvnStackTemp;
Expand Down Expand Up @@ -244,13 +235,17 @@ contract SetDVNs is BaseInherited, Script {

// populate the output array and sort ascending
desiredDVNs = new address[](dvnStackTemp.length);
for (uint256 i=0; i<dvnStackTemp.length; i++) {
for (uint256 i = 0; i < dvnStackTemp.length; i++) {
desiredDVNs[i] = dvnStackTemp[i];
}
desiredDVNs = Arrays.sort(desiredDVNs);
}

function incorrectDvnMatchMsg(string memory dvnName, uint256 chainId1, uint256 chainId2) public pure virtual returns (string memory) {
function incorrectDvnMatchMsg(
string memory dvnName,
uint256 chainId1,
uint256 chainId2
) public pure virtual returns (string memory) {
string memory message = string.concat("DVN Stack misconfigured: ", chainId1.toString());
message = string.concat(message, " <> ");
message = string.concat(message, chainId2.toString());
Expand All @@ -259,15 +254,18 @@ contract SetDVNs is BaseInherited, Script {
return message;
}

function getDvnStack(uint256 _srcChainId, uint256 _dstChainId) public virtual view returns (DvnStack memory dvnStack) {
require(_srcChainId != _dstChainId, "_srcChainId == _dstChainId"); // cannot set dvn options to self

function getDvnStack(
uint256 _srcChainId,
uint256 _dstChainId
) public view virtual returns (DvnStack memory dvnStack) {
require(_srcChainId != _dstChainId, "_srcChainId == _dstChainId"); // cannot set dvn options to self

// craft path
string memory root = vm.projectRoot();
root = string.concat(root, "/config/dvn/");
string memory name = string.concat(_srcChainId.toString(), ".json");
string memory path = string.concat(root, name);

// load json
string memory jsonFile = vm.readFile(path);

Expand Down
6 changes: 5 additions & 1 deletion scripts/ops/fix/FixDVNs/FixDVNsInherited.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ contract FixDVNsInherited is DeployFraxOFTProtocol {

function filenameForStep(string memory _stepName) public view returns (string memory) {
string memory root = vm.projectRoot();
root = string.concat(root, "/scripts/ops/fix/FixDVNs/generated/canary-nethermind/evm/");
string memory generatedDir = vm.envOr(
"FIX_DVNS_GENERATED_DIR",
string("scripts/ops/fix/FixDVNs/generated/canary-nethermind")
);
root = string.concat(root, "/", generatedDir, "/evm/");
Comment on lines +20 to +24

string memory name = string.concat((block.timestamp).toString(), "-");
name = string.concat(name, _stepName);
Expand Down
17 changes: 13 additions & 4 deletions scripts/ops/fix/FixDVNs/generate-zk-manual-batches.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@ const path = require("path");
const { ethers } = require("ethers");

const ROOT = path.resolve(__dirname, "../../../..");
const OUTPUT_DIR = path.join(__dirname, "generated/canary-nethermind");
const DEFAULT_OUTPUT_DIR = path.join(__dirname, "generated/canary-nethermind");
const OUTPUT_DIR = process.env.FIX_DVNS_GENERATED_DIR
? path.resolve(process.cwd(), process.env.FIX_DVNS_GENERATED_DIR)
: DEFAULT_OUTPUT_DIR;
const SET_CONFIG_ONLY = process.env.FIX_DVNS_SET_CONFIG_ONLY === "true";
const FRAXTAL_CHAIN_ID = 252;
const FRAXTAL_EID = 30255;
const CONFIG_TYPE_ULN = 2;
const CREATED_AT = Date.parse("2026-05-06T00:00:00.000Z");
const NIL_DVN_COUNT = 255;

const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
const DVN_KEYS = ["bcwGroup", "canary", "frax", "horizen", "lz", "nethermind", "stargate"];
Expand Down Expand Up @@ -85,7 +90,7 @@ function craftDvnStack(srcChainId, dstChainId) {
function ulnConfig(requiredDVNs, confirmations) {
return coder.encode(
["tuple(uint64,uint8,uint8,uint8,address[],address[])"],
[[confirmations, requiredDVNs.length, 0, 0, requiredDVNs, []]]
[[confirmations, requiredDVNs.length, NIL_DVN_COUNT, 0, requiredDVNs, []]]
);
}

Expand Down Expand Up @@ -138,7 +143,11 @@ function setConfigTransactions(chain) {
}

for (const chain of ZK_CHAINS) {
writeBatch("1b_SetBlockSendLibZK", chain.chainId, setSendLibraryTransactions(chain, chain.blockedLibrary));
if (!SET_CONFIG_ONLY) {
writeBatch("1b_SetBlockSendLibZK", chain.chainId, setSendLibraryTransactions(chain, chain.blockedLibrary));
}
writeBatch("2b_FixDVNsZK", chain.chainId, setConfigTransactions(chain));
writeBatch("3b_SetSendLibZK", chain.chainId, setSendLibraryTransactions(chain, chain.sendLib302));
if (!SET_CONFIG_ONLY) {
writeBatch("3b_SetSendLibZK", chain.chainId, setSendLibraryTransactions(chain, chain.sendLib302));
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading