Skip to content

Commit

Permalink
clippy and format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-liu801 committed Jul 12, 2023
1 parent cc0e11a commit 5b16f91
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 45 deletions.
25 changes: 7 additions & 18 deletions fhe-debugger/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
use actix_web::{get, App, HttpResponse, HttpServer, Responder};
use petgraph::{
dot::Dot,
stable_graph::{EdgeReference, Edges, Neighbors, NodeIndex, StableGraph},
visit::{EdgeRef, IntoNodeIdentifiers},
Directed, Direction,
};
use serde::{Deserialize, Serialize};
use serde_json::{json, Deserializer, Serializer};

use sunscreen::{
fhe_program,
types::{bfv::Rational, bfv::Signed, Cipher},
Compiler, Error, Runtime,
};
use sunscreen_compiler_common::{
CompilationResult, Context, EdgeInfo, NodeInfo, Operation, Render,
Compiler, Error,
};
use sunscreen_fhe_program::FheProgram;

#[fhe_program(scheme = "bfv")]
fn simple_multiply(a: Cipher<Signed>, b: Cipher<Signed>) -> Cipher<Signed> {
Expand Down Expand Up @@ -49,7 +38,7 @@ fn complex_rational(
#[get("/rationaladd")]
async fn rational_add_handler() -> impl Responder {
match process_rational_add().await {
Ok(result) => HttpResponse::Ok().body(format!("{}", result)),
Ok(result) => HttpResponse::Ok().body(result),
Err(err) => {
eprintln!("Error: {:?}", err);
HttpResponse::InternalServerError().finish()
Expand All @@ -60,7 +49,7 @@ async fn rational_add_handler() -> impl Responder {
#[get("/rationalmul")]
async fn rational_mul_handler() -> impl Responder {
match process_rational_mul().await {
Ok(result) => HttpResponse::Ok().body(format!("{}", result)),
Ok(result) => HttpResponse::Ok().body(result),
Err(err) => {
eprintln!("Error: {:?}", err);
HttpResponse::InternalServerError().finish()
Expand All @@ -71,7 +60,7 @@ async fn rational_mul_handler() -> impl Responder {
#[get("/rationalcomplex")]
async fn rational_complex_handler() -> impl Responder {
match process_rational_complex().await {
Ok(result) => HttpResponse::Ok().body(format!("{}", result)),
Ok(result) => HttpResponse::Ok().body(result),
Err(err) => {
eprintln!("Error: {:?}", err);
HttpResponse::InternalServerError().finish()
Expand All @@ -82,7 +71,7 @@ async fn rational_complex_handler() -> impl Responder {
#[get("/multiply")]
async fn multiply_handler() -> impl Responder {
match process_multiply().await {
Ok(result) => HttpResponse::Ok().body(format!("{}", result)),
Ok(result) => HttpResponse::Ok().body(result),
Err(err) => {
eprintln!("Error: {:?}", err);
HttpResponse::InternalServerError().finish()
Expand All @@ -93,7 +82,7 @@ async fn multiply_handler() -> impl Responder {
#[get("/add")]
async fn add_handler() -> impl Responder {
match process_add().await {
Ok(result) => HttpResponse::Ok().body(format!("{}", result)),
Ok(result) => HttpResponse::Ok().body(result),
Err(err) => {
eprintln!("Error: {:?}", err);
HttpResponse::InternalServerError().finish()
Expand Down
2 changes: 1 addition & 1 deletion sunscreen_backend/src/noise_model/measured_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ impl MeasuredModel {
&evaluator,
&relin_keys.as_ref(),
&galois_keys.as_ref(),
Some(&private_key)
Some(&private_key),
)
}?;

Expand Down
13 changes: 5 additions & 8 deletions sunscreen_compiler_common/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use petgraph::Graph;
use serde::{Deserialize, Serialize};

use crate::{Operation, Render};
use radix_trie::Trie;

/**
* Stores information about the nodes associated with a certain operation.
Expand Down Expand Up @@ -95,7 +94,7 @@ where
*/
pub fn new(operation: O, #[cfg(feature = "debugger")] id: u64) -> Self {
Self {
operation: operation,
operation,
#[cfg(feature = "debugger")]
group_id: id,
}
Expand Down Expand Up @@ -289,11 +288,10 @@ where
* Create a new [`CompilationResult`]
*/
pub fn new() -> Self {

Self {
graph: StableGraph::new(),
#[cfg(feature = "debugger")]
metadata: DebugData::new()
metadata: DebugData::new(),
}
}
}
Expand Down Expand Up @@ -353,9 +351,9 @@ where
Self {
graph: CompilationResult::<O>::new(),
data,
#[cfg(feature = "debugger")]
#[cfg(feature = "debugger")]
group_stack: Vec::new(),
#[cfg(feature = "debugger")]
#[cfg(feature = "debugger")]
group_counter: 0,
}
}
Expand All @@ -370,9 +368,8 @@ where
self.graph.add_node(NodeInfo {
operation,
#[cfg(feature = "debugger")]
group_id
group_id,
})

}

/**
Expand Down
44 changes: 33 additions & 11 deletions sunscreen_runtime/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;

use seal_fhe::{
Ciphertext, Error as SealError, Evaluator, GaloisKeys, Plaintext, RelinearizationKeys, SecretKey,
Ciphertext, Error as SealError, Evaluator, GaloisKeys, Plaintext, RelinearizationKeys,
SecretKey,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)]
Expand Down Expand Up @@ -93,7 +94,7 @@ pub struct DebugInfo<'a> {
/**
* The name of the debugger session.
*/
pub session_name: String
pub session_name: String,
}

/**
Expand All @@ -118,7 +119,7 @@ pub unsafe fn run_program_unchecked<E: Evaluator + Sync + Send>(
evaluator: &E,
relin_keys: &Option<&RelinearizationKeys>,
galois_keys: &Option<&GaloisKeys>,
secret_key: Option<&SecretKey>,
_secret_key: Option<&SecretKey>,
) -> Result<Vec<Ciphertext>, FheProgramRunFailure> {
fn get_data(
data: &[AtomicCell<Option<Arc<SealData>>>],
Expand Down Expand Up @@ -634,8 +635,15 @@ mod tests {
let ct_1 = encryptor.encrypt(&pt_1).unwrap();

let output = unsafe {
run_program_unchecked(&ir, &[ct_0.into(), ct_1.into()], &evaluator, &None, &None, Some(&private_key))
.unwrap()
run_program_unchecked(
&ir,
&[ct_0.into(), ct_1.into()],
&evaluator,
&None,
&None,
Some(&private_key),
)
.unwrap()
};

assert_eq!(output.len(), 1);
Expand Down Expand Up @@ -730,7 +738,7 @@ mod tests {
&evaluator,
&Some(&relin_keys),
&None,
Some(&private_key)
Some(&private_key),
)
.unwrap()
};
Expand Down Expand Up @@ -794,7 +802,7 @@ mod tests {
&evaluator,
&Some(&relin_keys),
&None,
Some(&private_key)
Some(&private_key),
)
.unwrap()
};
Expand Down Expand Up @@ -835,8 +843,15 @@ mod tests {
let ct_0 = encryptor.encrypt(&pt_0).unwrap();

let output = unsafe {
run_program_unchecked(&ir, &[ct_0.into()], &evaluator, &None, &Some(&galois_keys), Some(&private_key))
.unwrap()
run_program_unchecked(
&ir,
&[ct_0.into()],
&evaluator,
&None,
&Some(&galois_keys),
Some(&private_key),
)
.unwrap()
};

assert_eq!(output.len(), 1);
Expand Down Expand Up @@ -880,8 +895,15 @@ mod tests {
let ct_0 = encryptor.encrypt(&pt_0).unwrap();

let output = unsafe {
run_program_unchecked(&ir, &[ct_0.into()], &evaluator, &None, &Some(&galois_keys), Some(&private_key))
.unwrap()
run_program_unchecked(
&ir,
&[ct_0.into()],
&evaluator,
&None,
&Some(&galois_keys),
Some(&private_key),
)
.unwrap()
};

assert_eq!(output.len(), 1);
Expand Down
14 changes: 7 additions & 7 deletions sunscreen_runtime/src/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::marker::PhantomData;
use std::time::Instant;

use crate::DebugInfo;
use crate::error::*;
use crate::metadata::*;
use crate::DebugInfo;
use crate::ZkpProgramInput;
use crate::{
run_program_unchecked, serialization::WithContext, Ciphertext, FheProgramInput,
Expand Down Expand Up @@ -265,7 +265,7 @@ where
fhe_program: &CompiledFheProgram,
mut arguments: Vec<I>,
public_key: &PublicKey,
dbg_info: Option<DebugInfo>
dbg_info: Option<DebugInfo>,
) -> Result<Vec<Ciphertext>>
where
I: Into<FheProgramInput>,
Expand Down Expand Up @@ -351,7 +351,7 @@ where
let galois_key = public_key.galois_key.as_ref().map(|p| &p.data);
let sec_key: Option<&SecretKey> = match dbg_info {
Some(dbg_info) => Some(dbg_info.secret_key),
None => None
None => None,
};

let mut raw_ciphertexts = unsafe {
Expand Down Expand Up @@ -399,7 +399,7 @@ where
pub fn run<I>(
&self,
fhe_program: &CompiledFheProgram,
mut arguments: Vec<I>,
arguments: Vec<I>,
public_key: &PublicKey,
) -> Result<Vec<Ciphertext>>
where
Expand All @@ -414,11 +414,11 @@ where
pub fn debug_fhe_program<I>(
&self,
fhe_program: &CompiledFheProgram,
mut arguments: Vec<I>,
arguments: Vec<I>,
public_key: &PublicKey,
dbg_info: Option<DebugInfo>
dbg_info: Option<DebugInfo>,
) -> Result<Vec<Ciphertext>>
where
where
I: Into<FheProgramInput>,
{
self.run_impl(fhe_program, arguments, public_key, dbg_info)
Expand Down

0 comments on commit 5b16f91

Please sign in to comment.