Module bfv

Source
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 Signed type 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 Fractional type is a quasi fixed-point value. It allows you to homomorphically compute decimal values as efficiently as the Signed type. This type has complex overflow conditions. This type intrinsically supports homomorphic addition multiplication, and negation. Dividing by an f64 constant is supported. Dividing by ciphertext is not possible.
  • The Rational type 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 two Signed values. However, this type is less efficient than Fractional, as it requires 2 multiplications for addition and subtraction. Unlike other types, Rational supports ciphertext-ciphertext division.
  • The Batched type 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 operation a + b will element-wise add the many lanes of a to the many lanes in b. Type comparison:
Type# ciphertextsoverflow conditionsvaluesops/addops/mulops/subops/negops/div
Signed1moderatesigned integral1 add1 mul1 sub1 neg-
Fractional1complexsigned decimal1 add1 mul1 sub1 neg1 mul*
Rational2moderatesigned decimal2 muls + 1 sub2 muls2 muls + 1 sub1 neg2 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 LANES columns. The LANES value 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