From f09cc852482227ba944890a88bdd9667505c9e73 Mon Sep 17 00:00:00 2001 From: Danil Date: Thu, 14 Nov 2024 22:13:13 +0700 Subject: [PATCH] Make correct chain admin registartion Signed-off-by: Danil --- contracts | 2 +- .../common/src/ethereum/chain_registrar.rs | 18 ++--- .../src/commands/chain/init/configs.rs | 19 ++--- .../zkstack/src/commands/chain/init/mod.rs | 69 ++++++++++++++----- .../src/commands/chain/register_chain.rs | 8 +-- 5 files changed, 65 insertions(+), 51 deletions(-) diff --git a/contracts b/contracts index 76100826a511..91bd952da3bb 160000 --- a/contracts +++ b/contracts @@ -1 +1 @@ -Subproject commit 76100826a511f64340f01fbfbf5ceee5646bbdff +Subproject commit 91bd952da3bb5760421adbf2a529fb8dd3b5527c diff --git a/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs b/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs index 2605ae8bc2b8..ff25f6eb9635 100644 --- a/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs +++ b/zkstack_cli/crates/common/src/ethereum/chain_registrar.rs @@ -5,7 +5,7 @@ use ethers::{ contract::abigen, core::k256::U256, middleware::{Middleware, MiddlewareBuilder}, - prelude::H160, + prelude::{Http, Provider, H160}, types::{BlockNumber, Filter, H256, U64}, }; @@ -16,7 +16,7 @@ abigen!( event NewChainDeployed(uint256 indexed chainId, address author, address diamondProxy, address chainAdmin) event NewChainRegistrationProposal(uint256 indexed chainId, address author, bytes32 key) event SharedBridgeRegistered(uint256 indexed chainId, address l2Address) - function proposeChainRegistration(uint256 chainId, uint8 pubdataPricingMode, address commitOperator,address operator,address governor,address tokenAddress,address tokenMultiplierSetter,uint128 gasPriceMultiplierNominator,uint128 gasPriceMultiplierDenominator) + function proposeChainRegistration(uint256 chainId, uint8 pubdataPricingMode, address blobOperator,address operator,address governor,address tokenAddress,address tokenMultiplierSetter,uint128 gasPriceMultiplierNominator,uint128 gasPriceMultiplierDenominator) ]" ); @@ -26,7 +26,7 @@ pub async fn propose_registration( l1_rpc: String, l1_chain_id: u64, l2_chain_id: u64, - commit_operator: Address, + blob_operator: Address, operator: Address, governor: Address, token_address: Address, @@ -44,7 +44,7 @@ pub async fn propose_registration( l2_chain_id.into(), // TODO pass the correct value 0, - commit_operator, + blob_operator, operator, governor, token_address, @@ -109,17 +109,11 @@ pub struct ChainRegistrationResult { pub async fn load_contracts_for_chain( chain_registrar: Address, - main_wallet: Wallet, l1_rpc: String, l1_chain_id: u64, l2_chain_id: u64, ) -> anyhow::Result { - let client = Arc::new(create_ethers_client( - main_wallet.private_key.unwrap(), - l1_rpc, - Some(l1_chain_id), - )?); - + let client = Arc::new(Provider::::try_from(l1_rpc)?); let block = client.get_block_number().await?; let contract = ChainRegistar::new(chain_registrar, client); let events = contract @@ -129,7 +123,7 @@ pub async fn load_contracts_for_chain( .topic1(H256::from_low_u64_be(l2_chain_id)); let result = events.query().await?; let mut builder = ChainRegistrationResultBuilder::new(); - for event in result { + for event in &result { match event { ChainRegistarEvents::NewChainDeployedFilter(event) => { builder = builder diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs index f5b7dd247193..26146bbbb453 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs @@ -12,6 +12,7 @@ use crate::{ chain::{ args::init::configs::{InitConfigsArgs, InitConfigsArgsFinal}, genesis, + init::fill_contracts_config_from_l1, }, portal::update_portal_config, }, @@ -33,24 +34,16 @@ pub async fn run(args: InitConfigsArgs, shell: &Shell) -> anyhow::Result<()> { let args = args.fill_values_with_prompt(&chain_config); let mut contracts = init_configs(&args, shell, &ecosystem_config, &chain_config).await?; - let wallets = chain_config.get_wallets_config()?; - let secrets = chain_config.get_secrets_config()?; let genesis = chain_config.get_genesis_config()?; - let res = ethereum::chain_registrar::load_contracts_for_chain( - contracts.ecosystem_contracts.chain_registrar, - wallets.governor, - secrets.l1.unwrap().l1_rpc_url.expose_str().to_string(), - genesis.l1_chain_id.0, - genesis.l2_chain_id.as_u64(), + contracts = fill_contracts_config_from_l1( + contracts, + genesis.l1_chain_id, + genesis.l2_chain_id, + args.l1_rpc_url, ) .await?; - contracts.l1.chain_admin_addr = res.chain_admin; - contracts.l1.diamond_proxy_addr = res.diamond_proxy; - contracts.bridges.shared.l2_address = Some(res.l2_shared_bridge); - contracts.bridges.erc20.l2_address = Some(res.l2_shared_bridge); contracts.save_with_base_path(shell, &chain_config.configs)?; logger::outro(MSG_CHAIN_CONFIGS_INITIALIZED); - Ok(()) } diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs index 6dbf646d9c6a..6df93196bcf8 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs @@ -1,9 +1,12 @@ use anyhow::Context; use clap::{command, Parser, Subcommand}; -use common::{git, logger, spinner::Spinner}; -use config::{traits::SaveConfigWithBasePath, ChainConfig, EcosystemConfig}; +use common::{ethereum, git, logger, spinner::Spinner, wallets::Wallet}; +use config::{ + traits::SaveConfigWithBasePath, ChainConfig, ContractsConfig, EcosystemConfig, WalletsConfig, +}; use types::BaseToken; use xshell::Shell; +use zksync_basic_types::{L1ChainId, L2ChainId}; use crate::{ accept_ownership::accept_admin, @@ -95,27 +98,12 @@ pub async fn init( init_args.forge_args.clone(), ecosystem_config, chain_config, - &mut contracts_config, + &contracts_config, init_args.l1_rpc_url.clone(), None, true, ) .await?; - contracts_config.save_with_base_path(shell, &chain_config.configs)?; - spinner.finish(); - - // Accept ownership for DiamondProxy (run by L2 Governor) - let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); - accept_admin( - shell, - ecosystem_config, - contracts_config.l1.chain_admin_addr, - &chain_config.get_wallets_config()?.governor, - contracts_config.l1.diamond_proxy_addr, - &init_args.forge_args.clone(), - init_args.l1_rpc_url.clone(), - ) - .await?; spinner.finish(); // Set token multiplier setter address (run by L2 Governor) @@ -150,6 +138,31 @@ pub async fn init( .await?; contracts_config.save_with_base_path(shell, &chain_config.configs)?; + let genesis_config = chain_config.get_genesis_config()?; + + contracts_config = fill_contracts_config_from_l1( + contracts_config, + genesis_config.l1_chain_id, + genesis_config.l2_chain_id, + init_args.l1_rpc_url.clone(), + ) + .await?; + contracts_config.save_with_base_path(shell, &chain_config.configs)?; + + // Accept ownership for DiamondProxy (run by L2 Governor) + let spinner = Spinner::new(MSG_ACCEPTING_ADMIN_SPINNER); + accept_admin( + shell, + ecosystem_config, + contracts_config.l1.chain_admin_addr, + &chain_config.get_wallets_config()?.governor, + contracts_config.l1.diamond_proxy_addr, + &init_args.forge_args.clone(), + init_args.l1_rpc_url.clone(), + ) + .await?; + spinner.finish(); + // Setup legacy bridge - shouldn't be used for new chains (run by L1 Governor) if let Some(true) = chain_config.legacy_bridge { setup_legacy_bridge( @@ -184,3 +197,23 @@ pub async fn init( Ok(()) } + +async fn fill_contracts_config_from_l1( + mut contracts: ContractsConfig, + l1_chain_id: L1ChainId, + l2_chain_id: L2ChainId, + l1_rpc_url: String, +) -> anyhow::Result { + let res = ethereum::chain_registrar::load_contracts_for_chain( + contracts.ecosystem_contracts.chain_registrar, + l1_rpc_url, + l1_chain_id.0, + l2_chain_id.as_u64(), + ) + .await?; + contracts.l1.chain_admin_addr = res.chain_admin; + contracts.l1.diamond_proxy_addr = res.diamond_proxy; + contracts.bridges.shared.l2_address = Some(res.l2_shared_bridge); + contracts.bridges.erc20.l2_address = Some(res.l2_shared_bridge); + Ok(contracts) +} diff --git a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs index 65ee05a1ea5f..f6688ec32ca8 100644 --- a/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs +++ b/zkstack_cli/crates/zkstack/src/commands/chain/register_chain.rs @@ -59,7 +59,7 @@ pub async fn register_chain( forge_args: ForgeScriptArgs, config: &EcosystemConfig, chain_config: &ChainConfig, - contracts: &mut ContractsConfig, + contracts: &ContractsConfig, l1_rpc_url: String, sender: Option, broadcast: bool, @@ -86,11 +86,5 @@ pub async fn register_chain( } forge.run(shell)?; - - let register_chain_output = RegisterChainOutput::read( - shell, - REGISTER_CHAIN_SCRIPT_PARAMS.output(&chain_config.link_to_code), - )?; - contracts.set_chain_contracts(®ister_chain_output); Ok(()) }