Skip to content

Commit

Permalink
SHARP smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
unstark committed May 18, 2024
1 parent eae8505 commit f4a4e65
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 7 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ authors = ["Apoorv Sadana <@apoorvsadana>"]

[workspace.dependencies]
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "7373f6db761d5a19888e3a0c527e8a3ca31e7a1e" }
alloy-primitives = "0.7.4"
async-trait = "0.1.77"
axum = { version = "0.7.4" }
axum-macros = "0.4.1"
Expand Down
4 changes: 4 additions & 0 deletions crates/prover_services/sharp_service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ edition.workspace = true

[dependencies]
alloy.workspace = true
alloy-primitives.workspace = true
async-trait.workspace = true
uuid.workspace = true
serde.workspace = true
Expand All @@ -18,3 +19,6 @@ utils.workspace = true
thiserror.workspace = true
hex.workspace = true
url.workspace = true

[dev-dependencies]
tokio.workspace = true
Binary file not shown.
Binary file not shown.
12 changes: 7 additions & 5 deletions crates/prover_services/sharp_service/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@ use uuid::Uuid;

use crate::error::SharpError;

/// SHARP endpoint for Sepolia testnet
pub const DEFAULT_SHARP_URL: &str = "https://testnet.provingservice.io";

/// SHARP API async wrapper
pub struct SharpClient {
url: Url,
base_url: Url,
client: reqwest::Client,
}

impl SharpClient {
pub fn new(url: Url) -> Self {
Self { url, client: reqwest::Client::new() }
Self { base_url: url, client: reqwest::Client::new() }
}

pub async fn add_job(&self, encoded_pie: &str) -> Result<CairoJobResponse, SharpError> {
let data = json!({ "action": "add_job", "request": { "cairo_pie": encoded_pie } });
let res = self.client.post(self.url.clone()).json(&data).send().await.map_err(SharpError::AddJobFailure)?;
let url = self.base_url.join("add_job").unwrap();
let res = self.client.post(url).json(&data).send().await.map_err(SharpError::AddJobFailure)?;

match res.status() {
reqwest::StatusCode::OK => res.json().await.map_err(SharpError::AddJobFailure),
Expand All @@ -30,8 +32,8 @@ impl SharpClient {

pub async fn get_job_status(&self, job_key: &Uuid) -> Result<CairoStatusResponse, SharpError> {
let data = json!({ "action": "get_status", "request": { "cairo_job_key": job_key } });
let res =
self.client.post(self.url.clone()).json(&data).send().await.map_err(SharpError::GetJobStatusFailure)?;
let url = self.base_url.join("get_status").unwrap();
let res = self.client.post(url).json(&data).send().await.map_err(SharpError::GetJobStatusFailure)?;

match res.status() {
reqwest::StatusCode::OK => res.json().await.map_err(SharpError::GetJobStatusFailure),
Expand Down
4 changes: 3 additions & 1 deletion crates/prover_services/sharp_service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use alloy::primitives::Address;
use serde::{Deserialize, Serialize};
use url::Url;

use crate::client::DEFAULT_SHARP_URL;

/// SHARP proving service configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SharpConfig {
Expand All @@ -17,7 +19,7 @@ impl Default for SharpConfig {
/// Default config for Sepolia testnet
fn default() -> Self {
Self {
service_url: "https://testnet.provingservice.io".parse().unwrap(),
service_url: DEFAULT_SHARP_URL.parse().unwrap(),
rpc_node_url: "https://sepolia.drpc.org".parse().unwrap(),
verifier_address: "0x07ec0D28e50322Eb0C159B9090ecF3aeA8346DFe".parse().unwrap(),
}
Expand Down
2 changes: 1 addition & 1 deletion crates/prover_services/sharp_service/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::hex::FromHexError;
use gps_fact_checker::error::FactCheckerError;
use hex::FromHexError;
use prover_service::ProverServiceError;
use reqwest::StatusCode;

Expand Down
42 changes: 42 additions & 0 deletions crates/prover_services/sharp_service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,45 @@ pub fn split_task_id(task_id: &TaskId) -> Result<(Uuid, B256), SharpError> {
let fact = B256::from_str(fact_str).map_err(SharpError::FactParse)?;
Ok((job_key, fact))
}

#[cfg(test)]
mod tests {
use std::{path::PathBuf, time::Duration};

use cairo_vm::vm::runners::cairo_pie::CairoPie;
use prover_service::{ProverService, Task, TaskStatus};
use utils::settings::default::DefaultSettingsProvider;

use crate::SharpProverService;

/// DO NOT RUN THIS TEST IN CI PIPELINE
#[ignore]
#[tokio::test]
async fn sharp_smoke_test() {
let sharp_service = SharpProverService::with_settings(&DefaultSettingsProvider {});
let cairo_pie_path: PathBuf =
[env!("CARGO_MANIFEST_DIR"), "src", "artifacts", "fibonacci.zip"].iter().collect();
let cairo_pie = CairoPie::read_zip_file(&cairo_pie_path).unwrap();
// Submit task to the testnet prover
let task_id = sharp_service.submit_task(Task::CairoPie(cairo_pie)).await.unwrap();
println!("SHARP: task {} submitted", task_id);
for attempt in 0..10 {
tokio::time::sleep(Duration::from_millis((attempt + 1) * 1000)).await;
match sharp_service.get_task_status(&task_id).await.unwrap() {
TaskStatus::Failed(err) => {
println!("SHARP: task failed with {}", err);
panic!("{:#?}", err);
}
TaskStatus::Processing => {
println!("SHARP: task is processing (attempt {})", attempt);
continue;
}
TaskStatus::Succeeded => {
println!("SHARP: task is completed");
return;
}
}
}
panic!("SHARP: timeout");
}
}

0 comments on commit f4a4e65

Please sign in to comment.