sp1_sdk/
artifacts.rs

1//! # SP1 Artifacts
2//!
3//! A library for exporting the SP1 artifacts to the specified output directory.
4
5use std::path::PathBuf;
6
7use anyhow::{Context, Result};
8
9use crate::install::try_install_circuit_artifacts;
10pub use sp1_prover::build::build_plonk_bn254_artifacts_with_dummy;
11
12/// Exports the solidity verifier for PLONK proofs to the specified output directory.
13///
14/// WARNING: If you are on development mode, this function assumes that the PLONK artifacts have
15/// already been built.
16pub fn export_solidity_plonk_bn254_verifier(output_dir: impl Into<PathBuf>) -> Result<()> {
17    let output_dir: PathBuf = output_dir.into();
18    let artifacts_dir = if sp1_prover::build::sp1_dev_mode() {
19        sp1_prover::build::plonk_bn254_artifacts_dev_dir()
20    } else {
21        try_install_circuit_artifacts("plonk")
22    };
23    let verifier_path = artifacts_dir.join("SP1VerifierPlonk.sol");
24
25    if !verifier_path.exists() {
26        return Err(anyhow::anyhow!("verifier file not found at {:?}", verifier_path));
27    }
28
29    std::fs::create_dir_all(&output_dir).context("Failed to create output directory.")?;
30    let output_path = output_dir.join("SP1VerifierPlonk.sol");
31    std::fs::copy(&verifier_path, &output_path).context("Failed to copy verifier file.")?;
32    tracing::info!(
33        "exported verifier from {} to {}",
34        verifier_path.display(),
35        output_path.display()
36    );
37
38    Ok(())
39}
40
41/// Exports the solidity verifier for Groth16 proofs to the specified output directory.
42///
43/// WARNING: If you are on development mode, this function assumes that the Groth16 artifacts have
44/// already been built.
45pub fn export_solidity_groth16_bn254_verifier(output_dir: impl Into<PathBuf>) -> Result<()> {
46    let output_dir: PathBuf = output_dir.into();
47    let artifacts_dir = if sp1_prover::build::sp1_dev_mode() {
48        sp1_prover::build::groth16_bn254_artifacts_dev_dir()
49    } else {
50        try_install_circuit_artifacts("groth16")
51    };
52    let verifier_path = artifacts_dir.join("SP1VerifierGroth16.sol");
53
54    if !verifier_path.exists() {
55        return Err(anyhow::anyhow!("verifier file not found at {:?}", verifier_path));
56    }
57
58    std::fs::create_dir_all(&output_dir).context("Failed to create output directory.")?;
59    let output_path = output_dir.join("SP1VerifierGroth16.sol");
60    std::fs::copy(&verifier_path, &output_path).context("Failed to copy verifier file.")?;
61    tracing::info!(
62        "exported verifier from {} to {}",
63        verifier_path.display(),
64        output_path.display()
65    );
66
67    Ok(())
68}