Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
kelemeno committed Sep 27, 2024
1 parent acdf8e9 commit 9791cec
Show file tree
Hide file tree
Showing 12 changed files with 325 additions and 42 deletions.
4 changes: 2 additions & 2 deletions l1-contracts/contracts/bridge/asset-router/L2AssetRouter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
//////////////////////////////////////////////////////////////*/

// kl todo add handle Legaacy data here, which calls esureTokenRegisteredWithNTV
// have handleLegacyData called from somewhere.
// have handleLegacyData called from somewhere.

/// @inheritdoc AssetRouterBase
function _ensureTokenRegisteredWithNTV(address _token) internal override returns (bytes32 assetId) {
Expand All @@ -155,7 +155,7 @@ contract L2AssetRouter is AssetRouterBase, IL2AssetRouter {
_withdrawSender(_assetId, _assetData, msg.sender, true);
}

function withdrawToken(address _l2NativeToken, bytes memory _assetData) public {
function withdrawToken(address _l2NativeToken, bytes memory _assetData) public {
bytes32 assetId = _ensureTokenRegisteredWithNTV(_l2NativeToken);
_withdrawSender(assetId, _assetData, msg.sender, true);
}
Expand Down
1 change: 0 additions & 1 deletion l1-contracts/deploy-scripts/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ contract DeployL1Script is Script {
address internal constant ADDRESS_ONE = 0x0000000000000000000000000000000000000001;
address internal constant DETERMINISTIC_CREATE2_ADDRESS = 0x4e59b44847b379578588920cA78FbF26c0B4956C;


// solhint-disable-next-line gas-struct-packing
struct GeneratedData {
bytes forceDeploymentsData;
Expand Down
106 changes: 103 additions & 3 deletions l1-contracts/deploy-scripts/GatewayPreparation.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ import {GatewayTransactionFilterer} from "contracts/transactionFilterer/GatewayT
import {TransparentUpgradeableProxy} from "@openzeppelin/contracts-v4/proxy/transparent/TransparentUpgradeableProxy.sol";
import {SET_ASSET_HANDLER_COUNTERPART_ENCODING_VERSION} from "contracts/bridge/asset-router/IAssetRouterBase.sol";
import {CTM_DEPLOYMENT_TRACKER_ENCODING_VERSION} from "contracts/bridgehub/CTMDeploymentTracker.sol";
import {L2AssetRouter} from "contracts/bridge/asset-router/L2AssetRouter.sol";
import {L1Nullifier} from "contracts/bridge/L1Nullifier.sol";
import {BridgehubMintCTMAssetData} from "contracts/bridgehub/IBridgehub.sol";
import {IAssetRouterBase} from "contracts/bridge/asset-router/IAssetRouterBase.sol";
import {L2_ASSET_ROUTER_ADDR} from "contracts/common/L2ContractAddresses.sol";
import {IAdmin} from "contracts/state-transition/chain-interfaces/IAdmin.sol";
import {FinalizeL1DepositParams} from "contracts/bridge/interfaces/IL1Nullifier.sol";

import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol";

/// @notice Scripts that is responsible for preparing the chain to become a gateway
contract GatewayPreparation is Script {
Expand All @@ -44,6 +53,7 @@ contract GatewayPreparation is Script {
address gatewayChainAdmin;
address gatewayAccessControlRestriction;
address gatewayChainProxyAdmin;
address l1NullifierProxy;
bytes gatewayDiamondCutData;
}

Expand All @@ -70,7 +80,7 @@ contract GatewayPreparation is Script {
l1ChainId = block.chainid;

string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/gateway-preparation-l1.toml");
string memory path = string.concat(root, vm.envString("GATEWAY_PREPARATION_L1_CONFIG"));
string memory toml = vm.readFile(path);

// Config file must be parsed key by key, otherwise values returned
Expand All @@ -89,7 +99,8 @@ contract GatewayPreparation is Script {
gatewayDiamondCutData: toml.readBytes("$.gateway_diamond_cut_data"),
gatewayChainAdmin: toml.readAddress("$.chain_admin"),
gatewayAccessControlRestriction: toml.readAddress("$.access_control_restriction"),
gatewayChainProxyAdmin: toml.readAddress("$.chain_proxy_admin")
gatewayChainProxyAdmin: toml.readAddress("$.chain_proxy_admin"),
l1NullifierProxy: toml.readAddress("$.l1_nullifier_proxy")
});
}

Expand Down Expand Up @@ -240,7 +251,7 @@ contract GatewayPreparation is Script {

uint256 currentSettlementLayer = IBridgehub(config.bridgehub).settlementLayer(chainId);
if (currentSettlementLayer == config.gatewayChainId) {
console.log("Chain already whitelisted as settlement layer");
console.log("Chain already using gateway as its settlement layer");
saveOutput(bytes32(0));
return;
}
Expand Down Expand Up @@ -272,6 +283,95 @@ contract GatewayPreparation is Script {
saveOutput(l2TxHash);
}

/// @dev Calling this function requires private key to the admin of the chain
function startMigrateChainFromGateway(
address chainAdmin,
address accessControlRestriction,
uint256 chainId
) public {
initializeConfig();

bytes32 chainAssetId = IBridgehub(config.bridgehub).ctmAssetIdFromChainId(chainId);

uint256 currentSettlementLayer = IBridgehub(config.bridgehub).settlementLayer(chainId);
// if (currentSettlementLayer == config.l1ChainId) {
// console.log("Chain already using L1 as its settlement layer");
// saveOutput(bytes32(0));
// return;
// }

// if (currentSettlementLayer == address(0)) {
// console.log("Chain has never used Gateway as its settlement layer");
// saveOutput(bytes32(0));
// return;
// }

// bytes memory bridgehubData = abi.encode(
// BridgehubBurnCTMAssetData({
// chainId: chainId,
// ctmData: abi.encode(chainAdmin, config.diamondCutData),
// chainData: abi.encode(IZKChain(IBridgehub(config.bridgehub).getZKChain(chainId)).getProtocolVersion())
// })
// );

// L2AssetRouter l2AssetRouter = L2AssetRouter(L2_ASSET_ROUTER_ADDR);
// l2AssetRouter.withdraw(
// ctmAssetId,
// bridgehubBurnData
// );

// saveOutput(l2TxHash);
}

function finishMigrateChainFromGateway(
IZKChain migratingChain,
uint256 migratingChainId,
uint256 gatewayChainId
) public {
initializeConfig();

// TODO(EVM-746): Use L2-based chain admin contract
// address l2ChainAdmin = AddressAliasHelper.applyL1ToL2Alias(chainAdmin);
IBridgehub bridgehub = IBridgehub(config.bridgehub);
bytes32 assetId = bridgehub.ctmAssetIdFromChainId(migratingChainId);
bytes32 baseTokenAssetId = bridgehub.baseTokenAssetId(migratingChainId);
IChainTypeManager ctm = IChainTypeManager(bridgehub.chainTypeManager(migratingChainId));

bytes memory chainData = abi.encode(IAdmin(address(migratingChain)).prepareChainCommitment());
bytes memory ctmData = abi.encode(
baseTokenAssetId,
msg.sender,
ctm.protocolVersion(),
config.gatewayDiamondCutData
);
BridgehubMintCTMAssetData memory data = BridgehubMintCTMAssetData({
chainId: migratingChainId,
baseTokenAssetId: baseTokenAssetId,
ctmData: ctmData,
chainData: chainData
});
bytes memory bridgehubMintData = abi.encode(data);

L1Nullifier l1Nullifier = L1Nullifier(config.l1NullifierProxy);

l1Nullifier.finalizeDeposit(
FinalizeL1DepositParams({
chainId: migratingChainId,
l2BatchNumber: 1,
l2MessageIndex: 1,
l2Sender: L2_ASSET_ROUTER_ADDR,
l2TxNumberInBatch: 1,
message: abi.encodePacked(
IAssetRouterBase.finalizeDeposit.selector,
gatewayChainId,
assetId,
bridgehubMintData
),
merkleProof: new bytes32[](0)
})
);
}

/// @dev Calling this function requires private key to the admin of the chain
function setDAValidatorPair(
address chainAdmin,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ contract DeploymentTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer,

function test_bridgeHubSetter() public {
uint256 chainId = zkChainIds[0];
// IChainTypeManager chainTypeManager = IChainTypeManager(bridgeHub.chainTypeManager(chainId));
uint256 randomChainId = 123456;

vm.mockCall(
Expand Down Expand Up @@ -129,7 +128,7 @@ contract DeploymentTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer,
);

address stmAddr = IZKChain(chain).getChainTypeManager();

vm.startBroadcast(owner);
bridgeHub.addChainTypeManager(stmAddr);
bridgeHub.addTokenAssetId(baseTokenAssetId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ contract GatewayPreparationForTests is GatewayPreparation {
);
config.governance = toml.readAddress("$.deployed_addresses.governance_addr");

path = string.concat(root, vm.envString("GATEWAY_CONFIG"));
path = string.concat(root, vm.envString("GATEWAY_AS_CHAIN_CONFIG"));
toml = vm.readFile(path);

config.gatewayChainId = toml.readUint("$.chain.chain_chain_id");

path = string.concat(root, vm.envString("GATEWAY_OUTPUT"));
path = string.concat(root, vm.envString("GATEWAY_AS_CHAIN_OUTPUT"));
toml = vm.readFile(path);

config.gatewayChainAdmin = toml.readAddress("$.chain_admin_addr");
Expand Down
15 changes: 8 additions & 7 deletions l1-contracts/test/foundry/l1/integration/L1GatewayTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,12 @@ contract GatewayTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer, L2T
{
IZKChain chain = IZKChain(bridgehub.getZKChain(migratingChainId));
bytes memory chainData = abi.encode(chain.getProtocolVersion());
bytes memory ctmData = abi.encode(address(1), msg.sender, chainTypeManager.protocolVersion(), ecosystemConfig.contracts.diamondCutData);
bytes memory ctmData = abi.encode(
address(1),
msg.sender,
chainTypeManager.protocolVersion(),
ecosystemConfig.contracts.diamondCutData
);
BridgehubBurnCTMAssetData memory data = BridgehubBurnCTMAssetData({
chainId: migratingChainId,
ctmData: ctmData,
Expand Down Expand Up @@ -254,7 +259,7 @@ contract GatewayTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer, L2T
bytes32 baseTokenAssetId = keccak256("baseTokenAssetId");

uint256 currentChainId = block.chainid;
// we are already on L1, so we have to set another chain id, it cannot be GW or mintChainId.
// we are already on L1, so we have to set another chain id, it cannot be GW or mintChainId.
vm.chainId(migratingChainId);
vm.mockCall(
address(bridgeHub),
Expand All @@ -274,11 +279,7 @@ contract GatewayTests is L1ContractDeployer, ZKChainDeployer, TokenDeployer, L2T

// bytes memory initialDiamondCut = getInitialDiamondCutData();
// gatewayScript.
gatewayScript.finishMigrateChainFromGateway(
migratingChain,
migratingChainId,
gatewayChainId
);
gatewayScript.finishMigrateChainFromGateway(migratingChain, migratingChainId, gatewayChainId);

vm.chainId(currentChainId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ contract GatewayDeployer is L1ContractDeployer {
"/test/foundry/l1/integration/deploy-scripts/script-config/config-deploy-zk-chain-10.toml"
);
vm.setEnv(
"GATEWAY_CONFIG",
"GATEWAY_AS_CHAIN_CONFIG",
"/test/foundry/l1/integration/deploy-scripts/script-config/config-deploy-zk-chain-11.toml"
);
vm.setEnv(
"GATEWAY_OUTPUT",
"GATEWAY_AS_CHAIN_OUTPUT",
"/test/foundry/l1/integration/deploy-scripts/script-out/output-deploy-zk-chain-11.toml"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {CTMDeploymentTracker} from "contracts/bridgehub/CTMDeploymentTracker.sol
import {IChainTypeManager} from "contracts/state-transition/IChainTypeManager.sol";
import {DeployedAddresses, Config} from "deploy-scripts/DeployL1.s.sol";


contract L1ContractDeployer is Test {
using stdStorage for StdStorage;

Expand Down Expand Up @@ -45,7 +44,10 @@ contract L1ContractDeployer is Test {
"ZK_CHAIN_OUT",
"/test/foundry/l1/integration/deploy-scripts/script-out/output-deploy-zk-chain-era.toml"
);
vm.setEnv("GATEWAY_PREPARATION_L1_CONFIG", "/test/foundry/l1/integration/deploy-scripts/script-config/gateway-preparation-l1.toml");
vm.setEnv(
"GATEWAY_PREPARATION_L1_CONFIG",
"/test/foundry/l1/integration/deploy-scripts/script-config/gateway-preparation-l1.toml"
);

l1Script = new DeployL1Script();
l1Script.runForTest();
Expand Down
Loading

0 comments on commit 9791cec

Please sign in to comment.