Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deploy l2 contracts and use governance for upgrades #441

Merged
merged 14 commits into from
May 14, 2024
7 changes: 4 additions & 3 deletions l1-contracts-foundry/foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ remappings = [
]
allow_paths = ["../l1-contracts/contracts", "../l2-contracts/contracts"]
fs_permissions = [
{ access = "read", path = "../system-contracts/bootloader/build/artifacts"},
{ access = "read", path = "../system-contracts/artifacts-zk/contracts-preprocessed"},
{ access = "read", path = "../system-contracts/bootloader/build/artifacts" },
kelemeno marked this conversation as resolved.
Show resolved Hide resolved
{ access = "read", path = "../system-contracts/artifacts-zk/contracts-preprocessed" },
{ access = "read", path = "../l2-contracts/artifacts-zk/" },
{ access = "read", path = "./script-config" },
{ access = "read-write", path = "./script-out" },
{ access = "read", path = "./out" }
]
evm_version="cancun"
evm_version = "cancun"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
chain_id = 215
l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
chain_id = 215
era_chain_id = 270
l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
governance = "0x6a08d69675af7755569a1a25ef37e795493473a1"
erc20_bridge = "0x84fbda16bd5f2d66d7fbaec5e8d816e7b7014595"
2 changes: 1 addition & 1 deletion l1-contracts-foundry/script/DeployL1.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ contract DeployL1Script is Script {
Diamond.DiamondCutData memory diamondCut = Diamond.DiamondCutData({
facetCuts: facetCuts,
initAddress: address(0),
initCalldata: hex""
initCalldata: ""
});
bytes memory bytecode = abi.encodePacked(
type(DiamondProxy).creationCode,
Expand Down
60 changes: 60 additions & 0 deletions l1-contracts-foundry/script/DeployPaymaster.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Utils} from "./Utils.sol";

contract DeployPaymaster is Script {
using stdToml for string;
Config config;

struct Config {
address bridgehubAddress;
address l1SharedBridgeProxy;
uint256 chainId;
address paymaster;
}

function initializeConfig() internal {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-deploy-paymaster.toml");
string memory toml = vm.readFile(path);
config.bridgehubAddress = toml.readAddress("$.bridgehub");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.chainId = toml.readUint("$.chain_id");
}

function saveOutput() internal {
string memory toml = vm.serializeAddress("root", "paymaster", config.paymaster);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-paymaster.toml");
vm.writeToml(toml, path);
}

function run() external {
initializeConfig();

deploy();

saveOutput();
}

function deploy() internal {
bytes memory testnetPaymasterBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/TestnetPaymaster.sol/TestnetPaymaster.json"
);

config.paymaster = Utils.deployThroughL1({
bytecode: testnetPaymasterBytecode,
constructorargs: "",
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: new bytes[](0),
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy,
chainId: config.chainId
});
}
}
2 changes: 1 addition & 1 deletion l1-contracts-foundry/script/InitializeL2WethToken.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ contract InitializeL2WethTokenScript is Script {
console.log("L2 WETH token initialized");
}

function getL2Calldata() internal returns (bytes memory) {
function getL2Calldata() internal view returns (bytes memory) {
// Low-level call is performed due to different solidity
// compiler versions between L1 and L2
// solhint-disable-next-line func-named-parameters
Expand Down
151 changes: 151 additions & 0 deletions l1-contracts-foundry/script/InitializeSharedBridgeOnL2.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
pragma solidity ^0.8.24;

import {Script} from "forge-std/Script.sol";
import {stdToml} from "forge-std/StdToml.sol";

import {Utils} from "./Utils.sol";
import {L2ContractHelper} from "contracts/common/libraries/L2ContractHelper.sol";
import {AddressAliasHelper} from "contracts/vendor/AddressAliasHelper.sol";
import {L1SharedBridge} from "contracts/bridge/L1SharedBridge.sol";

contract DeployL2Script is Script {
using stdToml for string;

Config config;
ContractsBytecodes contracts;

struct Config {
address bridgehubAddress;
address l1SharedBridgeProxy;
address governance;
address erc20BridgeProxy;
uint256 chainId;
uint256 eraChainId;
address l2SharedBridgeImplementation;
address l2SharedBridgeProxy;
}

struct ContractsBytecodes {
bytes l2StandardErc20FactoryBytecode;
bytes beaconProxy;
bytes l2StandardErc20Bytecode;
bytes l2SharedBridgeBytecode;
bytes l2SharedBridgeProxyBytecode;
}

function run() public {
initializeConfig();
loadContracts();

deployFactoryDeps();
deploySharedBridge();
deploySharedBridgeProxy();
initialize_chain();

saveOutput();
}

function loadContracts() internal {
//HACK: Meanwhile we are not integrated foundry zksync we use contracts that has been built using hardhat
contracts.l2StandardErc20FactoryBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol/UpgradeableBeacon.json"
);
contracts.beaconProxy = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol/BeaconProxy.json"
);
contracts.l2StandardErc20Bytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/bridge/L2StandardERC20.sol/L2StandardERC20.json"
);

contracts.l2SharedBridgeBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/bridge/L2SharedBridge.sol/L2SharedBridge.json"
);

