Skip to content

Commit

Permalink
guest build and binary flag update
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Feb 3, 2025
1 parent 2d9ae5b commit 5863da8
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 4 additions & 3 deletions bin/datatool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ zeroize.workspace = true

[features]
default = []
risc0 = ["strata-risc0-guest-builder", "bytemuck"]
sp1 = ["strata-sp1-guest-builder"]
sp1-docker = ["sp1", "strata-sp1-guest-builder/docker-build"]
risc0-builder = ["strata-risc0-guest-builder", "bytemuck"]
sp1-builder = ["strata-sp1-guest-builder/sp1-dev"]
sp1-mock-builder = ["sp1-builder", "strata-sp1-guest-builder/mock"]
sp1-docker-docker = ["sp1-builder", "strata-sp1-guest-builder/docker-build"]
10 changes: 5 additions & 5 deletions bin/datatool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub(super) fn exec_subc(cmd: Subcommand, ctx: &mut CmdContext) -> anyhow::Result
///
/// Returns an error if the export process fails.
fn export_elf(_elf_path: &PathBuf) -> anyhow::Result<()> {
#[cfg(feature = "sp1")]
#[cfg(feature = "sp1-builder")]
{
strata_sp1_guest_builder::export_elf(_elf_path)?
}
Expand All @@ -100,7 +100,7 @@ fn export_elf(_elf_path: &PathBuf) -> anyhow::Result<()> {
/// only one ZKVM can be supported at a time.
fn resolve_rollup_vk() -> RollupVerifyingKey {
// Use SP1 if only `sp1` feature is enabled
#[cfg(all(feature = "sp1", not(feature = "risc0")))]
#[cfg(all(feature = "sp1-builder", not(feature = "risc0-builder")))]
{
use strata_sp1_guest_builder::GUEST_CHECKPOINT_VK_HASH_STR;
let vk_buf32: Buf32 = GUEST_CHECKPOINT_VK_HASH_STR
Expand All @@ -110,7 +110,7 @@ fn resolve_rollup_vk() -> RollupVerifyingKey {
}

// Use Risc0 if only `risc0` feature is enabled
#[cfg(all(feature = "risc0", not(feature = "sp1")))]
#[cfg(all(feature = "risc0-builder", not(feature = "sp1-builder")))]
{
use strata_risc0_guest_builder::GUEST_RISC0_CHECKPOINT_ID;
let vk_u8: [u8; 32] = bytemuck::cast(GUEST_RISC0_CHECKPOINT_ID);
Expand All @@ -119,7 +119,7 @@ fn resolve_rollup_vk() -> RollupVerifyingKey {
}

// Panic if both `sp1` and `risc0` feature are enabled
#[cfg(all(feature = "risc0", feature = "sp1"))]
#[cfg(all(feature = "risc0-builder", feature = "sp1-builder"))]
{
panic!(
"Conflicting ZKVM features: both 'sp1' and 'risc0' are enabled. \
Expand All @@ -128,7 +128,7 @@ fn resolve_rollup_vk() -> RollupVerifyingKey {
}

// If neither `risc0` nor `sp1` is enabled, use the Native verifying key
#[cfg(all(not(feature = "risc0"), not(feature = "sp1")))]
#[cfg(all(not(feature = "risc0-builder"), not(feature = "sp1-builder")))]
{
RollupVerifyingKey::NativeVerifyingKey(Buf32::zero())
}
Expand Down
7 changes: 4 additions & 3 deletions bin/prover-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ strata-test-utils.workspace = true
[features]
default = []
sp1 = ["zkaleido-sp1-adapter/prover"]
sp1-dev = ["sp1", "strata-sp1-guest-builder/prover"]
sp1-mock = [
"sp1-dev",
sp1-mock = ["sp1", "zkaleido-sp1-adapter/mock"]
sp1-builder = ["sp1", "strata-sp1-guest-builder/prover"]
sp1-mock-builder = [
"sp1-builder",
"zkaleido-sp1-adapter/mock",
"strata-sp1-guest-builder/mock",
]
Expand Down
17 changes: 8 additions & 9 deletions bin/prover-client/src/hosts/sp1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ use std::sync::LazyLock;

use cfg_if::cfg_if;
use strata_primitives::proof::ProofContext;
#[cfg(feature = "sp1-dev")]
#[cfg(feature = "sp1-builder")]
use strata_sp1_guest_builder::*;
use zkaleido_sp1_adapter::SP1Host;

// Define a common base ELF path when not in "sp1-dev" mode
cfg_if! {
if #[cfg(not(feature = "sp1-dev"))] {
if #[cfg(not(feature = "sp1-builder"))] {
use std::env;
pub static ELF_BASE_PATH: LazyLock<String> = LazyLock::new(|| {
env::var("ELF_BASE_PATH").unwrap_or_else(|_| "elfs/sp1".to_string())
Expand All @@ -18,7 +17,7 @@ cfg_if! {

// BTC_BLOCKSPACE_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static BTC_BLOCKSPACE_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_BTC_BLOCKSPACE_PK));
} else {
Expand All @@ -33,7 +32,7 @@ cfg_if! {

// L1_BATCH_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static L1_BATCH_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_L1_BATCH_PK));
} else {
Expand All @@ -48,7 +47,7 @@ cfg_if! {

// EVM_EE_STF_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static EVM_EE_STF_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_EVM_EE_STF_PK));
} else {
Expand All @@ -63,7 +62,7 @@ cfg_if! {

// CL_STF_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static CL_STF_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_CL_STF_PK));
} else {
Expand All @@ -78,7 +77,7 @@ cfg_if! {

// CL_AGG_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static CL_AGG_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_CL_AGG_PK));
} else {
Expand All @@ -93,7 +92,7 @@ cfg_if! {

// CHECKPOINT_HOST
cfg_if! {
if #[cfg(feature = "sp1-dev")] {
if #[cfg(feature = "sp1-builder")] {
pub static CHECKPOINT_HOST: LazyLock<SP1Host> =
LazyLock::new(|| SP1Host::new_from_bytes(&GUEST_CHECKPOINT_PK));
} else {
Expand Down
Binary file removed elfs/sp1/guest-btc-blockspace.elf
Binary file not shown.
Binary file removed elfs/sp1/guest-checkpoint.elf
Binary file not shown.
Binary file removed elfs/sp1/guest-cl-agg.elf
Binary file not shown.
Binary file removed elfs/sp1/guest-cl-stf.elf
Binary file not shown.
Binary file removed elfs/sp1/guest-evm-ee-stf.elf
Binary file not shown.
Binary file removed elfs/sp1/guest-l1-batch.elf
Binary file not shown.
2 changes: 1 addition & 1 deletion functional-tests/run_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fi
# Conditionally run cargo build based on PROVER_TEST
if [ ! -z $PROVER_TEST ]; then
echo "Running on sp1-mock mode"
cargo build --release -F sp1
cargo build --release -F sp1-builder
export PATH=$(realpath ../target/release/):$PATH
else
echo "Running on seq mode"
Expand Down
2 changes: 2 additions & 0 deletions provers/sp1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ zkaleido-sp1-adapter = { git = "https://github.com/alpenlabs/zkaleido", tag = "v
bincode.workspace = true
cargo_metadata = "0.19.1"
sha2.workspace = true
cfg-if.workspace = true
sp1-helper = { git = "https://github.com/succinctlabs/sp1.git", rev = "6c5a7f2846cd3610ecd38b1641f0e370fd07ee83" }
sp1-sdk = "4.0.0"

Expand All @@ -21,3 +22,4 @@ default = ["prover"]
mock = []
prover = ["zkaleido-sp1-adapter"]
docker-build = []
sp1-dev = []
22 changes: 12 additions & 10 deletions provers/sp1/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ use std::{
path::{Path, PathBuf},
};

#[cfg(not(debug_assertions))]
use cfg_if::cfg_if;

cfg_if! {
if #[cfg(feature = "sp1-dev")] {
use bincode::{deserialize, serialize};
#[cfg(not(debug_assertions))]
use cargo_metadata::MetadataCommand;
#[cfg(not(debug_assertions))]
use sha2::{Digest, Sha256};
#[cfg(not(debug_assertions))]
use sp1_helper::{build_program_with_args, BuildArgs};
#[cfg(not(debug_assertions))]
use sp1_sdk::{HashableKey, ProverClient, SP1VerifyingKey};

}
}

// Guest program names
const EVM_EE_STF: &str = "guest-evm-ee-stf";
const CL_STF: &str = "guest-cl-stf";
Expand Down Expand Up @@ -167,7 +169,7 @@ fn get_output_dir() -> PathBuf {
}

/// Checks if the cache is valid by comparing the expected ID with the saved ID.
#[cfg(not(debug_assertions))]
#[cfg(feature = "sp1-dev")]
fn is_cache_valid(expected_id: &[u8; 32], paths: &[PathBuf; 4]) -> bool {
// Check if any required files are missing
if paths.iter().any(|path| !path.exists()) {
Expand All @@ -184,7 +186,7 @@ fn is_cache_valid(expected_id: &[u8; 32], paths: &[PathBuf; 4]) -> bool {
}

/// Ensures the cache is valid and returns the ELF contents and SP1 Verifying Key.
#[cfg(not(debug_assertions))]
#[cfg(feature = "sp1-dev")]
fn ensure_cache_validity(program: &str) -> Result<SP1VerifyingKey, String> {
let cache_dir = format!("{}/cache", program);
let paths = ["elf", "id", "vk", "pk"]
Expand Down Expand Up @@ -221,7 +223,7 @@ fn ensure_cache_validity(program: &str) -> Result<SP1VerifyingKey, String> {
}

/// Generates the ELF contents and VK hash for a given program.
#[cfg(not(debug_assertions))]
#[cfg(feature = "sp1-dev")]
fn generate_elf_contents_and_vk_hash(program: &str) -> ([u32; 8], String) {
let mut build_args = BuildArgs {
..Default::default()
Expand Down Expand Up @@ -259,7 +261,7 @@ fn generate_elf_contents_and_vk_hash(program: &str) -> ([u32; 8], String) {
(vk.hash_u32(), vk.bytes32())
}

#[cfg(debug_assertions)]
#[cfg(not(feature = "sp1-dev"))]
fn generate_elf_contents_and_vk_hash(_program: &str) -> ([u32; 8], String) {
(
[0u32; 8],
Expand All @@ -268,7 +270,7 @@ fn generate_elf_contents_and_vk_hash(_program: &str) -> ([u32; 8], String) {
}

/// Copies the compiled ELF file of the specified program to its cache directory.
#[cfg(not(debug_assertions))]
#[cfg(feature = "sp1-dev")]
fn migrate_elf(program: &str) {
// Get the build directory from the environment
let sp1_build_dir =
Expand Down

0 comments on commit 5863da8

Please sign in to comment.