diff --git a/prover/src/build.rs b/prover/src/build.rs index 6d3078577..0fc7c51b1 100644 --- a/prover/src/build.rs +++ b/prover/src/build.rs @@ -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() { @@ -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 } diff --git a/prover/src/install.rs b/prover/src/install.rs index 50c1b1054..dd9a9ae71 100644 --- a/prover/src/install.rs +++ b/prover/src/install.rs @@ -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"; @@ -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"); @@ -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") @@ -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(()) +} diff --git a/sdk/src/artifacts.rs b/sdk/src/artifacts.rs index 4b0e9df80..81c4376d0 100644 --- a/sdk/src/artifacts.rs +++ b/sdk/src/artifacts.rs @@ -17,7 +17,7 @@ pub fn export_solidity_plonk_bn254_verifier(output_dir: impl Into) -> 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"); diff --git a/sdk/src/provers/local.rs b/sdk/src/provers/local.rs index da8ce2438..4d5cb53b5 100644 --- a/sdk/src/provers/local.rs +++ b/sdk/src/provers/local.rs @@ -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 { diff --git a/sdk/src/provers/mod.rs b/sdk/src/provers/mod.rs index fad3c6292..565ef5527 100644 --- a/sdk/src/provers/mod.rs +++ b/sdk/src/provers/mod.rs @@ -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,