Skip to content

Commit

Permalink
chore: Enforce uniform import structure (matter-labs#617)
Browse files Browse the repository at this point in the history
## What ❔

...using `zk fmt` command by suppling relevant command-line args to
rustfmt. These args work on stable Rust (at least for now) despite being
unstable.

## Why ❔

More structured imports are easier to read.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
slowli authored Dec 7, 2023
1 parent 43c0964 commit 53a6bcf
Show file tree
Hide file tree
Showing 640 changed files with 4,414 additions and 4,176 deletions.
8 changes: 3 additions & 5 deletions core/bin/block_reverter/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use anyhow::Context as _;
use clap::{Parser, Subcommand};
use tokio::io::{self, AsyncReadExt};

use zksync_config::{ContractsConfig, DBConfig, ETHClientConfig, ETHSenderConfig, PostgresConfig};
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
use zksync_types::{L1BatchNumber, U256};

use zksync_core::block_reverter::{
BlockReverter, BlockReverterEthConfig, BlockReverterFlags, L1ExecutedBatchesRevert,
};
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
use zksync_types::{L1BatchNumber, U256};

#[derive(Debug, Parser)]
#[command(author = "Matter Labs", version, about = "Block revert utility", long_about = None)]
Expand Down
5 changes: 2 additions & 3 deletions core/bin/contract-verifier/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use std::cell::RefCell;

use anyhow::Context as _;
use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use prometheus_exporter::PrometheusExporterConfig;
use tokio::sync::watch;
use zksync_config::{configs::PrometheusConfig, ApiConfig, ContractVerifierConfig, PostgresConfig};
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
use zksync_queued_job_processor::JobProcessor;
use zksync_utils::wait_for_tasks::wait_for_tasks;

use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use tokio::sync::watch;

use crate::verifier::ContractVerifier;

pub mod error;
Expand Down
19 changes: 10 additions & 9 deletions core/bin/contract-verifier/src/verifier.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use std::collections::HashMap;
use std::env;
use std::path::Path;
use std::time::{Duration, Instant};
use std::{
collections::HashMap,
env,
path::Path,
time::{Duration, Instant},
};

use anyhow::Context as _;
use chrono::Utc;
use ethabi::{Contract, Token};
use lazy_static::lazy_static;
use regex::Regex;
use tokio::time;

use zksync_config::ContractVerifierConfig;
use zksync_dal::{ConnectionPool, StorageProcessor};
use zksync_env_config::FromEnv;
Expand All @@ -22,11 +23,11 @@ use zksync_types::{
Address,
};

use crate::error::ContractVerifierError;
use crate::zksolc_utils::{
Optimizer, Settings, Source, StandardJson, ZkSolc, ZkSolcInput, ZkSolcOutput,
use crate::{
error::ContractVerifierError,
zksolc_utils::{Optimizer, Settings, Source, StandardJson, ZkSolc, ZkSolcInput, ZkSolcOutput},
zkvyper_utils::{ZkVyper, ZkVyperInput},
};
use crate::zkvyper_utils::{ZkVyper, ZkVyperInput};

lazy_static! {
static ref DEPLOYER_CONTRACT: Contract = zksync_contracts::deployer_contract();
Expand Down
6 changes: 2 additions & 4 deletions core/bin/contract-verifier/src/zksolc_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::{collections::HashMap, io::Write, path::PathBuf, process::Stdio};

use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::io::Write;
use std::path::PathBuf;
use std::process::Stdio;

use crate::error::ContractVerifierError;

Expand Down
6 changes: 1 addition & 5 deletions core/bin/contract-verifier/src/zkvyper_utils.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::collections::HashMap;
use std::fs::File;
use std::io::Write;
use std::path::PathBuf;
use std::process::Stdio;
use std::{collections::HashMap, fs::File, io::Write, path::PathBuf, process::Stdio};

use crate::error::ContractVerifierError;

Expand Down
8 changes: 4 additions & 4 deletions core/bin/external_node/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use std::{env, time::Duration};

use anyhow::Context;
use serde::Deserialize;
use std::{env, time::Duration};
use url::Url;

use zksync_basic_types::{Address, L1ChainId, L2ChainId, MiniblockNumber};
use zksync_core::api_server::{
tx_sender::TxSenderConfig, web3::state::InternalApiConfig, web3::Namespace,
tx_sender::TxSenderConfig,
web3::{state::InternalApiConfig, Namespace},
};
use zksync_types::api::BridgeAddresses;

use zksync_web3_decl::{
jsonrpsee::http_client::{HttpClient, HttpClientBuilder},
namespaces::{EnNamespaceClient, EthNamespaceClient, ZksNamespaceClient},
Expand Down
7 changes: 3 additions & 4 deletions core/bin/external_node/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use anyhow::Context;
use clap::Parser;
use tokio::{sync::watch, task, time::sleep};

use std::{sync::Arc, time::Duration};

use anyhow::Context;
use clap::Parser;
use futures::{future::FusedFuture, FutureExt};
use prometheus_exporter::PrometheusExporterConfig;
use tokio::{sync::watch, task, time::sleep};
use zksync_basic_types::{Address, L2ChainId};
use zksync_core::{
api_server::{
Expand Down
5 changes: 2 additions & 3 deletions core/bin/merkle_tree_consistency_checker/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Context as _;
use clap::Parser;

use std::{path::Path, time::Instant};

use anyhow::Context as _;
use clap::Parser;
use zksync_config::DBConfig;
use zksync_env_config::FromEnv;
use zksync_merkle_tree::domain::ZkSyncTree;
Expand Down
4 changes: 2 additions & 2 deletions core/bin/rocksdb_util/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use anyhow::Context as _;
use clap::{Parser, Subcommand};

use zksync_config::DBConfig;
use zksync_env_config::FromEnv;
use zksync_storage::rocksdb::{
Expand Down Expand Up @@ -57,9 +56,10 @@ fn main() -> anyhow::Result<()> {

#[cfg(test)]
mod tests {
use super::*;
use tempfile::TempDir;

use super::*;

#[test]
fn backup_restore_workflow() {
let backup_dir = TempDir::new().expect("failed to get temporary directory for RocksDB");
Expand Down
1 change: 0 additions & 1 deletion core/bin/storage_logs_dedup_migration/src/consistency.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use clap::Parser;

use zksync_config::PostgresConfig;
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
Expand Down
1 change: 0 additions & 1 deletion core/bin/storage_logs_dedup_migration/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::hash_map::{Entry, HashMap};

use clap::Parser;

use zksync_config::PostgresConfig;
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
Expand Down
8 changes: 4 additions & 4 deletions core/bin/system-constants-generator/src/intrinsic_costs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//! as well as contracts/SystemConfig.json
//!

use multivm::vm_latest::constants::BOOTLOADER_TX_ENCODING_SPACE;
use zksync_types::{ethabi::Address, IntrinsicSystemGasConstants, U256};

use crate::utils::{
execute_internal_transfer_test, execute_user_txs_in_test_gas_vm, get_l1_tx, get_l1_txs,
get_l2_txs,
get_l2_txs, metrics_from_txs, TransactionGenerator,
};
use crate::utils::{metrics_from_txs, TransactionGenerator};
use multivm::vm_latest::constants::BOOTLOADER_TX_ENCODING_SPACE;
use zksync_types::{ethabi::Address, IntrinsicSystemGasConstants, U256};

#[derive(Debug, Clone, Copy, PartialEq)]
pub(crate) struct VmSpentResourcesResult {
Expand Down
21 changes: 11 additions & 10 deletions core/bin/system-constants-generator/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
use std::fs;

use codegen::{Block, Scope};
use multivm::vm_latest::constants::{
BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_L1_GAS, BOOTLOADER_TX_ENCODING_SPACE, MAX_PUBDATA_PER_BLOCK,
};
use serde::{Deserialize, Serialize};
use zksync_types::{
zkevm_test_harness::zk_evm::zkevm_opcode_defs::{
circuit_prices::{
ECRECOVER_CIRCUIT_COST_IN_ERGS, KECCAK256_CIRCUIT_COST_IN_ERGS,
SHA256_CIRCUIT_COST_IN_ERGS,
},
system_params::MAX_TX_ERGS_LIMIT,
},
IntrinsicSystemGasConstants, GUARANTEED_PUBDATA_IN_TX, L1_GAS_PER_PUBDATA_BYTE,
MAX_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, MAX_TXS_IN_BLOCK,
};

mod intrinsic_costs;
mod utils;

use codegen::Block;
use codegen::Scope;
use multivm::vm_latest::constants::{
BLOCK_OVERHEAD_GAS, BLOCK_OVERHEAD_L1_GAS, BOOTLOADER_TX_ENCODING_SPACE, MAX_PUBDATA_PER_BLOCK,
};
use zksync_types::zkevm_test_harness::zk_evm::zkevm_opcode_defs::circuit_prices::{
ECRECOVER_CIRCUIT_COST_IN_ERGS, KECCAK256_CIRCUIT_COST_IN_ERGS, SHA256_CIRCUIT_COST_IN_ERGS,
};
use zksync_types::zkevm_test_harness::zk_evm::zkevm_opcode_defs::system_params::MAX_TX_ERGS_LIMIT;

// Params needed for L1 contracts
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
Expand Down
25 changes: 13 additions & 12 deletions core/bin/system-constants-generator/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use once_cell::sync::Lazy;
use std::cell::RefCell;
use std::rc::Rc;

use multivm::interface::{
dyn_tracers::vm_1_4_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface,
};
use multivm::vm_latest::{
constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE},
BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, Vm, VmTracer,
ZkSyncVmState,
use std::{cell::RefCell, rc::Rc};

use multivm::{
interface::{
dyn_tracers::vm_1_4_0::DynTracer, tracer::VmExecutionStopReason, L1BatchEnv, L2BlockEnv,
SystemEnv, TxExecutionMode, VmExecutionMode, VmInterface,
},
vm_latest::{
constants::{BLOCK_GAS_LIMIT, BOOTLOADER_HEAP_PAGE},
BootloaderState, HistoryEnabled, HistoryMode, SimpleMemory, ToTracerPointer, Vm, VmTracer,
ZkSyncVmState,
},
};
use once_cell::sync::Lazy;
use zksync_contracts::{
load_sys_contract, read_bootloader_code, read_sys_contract_bytecode, read_zbin_bytecode,
BaseSystemContracts, ContractLanguage, SystemContractCode,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{fs::File, io::BufWriter};

use bincode::serialize_into;
use std::fs::File;
use std::io::BufWriter;
use structopt::StructOpt;
use zksync_verification_key_server::get_vk_for_circuit_type;

Expand Down
44 changes: 22 additions & 22 deletions core/bin/verification_key_generator_and_server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
use ff::to_hex;
use once_cell::sync::Lazy;
use std::collections::HashMap;
use std::path::Path;
use std::str::FromStr;
use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit;
use zksync_types::zkevm_test_harness::bellman::bn256::Bn256;
use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::setup::VerificationKey;
use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle;
use std::{collections::HashMap, path::Path, str::FromStr};

use ff::to_hex;
use itertools::Itertools;
use once_cell::sync::Lazy;
use structopt::lazy_static::lazy_static;
use zksync_types::circuit::SCHEDULER_CIRCUIT_INDEX;
use zksync_types::circuit::{
GEOMETRY_CONFIG, LEAF_CIRCUIT_INDEX, LEAF_SPLITTING_FACTOR, NODE_CIRCUIT_INDEX,
NODE_SPLITTING_FACTOR, SCHEDULER_UPPER_BOUND,
};
use zksync_types::protocol_version::{L1VerifierConfig, VerifierParams};
use zksync_types::vk_transform::generate_vk_commitment;
use zksync_types::zkevm_test_harness::witness;
use zksync_types::zkevm_test_harness::witness::full_block_artifact::BlockBasicCircuits;
use zksync_types::zkevm_test_harness::witness::recursive_aggregation::{
erase_vk_type, padding_aggregations,
use zksync_types::{
circuit::{
GEOMETRY_CONFIG, LEAF_CIRCUIT_INDEX, LEAF_SPLITTING_FACTOR, NODE_CIRCUIT_INDEX,
NODE_SPLITTING_FACTOR, SCHEDULER_CIRCUIT_INDEX, SCHEDULER_UPPER_BOUND,
},
protocol_version::{L1VerifierConfig, VerifierParams},
vk_transform::generate_vk_commitment,
zkevm_test_harness::{
abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit,
bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey},
witness,
witness::{
full_block_artifact::BlockBasicCircuits,
oracle::VmWitnessOracle,
recursive_aggregation::{erase_vk_type, padding_aggregations},
vk_set_generator::circuits_for_vk_generation,
},
},
H256,
};
use zksync_types::zkevm_test_harness::witness::vk_set_generator::circuits_for_vk_generation;
use zksync_types::H256;

#[cfg(test)]
mod tests;
Expand Down
15 changes: 9 additions & 6 deletions core/bin/verification_key_generator_and_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
use std::collections::HashSet;
use std::env;
use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit;
use zksync_types::zkevm_test_harness::bellman::bn256::Bn256;
use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::cs::PlonkCsWidth4WithNextStepAndCustomGatesParams;
use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle;
use std::{collections::HashSet, env};

use zksync_types::zkevm_test_harness::{
abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit,
bellman::{
bn256::Bn256, plonk::better_better_cs::cs::PlonkCsWidth4WithNextStepAndCustomGatesParams,
},
witness::oracle::VmWitnessOracle,
};
use zksync_verification_key_server::{get_circuits_for_vk, save_vk_for_circuit_type};

/// Creates verification keys for the given circuit.
Expand Down
14 changes: 8 additions & 6 deletions core/bin/verification_key_generator_and_server/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use crate::{get_vk_for_circuit_type, get_vks_for_basic_circuits, get_vks_for_commitment};
use std::collections::HashMap;

use itertools::Itertools;
use serde_json::Value;
use std::collections::HashMap;
use zksync_types::zkevm_test_harness::abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit;
use zksync_types::zkevm_test_harness::bellman::bn256::Bn256;
use zksync_types::zkevm_test_harness::bellman::plonk::better_better_cs::setup::VerificationKey;
use zksync_types::zkevm_test_harness::{
abstract_zksync_circuit::concrete_circuits::ZkSyncCircuit,
bellman::{bn256::Bn256, plonk::better_better_cs::setup::VerificationKey},
witness::oracle::VmWitnessOracle,
};

use zksync_types::zkevm_test_harness::witness::oracle::VmWitnessOracle;
use crate::{get_vk_for_circuit_type, get_vks_for_basic_circuits, get_vks_for_commitment};

#[test]
fn test_get_vk_for_circuit_type() {
Expand Down
1 change: 1 addition & 0 deletions core/bin/verified_sources_fetcher/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io::Write;

use zksync_config::PostgresConfig;
use zksync_dal::ConnectionPool;
use zksync_env_config::FromEnv;
Expand Down
11 changes: 4 additions & 7 deletions core/bin/zksync_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use anyhow::Context as _;
use clap::Parser;

use std::{str::FromStr, time::Duration};

use anyhow::Context as _;
use clap::Parser;
use zksync_config::{
configs::{
api::{HealthCheckConfig, MerkleTreeApiConfig, Web3JsonRpcConfig},
Expand All @@ -18,11 +17,9 @@ use zksync_config::{
ApiConfig, ContractsConfig, DBConfig, ETHClientConfig, ETHSenderConfig, ETHWatchConfig,
FetcherConfig, GasAdjusterConfig, ObjectStoreConfig, PostgresConfig, ProverConfigs,
};

use zksync_core::temp_config_store::TempConfigStore;
use zksync_core::{
genesis_init, initialize_components, is_genesis_needed, setup_sigint_handler, Component,
Components,
genesis_init, initialize_components, is_genesis_needed, setup_sigint_handler,
temp_config_store::TempConfigStore, Component, Components,
};
use zksync_env_config::FromEnv;
use zksync_storage::RocksDB;
Expand Down
Loading

0 comments on commit 53a6bcf

Please sign in to comment.