Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(zktoolbox): added checking the contract owner in set-attester-committee command #3061

Merged
merged 12 commits into from
Oct 11, 2024
2 changes: 1 addition & 1 deletion core/lib/protobuf_config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub fn read_optional_repr<P: ProtoRepr>(field: &Option<P>) -> Option<P::Type> {
.transpose()
// This error will printed, only if the config partially filled, allows to debug config issues easier
.map_err(|err| {
tracing::error!("Failed to serialize config: {err}");
tracing::error!("Failed to parse config: {err:#}");
err
})
.ok()
Expand Down
31 changes: 19 additions & 12 deletions zk_toolbox/crates/zk_inception/src/commands/consensus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc};
/// Includes code duplicated from `zksync_node_consensus::registry::abi`.
use anyhow::Context as _;
use common::logger;
use common::wallets::Wallet;
use config::EcosystemConfig;
use conv::*;
use ethers::{
signers::LocalWallet,
abi::Detokenize,
contract::{FunctionCall, Multicall},
middleware::{Middleware, NonceManagerMiddleware, SignerMiddleware},
Expand Down Expand Up @@ -174,19 +176,20 @@ impl Setup {
)?)
}

fn governor(&self) -> anyhow::Result<Arc<impl Middleware>> {
let governor = self
fn governor(&self) -> anyhow::Result<Wallet> {
Ok(self
.chain
.get_wallets_config()
.context("get_wallets_config()")?
.governor
.private_key
.context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?;
let governor = governor.with_chain_id(self.genesis.l2_chain_id.as_u64());
.governor)
}

fn signer(&self, wallet: LocalWallet) -> anyhow::Result<Arc<impl Middleware>> {
let wallet = wallet.with_chain_id(self.genesis.l2_chain_id.as_u64());
let provider = self.provider().context("provider()")?;
let signer = SignerMiddleware::new(provider, governor.clone());
let signer = SignerMiddleware::new(provider, wallet.clone());
// Allows us to send next transaction without waiting for the previous to complete.
let signer = NonceManagerMiddleware::new(signer, governor.address());
let signer = NonceManagerMiddleware::new(signer, wallet.address());
Ok(Arc::new(signer))
}

Expand Down Expand Up @@ -279,10 +282,14 @@ impl Setup {
let provider = self.provider().context("provider()")?;
let block_id = self.last_block(&provider).await.context("last_block()")?;
let governor = self.governor().context("governor()")?;
let consensus_registry = self
.consensus_registry(governor.clone())
.context("consensus_registry()")?;
let mut multicall = self.multicall(governor.clone()).context("multicall()")?;
let signer = self.signer(governor.private_key.clone().context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?)?;
let consensus_registry = self.consensus_registry(signer.clone()).context("consensus_registry()")?;
let mut multicall = self.multicall(signer).context("multicall()")?;

let owner = consensus_registry.owner().call().await.context("owner()")?;
if owner != governor.address {
anyhow::bail!("governor ({:#x}) is different than the consensus registry owner ({:#x})", governor.address, owner);
}

// Fetch contract state.
let n: usize = consensus_registry
Expand Down
Loading