Skip to content

Commit cab13b8

Browse files
aakoshhpompon0
andauthored
feat(zk_toolbox): Deploy ConsensusRegistry (BFT-504) (#2713)
## What ❔ Adds a `zk_inception chain deploy-consensus-registry` command. TODO: - [x] Change `contracts` submodule back to `main` once matter-labs/era-contracts#735 is merged ### Contract Owner The agreement was that on testnet the `ConsensusRegistry` contract should be owned by the governor account, which is 0xD64e136566a9E04eb05B30184fF577F52682D182, while on mainnet it should be owned by the [developer multisig account](https://app.safe.global/transactions/queue?safe=eth:0x9e543149DdfEEE18e95A4655D07096398Dd2Bf52). The owner is set in [DeployL2ContractsInput::consensus_registry_owner](https://github.com/matter-labs/zksync-era/blob/f4b7c12431d4bb063c735947f74e30c749119b5f/zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs#L19) which has access to contract and wallet configuration and these are written to a config file just before deployment. ~~I added an optional `developer_multisig` wallet to `WalletConfig`, so the address can be added at the same place as the `governor` address is; if `developer_multisig` is missing then `governor` is used. I suppose it could be made part of the `ContractsConfig` instead, but since this is a wallet with funds that developers can access, I thought it wouldn't be out of place in `wallets.yaml` even if one doesn't have any of the corresponding private keys. Let me know if I should be using something else.~~ ### Testing Since the `zk_toolbox` is replacing the `zk` commands, and `zk init` doesn't deploy the consensus registry, we have to use the following commands to see that the contract is built, deployed and its address is written to the config file: ```shell ./bin/zkt zk_inception ecosystem create zk_inception containers zk_inception ecosystem init --dev ``` After this we can check if we see the address in the generated config file: ```console ❯ cat ./chains/era/configs/contracts.yaml | yq .l2.consensus_registry 0x72ada8c211f45e768c9a7781793da84daf1d0d1b ``` Finally clean up: ```shell zk_supervisor clean all ``` ## Why ❔ So that we can deploy the L2 consensus registry contract using the `zk_toolbox`. ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [x] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [x] Tests for the changes have been added / updated. - [x] Documentation comments have been added / updated. - [x] Code has been formatted via `zk fmt` and `zk lint`. --------- Co-authored-by: Grzegorz Prusak <pompon.pompon@gmail.com>
1 parent 1559afb commit cab13b8

File tree

6 files changed

+106
-42
lines changed

6 files changed

+106
-42
lines changed

zk_toolbox/crates/config/src/contracts.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use crate::{
55
consts::CONTRACTS_FILE,
66
forge_interface::{
77
deploy_ecosystem::output::DeployL1Output,
8-
deploy_l2_contracts::output::{DefaultL2UpgradeOutput, InitializeBridgeOutput},
8+
deploy_l2_contracts::output::{
9+
ConsensusRegistryOutput, DefaultL2UpgradeOutput, InitializeBridgeOutput,
10+
},
911
register_chain::output::RegisterChainOutput,
1012
},
1113
traits::{FileConfigWithDefaultName, ZkToolboxConfig},
@@ -84,6 +86,14 @@ impl ContractsConfig {
8486
Ok(())
8587
}
8688

89+
pub fn set_consensus_registry(
90+
&mut self,
91+
consensus_registry_output: &ConsensusRegistryOutput,
92+
) -> anyhow::Result<()> {
93+
self.l2.consensus_registry = Some(consensus_registry_output.consensus_registry_proxy);
94+
Ok(())
95+
}
96+
8797
pub fn set_default_l2_upgrade(
8898
&mut self,
8999
default_upgrade_output: &DefaultL2UpgradeOutput,
@@ -140,4 +150,5 @@ pub struct L1Contracts {
140150
pub struct L2Contracts {
141151
pub testnet_paymaster_addr: Address,
142152
pub default_l2_upgrader: Address,
153+
pub consensus_registry: Option<Address>,
143154
}

zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/input.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use crate::{traits::ZkToolboxConfig, ChainConfig};
66

77
impl ZkToolboxConfig for DeployL2ContractsInput {}
88

9+
/// Fields corresponding to `contracts/l1-contracts/deploy-script-config-template/config-deploy-l2-config.toml`
10+
/// which are read by `contracts/l1-contracts/deploy-scripts/DeployL2Contracts.sol`.
911
#[derive(Debug, Clone, Serialize, Deserialize)]
1012
pub struct DeployL2ContractsInput {
1113
pub era_chain_id: L2ChainId,
@@ -14,6 +16,7 @@ pub struct DeployL2ContractsInput {
1416
pub bridgehub: Address,
1517
pub governance: Address,
1618
pub erc20_bridge: Address,
19+
pub consensus_registry_owner: Address,
1720
}
1821

1922
impl DeployL2ContractsInput {
@@ -27,6 +30,7 @@ impl DeployL2ContractsInput {
2730
bridgehub: contracts.ecosystem_contracts.bridgehub_proxy_addr,
2831
governance: wallets.governor.address,
2932
erc20_bridge: contracts.bridges.erc20.l1_address,
33+
consensus_registry_owner: wallets.governor.address,
3034
})
3135
}
3236
}

zk_toolbox/crates/config/src/forge_interface/deploy_l2_contracts/output.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use serde::{Deserialize, Serialize};
44
use crate::traits::ZkToolboxConfig;
55

66
impl ZkToolboxConfig for InitializeBridgeOutput {}
7-
87
impl ZkToolboxConfig for DefaultL2UpgradeOutput {}
8+
impl ZkToolboxConfig for ConsensusRegistryOutput {}
99

1010
#[derive(Debug, Clone, Serialize, Deserialize)]
1111
pub struct InitializeBridgeOutput {
@@ -17,3 +17,9 @@ pub struct InitializeBridgeOutput {
1717
pub struct DefaultL2UpgradeOutput {
1818
pub l2_default_upgrader: Address,
1919
}
20+
21+
#[derive(Debug, Clone, Serialize, Deserialize)]
22+
pub struct ConsensusRegistryOutput {
23+
pub consensus_registry_implementation: Address,
24+
pub consensus_registry_proxy: Address,
25+
}

zk_toolbox/crates/zk_inception/src/commands/chain/deploy_l2_contracts.rs

Lines changed: 75 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use config::{
1111
forge_interface::{
1212
deploy_l2_contracts::{
1313
input::DeployL2ContractsInput,
14-
output::{DefaultL2UpgradeOutput, InitializeBridgeOutput},
14+
output::{ConsensusRegistryOutput, DefaultL2UpgradeOutput, InitializeBridgeOutput},
1515
},
1616
script_params::DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS,
1717
},
@@ -31,7 +31,8 @@ use crate::{
3131
pub enum Deploy2ContractsOption {
3232
All,
3333
Upgrader,
34-
IntiailizeBridges,
34+
InitiailizeBridges,
35+
ConsensusRegistry,
3536
}
3637

3738
pub async fn run(
@@ -70,7 +71,17 @@ pub async fn run(
7071
)
7172
.await?;
7273
}
73-
Deploy2ContractsOption::IntiailizeBridges => {
74+
Deploy2ContractsOption::ConsensusRegistry => {
75+
deploy_consensus_registry(
76+
shell,
77+
&chain_config,
78+
&ecosystem_config,
79+
&mut contracts,
80+
args,
81+
)
82+
.await?;
83+
}
84+
Deploy2ContractsOption::InitiailizeBridges => {
7485
initialize_bridges(
7586
shell,
7687
&chain_config,
@@ -88,29 +99,43 @@ pub async fn run(
8899
Ok(())
89100
}
90101

102+
/// Build the L2 contracts, deploy one or all of them with `forge`, then update the config
103+
/// by reading one or all outputs written by the deploy scripts.
104+
async fn build_and_deploy(
105+
shell: &Shell,
106+
chain_config: &ChainConfig,
107+
ecosystem_config: &EcosystemConfig,
108+
forge_args: ForgeScriptArgs,
109+
signature: Option<&str>,
110+
mut update_config: impl FnMut(&Shell, &Path) -> anyhow::Result<()>,
111+
) -> anyhow::Result<()> {
112+
build_l2_contracts(shell, &ecosystem_config.link_to_code)?;
113+
call_forge(shell, chain_config, ecosystem_config, forge_args, signature).await?;
114+
update_config(
115+
shell,
116+
&DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code),
117+
)?;
118+
Ok(())
119+
}
120+
91121
pub async fn initialize_bridges(
92122
shell: &Shell,
93123
chain_config: &ChainConfig,
94124
ecosystem_config: &EcosystemConfig,
95125
contracts_config: &mut ContractsConfig,
96126
forge_args: ForgeScriptArgs,
97127
) -> anyhow::Result<()> {
98-
build_l2_contracts(shell, &ecosystem_config.link_to_code)?;
99-
call_forge(
128+
build_and_deploy(
100129
shell,
101130
chain_config,
102131
ecosystem_config,
103132
forge_args,
104133
Some("runDeploySharedBridge"),
134+
|shell, out| {
135+
contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)
136+
},
105137
)
106-
.await?;
107-
let output = InitializeBridgeOutput::read(
108-
shell,
109-
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code),
110-
)?;
111-
112-
contracts_config.set_l2_shared_bridge(&output)?;
113-
Ok(())
138+
.await
114139
}
115140

116141
pub async fn deploy_upgrader(
@@ -120,48 +145,60 @@ pub async fn deploy_upgrader(
120145
contracts_config: &mut ContractsConfig,
121146
forge_args: ForgeScriptArgs,
122147
) -> anyhow::Result<()> {
123-
build_l2_contracts(shell, &ecosystem_config.link_to_code)?;
124-
call_forge(
148+
build_and_deploy(
125149
shell,
126150
chain_config,
127151
ecosystem_config,
128152
forge_args,
129153
Some("runDefaultUpgrader"),
154+
|shell, out| {
155+
contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?)
156+
},
130157
)
131-
.await?;
132-
let output = DefaultL2UpgradeOutput::read(
133-
shell,
134-
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code),
135-
)?;
136-
137-
contracts_config.set_default_l2_upgrade(&output)?;
138-
Ok(())
158+
.await
139159
}
140160

141-
pub async fn deploy_l2_contracts(
161+
pub async fn deploy_consensus_registry(
142162
shell: &Shell,
143163
chain_config: &ChainConfig,
144164
ecosystem_config: &EcosystemConfig,
145165
contracts_config: &mut ContractsConfig,
146166
forge_args: ForgeScriptArgs,
147167
) -> anyhow::Result<()> {
148-
build_l2_contracts(shell, &ecosystem_config.link_to_code)?;
149-
call_forge(shell, chain_config, ecosystem_config, forge_args, None).await?;
150-
let output = InitializeBridgeOutput::read(
168+
build_and_deploy(
151169
shell,
152-
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code),
153-
)?;
154-
155-
contracts_config.set_l2_shared_bridge(&output)?;
170+
chain_config,
171+
ecosystem_config,
172+
forge_args,
173+
Some("runDeployConsensusRegistry"),
174+
|shell, out| {
175+
contracts_config.set_consensus_registry(&ConsensusRegistryOutput::read(shell, out)?)
176+
},
177+
)
178+
.await
179+
}
156180

157-
let output = DefaultL2UpgradeOutput::read(
181+
pub async fn deploy_l2_contracts(
182+
shell: &Shell,
183+
chain_config: &ChainConfig,
184+
ecosystem_config: &EcosystemConfig,
185+
contracts_config: &mut ContractsConfig,
186+
forge_args: ForgeScriptArgs,
187+
) -> anyhow::Result<()> {
188+
build_and_deploy(
158189
shell,
159-
DEPLOY_L2_CONTRACTS_SCRIPT_PARAMS.output(&chain_config.link_to_code),
160-
)?;
161-
162-
contracts_config.set_default_l2_upgrade(&output)?;
163-
164-
Ok(())
190+
chain_config,
191+
ecosystem_config,
192+
forge_args,
193+
None,
194+
|shell, out| {
195+
contracts_config.set_l2_shared_bridge(&InitializeBridgeOutput::read(shell, out)?)?;
196+
contracts_config.set_default_l2_upgrade(&DefaultL2UpgradeOutput::read(shell, out)?)?;
197+
contracts_config.set_consensus_registry(&ConsensusRegistryOutput::read(shell, out)?)?;
198+
Ok(())
199+
},
200+
)
201+
.await
165202
}
166203

167204
async fn call_forge(

zk_toolbox/crates/zk_inception/src/commands/chain/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ pub enum ChainCommands {
3131
/// Deploy all l2 contracts
3232
#[command(alias = "l2")]
3333
DeployL2Contracts(ForgeScriptArgs),
34+
/// Deploy L2 consensus registry
35+
#[command(alias = "consensus")]
36+
DeployConsensusRegistry(ForgeScriptArgs),
3437
/// Deploy Default Upgrader
3538
Upgrader(ForgeScriptArgs),
3639
/// Deploy paymaster smart contract
@@ -48,11 +51,14 @@ pub(crate) async fn run(shell: &Shell, args: ChainCommands) -> anyhow::Result<()
4851
ChainCommands::DeployL2Contracts(args) => {
4952
deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::All).await
5053
}
54+
ChainCommands::DeployConsensusRegistry(args) => {
55+
deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::ConsensusRegistry).await
56+
}
5157
ChainCommands::Upgrader(args) => {
5258
deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::Upgrader).await
5359
}
5460
ChainCommands::InitializeBridges(args) => {
55-
deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::IntiailizeBridges).await
61+
deploy_l2_contracts::run(args, shell, Deploy2ContractsOption::InitiailizeBridges).await
5662
}
5763
ChainCommands::DeployPaymaster(args) => deploy_paymaster::run(args, shell).await,
5864
ChainCommands::UpdateTokenMultiplierSetter(args) => {

0 commit comments

Comments
 (0)