BGV

The BGV dialect defines the types and operations of the BGV cryptosystem.

BGV attributes

BGVRingsAttr

Syntax:

#bgv.rings<
  ::llvm::ArrayRef<::mlir::heir::polynomial::RingAttr>   # rings
>

Parameters:

ParameterC++ typeDescription
rings::llvm::ArrayRef<::mlir::heir::polynomial::RingAttr>

BGV types

CiphertextType

a BGV ciphertext

Syntax:

!bgv.ciphertext<
  ::mlir::heir::bgv::BGVRingsAttr,   # rings
  unsigned,   # dim
  std::optional<uint64_t>   # level
>

This type tracks the BGV ciphertext parameters, including the ciphertext dimension (number of polynomials) and the set of rings that were used for the particular BGV scheme instance. The default dimension is 2, representing a ciphertext that is canonically encrypted against the key basis $(1, s)$.

The type also includes a ring parameter specification.

For example, bgv.ciphertext<rings=#rings, dim=3> is a ciphertext with 3 polynomials $(c_0, c_1, c_2)$.

The optional attribute level specifies the “current ring”.

Parameters:

ParameterC++ typeDescription
rings::mlir::heir::bgv::BGVRingsAttr
dimunsigned
levelstd::optional<uint64_t>

BGV ops

bgv.add (heir::bgv::AddOp)

Addition operation between ciphertexts.

Syntax:

operation ::= `bgv.add` `(` operands `)` attr-dict `:` type($output)

Traits: Commutative, SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
xa BGV ciphertext
ya BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.modulus_switch (heir::bgv::ModulusSwitch)

Lower the modulus level of the ciphertext.

Syntax:

operation ::= `bgv.modulus_switch` `(` operands `)` attr-dict `:`  `(` type(operands) `)` `->` type(results)

Traits: SameOperandsAndResultRings

Attributes:

AttributeMLIR TypeDescription
from_level::mlir::IntegerAttr64-bit signless integer attribute
to_level::mlir::IntegerAttr64-bit signless integer attribute

Operands:

OperandDescription
xa BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.mul (heir::bgv::MulOp)

Multiplication operation between ciphertexts.

Syntax:

operation ::= `bgv.mul` `(` operands `)` attr-dict `:` type($x) `->` type($output)

Traits: Commutative, SameOperandsAndResultRings, SameTypeOperands

Operands:

OperandDescription
xa BGV ciphertext
ya BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.negate (heir::bgv::Negate)

Negate the coefficients of the ciphertext.

Syntax:

operation ::= `bgv.negate` `(` operands `)` attr-dict `:` type($output)

Traits: SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
xa BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.relinearize (heir::bgv::Relinearize)

Relinearize the ciphertext.

Syntax:

operation ::= `bgv.relinearize` `(` operands `)` attr-dict `:`  `(` type(operands) `)` `->` type(results)

This op takes integer array attributes from_basis and to_basis that are used to indicate the key basis from which and to which the ciphertext is encrypted against. A ciphertext is canonically encrypted against key basis (1, s). After a multiplication, its size will increase and the basis will be (1, s, s^2). The array that represents the key basis is constructed by listing the powers of s at each position of the array. For example, (1, s, s^2) corresponds to [0, 1, 2], while (1, s^2) corresponds to [0, 2].

Traits: SameOperandsAndResultRings

Attributes:

AttributeMLIR TypeDescription
from_basis::mlir::DenseI32ArrayAttri32 dense array attribute
to_basis::mlir::DenseI32ArrayAttri32 dense array attribute

Operands:

OperandDescription
xa BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.rotate (heir::bgv::Rotate)

Rotate the coefficients of the ciphertext using a Galois automorphism.

Syntax:

operation ::= `bgv.rotate` `(` operands `)` attr-dict `:`  `(` type(operands) `)` `->` type(results)

Traits: SameOperandsAndResultRings

Attributes:

AttributeMLIR TypeDescription
offset::mlir::IntegerAttr64-bit signless integer attribute

Operands:

OperandDescription
xa BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext

bgv.sub (heir::bgv::SubOp)

Subtraction operation between ciphertexts.

Syntax:

operation ::= `bgv.sub` `(` operands `)` attr-dict `:` type($output)

Traits: SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
xa BGV ciphertext
ya BGV ciphertext

Results:

ResultDescription
outputa BGV ciphertext