contracts.l2SharedBridgeProxyBytecode = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol/TransparentUpgradeableProxy.json"
);
}

function initializeConfig() internal {
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-config/config-initialize-shared-bridges.toml");
string memory toml = vm.readFile(path);
config.bridgehubAddress = toml.readAddress("$.bridgehub");
config.governance = toml.readAddress("$.governance");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.erc20BridgeProxy = toml.readAddress("$.erc20_bridge");
config.chainId = toml.readUint("$.chain_id");
config.eraChainId = toml.readUint("$.era_chain_id");
}

function saveOutput() internal {
vm.serializeAddress("root", "l2_shared_bridge_implementation", config.l2SharedBridgeImplementation);
string memory toml = vm.serializeAddress("root", "l2_shared_bridge_proxy", config.l2SharedBridgeProxy);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-initialize-shared-bridges.toml");
vm.writeToml(toml, path);
}

function deployFactoryDeps() public {
bytes[] memory factoryDeps = new bytes[](3);
factoryDeps[0] = contracts.l2StandardErc20FactoryBytecode;
factoryDeps[1] = contracts.l2StandardErc20Bytecode;
factoryDeps[2] = contracts.beaconProxy;
Utils.publishBytecodes(factoryDeps, config.chainId, config.bridgehubAddress, config.l1SharedBridgeProxy);
}

function deploySharedBridge() public {
bytes[] memory factoryDeps = new bytes[](1);
factoryDeps[0] = contracts.beaconProxy;

bytes memory constructorData = abi.encode(config.eraChainId);

config.l2SharedBridgeImplementation = Utils.deployThroughL1({
bytecode: contracts.l2SharedBridgeBytecode,
constructorargs: constructorData,
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: factoryDeps,
chainId: config.chainId,
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy
});
}

function deploySharedBridgeProxy() public {
address l2GovernorAddress = AddressAliasHelper.applyL1ToL2Alias(config.governance);
bytes32 l2StandardErc20BytecodeHash = L2ContractHelper.hashL2Bytecode(contracts.beaconProxy);

// solhint-disable-next-line func-named-parameters
bytes memory proxyInitializationParams = abi.encodeWithSignature(
"initialize(address,address,bytes32,address)",
config.l1SharedBridgeProxy,
config.erc20BridgeProxy,
l2StandardErc20BytecodeHash,
l2GovernorAddress
);

bytes memory l2SharedBridgeProxyConstructorData = abi.encode(
config.l2SharedBridgeImplementation,
l2GovernorAddress,
proxyInitializationParams
);

config.l2SharedBridgeProxy = Utils.deployThroughL1({
bytecode: contracts.l2SharedBridgeProxyBytecode,
constructorargs: l2SharedBridgeProxyConstructorData,
create2salt: "",
l2GasLimit: Utils.MAX_PRIORITY_TX_GAS,
factoryDeps: new bytes[](0),
chainId: config.chainId,
bridgehubAddress: config.bridgehubAddress,
l1SharedBridgeProxy: config.l1SharedBridgeProxy
});
}

function initialize_chain() public {
L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy);
vm.broadcast();
bridge.initializeChainGovernance(config.chainId, config.l2SharedBridgeProxy);
}
}
8 changes: 4 additions & 4 deletions l1-contracts-foundry/script/RegisterHyperchain.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {IBridgehub} from "contracts/bridgehub/IBridgehub.sol";
import {IZkSyncHyperchain} from "contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol";
import {ValidatorTimelock} from "contracts/state-transition/ValidatorTimelock.sol";
import {Governance} from "contracts/governance/Governance.sol";
import {PubdataPricingMode} from "contracts/state-transition/chain-deps/ZkSyncHyperchainStorage.sol";

contract RegisterHyperchainScript is Script {
using stdToml for string;
Expand Down Expand Up @@ -196,10 +197,9 @@ contract RegisterHyperchainScript is Script {
config.baseTokenGasPriceMultiplierDenominator
);

// TODO: support validium mode when available
// if (config.contractsMode) {
// zkSyncStateTransition.setValidiumMode(PubdataPricingMode.Validium);
// }
if (config.validiumMode) {
hyperchain.setPubdataPricingMode(PubdataPricingMode.Validium);
}

vm.stopBroadcast();
console.log("ZkSync State Transition configured");
Expand Down
Loading
Loading