Skip to content

Commit

Permalink
datatool export elf
Browse files Browse the repository at this point in the history
  • Loading branch information
MdTeach committed Jan 30, 2025
1 parent 6ced1e8 commit 8ec42b6
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 0 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.

3 changes: 3 additions & 0 deletions bin/datatool/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ pub(crate) struct SubcParams {
description = "permit blank proofs after timeout in millis (default strict)"
)]
pub(crate) proof_timeout: Option<u32>,

#[argh(option, description = "directory to export the generated ELF")]
pub(crate) elf_path: Option<PathBuf>,
}

pub(crate) struct CmdContext {
Expand Down
24 changes: 24 additions & 0 deletions bin/datatool/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ pub(super) fn exec_subc(cmd: Subcommand, ctx: &mut CmdContext) -> anyhow::Result
}
}

/// Exports an ELF file to the specified path.
///
/// When the `sp1` feature is enabled, uses `strata_sp1_guest_builder` for the export.
///
/// # Arguments
///
/// * `elf_path` - The destination path for the ELF file.
///
/// # Errors
///
/// Returns an error if the export process fails.
fn export_elf(elf_path: &PathBuf) -> anyhow::Result<()> {
#[cfg(feature = "sp1")]
{
strata_sp1_guest_builder::export_elf(elf_path)?
}

Ok(())
}

/// Returns the appropriate [`RollupVerifyingKey`] based on the enabled features.
///
/// # Behavior
Expand Down Expand Up @@ -278,6 +298,10 @@ fn exec_genparams(cmd: SubcParams, ctx: &mut CmdContext) -> anyhow::Result<()> {
println!("{params_buf}");
}

if let Some(elf_path) = &cmd.elf_path {
export_elf(elf_path)?;
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions provers/sp1/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ name = "strata-sp1-guest-builder"
version = "0.1.0"

[dependencies]
anyhow.workspace = true
once_cell = "1.20.2"
zkaleido-sp1-adapter = { git = "https://github.com/alpenlabs/zkaleido", tag = "v0.1.0-alpha-rc1", features = [
"prover",
Expand Down
45 changes: 45 additions & 0 deletions provers/sp1/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
use std::path::PathBuf;

use anyhow::{Context, Result};

include!(concat!(env!("OUT_DIR"), "/methods.rs"));

pub fn export_elf(elf_path: &PathBuf) -> Result<()> {
// Create output directory if it doesn't exist
fs::create_dir_all(elf_path).context("Failed to create ELF output directory")?;

// Get the current crate's directory
let cargo_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));

// Iterate over entries in cargo_dir
for entry in fs::read_dir(&cargo_dir)
.with_context(|| format!("Failed to read directory {:?}", cargo_dir))?
{
let entry = entry?;
let path = entry.path();
if path.is_dir() {
if let Some(folder_name) = path.file_name().and_then(|n| n.to_str()) {
if folder_name.starts_with("guest-") {
let cache_dir = path.join("cache");
if cache_dir.is_dir() {
for file in fs::read_dir(&cache_dir).with_context(|| {
format!("Failed to read cache directory {:?}", cache_dir)
})? {
let file = file?;
let file_path = file.path();
if file_path.is_file()
&& file_path.extension().and_then(|s| s.to_str()) == Some("elf")
{
let file_name = file_path.file_name().unwrap();
let dest_file = elf_path.join(file_name);
fs::copy(&file_path, &dest_file).with_context(|| {
format!("Failed to copy {:?} to {:?}", file_path, dest_file)
})?;
}
}
}
}
}
}
}
Ok(())
}

0 comments on commit 8ec42b6

Please sign in to comment.