Skip to content

Commit

Permalink
revert(env): Remove ZKSYNC_HOME env var from server (#1713)
Browse files Browse the repository at this point in the history
Reverts #1644
  • Loading branch information
RomanBrodetski committed Apr 17, 2024
1 parent 8ab2488 commit aed23e1
Show file tree
Hide file tree
Showing 18 changed files with 144 additions and 196 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 8 additions & 7 deletions core/bin/contract-verifier/src/main.rs
Expand Up @@ -3,7 +3,6 @@ use std::{cell::RefCell, time::Duration};
use anyhow::Context as _;
use futures::{channel::mpsc, executor::block_on, SinkExt, StreamExt};
use prometheus_exporter::PrometheusExporterConfig;
use structopt::StructOpt;
use tokio::sync::watch;
use zksync_config::{
configs::{ObservabilityConfig, PrometheusConfig},
Expand All @@ -12,7 +11,7 @@ use zksync_config::{
use zksync_dal::{ConnectionPool, Core, CoreDal};
use zksync_env_config::FromEnv;
use zksync_queued_job_processor::JobProcessor;
use zksync_utils::{wait_for_tasks::ManagedTasks, workspace_dir_or_current_dir};
use zksync_utils::wait_for_tasks::ManagedTasks;

use crate::verifier::ContractVerifier;

Expand All @@ -25,9 +24,9 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
let mut storage = connection_pool.connection().await.unwrap();
let mut transaction = storage.start_transaction().await.unwrap();

let zksync_home = workspace_dir_or_current_dir();
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());

let zksolc_path = zksync_home.join("etc/zksolc-bin/");
let zksolc_path = format!("{}/etc/zksolc-bin/", zksync_home);
let zksolc_versions: Vec<String> = std::fs::read_dir(zksolc_path)
.unwrap()
.filter_map(|file| {
Expand All @@ -48,7 +47,7 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
.await
.unwrap();

let solc_path = zksync_home.join("etc/solc-bin/");
let solc_path = format!("{}/etc/solc-bin/", zksync_home);
let solc_versions: Vec<String> = std::fs::read_dir(solc_path)
.unwrap()
.filter_map(|file| {
Expand All @@ -69,7 +68,7 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
.await
.unwrap();

let zkvyper_path = zksync_home.join("etc/zkvyper-bin/");
let zkvyper_path = format!("{}/etc/zkvyper-bin/", zksync_home);
let zkvyper_versions: Vec<String> = std::fs::read_dir(zkvyper_path)
.unwrap()
.filter_map(|file| {
Expand All @@ -90,7 +89,7 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
.await
.unwrap();

let vyper_path = zksync_home.join("etc/vyper-bin/");
let vyper_path = format!("{}/etc/vyper-bin/", zksync_home);
let vyper_versions: Vec<String> = std::fs::read_dir(vyper_path)
.unwrap()
.filter_map(|file| {
Expand All @@ -115,6 +114,8 @@ async fn update_compiler_versions(connection_pool: &ConnectionPool<Core>) {
transaction.commit().await.unwrap();
}

use structopt::StructOpt;

#[derive(StructOpt)]
#[structopt(name = "zkSync contract code verifier", author = "Matter Labs")]
struct Opt {
Expand Down
16 changes: 7 additions & 9 deletions core/bin/contract-verifier/src/verifier.rs
@@ -1,5 +1,6 @@
use std::{
collections::HashMap,
env,
path::Path,
time::{Duration, Instant},
};
Expand All @@ -21,7 +22,6 @@ use zksync_types::{
},
Address,
};
use zksync_utils::workspace_dir_or_current_dir;

use crate::{
error::ContractVerifierError,
Expand All @@ -33,10 +33,6 @@ lazy_static! {
static ref DEPLOYER_CONTRACT: Contract = zksync_contracts::deployer_contract();
}

fn home_path() -> &'static Path {
workspace_dir_or_current_dir()
}

#[derive(Debug)]
enum ConstructorArgs {
Check(Vec<u8>),
Expand Down Expand Up @@ -123,7 +119,8 @@ impl ContractVerifier {
};
let input = Self::build_zksolc_input(request.clone(), file_name.clone())?;

let zksolc_path = Path::new(&home_path())
let zksync_home = env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let zksolc_path = Path::new(&zksync_home)
.join("etc")
.join("zksolc-bin")
.join(request.req.compiler_versions.zk_compiler_version())
Expand All @@ -135,7 +132,7 @@ impl ContractVerifier {
));
}

let solc_path = Path::new(&home_path())
let solc_path = Path::new(&zksync_home)
.join("etc")
.join("solc-bin")
.join(request.req.compiler_versions.compiler_version())
Expand Down Expand Up @@ -221,7 +218,8 @@ impl ContractVerifier {
};
let input = Self::build_zkvyper_input(request.clone())?;

let zkvyper_path = Path::new(&home_path())
let zksync_home = env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let zkvyper_path = Path::new(&zksync_home)
.join("etc")
.join("zkvyper-bin")
.join(request.req.compiler_versions.zk_compiler_version())
Expand All @@ -233,7 +231,7 @@ impl ContractVerifier {
));
}

let vyper_path = Path::new(&home_path())
let vyper_path = Path::new(&zksync_home)
.join("etc")
.join("vyper-bin")
.join(request.req.compiler_versions.compiler_version())
Expand Down
5 changes: 2 additions & 3 deletions core/bin/system-constants-generator/src/main.rs
Expand Up @@ -17,7 +17,6 @@ use zksync_types::{
IntrinsicSystemGasConstants, ProtocolVersionId, GUARANTEED_PUBDATA_IN_TX,
L1_GAS_PER_PUBDATA_BYTE, MAX_NEW_FACTORY_DEPS, REQUIRED_L1_TO_L2_GAS_PER_PUBDATA_BYTE,
};
use zksync_utils::workspace_dir_or_current_dir;

// For configs we will use the default value of `800_000` to represent the rough amount of L1 gas
// needed to cover the batch expenses.
Expand Down Expand Up @@ -210,8 +209,8 @@ fn generate_rust_fee_constants(intrinsic_gas_constants: &IntrinsicSystemGasConst
}

fn save_file(path_in_repo: &str, content: String) {
let zksync_home = workspace_dir_or_current_dir();
let fee_constants_path = zksync_home.join(path_in_repo);
let zksync_home = std::env::var("ZKSYNC_HOME").expect("No ZKSYNC_HOME env var");
let fee_constants_path = format!("{zksync_home}/{path_in_repo}");

fs::write(fee_constants_path, content)
.unwrap_or_else(|_| panic!("Failed to write to {}", path_in_repo));
Expand Down
39 changes: 20 additions & 19 deletions core/lib/contracts/src/lib.rs
@@ -1,6 +1,6 @@
//! Set of utility functions to read contracts both in Yul and Sol format.
//!
//! Careful: some of the methods are reading the contracts based on the workspace environment variable.
//! Careful: some of the methods are reading the contracts based on the ZKSYNC_HOME environment variable.

#![allow(clippy::derive_partial_eq_without_eq)]

Expand All @@ -15,7 +15,7 @@ use ethabi::{
};
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words, workspace_dir_or_current_dir};
use zksync_utils::{bytecode::hash_bytecode, bytes_to_be_words};

pub mod test_contracts;

Expand All @@ -40,12 +40,8 @@ const LOADNEXT_CONTRACT_FILE: &str =
const LOADNEXT_SIMPLE_CONTRACT_FILE: &str =
"etc/contracts-test-data/artifacts-zk/contracts/loadnext/loadnext_contract.sol/Foo.json";

fn home_path() -> &'static Path {
workspace_dir_or_current_dir()
}

fn read_file_to_json_value(path: impl AsRef<Path> + std::fmt::Debug) -> serde_json::Value {
let zksync_home = home_path();
fn read_file_to_json_value(path: impl AsRef<Path>) -> serde_json::Value {
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let path = Path::new(&zksync_home).join(path);
serde_json::from_reader(
File::open(&path).unwrap_or_else(|e| panic!("Failed to open file {:?}: {}", path, e)),
Expand All @@ -54,7 +50,7 @@ fn read_file_to_json_value(path: impl AsRef<Path> + std::fmt::Debug) -> serde_js
}

fn load_contract_if_present<P: AsRef<Path> + std::fmt::Debug>(path: P) -> Option<Contract> {
let zksync_home = home_path();
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let path = Path::new(&zksync_home).join(path);
path.exists().then(|| {
serde_json::from_value(read_file_to_json_value(&path)["abi"].take())
Expand Down Expand Up @@ -130,14 +126,16 @@ pub fn l1_messenger_contract() -> Contract {
load_sys_contract("L1Messenger")
}

/// Reads bytecode from the path RELATIVE to the Cargo workspace location.
pub fn read_bytecode(relative_path: impl AsRef<Path> + std::fmt::Debug) -> Vec<u8> {
read_bytecode_from_path(relative_path)
/// Reads bytecode from the path RELATIVE to the ZKSYNC_HOME environment variable.
pub fn read_bytecode(relative_path: impl AsRef<Path>) -> Vec<u8> {
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let artifact_path = Path::new(&zksync_home).join(relative_path);
read_bytecode_from_path(artifact_path)
}

/// Reads bytecode from a given path.
fn read_bytecode_from_path(artifact_path: impl AsRef<Path> + std::fmt::Debug) -> Vec<u8> {
let artifact = read_file_to_json_value(&artifact_path);
fn read_bytecode_from_path(artifact_path: PathBuf) -> Vec<u8> {
let artifact = read_file_to_json_value(artifact_path.clone());

let bytecode = artifact["bytecode"]
.as_str()
Expand All @@ -158,17 +156,19 @@ static DEFAULT_SYSTEM_CONTRACTS_REPO: Lazy<SystemContractsRepo> =

/// Structure representing a system contract repository - that allows
/// fetching contracts that are located there.
/// As most of the static methods in this file, is loading data based on the Cargo workspace location.
/// As most of the static methods in this file, is loading data based on ZKSYNC_HOME environment variable.
pub struct SystemContractsRepo {
// Path to the root of the system contracts repository.
pub root: PathBuf,
}

impl SystemContractsRepo {
/// Returns the default system contracts repository with directory based on the Cargo workspace location.
/// Returns the default system contracts repository with directory based on the ZKSYNC_HOME environment variable.
pub fn from_env() -> Self {
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let zksync_home = PathBuf::from(zksync_home);
SystemContractsRepo {
root: home_path().join("contracts/system-contracts"),
root: zksync_home.join("contracts/system-contracts"),
}
}

Expand Down Expand Up @@ -206,9 +206,10 @@ fn read_playground_batch_bootloader_bytecode() -> Vec<u8> {
read_bootloader_code("playground_batch")
}

/// Reads zbin bytecode from a given path, relative to workspace location.
/// Reads zbin bytecode from a given path, relative to ZKSYNC_HOME.
pub fn read_zbin_bytecode(relative_zbin_path: impl AsRef<Path>) -> Vec<u8> {
let bytecode_path = Path::new(&home_path()).join(relative_zbin_path);
let zksync_home = std::env::var("ZKSYNC_HOME").unwrap_or_else(|_| ".".into());
let bytecode_path = Path::new(&zksync_home).join(relative_zbin_path);
read_zbin_bytecode_from_path(bytecode_path)
}

Expand Down
2 changes: 1 addition & 1 deletion core/lib/types/src/system_contracts.rs
Expand Up @@ -168,7 +168,7 @@ static SYSTEM_CONTRACTS: Lazy<Vec<DeployedContract>> = Lazy::new(|| {
.collect::<Vec<_>>()
});

/// Gets default set of system contracts, based on Cargo workspace location.
/// Gets default set of system contracts, based on ZKSYNC_HOME environment variable.
pub fn get_system_smart_contracts() -> Vec<DeployedContract> {
SYSTEM_CONTRACTS.clone()
}
Expand Down
3 changes: 1 addition & 2 deletions core/lib/utils/Cargo.toml
Expand Up @@ -25,9 +25,8 @@ futures.workspace = true
hex.workspace = true
reqwest = { workspace = true, features = ["blocking"] }
itertools.workspace = true
serde_json.workspace = true
once_cell.workspace = true

[dev-dependencies]
serde_json.workspace = true
rand.workspace = true
tokio = { workspace = true, features = ["macros", "rt"] }
68 changes: 0 additions & 68 deletions core/lib/utils/src/env.rs

This file was deleted.

5 changes: 3 additions & 2 deletions core/lib/utils/src/lib.rs
Expand Up @@ -2,12 +2,13 @@

pub mod bytecode;
mod convert;
mod env;
pub mod http_with_retries;
pub mod misc;
pub mod panic_extractor;
mod serde_wrappers;
pub mod time;
pub mod wait_for_tasks;

pub use self::{convert::*, env::*, misc::*, serde_wrappers::*};
pub use convert::*;
pub use misc::*;
pub use serde_wrappers::*;

0 comments on commit aed23e1

Please sign in to comment.