diff --git a/contracts b/contracts index fd4aebcfe883..d3687694f71d 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit fd4aebcfe8833b26e096e87e142a5e7e4744f3fa +Subproject commit d3687694f71d83fa286b9c186b4c3ea173028f83 diff --git a/zk_toolbox/crates/config/src/contracts.rs b/zk_toolbox/crates/config/src/contracts.rs index 6042c4bea088..19d432909487 100644 --- a/zk_toolbox/crates/config/src/contracts.rs +++ b/zk_toolbox/crates/config/src/contracts.rs @@ -5,7 +5,9 @@ use crate::{ consts::CONTRACTS_FILE, forge_interface::{ deploy_ecosystem::output::DeployL1Output, - deploy_l2_contracts::output::{DefaultL2UpgradeOutput, InitializeBridgeOutput}, + deploy_l2_contracts::output::{ + ConsensusRegistryOutput, DefaultL2UpgradeOutput, InitializeBridgeOutput, + }, register_chain::output::RegisterChainOutput, }, traits::{FileConfigWithDefaultName, ZkToolboxConfig}, @@ -84,6 +86,14 @@ impl ContractsConfig { Ok(()) } + pub fn set_consensus_registry( + &mut self, + consensus_registry_output: &ConsensusRegistryOutput, + ) -> anyhow::Result<()> { + self.l2.consensus_registry = Some(consensus_registry_output.consensus_registry_proxy); + Ok(()) + } + pub fn set_default_l2_upgrade( &mut self, default_upgrade_output: &DefaultL2UpgradeOutput, @@ -140,4 +150,5 @@ pub struct L1Contracts { pub struct L2Contracts { pub testnet_paymaster_addr: Address, pub default_l2_upgrader: Address, + pub consensus_registry: Option
, } diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs b/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs index f48fd0ba2b5e..b20b58f99c58 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs +++ b/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs @@ -6,6 +6,8 @@ use crate::{traits::ZkToolboxConfig, ChainConfig}; impl ZkToolboxConfig for DeployL2ContractsInput {} +/// Fields corresponding to `contracts/l1-contracts/deploy-script-config-template/config-deploy-l2-config.toml` +/// which are read by `contracts/l1-contracts/deploy-scripts/DeployL2Contracts.sol`. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct DeployL2ContractsInput { pub era_chain_id: L2ChainId, @@ -14,6 +16,7 @@ pub struct DeployL2ContractsInput { pub bridgehub: Address, pub governance: Address, pub erc20_bridge: Address, + pub consensus_registry_owner: Address, } impl DeployL2ContractsInput { @@ -27,6 +30,7 @@ impl DeployL2ContractsInput { bridgehub: contracts.ecosystem_contracts.bridgehub_proxy_addr, governance: wallets.governor.address, erc20_bridge: contracts.bridges.erc20.l1_address, + consensus_registry_owner: wallets.governor.address, }) } } diff --git a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs b/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs index 22f3dc9381b3..860e7e293f99 100644 --- a/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs +++ b/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs @@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize}; use crate::traits::ZkToolboxConfig; impl ZkToolboxConfig for InitializeBridgeOutput {} - impl ZkToolboxConfig for DefaultL2UpgradeOutput {} +impl ZkToolboxConfig for ConsensusRegistryOutput {} #[derive(Debug, Clone, Serialize, Deserialize)] pub struct InitializeBridgeOutput { @@ -17,3 +17,9 @@ pub struct InitializeBridgeOutput { pub struct DefaultL2UpgradeOutput { pub l2_default_upgrader: Address, } + +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct ConsensusRegistryOutput { + pub consensus_registry_implementation: Address, + pub consensus_registry_proxy: Address, +} diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs index 30f361e44af2..3625abfb15a9 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs @@ -11,7 +11,7 @@ use config::{ forge_interface::{ deploy_l2_contracts::{ input::DeployL2ContractsInput, - output::{DefaultL2UpgradeOutput, InitializeBridgeOutput}, + output::{ConsensusRegistryOutput, DefaultL2UpgradeOutput, InitializeBridgeOutput}, }, script_params::DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS, }, @@ -31,7 +31,8 @@ use crate::{ pub enum Deploy2ContractsOption { All, Upgrader, - IntiailizeBridges, + InitiailizeBridges, + ConsensusRegistry, } pub async fn run( @@ -70,7 +71,17 @@ pub async fn run( ) .await?; } - Deploy2ContractsOption::IntiailizeBridges => { + Deploy2ContractsOption::ConsensusRegistry => { + deploy_consensus_registry( + shell, + &chain_config, + &ecosystem_config, + &mut contracts, + args, + ) + .await?; + } + Deploy2ContractsOption::InitiailizeBridges => { initialize_bridges( shell, &chain_config, @@ -88,6 +99,25 @@ pub async fn run( Ok(()) } +/// Build the L2 contracts, deploy one or all of them with `forge`, then update the config +/// by reading one or all outputs written by the deploy scripts. +async fn build_and_deploy( + shell: &Shell, + chain_config: &ChainConfig, + ecosystem_config: &EcosystemConfig, + forge_args: ForgeScriptArgs, + signature: Option<&str>, + mut update_config: impl FnMut(&Shell, &Path) -> anyhow::Result<()>, +) -> anyhow::Result<()> { + build_l2_contracts(shell, &ecosystem_config.link_to_code)?; + call_forge(shell, chain_config, ecosystem_config, forge_args, signature).await?; + update_config( + shell, + &DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), + )?; + Ok(()) +} + pub async fn initialize_bridges( shell: &Shell, chain_config: &ChainConfig, @@ -95,22 +125,17 @@ pub async fn initialize_bridges( contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { - build_l2_contracts(shell, &ecosystem_config.link_to_code)?; - call_forge( + build_and_deploy( shell, chain_config, ecosystem_config, forge_args, Some("runDeploySharedBridge"), + |shell, out| { + contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?) + }, ) - .await?; - let output = InitializeBridgeOutput::read( - shell, - DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - - contracts_config.set_l2_shared_bridge(&output)?; - Ok(()) + .await } pub async fn deploy_upgrader( @@ -120,48 +145,60 @@ pub async fn deploy_upgrader( contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { - build_l2_contracts(shell, &ecosystem_config.link_to_code)?; - call_forge( + build_and_deploy( shell, chain_config, ecosystem_config, forge_args, Some("runDefaultUpgrader"), + |shell, out| { + contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?) + }, ) - .await?; - let output = DefaultL2UpgradeOutput::read( - shell, - DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - - contracts_config.set_default_l2_upgrade(&output)?; - Ok(()) + .await } -pub async fn deploy_l2_contracts( +pub async fn deploy_consensus_registry( shell: &Shell, chain_config: &ChainConfig, ecosystem_config: &EcosystemConfig, contracts_config: &mut ContractsConfig, forge_args: ForgeScriptArgs, ) -> anyhow::Result<()> { - build_l2_contracts(shell, &ecosystem_config.link_to_code)?; - call_forge(shell, chain_config, ecosystem_config, forge_args, None).await?; - let output = InitializeBridgeOutput::read( + build_and_deploy( shell, - DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - - contracts_config.set_l2_shared_bridge(&output)?; + chain_config, + ecosystem_config, + forge_args, + Some("runDeployConsensusRegistry"), + |shell, out| { + contracts_config.set_consensus_registry(&ConsensusRegistryOutput::read(shell, out)?) + }, + ) + .await +} - let output = DefaultL2UpgradeOutput::read( +pub async fn deploy_l2_contracts( + shell: &Shell, + chain_config: &ChainConfig, + ecosystem_config: &EcosystemConfig, + contracts_config: &mut ContractsConfig, + forge_args: ForgeScriptArgs, +) -> anyhow::Result<()> { + build_and_deploy( shell, - DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - - contracts_config.set_default_l2_upgrade(&output)?; - - Ok(()) + chain_config, + ecosystem_config, + forge_args, + None, + |shell, out| { + contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)?; + contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?)?; + contracts_config.set_consensus_registry(&ConsensusRegistryOutput::read(shell, out)?)?; + Ok(()) + }, + ) + .await } async fn call_forge( diff --git a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs index dbddc923336a..afc92d2288bf 100644 --- a/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs +++ b/zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs @@ -31,6 +31,9 @@ pub enum ChainCommands { /// Deploy all l2 contracts #[command(alias = "l2")] DeployL2Contracts(ForgeScriptArgs), + /// Deploy L2 consensus registry + #[command(alias = "consensus")] + DeployConsensusRegistry(ForgeScriptArgs), /// Deploy Default Upgrader Upgrader(ForgeScriptArgs), /// Deploy paymaster smart contract @@ -48,11 +51,14 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<() ChainCommands::DeployL2Contracts(args) => { deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await } + ChainCommands::DeployConsensusRegistry(args) => { + deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::ConsensusRegistry).await + } ChainCommands::Upgrader(args) => { deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::Upgrader).await } ChainCommands::InitializeBridges(args) => { - deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::IntiailizeBridges).await + deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::InitiailizeBridges).await } ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell).await, ChainCommands::UpdateTokenMultiplierSetter(args) => {