BGV

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

BGV ops

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

Addition operation between ciphertexts.

Syntax:

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

Traits: Commutative, SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
lhsA type for RLWE ciphertexts
rhsA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.add_plain (heir::bgv::AddPlainOp)

Addition operation between ciphertext-plaintext.

Syntax:

operation ::= `bgv.add_plain` operands attr-dict `:`  functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ciphertextInputA type for RLWE ciphertexts
plaintextInputA type for RLWE plaintexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.decrypt (heir::bgv::DecryptOp)

Decrypt an encoded plaintext into a BGV ciphertext.

Syntax:

operation ::= `bgv.decrypt` operands attr-dict `:`  functional-type(operands, results)

Operands:

OperandDescription
inputA type for RLWE ciphertexts
secret_keyA secret key for RLWE

Results:

ResultDescription
outputA type for RLWE plaintexts

bgv.encrypt (heir::bgv::EncryptOp)

Encrypt an encoded plaintext into a BGV ciphertext.

Syntax:

operation ::= `bgv.encrypt` operands attr-dict `:`  functional-type(operands, results)

Operands:

OperandDescription
inputA type for RLWE plaintexts
keyA secret key for RLWE or A public key for RLWE

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.extract (heir::bgv::ExtractOp)

Extract the i-th element of a ciphertext.

Syntax:

operation ::= `bgv.extract` operands attr-dict `:`  functional-type(operands, results)

While this operation is costly to compute in FHE, we represent it so we can implement efficient lowerings and folders.

This op can be implemented as a plaintext multiplication with a one-hot vector and a rotate into the zero-th index.

An extraction op’s input ciphertext type is asserted to have an underlying_type corresponding to a ranked tensor type, and this op’s return type is inferred to have the underlying_type corresponding to the element type of that tensor type.

Traits: SameOperandsAndResultRings

Operands:

OperandDescription
inputA type for RLWE ciphertexts
offsetsignless integer or index

Results:

ResultDescription
outputA type for RLWE ciphertexts

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

Lower the modulus level of the ciphertext.

Syntax:

operation ::= `bgv.modulus_switch` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))

Attributes:

AttributeMLIR TypeDescription
to_ring::mlir::heir::polynomial::RingAttrAn attribute specifying a ring.

Operands:

OperandDescription
inputA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

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

Multiplication operation between ciphertexts.

Syntax:

operation ::= `bgv.mul` operands attr-dict `:`  functional-type(operands, results)

Traits: Commutative, InferTypeOpAdaptor, SameOperandsAndResultRings, SameTypeOperands

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
lhsA type for RLWE ciphertexts
rhsA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.mul_plain (heir::bgv::MulPlainOp)

Multiplication operation between ciphertext-plaintext.

Syntax:

operation ::= `bgv.mul_plain` operands attr-dict `:`  functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ciphertextInputA type for RLWE ciphertexts
plaintextInputA type for RLWE plaintexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

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

Negate the coefficients of the ciphertext.

Syntax:

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

Traits: SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
inputA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

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

Relinearize the ciphertext.

Syntax:

operation ::= `bgv.relinearize` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))

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: InferTypeOpAdaptor, SameOperandsAndResultRings

Interfaces: InferTypeOpInterface

Attributes:

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

Operands:

OperandDescription
inputA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.rotate (heir::bgv::RotateOp)

Rotate the coefficients of the ciphertext using a Galois automorphism.

Syntax:

operation ::= `bgv.rotate` operands attr-dict `:` qualified(type($input)) `,` type($offset)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
inputA type for RLWE ciphertexts
offsetsignless-integer-like

Results:

ResultDescription
outputA type for RLWE ciphertexts

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

Subtraction operation between ciphertexts.

Syntax:

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

Traits: SameOperandsAndResultType

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
lhsA type for RLWE ciphertexts
rhsA type for RLWE ciphertexts

Results:

ResultDescription
outputA type for RLWE ciphertexts

bgv.sub_plain (heir::bgv::SubPlainOp)

Subtraction operation between ciphertext-plaintext.

Syntax:

operation ::= `bgv.sub_plain` operands attr-dict `:`  functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ciphertextInputA type for RLWE ciphertexts
plaintextInputA type for RLWE plaintexts

Results:

ResultDescription
outputA type for RLWE ciphertexts