Skip to content

Commit

Permalink
attempt to support other field
Browse files Browse the repository at this point in the history
  • Loading branch information
quackzar committed Aug 19, 2024
1 parent 5d44702 commit e20f2bb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pycare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn preproc(number_of_shares: usize, paths_to_pre: &Bound<'_, PyTuple>) {
.map(|x| x.extract::<String>().unwrap())
.map(|p| File::create(p).unwrap())
.collect();
do_preproc(&mut files, vec![number_of_shares, number_of_shares]);
do_preproc(&mut files, vec![number_of_shares, number_of_shares], false);
}

#[pymethods]
Expand Down
4 changes: 1 addition & 3 deletions src/algebra/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Here we have a prime field that is very close to 2^32.
use ff::{
derive::subtle::{Choice, ConditionallySelectable, ConstantTimeEq},
PrimeField,
Field, PrimeField,
};
use rand::Rng;

Expand Down Expand Up @@ -88,8 +88,6 @@ pub struct Mod11(pub(crate) u8);
use overload::overload;
use std::ops;

use crate::algebra::field::Field;

// Now instead of three implementations for each we just have one!
overload!((a: ?Mod11) + (b: ?Mod11) -> Mod11 {Mod11((a.0 + b.0) % 11)});
overload!((a: ?Mod11) - (b: ?Mod11) -> Mod11 {Mod11((a.0 + 11 - b.0) % 11)});
Expand Down
33 changes: 22 additions & 11 deletions wecare/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,18 +139,29 @@ impl std::fmt::Display for MpcError {

impl std::error::Error for MpcError {}

pub fn do_preproc(files: &mut [File], number_of_shares: Vec<usize>) {
pub fn do_preproc(files: &mut [File], number_of_shares: Vec<usize>, use_32: bool) {
assert_eq!(files.len(), number_of_shares.len());
let known_to_each = vec![number_of_shares[0], number_of_shares[1]];
let number_of_triplets = 0;
let num = S25519::from_f64(0.0);
preprocessing::write_preproc_to_file(
files,
known_to_each,
number_of_triplets,
num,
)
.unwrap();
if use_32 {
let num = S32::from_f64(0.0);
preprocessing::write_preproc_to_file(
files,
known_to_each,
number_of_triplets,
num,
)
.unwrap();
} else {
let num = S25519::from_f64(0.0);
preprocessing::write_preproc_to_file(
files,
known_to_each,
number_of_triplets,
num,
)
.unwrap();
}
}

pub type Engine = generic::AdderEngine;
Expand Down Expand Up @@ -364,7 +375,7 @@ mod test {
let ctx1 = tempfile::tempfile().unwrap();
let ctx2 = tempfile::tempfile().unwrap();
let mut files = [ctx1, ctx2];
do_preproc(&mut files, vec![1, 1]);
do_preproc(&mut files, vec![1, 1], false);
let [mut ctx1, mut ctx2] = files;
ctx1.rewind().unwrap();
ctx2.rewind().unwrap();
Expand Down Expand Up @@ -409,7 +420,7 @@ mod test {
let ctx1 = tempfile::tempfile().unwrap();
let ctx2 = tempfile::tempfile().unwrap();
let mut files = [ctx1, ctx2];
do_preproc(&mut files, vec![2, 2]);
do_preproc(&mut files, vec![2, 2], false);
let [mut ctx1, mut ctx2] = files;
ctx1.rewind().unwrap();
ctx2.rewind().unwrap();
Expand Down

0 comments on commit e20f2bb

Please sign in to comment.