Skip to content

Commit

Permalink
feat: Introduce downloading from our AWS private bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
storojs72 committed Jun 18, 2024
1 parent c37602d commit 97477e8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
3 changes: 3 additions & 0 deletions aptos/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 aptos/solidity/contracts-generator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ path = "src/bin/main.rs"
[dependencies]
anyhow = "1.0.86"
log = "0.4.21"
home = "0.5.9"
tempfile = "3.9.0"
sphinx-sdk = { workspace = true }
sphinx-prover = { workspace = true }
79 changes: 76 additions & 3 deletions aptos/solidity/contracts-generator/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
use anyhow::Result;
use home::home_dir;
use log::info;
use sphinx_sdk::artifacts::try_install_plonk_bn254_artifacts;
use sphinx_sdk::utils::setup_logger;
use std::fs::create_dir_all;
use std::path::PathBuf;
use std::process::Command;

fn main() -> Result<()> {
setup_logger();

let artifacts_dir = try_install_plonk_bn254_artifacts();
// This should be replaced with
//
// `sphinx_sdk::artifacts::try_install_plonk_bn254_artifacts`
//
// once we can make our AWS bucket public
let artifacts_dir = download_artifacts_from_private_aws();

// Read all Solidity files from the artifacts_dir.
let sol_files = std::fs::read_dir(artifacts_dir)?
Expand All @@ -28,7 +35,73 @@ fn main() -> Result<()> {
)?;
}

info!("Contracts have been installed to: {:?}", contracts_src_dir);
info!(
"[contracts-generator] Contracts have been installed to: {:?}",
contracts_src_dir
);

Ok(())
}

fn plonk_bn254_artifacts_dir() -> PathBuf {
home_dir()
.unwrap()
.join(".sp1")
.join("circuits")
.join("plonk_bn254")
.join(sphinx_prover::install::PLONK_BN254_ARTIFACTS_COMMIT)
}

fn download_artifacts_from_private_aws() -> PathBuf {
let build_dir = plonk_bn254_artifacts_dir();
if build_dir.exists() {
info!(
"[contracts-generator] plonk bn254 artifacts already seem to exist at {}. if you want to re-download them, delete the directory",
build_dir.display()
);
} else {
info!(
"[contracts-generator] plonk bn254 artifacts for commit {} do not exist at {}. downloading...",
sphinx_prover::install::PLONK_BN254_ARTIFACTS_COMMIT,
build_dir.display()
);

create_dir_all(build_dir.clone()).unwrap();

let archive_path = format!("{}.tar.gz", build_dir.to_str().unwrap());
let mut res = Command::new("aws")
.args([
"s3",
"cp",
format!(
"s3://sphinx-plonk-params/{}.tar.gz",
sphinx_prover::install::PLONK_BN254_ARTIFACTS_COMMIT
)
.as_str(),
archive_path.as_str(),
])
.spawn()
.expect("couldn't run `aws` command. Probably it is not installed");
res.wait().unwrap();

// Extract the tarball to the build directory.
let mut res = Command::new("tar")
.args([
"-Pxzf",
archive_path.as_str(),
"-C",
build_dir.to_str().unwrap(),
])
.spawn()
.expect("failed to extract tarball");
res.wait().unwrap();

// Remove archive
let mut res = Command::new("rm")
.args(["-rf", archive_path.as_str()])
.spawn()
.expect("failed to remove the archive");
res.wait().unwrap();
}
build_dir
}

0 comments on commit 97477e8

Please sign in to comment.