Skip to content

Commit

Permalink
feat(zktoolbox): added checking the contract owner in set-attester-co…
Browse files Browse the repository at this point in the history
…mmittee command (#3061)

This way we obtain a human readable error in case wrong account is used
to update the attester committee.
  • Loading branch information
pompon0 authored Oct 11, 2024
1 parent 5d339b4 commit 9b0a606
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
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
40 changes: 28 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 @@ -3,15 +3,15 @@ use std::{borrow::Borrow, collections::HashMap, path::PathBuf, sync::Arc};
/// Consensus registry contract operations.
/// Includes code duplicated from `zksync_node_consensus::registry::abi`.
use anyhow::Context as _;
use common::logger;
use common::{logger, wallets::Wallet};
use config::EcosystemConfig;
use conv::*;
use ethers::{
abi::Detokenize,
contract::{FunctionCall, Multicall},
middleware::{Middleware, NonceManagerMiddleware, SignerMiddleware},
providers::{Http, JsonRpcClient, PendingTransaction, Provider, RawCall as _},
signers::Signer as _,
signers::{LocalWallet, Signer as _},
types::{Address, BlockId, H256},
};
use xshell::Shell;
Expand Down Expand Up @@ -174,19 +174,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 +280,25 @@ 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 signer = self.signer(
governor
.private_key
.clone()
.context(messages::MSG_GOVERNOR_PRIVATE_KEY_NOT_SET)?,
)?;
let consensus_registry = self
.consensus_registry(governor.clone())
.consensus_registry(signer.clone())
.context("consensus_registry()")?;
let mut multicall = self.multicall(governor.clone()).context("multicall()")?;
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

0 comments on commit 9b0a606

Please sign in to comment.