diff --git a/Makefile.toml b/Makefile.toml deleted file mode 100644 index 07962d6..0000000 --- a/Makefile.toml +++ /dev/null @@ -1,62 +0,0 @@ -[config] -min_version = "0.32.0" - -[env] -RUST_BACKTRACE = "1" -CARGO_INCREMENTAL = "0" - -[tasks.setupCairo] -description = "Installing dependencies and tools" -script_runner = "sh" -script = [ - "echo Installing the Cairo program...", - "cargo install --git https://github.com/cartridge-gg/stone-prover.git --branch docker/both-cairo-versions cairo1-compile", -] -category = "Setup" - - -[tasks.setupCairoZero] -description = "Install dependencies or tools from a local path" -script_runner = "sh" -script = ["sh scripts/0-venv.sh"] - - -[tasks.compileCairoZero] -description = "Compiling the CairoZero program" -script = ["echo Compiling the CairoZero program...", "sh scripts/1-compile.sh"] - - -[tasks.compileCairo] -script_runner = "sh" -script = [ - "echo Compiling the Cairo program...", - "mkdir -p resources", - "cairo1-compile compile examples/Cairo/fibonacci.cairo > resources/fibonacci_compiled.json", -] - - -[tasks.mergeCairo] -script_runner = "sh" -script = [ - "echo Merging the Cairo program...", - "cairo1-compile merge -o examples/Cairo/prover_input.json resources/fibonacci_compiled.json examples/Cairo/input.json", - "rm resources/fibonacci_compiled.json", -] - - -[tasks.mergeCairoZero] -script_runner = "sh" -script = [ - "echo Merging the CairoZero program...", - "sh scripts/2-merge.sh", - "rm resources/fibonacci_compiled.json", -] - -[tasks.prepareCairo] -dependencies = ["setupCairo", "compileCairo", "mergeCairo"] -workspace = false - - -[tasks.prepareCairoZero] -dependencies = ["setupCairoZero", "compileCairoZero", "mergeCairoZero"] -workspace = false diff --git a/bin/register/README.md b/bin/register/README.md index 9bd91e1..d89dcde 100644 --- a/bin/register/README.md +++ b/bin/register/README.md @@ -12,11 +12,11 @@ This project provides a command-line tool for registering new keys with the Prov ## Installation ```bash -cargo install --git https://github.com/chudkowsky/http_prover_refactored.git register +cargo install --git https://github.com/cartridge-gg/http-prover.git register ``` or alternatively ```bash -git clone https://github.com/chudkowsky/http_prover_refactored.git +git clone https://github.com/cartridge-gg/http-prover.git cargo build cargo run -p register ``` diff --git a/bin/register/src/main.rs b/bin/register/src/main.rs index c43d402..8751b30 100644 --- a/bin/register/src/main.rs +++ b/bin/register/src/main.rs @@ -1,6 +1,6 @@ use clap::{arg, Parser}; use ed25519_dalek::VerifyingKey; -use prover_sdk::{access_key::ProverAccessKey, sdk::ProverSDK}; +use prover_sdk::{access_key::ProverAccessKey, errors::SdkErrors, sdk::ProverSDK}; use url::Url; /// Command line arguments for the server @@ -18,17 +18,19 @@ pub struct Args { } #[tokio::main] -async fn main() { +async fn main() -> Result<(), SdkErrors> { let args = Args::parse(); - let key = ProverAccessKey::from_hex_string(&args.private_key).unwrap(); + let key = + ProverAccessKey::from_hex_string(&args.private_key).map_err(|_| SdkErrors::InvalidKey)?; let mut sdk = ProverSDK::new(args.url, key) .await .expect("Failed to create SDK instance"); - let bytes: [u8; 32] = prefix_hex::decode(&args.added_key).unwrap(); - let added_key = VerifyingKey::from_bytes(&bytes).unwrap(); + let bytes: [u8; 32] = + prefix_hex::decode(&args.added_key).map_err(|e| SdkErrors::PrefixError(e.to_string()))?; + let added_key = VerifyingKey::from_bytes(&bytes).map_err(|_| SdkErrors::InvalidKey)?; - sdk.register(added_key).await.unwrap(); + sdk.register(added_key).await } diff --git a/common/src/models.rs b/common/src/models.rs index ed55bc0..8227c53 100644 --- a/common/src/models.rs +++ b/common/src/models.rs @@ -16,4 +16,5 @@ pub enum JobStatus { Running, Completed, Failed, + Unknown, } diff --git a/prover-sdk/README.md b/prover-sdk/README.md index 1a568e8..0f06eb3 100644 --- a/prover-sdk/README.md +++ b/prover-sdk/README.md @@ -54,7 +54,7 @@ Authenticate with the Prover service using your private key and the authenticati async fn main() -> Result<(), ProverSdkErrors> { let private_key_hex : String= env::var("PRIVATE_KEY")?; let url_auth = "http://localhost:3000/auth"; - let url_prover = "http://localhost:3000/prove/cairo1"; + let url_prover = "http://localhost:3000/prove/cairo"; let result = ProverSDK::new(url_auth, url_prover) .auth(&private_key_hex) diff --git a/prover-sdk/src/errors.rs b/prover-sdk/src/errors.rs index f8b2e82..a1317ae 100644 --- a/prover-sdk/src/errors.rs +++ b/prover-sdk/src/errors.rs @@ -30,4 +30,6 @@ pub enum SdkErrors { RegisterResponseError(String), #[error("SSE error: {0}")] SSEError(String), + #[error("Invalid key")] + InvalidKey, } diff --git a/prover/README.md b/prover/README.md index 4134342..d7a8371 100644 --- a/prover/README.md +++ b/prover/README.md @@ -8,7 +8,7 @@ The Cairo Proving Server is the core component responsible for managing and veri Here is an example of running the server with custom settings: ```sh -cairo-prover-server --host 127.0.0.1 --port 8080 --message-expiration-time 7200 --session-expiration-time 14400 --jwt-secret-key "my_super_secret_key" --authorized-keys-path /path/to/authorized_keys.json --authorized-keys "key1,key2,key3" --num-workers 8 --admin-key "admin_super_secret_key" +cairo-prover-server --host 127.0.0.1 --port 8080 --message-expiration-time 7200 --session-expiration-time 14400 --jwt-secret-key "my_super_secret_key" --authorized-keys-path /path/to/authorized_keys.json --authorized-keys key1,key2,key3 --num-workers 8 --admin-key "admin_super_secret_key" ``` ## Command-Line Options diff --git a/prover/src/errors.rs b/prover/src/errors.rs index 7d36f67..ca245cd 100644 --- a/prover/src/errors.rs +++ b/prover/src/errors.rs @@ -32,12 +32,19 @@ pub enum ProverError { AddressParse(#[from] AddrParseError), #[error(transparent)] KeyError(#[from] ed25519_dalek::SignatureError), + #[error("Failed to send message via SSE{0}")] + SseError(String), } impl From> for ProverError { fn from(err: SendError) -> ProverError { ProverError::SendError(err.to_string()) } } +impl From> for ProverError { + fn from(err: Vec) -> Self { + ProverError::Authorizer(AuthorizerError::DataError(err)) + } +} impl IntoResponse for ProverError { fn into_response(self) -> Response { let (status, error_message) = match &self { @@ -73,6 +80,7 @@ impl IntoResponse for ProverError { }, ProverError::AddressParse(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), ProverError::KeyError(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), + ProverError::SseError(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()), }; let body = Json(json!({ "error": error_message })); diff --git a/prover/src/server.rs b/prover/src/server.rs index c7d9558..307fd1b 100644 --- a/prover/src/server.rs +++ b/prover/src/server.rs @@ -52,13 +52,13 @@ pub async fn start(args: Args) -> Result<(), ProverError> { let admin_key_bytes = prefix_hex::decode::>(args.admin_key) .map_err(|e| AuthorizerError::PrefixHexConversionError(e.to_string()))?; - let admin_key = VerifyingKey::from_bytes(&admin_key_bytes.try_into().unwrap())?; + let admin_key = VerifyingKey::from_bytes(&admin_key_bytes.try_into()?)?; authorizer.authorize(admin_key).await?; for key in args.authorized_keys.iter() { let verifying_key_bytes = prefix_hex::decode::>(key) .map_err(|e| AuthorizerError::PrefixHexConversionError(e.to_string()))?; - let verifying_key = VerifyingKey::from_bytes(&verifying_key_bytes.try_into().unwrap())?; + let verifying_key = VerifyingKey::from_bytes(&verifying_key_bytes.try_into()?)?; authorizer.authorize(verifying_key).await?; } let (sse_tx, _) = broadcast::channel(100); diff --git a/prover/src/sse.rs b/prover/src/sse.rs index ffe46d7..4fb1868 100644 --- a/prover/src/sse.rs +++ b/prover/src/sse.rs @@ -28,11 +28,12 @@ pub async fn sse_handler( jobs.iter() .find(|job| job.id == job_id) .map(|job| job.status.clone()) + .unwrap_or(JobStatus::Unknown) }; let stream = stream! { - if job_status.is_some() && matches!(job_status.clone().unwrap(), JobStatus::Completed | JobStatus::Failed) { - yield Ok(axum::response::sse::Event::default().data(serde_json::to_string(&(job_status.unwrap(), job_id)).unwrap())); + if matches!(job_status.clone(), JobStatus::Completed | JobStatus::Failed) { + yield Ok(axum::response::sse::Event::default().data(serde_json::to_string(&(job_status, job_id)).unwrap())); return; } while let Ok(message) = rx.recv().await { diff --git a/prover/src/utils/job.rs b/prover/src/utils/job.rs index 54cfa5a..7b6345d 100644 --- a/prover/src/utils/job.rs +++ b/prover/src/utils/job.rs @@ -88,6 +88,12 @@ pub async fn get_job( .unwrap_or_else(|| "Unknown error".to_string()), }), ), + _ => ( + StatusCode::INTERNAL_SERVER_ERROR, + Json(JobResponse::Failed { + error: "Unknown error".to_string(), + }), + ), }; (status, response).into_response() } else { diff --git a/prover/src/verifier.rs b/prover/src/verifier.rs index 49d1e6d..d1315b8 100644 --- a/prover/src/verifier.rs +++ b/prover/src/verifier.rs @@ -74,7 +74,7 @@ pub async fn verify_proof( if sender.receiver_count() > 0 { sender .send(serde_json::to_string(&(JobStatus::Completed, job_id))?) - .unwrap(); + .map_err(|e| ProverError::SseError(e.to_string()))?; } Ok(()) }