Skip to content

Commit

Permalink
♻️ refactor types
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdelStark committed Jul 26, 2024
1 parent 517928d commit 0c4d90f
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 48 deletions.
3 changes: 1 addition & 2 deletions crates/cli/src/user_cli.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/db.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
41 changes: 39 additions & 2 deletions crates/core/src/dvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
}
}
}
}
1 change: 0 additions & 1 deletion crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ pub mod config;
pub mod db;
pub mod dvm;
pub mod prover_service;
pub mod types;
pub mod verifier_service;
2 changes: 1 addition & 1 deletion crates/core/src/prover_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
40 changes: 0 additions & 40 deletions crates/core/src/types.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/core/src/verifier_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down

0 comments on commit 0c4d90f

Please sign in to comment.