Upgrade ZisK to v0.10.0 (#95)

This commit is contained in:
Han
2025-08-18 22:35:04 +08:00
committed by GitHub
parent 80330caf59
commit 7749e1dfc6
8 changed files with 120 additions and 51 deletions

View File

@@ -41,7 +41,7 @@ fn generate_zkvm_sdk_version_impl() {
// Once ZisK's SDK is ready, we should update this to detect the SDK
// version.
// The issue for tracking https://github.com/eth-act/ere/issues/73.
let zisk_version = "0.9.0";
let zisk_version = "0.10.0";
let zkvm_sdk_version_impl = format!(
r#"impl crate::ErezkVM {{

View File

@@ -50,23 +50,24 @@ impl DockerBuildCmd {
Self::default()
}
pub fn file(mut self, file: impl AsRef<Path>) -> Self {
self.options
.push(CmdOption::new("file", file.as_ref().to_string_lossy()));
pub fn option(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new(key, value));
self
}
pub fn tag(mut self, tag: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new("tag", tag));
self
pub fn file(self, file: impl AsRef<Path>) -> Self {
self.option("file", file.as_ref().to_string_lossy())
}
pub fn bulid_arg(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new(
pub fn tag(self, tag: impl AsRef<str>) -> Self {
self.option("tag", tag)
}
pub fn bulid_arg(self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
self.option(
"build-arg",
format!("{}={}", to_string(key), to_string(value)),
));
self
)
}
pub fn exec(self, context: impl AsRef<Path>) -> Result<(), io::Error> {
@@ -102,16 +103,25 @@ impl DockerRunCmd {
}
}
pub fn volume(mut self, host: impl AsRef<Path>, container: impl AsRef<Path>) -> Self {
self.options.push(CmdOption::new(
pub fn flag(mut self, key: impl AsRef<str>) -> Self {
self.options.push(CmdOption::flag(key));
self
}
pub fn option(mut self, key: impl AsRef<str>, value: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new(key, value));
self
}
pub fn volume(self, host: impl AsRef<Path>, container: impl AsRef<Path>) -> Self {
self.option(
"volume",
format!(
"{}:{}",
host.as_ref().display(),
container.as_ref().display(),
),
));
self
)
}
/// Mounts `/var/run/docker.sock` to allow Docker-out-of-Docker (DooD).
@@ -119,29 +129,25 @@ impl DockerRunCmd {
self.volume(DOCKER_SOCKET, DOCKER_SOCKET)
}
pub fn gpus(mut self, devices: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new("gpus", devices));
self
pub fn gpus(self, devices: impl AsRef<str>) -> Self {
self.option("gpus", devices)
}
pub fn network(mut self, name: impl AsRef<str>) -> Self {
self.options.push(CmdOption::new("network", name));
self
pub fn network(self, name: impl AsRef<str>) -> Self {
self.option("network", name)
}
/// Inherit environment variable `key` if it's set and valid.
pub fn inherit_env(mut self, key: impl AsRef<str>) -> Self {
pub fn inherit_env(self, key: impl AsRef<str>) -> Self {
let key = key.as_ref();
if let Ok(val) = env::var(key) {
self.options
.push(CmdOption::new("env", format!("{key}={val}")));
match env::var(key) {
Ok(val) => self.option("env", format!("{key}={val}")),
Err(_) => self,
}
self
}
pub fn rm(mut self) -> Self {
self.options.push(CmdOption::flag("rm"));
self
pub fn rm(self) -> Self {
self.flag("rm")
}
pub fn exec(self, commands: impl IntoIterator<Item: AsRef<str>>) -> Result<(), io::Error> {

View File

@@ -356,21 +356,31 @@ impl zkVM for EreDockerizedzkVM {
.inherit_env("NO_COLOR")
.volume(tempdir.path(), "/workspace");
// zkVM specific options
cmd = match self.zkvm {
// ZisK uses shared memory to exchange data between processes, it
// requires at least 8G shared memory, here we set 16G for safety.
ErezkVM::Zisk => cmd.option("shm-size", "16G"),
_ => cmd,
};
// zkVM specific options when using GPU
if matches!(self.resource, ProverResourceType::Gpu) {
// SP1's and Risc0's GPU proving requires Docker to start GPU prover
// service, to give the client access to the prover service, we need
// to use the host networking driver.
match self.zkvm {
ErezkVM::SP1 => cmd = cmd.mount_docker_socket().network("host"),
ErezkVM::Risc0 => {
cmd = cmd
.mount_docker_socket()
.network("host")
.inherit_env("CUDA_VISIBLE_DEVICES")
.inherit_env("SEGMENT_SIZE")
.inherit_env("RISC0_KECCAK_PO2")
}
_ => {}
cmd = match self.zkvm {
// SP1's and Risc0's GPU proving requires Docker to start GPU prover
// service, to give the client access to the prover service, we need
// to use the host networking driver.
// The `--gpus` flags will be set when the GPU prover service is
// spin up, so we don't need to set here.
ErezkVM::SP1 => cmd.mount_docker_socket().network("host"),
ErezkVM::Risc0 => cmd
.mount_docker_socket()
.network("host")
.inherit_env("CUDA_VISIBLE_DEVICES")
.inherit_env("SEGMENT_SIZE")
.inherit_env("RISC0_KECCAK_PO2"),
ErezkVM::Zisk => cmd.gpus("all"),
_ => cmd,
}
}

View File

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

View File

@@ -15,6 +15,7 @@ use std::{
time,
};
use tempfile::{TempDir, tempdir};
use tracing::info;
use zkvm_interface::{
Compiler, Input, InputItem, ProgramExecutionReport, ProgramProvingReport, ProverResourceType,
zkVM, zkVMError,
@@ -25,6 +26,9 @@ include!(concat!(env!("OUT_DIR"), "/name_and_sdk_version.rs"));
mod compile;
mod error;
/// Lock for the command `cargo-zisk check-setup` to avoid multiple runs.
static SETUP_LOCK: Mutex<bool> = Mutex::new(false);
/// It panics if `EreZisk::prove` is called concurrently, so we need a lock here
/// to avoid that.
static PROVE_LOCK: Mutex<()> = Mutex::new(());
@@ -119,6 +123,9 @@ impl zkVM for EreZisk {
}
fn prove(&self, inputs: &Input) -> Result<(Vec<u8>, ProgramProvingReport), zkVMError> {
// Make sure proving key setup is done.
check_setup()?;
// Obtain the prove lock to make sure proving can't be called concurrently.
let _guard = PROVE_LOCK
.lock()
@@ -143,6 +150,8 @@ impl zkVM for EreZisk {
// Setup ROM.
if !is_bin_exists(&self.elf, tempdir.elf_path()) {
info!("Running command `cargo-zisk rom-setup` ...");
let status = Command::new("cargo-zisk")
.arg("rom-setup")
.arg("--elf")
@@ -157,6 +166,8 @@ impl zkVM for EreZisk {
ZiskError::Prove(ProveError::CargoZiskRomSetupFailed { status }).into(),
);
}
info!("Command `cargo-zisk rom-setup` succeeded");
}
// Prove.
@@ -180,7 +191,7 @@ impl zkVM for EreZisk {
"--aggregation",
"--verify-proofs",
"--save-proofs",
// Uncomment this when in memory constrained environment.
// Uncomment this if locked memory is not enough.
// "--unlock-mapped-memory",
])
.status()
@@ -213,8 +224,9 @@ impl zkVM for EreZisk {
"--aggregation",
"--verify-proofs",
"--save-proofs",
// Comment out this if GPU RAM is not enough.
"--preallocate",
// Uncomment this when in memory constrained environment.
// Uncomment this if locked memory is not enough.
// "--unlock-mapped-memory",
])
.status()
@@ -315,6 +327,41 @@ fn dot_zisk_dir_path() -> PathBuf {
PathBuf::from(std::env::var("HOME").expect("env `$HOME` should be set")).join(".zisk")
}
fn check_setup() -> Result<(), zkVMError> {
let mut setup = SETUP_LOCK
.lock()
.map_err(|_| zkVMError::Other("Setup lock is poisoned".into()))?;
if !*setup {
info!("Running command `cargo-zisk check-setup --aggregation`...");
let output = Command::new("cargo-zisk")
.args(["check-setup", "--aggregation"])
.output()
.map_err(|e| {
zkVMError::Other(
format!("Failed to run command `cargo-zisk check-setup`: {e}").into(),
)
})?;
if !output.status.success() {
return Err(zkVMError::Other(
format!(
"Command `cargo-zisk check-setup` failed: {}",
String::from_utf8_lossy(&output.stderr)
)
.into(),
));
}
info!("Command `cargo-zisk check-setup --aggregation` succeeded");
*setup = true;
}
Ok(())
}
/// Check if these files exists in `$HOME/.zisk/cache`:
///
/// - `{elf_file_stem}-{elf_hash}-mo.bin`

View File

@@ -34,6 +34,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
# If current environment is in CI or not.
ARG CI
# Install CUDA Toolkit 12.9
#
# If argument `CI` is set, we skip the installation.
RUN [ -n "$CI" ] || \
(wget https://developer.download.nvidia.com/compute/cuda/repos/$(. /etc/os-release && echo "${ID}${VERSION_ID}" | tr -d '.')/$(uname -i)/cuda-keyring_1.1-1_all.deb && \
dpkg -i cuda-keyring_1.1-1_all.deb && \
@@ -50,10 +53,13 @@ RUN chmod +x /tmp/install_zisk_sdk.sh
# This script installs the 'zisk' Rust toolchain and `cargo-zisk`
#
# If argument `CI` is set, we only install verifying key, this is used by github
# CI runner which only has small disk space (proving key requires ~35 GB).
# CI runner which only has small disk space (proving key requires ~27 GB).
RUN if [ -n "$CI" ]; then export SETUP_KEY=verify; fi && \
/tmp/install_zisk_sdk.sh && \
rm /tmp/install_zisk_sdk.sh # Clean up the script
rm /tmp/install_zisk_sdk.sh && \
# Remove the merkle tree of proving key to reduce docker image size (~20 GB).
# Re-generating takes only ~30 seconds.
find "/root/.zisk/provingKey" -name "*.consttree" -type f -delete
# The 'zisk' Rust toolchain is now installed.
# cargo-zisk is installed in /root/.zisk/bin.
@@ -63,6 +69,6 @@ ENV ZISK_BIN_DIR="/root/.zisk/bin"
ENV PATH="${PATH}:${ZISK_BIN_DIR}"
# Verify cargo-zisk is accessible
RUN echo "Verifying Zisk installation in Dockerfile ..." && cargo-zisk --version
RUN echo "Verifying ZisK installation in Dockerfile ..." && cargo-zisk --version
CMD ["/bin/bash"]

View File

@@ -32,7 +32,7 @@ ensure_tool_installed "cargo" "as cargo-zisk is a cargo subcommand"
# Step 1: Download and run the script that installs the ziskup binary itself.
# Export SETUP_KEY=proving to ensure no interactive options in `ziskup`.
export ZISK_VERSION="0.9.0"
export ZISK_VERSION="0.10.0"
export SETUP_KEY=${SETUP_KEY:=proving}
curl "https://raw.githubusercontent.com/0xPolygonHermez/zisk/main/ziskup/install.sh" | bash
unset SETUP_KEY

View File

@@ -7,5 +7,5 @@ edition = "2021"
[dependencies]
bincode = "1.3.3"
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.9.0" }
ziskos = { git = "https://github.com/0xPolygonHermez/zisk.git", tag = "v0.10.0" }
test-utils = { path = "../../../crates/test-utils" }