Skip to main content

sp1_sdk/
utils.rs

1//! # SP1 SDK Utilities
2//!
3//! A collection of utilities for the SP1 SDK.
4
5use sp1_core_machine::io::SP1Stdin;
6pub use sp1_core_machine::utils::setup_logger;
7use sp1_prover_types::network_base_types::ProofMode;
8use sp1_verifier::SP1ProofMode;
9
10/// Dump the program and stdin to files for debugging if `SP1_DUMP` is set.
11pub(crate) fn sp1_dump(elf: &[u8], stdin: &SP1Stdin) {
12    if std::env::var("SP1_DUMP").is_ok_and(|v| v == "1" || v.eq_ignore_ascii_case("true")) {
13        std::fs::write("program.bin", elf).unwrap();
14        let stdin = bincode::serialize(&stdin).unwrap();
15        std::fs::write("stdin.bin", stdin.clone()).unwrap();
16
17        tracing::info!("Dumped program.bin and stdin.bin.");
18        // Exit with the success status.
19        std::process::exit(0);
20    }
21}
22
23pub(crate) fn proof_mode(mode: SP1ProofMode) -> ProofMode {
24    match mode {
25        SP1ProofMode::Core => ProofMode::Core,
26        SP1ProofMode::Compressed => ProofMode::Compressed,
27        SP1ProofMode::Groth16 => ProofMode::Groth16,
28        SP1ProofMode::Plonk => ProofMode::Plonk,
29    }
30}
31
32// Re-enable when the EnvProver is reimplemented.
33// /// Check that SP1 SDK was built in release mode. Ensures that the prover and executor
34// /// will be performant, which is important for benchmarking.
35// pub(crate) fn check_release_build() {
36//     #[cfg(debug_assertions)]
37//     panic!("sp1-sdk must be built in release mode, please compile with the --release flag.");
38// }