Skip to content

Commit

Permalink
feat(integer): Adds bitslice operation
Browse files Browse the repository at this point in the history
  • Loading branch information
nsarlin-zama committed Aug 8, 2024
1 parent 5340859 commit 07c764f
Show file tree
Hide file tree
Showing 8 changed files with 1,475 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tfhe/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::fmt::{Debug, Display, Formatter};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ErrorKind {
Message(String),
/// The provide range for a slicing operation was invalid
InvalidRange(InvalidRangeError),
/// The zero knowledge proof and the content it is supposed to prove
/// failed to correctly prove
#[cfg(feature = "zk-pok")]
Expand Down Expand Up @@ -34,6 +36,7 @@ impl Display for Error {
ErrorKind::InvalidZkProof => {
write!(f, "The zero knowledge proof and the content it is supposed to prove were not valid")
}
ErrorKind::InvalidRange(err) => write!(f, "Invalid range: {err}"),
}
}
}
Expand All @@ -56,6 +59,13 @@ impl From<String> for Error {
}
}

impl From<InvalidRangeError> for Error {
fn from(value: InvalidRangeError) -> Self {
let kind = ErrorKind::InvalidRange(value);
Self { kind }
}
}

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

// This is useful to use infallible conversions as well as fallible ones in certain parts of the lib
Expand All @@ -65,3 +75,28 @@ impl From<std::convert::Infallible> for Error {
unreachable!()
}
}

/// Error returned when the provided range for a slice is invalid
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum InvalidRangeError {
/// The upper bound of the range is greater than the size of the integer
SliceTooBig,
/// The upper gound is smaller than the lower bound
WrongOrder,
}

impl Display for InvalidRangeError {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::SliceTooBig => write!(
f,
"The upper bound of the range is greater than the size of the integer"
),
Self::WrongOrder => {
write!(f, "The upper gound is smaller than the lower bound")
}
}
}
}

impl std::error::Error for InvalidRangeError {}
1 change: 1 addition & 0 deletions tfhe/src/integer/server_key/radix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod scalar_add;
pub(super) mod scalar_mul;
pub(super) mod scalar_sub;
mod shift;
pub(super) mod slice;
mod sub;

use super::ServerKey;
Expand Down
Loading

0 comments on commit 07c764f

Please sign in to comment.