Skip to content

Commit

Permalink
Make correct chain admin registartion
Browse files Browse the repository at this point in the history
Signed-off-by: Danil <[email protected]>
  • Loading branch information
Deniallugo committed Nov 14, 2024
1 parent 2429e60 commit f09cc85
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 51 deletions.
18 changes: 6 additions & 12 deletions zkstack_cli/crates/common/src/ethereum/chain_registrar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};

Expand All @@ -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)
]"
);

Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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<ChainRegistrationResult> {
let client = Arc::new(create_ethers_client(
main_wallet.private_key.unwrap(),
l1_rpc,
Some(l1_chain_id),
)?);

let client = Arc::new(Provider::<Http>::try_from(l1_rpc)?);
let block = client.get_block_number().await?;
let contract = ChainRegistar::new(chain_registrar, client);
let events = contract
Expand All @@ -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
Expand Down
19 changes: 6 additions & 13 deletions zkstack_cli/crates/zkstack/src/commands/chain/init/configs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
chain::{
args::init::configs::{InitConfigsArgs, InitConfigsArgsFinal},
genesis,
init::fill_contracts_config_from_l1,
},
portal::update_portal_config,
},
Expand All @@ -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(())
}

Expand Down
69 changes: 51 additions & 18 deletions zkstack_cli/crates/zkstack/src/commands/chain/init/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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<ContractsConfig> {
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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
broadcast: bool,
Expand All @@ -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(&register_chain_output);
Ok(())
}

0 comments on commit f09cc85

Please sign in to comment.