Skip to content

Commit

Permalink
feat: Deploy ConsensusRegistry through L1 to L2 transaction (BFT-504) (
Browse files Browse the repository at this point in the history
  • Loading branch information
aakoshh authored Sep 2, 2024
1 parent 446d391 commit d368769
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ l1_shared_bridge = "0x2ae37d8130b82c7e79b3863a39027178e073eedb"
bridgehub = "0xea785a9c91a07ed69b83eb165f4ce2c30ecb4c0b"
governance = "0x6a08d69675af7755569a1a25ef37e795493473a1"
erc20_bridge = "0x84fbda16bd5f2d66d7fbaec5e8d816e7b7014595"
consensus_registry_owner = "0xD64e136566a9E04eb05B30184fF577F52682D182"
79 changes: 78 additions & 1 deletion l1-contracts/deploy-scripts/DeployL2Contracts.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,15 @@ contract DeployL2Script is Script {
address l1SharedBridgeProxy;
address governance;
address erc20BridgeProxy;
// The owner of the contract sets the validator/attester weights.
// Can be the developer multisig wallet on mainnet.
address consensusRegistryOwner;
uint256 chainId;
uint256 eraChainId;
address l2SharedBridgeImplementation;
address l2SharedBridgeProxy;
address consensusRegistryImplementation;
address consensusRegistryProxy;
address forceDeployUpgraderAddress;
}

Expand All @@ -32,6 +37,8 @@ contract DeployL2Script is Script {
bytes l2StandardErc20Bytecode;
bytes l2SharedBridgeBytecode;
bytes l2SharedBridgeProxyBytecode;
bytes consensusRegistryBytecode;
bytes consensusRegistryProxyBytecode;
bytes forceDeployUpgrader;
}

Expand All @@ -44,6 +51,8 @@ contract DeployL2Script is Script {
deploySharedBridgeProxy();
initializeChain();
deployForceDeployer();
deployConsensusRegistry();
deployConsensusRegistryProxy();

saveOutput();
}
Expand All @@ -69,6 +78,16 @@ contract DeployL2Script is Script {
saveOutput();
}

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

deployConsensusRegistry();
deployConsensusRegistryProxy();

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(
Expand All @@ -84,10 +103,17 @@ contract DeployL2Script is Script {
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"
);

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

contracts.forceDeployUpgrader = Utils.readHardhatBytecode(
"/../l2-contracts/artifacts-zk/contracts/ForceDeployUpgrader.sol/ForceDeployUpgrader.json"
);
Expand All @@ -101,13 +127,16 @@ contract DeployL2Script is Script {
config.governance = toml.readAddress("$.governance");
config.l1SharedBridgeProxy = toml.readAddress("$.l1_shared_bridge");
config.erc20BridgeProxy = toml.readAddress("$.erc20_bridge");
config.consensusRegistryOwner = toml.readAddress("$.consensus_registry_owner");
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);
vm.serializeAddress("root", "l2_shared_bridge_proxy", config.l2SharedBridgeProxy);
vm.serializeAddress("root", "consensus_registry_implementation", config.consensusRegistryImplementation);
vm.serializeAddress("root", "consensus_registry_proxy", config.consensusRegistryProxy);
string memory toml = vm.serializeAddress("root", "l2_default_upgrader", config.forceDeployUpgraderAddress);
string memory root = vm.projectRoot();
string memory path = string.concat(root, "/script-out/output-deploy-l2-contracts.toml");
Expand Down Expand Up @@ -185,6 +214,54 @@ contract DeployL2Script is Script {
});
}

// Deploy the ConsensusRegistry implementation and save its address into the config.
function deployConsensusRegistry() internal {
// ConsensusRegistry.sol doesn't have a constructor, just an initializer.
bytes memory constructorData = "";

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

// Deploy a transparent upgradable proxy for the already deployed consensus registry
// implementation and save its address into the config.
function deployConsensusRegistryProxy() internal {
// Admin for the proxy
address l2GovernorAddress = AddressAliasHelper.applyL1ToL2Alias(config.governance);

// Call ConsensusRegistry::initialize with the initial owner.
// solhint-disable-next-line func-named-parameters
bytes memory proxyInitializationParams = abi.encodeWithSignature(
"initialize(address)",
config.consensusRegistryOwner
);

bytes memory consensusRegistryProxyConstructorData = abi.encode(
config.consensusRegistryImplementation, // _logic
l2GovernorAddress, // admin_
proxyInitializationParams // _data
);

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

function initializeChain() internal {
L1SharedBridge bridge = L1SharedBridge(config.l1SharedBridgeProxy);

Expand Down

0 comments on commit d368769

Please sign in to comment.