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

Loading dependencies from an env var. #6

Merged
merged 3 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
This crate uses the external submodules
[pil-stark]([email protected]:powdr-labs/pil-stark.git) and
[zkevm-prover](https://github.com/powdr-labs/zkevm-prover) to generate EStark ZK
proofs from a Rust friendly interface.

At runtime, it needs to find the contents of cargo's `OUT_DIR` (which is
populated by `build.rs` at build time), otherwise execution will panic. This
means that, if used as a cargo dependency from the same machine it is built,
e.g. with `cargo run` or `cargo test`, it will work out of the box. But if the
binaries are executed from another machine, e.g. from a `nextest` archive, it
will fail unless the original `OUT_DIR` contents are manually provided.

The library will first search for the dependencies in the path given by
environment variable `PIL_STARK_PROVER_DEPS`, and if not set, it fallbacks to
the compile-time hardcoded path set by cargo's `OUT_DIR`, which is typically
`target/<profile>/build/pil-stark-prover-<hash>/out`.
24 changes: 20 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{
fs,
borrow::Cow,
env, fs,
io::{BufRead, BufReader},
path::{Path, PathBuf},
process::{Command, ExitStatus, Stdio},
Expand All @@ -14,7 +15,22 @@ pub struct OutputFiles {
}

const MAX_NODE_MEM: u32 = 1024 * 16;
const EXTERNALS_DIR: &str = env!("OUT_DIR");

fn deps_dir() -> Cow<'static, Path> {
const DEFAULT_DEPS_DIR: &str = env!("OUT_DIR");

match env::var_os("PIL_STARK_PROVER_DEPS") {
Some(deps_dir) => Cow::Owned(deps_dir.into()),
None => {
let default_deps_dir = Path::new(DEFAULT_DEPS_DIR);
if default_deps_dir.is_dir() {
Cow::Borrowed(default_deps_dir)
} else {
panic!("pil-stark-prover dependencies directory not found!\nEither set PIL_STARK_PROVER_DEPS environment variable, or build the project locally from source.\nSee README.md for more information.")
}
}
}
}

#[derive(thiserror::Error, Debug)]
pub enum Error {
Expand Down Expand Up @@ -72,7 +88,7 @@ pub fn generate_proof(
commits_bin: &Path,
output_dir: &Path,
) -> Result<OutputFiles, Error> {
let externals_dir = Path::new(EXTERNALS_DIR);
let externals_dir = deps_dir();
let pil_stark_root = externals_dir.join("pil-stark");
let pil_stark_src = pil_stark_root.join("src");

Expand Down Expand Up @@ -217,7 +233,7 @@ pub fn verify_proof(
proof_json: &Path,
publics_json: &Path,
) -> Result<(), Error> {
let externals_dir = Path::new(EXTERNALS_DIR);
let externals_dir = deps_dir();
let pil_stark_root = externals_dir.join("pil-stark");
let pil_stark_src = pil_stark_root.join("src");

Expand Down
Loading