BGV
‘bgv’ Dialect
The BGV dialect defines the types and operations of the BGV and B/FV cryptosystem.
Due to similarity with the BFV scheme, BGV dialect also represents the B/FV scheme.
The semantics of bgv dialect operations are determined by the scheme.bgv or scheme.bfv
annotation at the module level.
In B/FV mode, bgv.modulus_switch is an no-op.
BGV attributes
SchemeParamAttr
BGV Scheme Parameters
Syntax:
#bgv.scheme_param<
  int,   # logN
  DenseI64ArrayAttr,   # Q
  DenseI64ArrayAttr,   # P
  int64_t,   # plaintextModulus
  BGVEncryptionType,   # encryptionType
  BGVEncryptionTechnique   # encryptionTechnique
>
This attribute is used for recording the scheme parameters for CKKS.
The attribute is a struct with the following fields:
- intlogN: The log of the degree of the polynomial modulus.
- DenseI64ArrayAttrQ: The array of primes in the ciphertext modulus.
- DenseI64ArrayAttrP: The array of primes in the special modulus, used for key switching.
- int64_tplaintextModulus: The plaintext modulus.
Parameters:
| Parameter | C++ type | Description | 
|---|---|---|
| logN | int | |
| Q | DenseI64ArrayAttr | |
| P | DenseI64ArrayAttr | |
| plaintextModulus | int64_t | |
| encryptionType | BGVEncryptionType | |
| encryptionTechnique | BGVEncryptionTechnique | 
BGV ops
bgv.add (heir::bgv::AddOp)
Addition operation between ciphertexts.
Syntax:
operation ::= `bgv.add` operands attr-dict `:`  functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, InferTypeOpAdaptor, SameOperandsAndResultPlaintextTypes, SameOperandsAndResultRings, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-ciphertext-like | 
| rhs | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.add_plain (heir::bgv::AddPlainOp)
Addition operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.add_plain` operands attr-dict `:`  functional-type(operands, results)
Traits: AllCiphertextTypesMatch, AlwaysSpeculatableImplTrait, Commutative, Elementwise, InferTypeOpAdaptor, IsCiphertextPlaintextOp, SameOperandsAndResultPlaintextTypes, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-plaintext-or-ciphertext-like | 
| rhs | lwe-plaintext-or-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.level_reduce (heir::bgv::LevelReduceOp)
Lower the modulus level of the ciphertext via dropping RNS limbs.
Syntax:
operation ::= `bgv.level_reduce` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait, Elementwise, SameOperandsAndResultPlaintextTypes, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description | 
|---|---|---|
| levelToDrop | ::mlir::IntegerAttr | 64-bit signless integer attribute | 
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.modulus_switch (heir::bgv::ModulusSwitchOp)
Lower the modulus level of the ciphertext via modulus switching.
Syntax:
operation ::= `bgv.modulus_switch` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description | 
|---|---|---|
| to_ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring | 
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.mul (heir::bgv::MulOp)
Multiplication operation between ciphertexts.
Syntax:
operation ::= `bgv.mul` operands attr-dict `:`  functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, InferTypeOpAdaptor, SameOperandsAndResultRings, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-ciphertext-like | 
| rhs | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.mul_plain (heir::bgv::MulPlainOp)
Multiplication operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.mul_plain` operands attr-dict `:`  functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait, Commutative, Elementwise, InferTypeOpAdaptor, IsCiphertextPlaintextOp, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-plaintext-or-ciphertext-like | 
| rhs | lwe-plaintext-or-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.negate (heir::bgv::NegateOp)
Negate the coefficients of the ciphertext.
Syntax:
operation ::= `bgv.negate` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait, Elementwise, Involution, SameOperandsAndResultType, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.relinearize (heir::bgv::RelinearizeOp)
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: AlwaysSpeculatableImplTrait, Elementwise, InferTypeOpAdaptor, SameOperandsAndResultPlaintextTypes, SameOperandsAndResultRings, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description | 
|---|---|---|
| from_basis | ::mlir::DenseI32ArrayAttr | i32 dense array attribute | 
| to_basis | ::mlir::DenseI32ArrayAttr | i32 dense array attribute | 
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.rotate_cols (heir::bgv::RotateColumnsOp)
Rotate the columns of the coefficients of the ciphertext using a Galois automorphism.
Syntax:
operation ::= `bgv.rotate_cols` operands attr-dict `:` qualified(type($input))
This operation rotates the columns of the coefficients of the ciphertext using a Galois automorphism.
Often BGV scheme is instantiated with a ring of the form Z_q[X]/(X^N + 1) and
plaintext modulus t where N is a power of 2 and t is a prime number. In
this case, the plaintext slots can be viewed as a 2 x N/2 matrix where
N/2 is the number of columns and 2 is the number of rows.
Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description | 
|---|---|---|
| offset | ::mlir::IntegerAttr | An Attribute containing a integer value | 
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.rotate_rows (heir::bgv::RotateRowsOp)
Rotate the rows of the coefficients of the ciphertext using a Galois automorphism.
Syntax:
operation ::= `bgv.rotate_rows` operands attr-dict `:` qualified(type($input))
This operation rotates the rows of the coefficients of the ciphertext using a Galois automorphism.
Often BGV scheme is instantiated with a ring of the form Z_q[X]/(X^N + 1) and
plaintext modulus t where N is a power of 2 and t is a prime number. In
this case, the plaintext slots can be viewed as a 2 x N/2 matrix where
N/2 is the number of columns and 2 is the number of rows.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description | 
|---|---|---|
| offset | ::mlir::IntegerAttr | An Attribute containing a integer value | 
Operands:
| Operand | Description | 
|---|---|
| input | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.sub (heir::bgv::SubOp)
Subtraction operation between ciphertexts.
Syntax:
operation ::= `bgv.sub` operands attr-dict `:`  functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait, Elementwise, InferTypeOpAdaptor, SameOperandsAndResultPlaintextTypes, SameOperandsAndResultRings, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-ciphertext-like | 
| rhs | lwe-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
bgv.sub_plain (heir::bgv::SubPlainOp)
Subtraction operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.sub_plain` operands attr-dict `:`  functional-type(operands, results)
Traits: AllCiphertextTypesMatch, AlwaysSpeculatableImplTrait, Elementwise, InferTypeOpAdaptor, IsCiphertextPlaintextOp, SameOperandsAndResultPlaintextTypes, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
| Operand | Description | 
|---|---|
| lhs | lwe-plaintext-or-ciphertext-like | 
| rhs | lwe-plaintext-or-ciphertext-like | 
Results:
| Result | Description | 
|---|---|
| output | lwe-ciphertext-like | 
BGV additional definitions
BGVEncryptionTechnique
An enum attribute representing an encryption technique
Cases:
| Symbol | Value | String | 
|---|---|---|
| standard | 0 | standard | 
| extended | 1 | extended | 
BGVEncryptionType
An enum attribute representing an encryption method
Cases:
| Symbol | Value | String | 
|---|---|---|
| pk | 0 | pk | 
| sk | 1 | sk |