Expand description
This module contains build-in types you can use as inputs and outputs from FHE programs using the BFV scheme.
§BFV Scheme types
The BFV scheme is a good choice for exactly and quickly computing a small number of simple operations.
Plaintexts under the BFV scheme are polynomials with N terms, where
N is the poly_degree scheme paramter. This parameter is (by default)
automatically configured during FHE program compilation based on its noise budget
requirements. Addition and multiplication imply adding and multiplying
polynomials.
However, working with polynomials directly is difficult, so Sunscreen provides types that transparently encode data you might actually want to use into and out of polynomials. These include:
- The
Signedtype represents a signed integer that encodes a binary value decomposed into a number of digits. This encoding allows for somewhat efficiently representing integers, but has unusual overflow semantics developers need to understand. This type supports addition, subtraction, multiplication, and negation. - The
Fractionaltype is a quasi fixed-point value. It allows you to homomorphically compute decimal values as efficiently as theSignedtype. This type has complex overflow conditions. This type intrinsically supports homomorphic addition multiplication, and negation. Dividing by anf64constant is supported. Dividing by ciphertext is not possible. - The
Rationaltype allows quasi fixed-point representation. This type interally uses 2 ciphertexts, and is thus requires twice as much space as other types. Its overflow semantics are effectively those of twoSignedvalues. However, this type is less efficient thanFractional, as it requires 2 multiplications for addition and subtraction. Unlike other types,Rationalsupports ciphertext-ciphertext division. - The
Batchedtype packs thousands of signed integers into lanes by exploiting the Chinese remainder theorem for cyclotomic polynomials. Arithmetic operations semantically execute per-lane, enabling high-throughput; e.g. a single addition operationa + bwill element-wise add the many lanes of a to the many lanes in b. Type comparison:
| Type | # ciphertexts | overflow conditions | values | ops/add | ops/mul | ops/sub | ops/neg | ops/div |
|---|---|---|---|---|---|---|---|---|
| Signed | 1 | moderate | signed integral | 1 add | 1 mul | 1 sub | 1 neg | - |
| Fractional | 1 | complex | signed decimal | 1 add | 1 mul | 1 sub | 1 neg | 1 mul* |
| Rational | 2 | moderate | signed decimal | 2 muls + 1 sub | 2 muls | 2 muls + 1 sub | 1 neg | 2 muls |
* Division by constant only.
The set of feasible computations under FHE with BFV is fairly limited. For example, comparisons, modulus, transcendentals, are generally very difficult and are often infeasible depending on scheme parameters and noise budget. One can sometimes approximate operations using Lagrange interpolation.
Structs§
- Batched
- A Batched vector of signed integers. The vector has 2 rows of
LANEScolumns. TheLANESvalue must be a power of 2 up to 16384. - Fractional
- A quasi fixed-point representation capable of storing values with both integer and fractional components.
- Rational
- Represents the ratio of two integers. Allows for fractional values and division.
- Signed
- A single signed integer.
- Unsigned
- A single unsigned integer.
Type Aliases§
- Unsigned64
- Unsigned 64-bit integer
- Unsigned128
- Unsigned 128-bit integer
- Unsigned256
- Unsigned 256-bit integer
- Unsigned512
- Unsigned 512-bit integer