Skip to content

Commit

Permalink
feat: Incorporate downloading using AWS cli
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed Jun 20, 2024
1 parent 317414f commit 092e842
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 16 deletions.
4 changes: 2 additions & 2 deletions prover/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::utils::{babybear_bytes_to_bn254, babybears_to_bn254, words_to_bytes};
use crate::{OuterSC, SphinxProver};

/// Tries to install the PLONK artifacts if they are not already installed.
pub fn try_install_plonk_bn254_artifacts() -> PathBuf {
pub fn try_install_plonk_bn254_artifacts(use_aws_cli: bool) -> PathBuf {
let build_dir = plonk_bn254_artifacts_dir();

if build_dir.exists() {
Expand All @@ -31,7 +31,7 @@ pub fn try_install_plonk_bn254_artifacts() -> PathBuf {
PLONK_BN254_ARTIFACTS_COMMIT,
build_dir.display()
);
install_plonk_bn254_artifacts(&build_dir);
install_plonk_bn254_artifacts(&build_dir, use_aws_cli);
}
build_dir
}
Expand Down
42 changes: 31 additions & 11 deletions prover/src/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use reqwest::Client;
use crate::utils::block_on;

/// The base URL for the S3 bucket containing the plonk bn254 artifacts.
pub const PLONK_BN254_ARTIFACTS_URL_BASE: &str = "https://sp1-circuits.s3-us-east-2.amazonaws.com";
pub const PLONK_BN254_ARTIFACTS_URL_BASE: &str = "s3://sphinx-plonk-params";

/// The current version of the plonk bn254 artifacts.
pub const PLONK_BN254_ARTIFACTS_COMMIT: &str = "4a525e9f";
Expand All @@ -21,7 +21,7 @@ pub const PLONK_BN254_ARTIFACTS_COMMIT: &str = "4a525e9f";
///
/// This function will download the latest plonk bn254 artifacts from the S3 bucket and extract them to
/// the directory specified by [plonk_bn254_artifacts_dir()].
pub fn install_plonk_bn254_artifacts(build_dir: &Path) {
pub fn install_plonk_bn254_artifacts(build_dir: &Path, use_aws_cli: bool) {
// Create the build directory.
std::fs::create_dir_all(build_dir).expect("failed to create build directory");

Expand All @@ -32,15 +32,21 @@ pub fn install_plonk_bn254_artifacts(build_dir: &Path) {
);
let mut artifacts_tar_gz_file =
tempfile::NamedTempFile::new().expect("failed to create tempfile");
let client = Client::builder()
.build()
.expect("failed to create reqwest client");
block_on(download_file(
&client,
&download_url,
&mut artifacts_tar_gz_file,
))
.expect("failed to download file");

if use_aws_cli {
block_on(download_file_aws(&download_url, &mut artifacts_tar_gz_file))
.expect("failed to download file [aws]");
} else {
let client = Client::builder()
.build()
.expect("failed to create reqwest client");
block_on(download_file(
&client,
&download_url,
&mut artifacts_tar_gz_file,
))
.expect("failed to download file");
}

// Extract the tarball to the build directory.
let mut res = Command::new("tar")
Expand Down Expand Up @@ -106,3 +112,17 @@ pub async fn download_file(

Ok(())
}

/// Download the file using the AWS cli
pub async fn download_file_aws(
url: &str,
file: &mut tempfile::NamedTempFile,
) -> Result<(), String> {
let mut res = Command::new("aws")
.args(["s3", "cp", url, file.path().to_str().unwrap()])
.spawn()
.expect("couldn't run `aws` command. Probably it is not installed / configured");
res.wait().unwrap();

Ok(())
}
2 changes: 1 addition & 1 deletion sdk/src/artifacts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub fn export_solidity_plonk_bn254_verifier(output_dir: impl Into<PathBuf>) -> R
let artifacts_dir = if sphinx_prover::build::sphinx_dev_mode() {
sphinx_prover::build::plonk_bn254_artifacts_dev_dir()
} else {
try_install_plonk_bn254_artifacts()
try_install_plonk_bn254_artifacts(true)
};
let verifier_path = artifacts_dir.join("SP1Verifier.sol");

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/provers/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl Prover for LocalProver {
&outer_proof.proof,
)
} else {
sphinx_prover::build::try_install_plonk_bn254_artifacts()
sphinx_prover::build::try_install_plonk_bn254_artifacts(true)
};
let proof = self.prover.wrap_plonk_bn254(outer_proof, &plonk_bn254_aritfacts);
Ok(SphinxProofWithPublicValues {
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/provers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub trait Prover: Send + Sync {
let plonk_bn254_aritfacts = if sphinx_prover::build::sphinx_dev_mode() {
sphinx_prover::build::plonk_bn254_artifacts_dev_dir()
} else {
sphinx_prover::build::try_install_plonk_bn254_artifacts()
sphinx_prover::build::try_install_plonk_bn254_artifacts(true)
};
sphinx_prover.verify_plonk_bn254(
&proof.proof,
Expand Down

0 comments on commit 092e842

Please sign in to comment.