Add automatic name and sdk version (#48)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
This commit is contained in:
Ignacio Hagopian
2025-07-09 14:07:32 +02:00
committed by GitHub
parent 5d58bc6724
commit 47e33298fb
28 changed files with 500 additions and 703 deletions

View File

@@ -11,6 +11,7 @@ on:
jobs:
build_pico_image:
if: ${{ false }} # See issue #49
name: Build Pico Docker Image
runs-on: ubuntu-latest

1018
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,6 @@
[workspace]
members = [
"crates/build-utils",
# zkVM interface
"crates/zkvm-interface",
# zkVMs
@@ -23,6 +24,7 @@ license = "MIT OR Apache-2.0"
[workspace.dependencies]
# local dependencies
zkvm-interface = { path = "crates/zkvm-interface" }
build-utils = { path = "crates/build-utils" }
[patch.crates-io]
# These patches are only needed by Jolt

View File

@@ -0,0 +1,12 @@
[package]
name = "build-utils"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
license.workspace = true
[dependencies]
cargo_metadata = "0.20.0"
[lints]
workspace = true

View File

@@ -0,0 +1,31 @@
use std::{env, fs, path::Path};
// Detect and generate a Rust source file that contains the name and version of the SDK.
pub fn detect_and_generate_name_and_sdk_version(name: &str, sdk_dep_name: &str) {
let meta = cargo_metadata::MetadataCommand::new()
.exec()
.expect("Failed to get cargo metadata");
let version = meta
.packages
.iter()
.find(|pkg| pkg.name.eq_ignore_ascii_case(sdk_dep_name))
.map(|pkg| pkg.version.to_string())
.unwrap_or_else(|| {
panic!("Dependency {sdk_dep_name} not found in Cargo.toml");
});
gen_name_and_sdk_version(name, &version);
}
// Generate a Rust source file that contains the provided name and version of the SDK.
pub fn gen_name_and_sdk_version(name: &str, version: &str) {
let out_dir = env::var("OUT_DIR").unwrap();
let dest = Path::new(&out_dir).join("name_and_sdk_version.rs");
fs::write(
&dest,
format!("const NAME: &str = \"{name}\";\nconst SDK_VERSION: &str = \"{version}\";"),
)
.unwrap();
println!("cargo:rerun-if-changed=Cargo.lock");
}

View File

@@ -20,5 +20,8 @@ thiserror = "2"
toml = "0.8"
ark-serialize = "0.5.0"
[build-dependencies]
build-utils = { workspace = true }
[lints]
workspace = true

5
crates/ere-jolt/build.rs Normal file
View File

@@ -0,0 +1,5 @@
use build_utils::detect_and_generate_name_and_sdk_version;
fn main() {
detect_and_generate_name_and_sdk_version("jolt", "jolt-sdk");
}

View File

@@ -11,6 +11,7 @@ use zkvm_interface::{
zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod error;
mod jolt_methods;
mod utils;
@@ -102,6 +103,14 @@ impl zkVM for EreJolt {
Err(zkVMError::from(JoltError::ProofVerificationFailed))
}
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
#[cfg(test)]

View File

@@ -16,5 +16,8 @@ openvm-transpiler = { git = "https://github.com/openvm-org/openvm.git", tag = "v
thiserror = "2"
[build-dependencies]
build-utils = { workspace = true }
[lints]
workspace = true

View File

@@ -0,0 +1,5 @@
use build_utils::detect_and_generate_name_and_sdk_version;
fn main() {
detect_and_generate_name_and_sdk_version("openvm", "openvm-sdk");
}

View File

@@ -18,6 +18,7 @@ use zkvm_interface::{
zkVM, zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod error;
use error::{CompileError, OpenVMError, VerifyError};
@@ -163,6 +164,14 @@ impl zkVM for EreOpenVM {
.map_err(|e| OpenVMError::Verify(VerifyError::Client(e.into())))
.map_err(zkVMError::from)
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
#[cfg(test)]

View File

@@ -8,8 +8,11 @@ license.workspace = true
[dependencies]
zkvm-interface = { workspace = true }
thiserror = "2"
pico-sdk = { git = "https://github.com/brevis-network/pico", tag = "v1.1.3" }
pico-sdk = { git = "https://github.com/brevis-network/pico", tag = "v1.1.4" }
bincode = "1.3.3"
[build-dependencies]
build-utils = { workspace = true }
[lints]
workspace = true

5
crates/ere-pico/build.rs Normal file
View File

@@ -0,0 +1,5 @@
use build_utils::detect_and_generate_name_and_sdk_version;
fn main() {
detect_and_generate_name_and_sdk_version("pico", "pico-sdk");
}

View File

@@ -5,6 +5,7 @@ use zkvm_interface::{
zkVM, zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod error;
use error::PicoError;
@@ -77,10 +78,10 @@ impl zkVM for ErePico {
}
let start = Instant::now();
let num_cycles = client.emulate(stdin);
let emulation_result = client.emulate(stdin);
Ok(ProgramExecutionReport {
total_num_cycles: num_cycles,
total_num_cycles: emulation_result.0,
execution_duration: start.elapsed(),
..Default::default()
})
@@ -126,6 +127,14 @@ impl zkVM for ErePico {
let _vk = client.riscv_vk();
todo!("Verification method missing from sdk")
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
#[cfg(test)]

View File

@@ -9,7 +9,7 @@ license.workspace = true
zkvm-interface = { workspace = true }
anyhow = "1.0" #TODO: remove only needed in tests
toml = "0.8"
risc0-zkvm = { version = "^2.1.0", features = ["unstable"] }
risc0-zkvm = { version = "^2.2.0", features = ["unstable"] }
borsh = "1.5.7"
hex = "*"
@@ -17,6 +17,9 @@ tempfile = "3.3"
serde_json = "1.0"
thiserror = "2"
[build-dependencies]
build-utils = { workspace = true }
[features]
metal = ["risc0-zkvm/metal"]
cuda = ["risc0-zkvm/cuda"]

View File

@@ -0,0 +1,5 @@
use build_utils::detect_and_generate_name_and_sdk_version;
fn main() {
detect_and_generate_name_and_sdk_version("risc0", "risc0-zkvm");
}

View File

@@ -7,6 +7,8 @@ use zkvm_interface::{
zkVM, zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod compile;
pub use compile::Risc0Program;
@@ -121,6 +123,14 @@ impl zkVM for EreRisc0 {
.verify(self.program.image_id)
.map_err(|err| zkVMError::Other(Box::new(err)))
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
#[cfg(test)]

View File

@@ -14,6 +14,9 @@ bincode = "1.3"
thiserror = "2"
tracing = "0.1"
[build-dependencies]
build-utils = { workspace = true }
[lib]
name = "ere_succinct"
path = "src/lib.rs"

5
crates/ere-sp1/build.rs Normal file
View File

@@ -0,0 +1,5 @@
use build_utils::detect_and_generate_name_and_sdk_version;
fn main() {
detect_and_generate_name_and_sdk_version("sp1", "sp1-sdk");
}

View File

@@ -13,6 +13,8 @@ use zkvm_interface::{
ProverResourceType, zkVM, zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod compile;
mod error;
@@ -212,6 +214,14 @@ impl zkVM for EreSP1 {
let client = Self::create_client(&self.resource);
client.verify(&proof, &self.vk).map_err(zkVMError::from)
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
#[cfg(test)]

View File

@@ -15,6 +15,9 @@ serde = { version = "1.0", features = ["derive"] }
bincode = "1.3"
blake3 = "1.3.1"
[build-dependencies]
build-utils = { workspace = true }
[lib]
name = "ere_zisk"
path = "src/lib.rs"

5
crates/ere-zisk/build.rs Normal file
View File

@@ -0,0 +1,5 @@
use build_utils::gen_name_and_sdk_version;
fn main() {
gen_name_and_sdk_version("zisk", "0.8.1");
}

View File

@@ -16,6 +16,8 @@ use zkvm_interface::{
zkVMError,
};
include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod compile;
mod error;
@@ -187,7 +189,9 @@ impl zkVM for EreZisk {
unimplemented!()
}
ProverResourceType::Network(_) => {
panic!("Network proving not yet implemented for ZisK. Use CPU or GPU resource type.");
panic!(
"Network proving not yet implemented for ZisK. Use CPU or GPU resource type."
);
}
}
let proving_time = start.elapsed();
@@ -243,6 +247,14 @@ impl zkVM for EreZisk {
Ok(())
}
fn name() -> &'static str {
NAME
}
fn sdk_version() -> &'static str {
SDK_VERSION
}
}
struct ZiskTempDir {

View File

@@ -81,4 +81,10 @@ pub trait zkVM {
/// TODO: We can also just have this return the public inputs, but then the user needs
/// TODO: ensure they check it for correct #[must_use]
fn verify(&self, proof: &[u8]) -> Result<(), zkVMError>;
/// Returns the name of the zkVM
fn name() -> &'static str;
/// Returns the version of the zkVM SDK (e.g. 0.1.0)
fn sdk_version() -> &'static str;
}

View File

@@ -1,11 +1,7 @@
[workspace]
members = [
"lib",
"app",
"prover",
]
members = ["lib", "app", "prover"]
resolver = "2"
[workspace.dependencies]
pico-sdk = { git = "https://github.com/brevis-network/pico" }
serde = { version = "1.0.205", features = ["derive"] }
pico-sdk = { git = "https://github.com/brevis-network/pico", tag = "v1.1.4" }
serde = { version = "1.0.205", features = ["derive"] }

View File

@@ -6,4 +6,4 @@ edition = "2021"
[workspace]
[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
sp1-zkvm = "5.0.5"

View File

@@ -6,4 +6,4 @@ edition = "2021"
[workspace]
[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
sp1-zkvm = "5.0.5"

View File

@@ -6,4 +6,4 @@ edition = "2021"
[workspace]
[dependencies]
sp1-zkvm = { git = "https://github.com/succinctlabs/sp1.git" }
sp1-zkvm = "5.0.5"