Skip to content

Commit

Permalink
fix(prover_cli): Fix the issues with home path (#2104)
Browse files Browse the repository at this point in the history
In this PR: [Pull Request
#2022](https://github.com/matter-labs/zksync-era/pull/2022/files), the
logic was changed to stop using the $ZKSYNC_HOME environment variable to
construct paths relative to the root of zksync-era.
But the prover is a separate workspace, so it fails to create the path
to the contract with the functions in the main workspace..

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `zk spellcheck`.
  • Loading branch information
ColoCarletti authored Jun 7, 2024
1 parent 70eb588 commit 1e18af2
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 13 deletions.
1 change: 1 addition & 0 deletions etc/pliconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PLI__DB_URL=postgres://postgres:notsecurepassword@localhost/prover_local
2 changes: 2 additions & 0 deletions prover/Cargo.lock

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

2 changes: 2 additions & 0 deletions prover/prover_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ prover_dal.workspace = true
zksync_eth_client.workspace = true
zksync_contracts.workspace = true
zksync_dal.workspace = true
zksync_utils.workspace = true
strum.workspace = true
colored.workspace = true
sqlx.workspace = true
circuit_definitions.workspace = true
serde_json.workspace = true
zkevm_test_harness = { workspace = true, optional = true, features = ["verbose_circuits"] }

[features]
Expand Down
13 changes: 6 additions & 7 deletions prover/prover_cli/src/commands/status/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ use zksync_eth_client::{
CallFunctionArgs,
};

use crate::helper;

pub(crate) async fn run() -> anyhow::Result<()> {
println!(" ====== L1 Status ====== ");
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env")?;
Expand All @@ -27,15 +29,15 @@ pub(crate) async fn run() -> anyhow::Result<()> {
let total_batches_committed: U256 = CallFunctionArgs::new("getTotalBatchesCommitted", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;

let total_batches_verified: U256 = CallFunctionArgs::new("getTotalBatchesVerified", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;
Expand Down Expand Up @@ -74,17 +76,14 @@ pub(crate) async fn run() -> anyhow::Result<()> {
);

let node_verification_key_hash: H256 = CallFunctionArgs::new("verificationKeyHash", ())
.for_contract(
contracts_config.verifier_addr,
&zksync_contracts::verifier_contract(),
)
.for_contract(contracts_config.verifier_addr, &helper::verifier_contract())
.call(&query_client)
.await?;

let node_verifier_params: VerifierParams = CallFunctionArgs::new("getVerifierParams", ())
.for_contract(
contracts_config.diamond_proxy_addr,
&zksync_contracts::hyperchain_contract(),
&helper::hyperchain_contract(),
)
.call(&query_client)
.await?;
Expand Down
14 changes: 8 additions & 6 deletions prover/prover_cli/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::io::Write;
use std::{io::Write, path::PathBuf};

pub fn get_envfile() -> anyhow::Result<String> {
use crate::helper::core_workspace_dir_or_current_dir;

pub fn get_envfile() -> anyhow::Result<PathBuf> {
if let Ok(envfile) = std::env::var("PLI__CONFIG") {
return Ok(envfile);
return Ok(envfile.into());
}
Ok(std::env::var("ZKSYNC_HOME").map(|home| home + "/etc/pliconfig")?)
Ok(core_workspace_dir_or_current_dir().join("etc/pliconfig"))
}

pub fn load_envfile(path: impl AsRef<std::path::Path>) -> anyhow::Result<()> {
Expand All @@ -13,7 +15,6 @@ pub fn load_envfile(path: impl AsRef<std::path::Path>) -> anyhow::Result<()> {
.filter(|l| !l.starts_with('#'))
.filter_map(|l| l.split_once('='))
.for_each(|(k, v)| std::env::set_var(k, v));

Ok(())
}

Expand All @@ -28,7 +29,8 @@ pub fn update_envfile(
let mut out = std::io::BufWriter::new(std::fs::File::create_new(&swapfile)?);
let mut found = false;

std::fs::read_to_string(path)?
std::fs::read_to_string(path)
.unwrap_or_default()
.lines()
.map(|l| {
if l.starts_with(&prefix) {
Expand Down
47 changes: 47 additions & 0 deletions prover/prover_cli/src/helper.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::{
fs::File,
path::{Path, PathBuf},
};

use zksync_types::ethabi::Contract;
use zksync_utils::locate_workspace;

const ZKSYNC_HYPERCHAIN_CONTRACT_FILE: &str =
"contracts/l1-contracts/artifacts/contracts/state-transition/chain-interfaces/IZkSyncHyperchain.sol/IZkSyncHyperchain.json";
const VERIFIER_CONTRACT_FILE: &str =
"contracts/l1-contracts/artifacts/contracts/state-transition/Verifier.sol/Verifier.json";

pub fn hyperchain_contract() -> Contract {
load_contract_if_present(ZKSYNC_HYPERCHAIN_CONTRACT_FILE)
}

pub fn verifier_contract() -> Contract {
load_contract_if_present(VERIFIER_CONTRACT_FILE)
}

fn read_file_to_json_value(path: &PathBuf) -> serde_json::Value {
serde_json::from_reader(
File::open(path).unwrap_or_else(|e| panic!("Failed to open file {:?}: {}", path, e)),
)
.unwrap_or_else(|e| panic!("Failed to parse file {:?}: {}", path, e))
}

fn load_contract_if_present(path: &str) -> Contract {
let home = core_workspace_dir_or_current_dir();
let path = Path::new(&home).join(path);
path.exists()
.then(|| {
serde_json::from_value(read_file_to_json_value(&path)["abi"].take()).unwrap_or_else(
|e| panic!("Failed to parse contract abi from file {:?}: {}", path, e),
)
})
.unwrap_or_else(|| {
panic!("Failed to load contract from {:?}", path);
})
}

pub fn core_workspace_dir_or_current_dir() -> PathBuf {
locate_workspace()
.map(|a| a.join(".."))
.unwrap_or_else(|| PathBuf::from("."))
}
1 change: 1 addition & 0 deletions prover/prover_cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod cli;
pub mod commands;
pub mod config;
pub mod helper;

0 comments on commit 1e18af2

Please sign in to comment.