From 0c4d90f8c9eb6d011892655a67bc33b13d0be8ea Mon Sep 17 00:00:00 2001 From: "Abdel @ StarkWare" Date: Fri, 26 Jul 2024 16:15:47 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor=20types?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/cli/src/user_cli.rs | 3 +-- crates/core/src/db.rs | 2 +- crates/core/src/dvm/mod.rs | 41 +++++++++++++++++++++++++++-- crates/core/src/lib.rs | 1 - crates/core/src/prover_service.rs | 2 +- crates/core/src/types.rs | 40 ---------------------------- crates/core/src/verifier_service.rs | 2 +- 7 files changed, 43 insertions(+), 48 deletions(-) delete mode 100644 crates/core/src/types.rs diff --git a/crates/cli/src/user_cli.rs b/crates/cli/src/user_cli.rs index 176d9c9..a18aa6a 100644 --- a/crates/cli/src/user_cli.rs +++ b/crates/cli/src/user_cli.rs @@ -1,7 +1,6 @@ use askeladd::config::Settings; use askeladd::dvm::customer::Customer; -use askeladd::dvm::types::GenerateZKPJobRequest; -use askeladd::types::FibonnacciProvingRequest; +use askeladd::dvm::types::{FibonnacciProvingRequest, GenerateZKPJobRequest}; use dotenv::dotenv; use log::info; diff --git a/crates/core/src/db.rs b/crates/core/src/db.rs index f898889..3f70bb7 100644 --- a/crates/core/src/db.rs +++ b/crates/core/src/db.rs @@ -1,6 +1,6 @@ use rusqlite::{params, Connection, Result}; -use crate::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; +use crate::dvm::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; pub struct Database { conn: Connection, diff --git a/crates/core/src/dvm/mod.rs b/crates/core/src/dvm/mod.rs index 541581d..97280f7 100644 --- a/crates/core/src/dvm/mod.rs +++ b/crates/core/src/dvm/mod.rs @@ -13,10 +13,9 @@ pub mod constants { pub mod types { use serde::{Deserialize, Serialize}; + use stwo_prover::core::prover::StarkProof; use uuid::Uuid; - use crate::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; - #[derive(Debug, Serialize, Deserialize, Clone)] pub struct GenerateZKPJobRequest { pub job_id: String, @@ -48,4 +47,42 @@ pub mod types { pub job_id: String, pub response: FibonnacciProvingResponse, } + + #[derive(Debug, Serialize, Deserialize, Clone)] + pub struct FibonnacciProvingRequest { + pub log_size: u32, + pub claim: u32, + } + + #[derive(Debug, Serialize, Deserialize)] + pub struct FibonnacciProvingResponse { + pub log_size: u32, + pub claim: u32, + pub proof: StarkProof, + } + + impl FibonnacciProvingResponse { + pub fn new(log_size: u32, claim: u32, proof: StarkProof) -> Self { + Self { + log_size, + claim, + proof, + } + } + } + + impl Clone for FibonnacciProvingResponse { + fn clone(&self) -> Self { + // Temporarily use serde for a dirty clone + // TODO: Implement a proper clone or find a better design that does not require cloning + // the proof + let proof_json = serde_json::to_string(&self.proof).unwrap(); + let proof = serde_json::from_str(&proof_json).unwrap(); + Self { + log_size: self.log_size, + claim: self.claim, + proof, + } + } + } } diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 4e91b3b..c11aedd 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -2,5 +2,4 @@ pub mod config; pub mod db; pub mod dvm; pub mod prover_service; -pub mod types; pub mod verifier_service; diff --git a/crates/core/src/prover_service.rs b/crates/core/src/prover_service.rs index 6da6e2a..d83281d 100644 --- a/crates/core/src/prover_service.rs +++ b/crates/core/src/prover_service.rs @@ -2,7 +2,7 @@ use stwo_prover::core::fields::m31::BaseField; use stwo_prover::core::prover::ProvingError; use stwo_prover::examples::fibonacci::Fibonacci; -use crate::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; +use crate::dvm::types::{FibonnacciProvingRequest, FibonnacciProvingResponse}; #[derive(Debug, Default)] pub struct ProverService {} diff --git a/crates/core/src/types.rs b/crates/core/src/types.rs deleted file mode 100644 index e056d05..0000000 --- a/crates/core/src/types.rs +++ /dev/null @@ -1,40 +0,0 @@ -use serde::{Deserialize, Serialize}; -use stwo_prover::core::prover::StarkProof; - -#[derive(Debug, Serialize, Deserialize, Clone)] -pub struct FibonnacciProvingRequest { - pub log_size: u32, - pub claim: u32, -} - -#[derive(Debug, Serialize, Deserialize)] -pub struct FibonnacciProvingResponse { - pub log_size: u32, - pub claim: u32, - pub proof: StarkProof, -} - -impl FibonnacciProvingResponse { - pub fn new(log_size: u32, claim: u32, proof: StarkProof) -> Self { - Self { - log_size, - claim, - proof, - } - } -} - -impl Clone for FibonnacciProvingResponse { - fn clone(&self) -> Self { - // Temporarily use serde for a dirty clone - // TODO: Implement a proper clone or find a better design that does not require cloning the - // proof - let proof_json = serde_json::to_string(&self.proof).unwrap(); - let proof = serde_json::from_str(&proof_json).unwrap(); - Self { - log_size: self.log_size, - claim: self.claim, - proof, - } - } -} diff --git a/crates/core/src/verifier_service.rs b/crates/core/src/verifier_service.rs index 7b4e007..c2e5671 100644 --- a/crates/core/src/verifier_service.rs +++ b/crates/core/src/verifier_service.rs @@ -2,7 +2,7 @@ use stwo_prover::core::fields::m31::BaseField; use stwo_prover::core::prover::VerificationError; use stwo_prover::examples::fibonacci::Fibonacci; -use crate::types::FibonnacciProvingResponse; +use crate::dvm::types::FibonnacciProvingResponse; #[derive(Debug, Default)] pub struct VerifierService {}