CKKS
‘ckks’ Dialect
The CKKS dialect defines the types and operations of the CKKS cryptosystem.
CKKS attributes
SchemeParamAttr
CKKS Scheme Parameters
Syntax:
#ckks.scheme_param<
int, # logN
DenseI64ArrayAttr, # Q
DenseI64ArrayAttr, # P
int, # logDefaultScale
CKKSEncryptionType, # encryptionType
CKKSEncryptionTechnique, # encryptionTechnique
DenseI32ArrayAttr # moduliPerLevel
>
This attribute is used for recording the scheme parameters for CKKS.
The attribute is a struct with the following fields:
- `logN1: The log of the degree of the polynomial modulus.
Q: The array of moduli whose product is the ciphertext modulus, ordered from level 0 (the base modulus remaining after all rescalings) up to the maximum level L (the fresh encryption level).P: The array of moduli in the special modulus, used for key switching.logDefaultScale: The log of the default scale.encryptionType: The encryption type (optional, defaults topk).encryptionTechnique: The encryption technique (optional, defaults tostandard).moduliPerLevel: Optional array specifying how many moduli inQbelong to each level, ordered from level 0. I.e., ifmoduliPerLevel = {2, 3}, then the first level uses moduliQ[0], Q[1], and the second level uses moduliQ[2], Q[3], Q[4]. This is useful for variants of CKKS that require 32-bit word arithmetic, and employ techniques like composite rescaling to achieve intermediate widths of rescaling. When omitted, defaults to all 1s. When provided, all entries must be positive and their sum must equalQ.size().
Parameters:
| Parameter | C++ type | Description |
|---|---|---|
| logN | int | |
| Q | DenseI64ArrayAttr | |
| P | DenseI64ArrayAttr | |
| logDefaultScale | int | |
| encryptionType | CKKSEncryptionType | |
| encryptionTechnique | CKKSEncryptionTechnique | |
| moduliPerLevel | DenseI32ArrayAttr |
CKKS ops
ckks.add (heir::ckks::AddOp)
Addition operation between ciphertexts.
Syntax:
operation ::= `ckks.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 |
ckks.add_plain (heir::ckks::AddPlainOp)
Addition operation between ciphertext-plaintext.
Syntax:
operation ::= `ckks.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 |
ckks.bootstrap (heir::ckks::BootstrapOp)
Bootstrap the ciphertext to reduce noise and refresh its parameters.
Syntax:
operation ::= `ckks.bootstrap` operands prop-dict attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Bootstrapping is a technique used in FHE to reduce the noise in a ciphertext and refresh its parameters, allowing for further computations on the ciphertext.
Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), ResetsLevelOpInterface, ResetsMulDepthOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description |
|---|---|---|
targetLevel | ::mlir::IntegerAttr | 64-bit signless integer attribute |
Operands:
| Operand | Description |
|---|---|
input | lwe-ciphertext-like |
Results:
| Result | Description |
|---|---|
output | lwe-ciphertext-like |
ckks.level_reduce (heir::ckks::LevelReduceOp)
Lower the modulus level of the ciphertext via dropping RNS limbs.
Syntax:
operation ::= `ckks.level_reduce` operands prop-dict attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait, Elementwise, InferTypeOpAdaptor, SameOperandsAndResultPlaintextTypes, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), ReducesLevelOpInterface
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 |
ckks.mul (heir::ckks::MulOp)
Multiplication operation between ciphertexts.
Syntax:
operation ::= `ckks.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 |
ckks.mul_plain (heir::ckks::MulPlainOp)
Multiplication operation between ciphertext-plaintext.
Syntax:
operation ::= `ckks.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 |
ckks.negate (heir::ckks::NegateOp)
Negate the coefficients of the ciphertext.
Syntax:
operation ::= `ckks.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 |
ckks.relinearize (heir::ckks::RelinearizeOp)
Relinearize the ciphertext.
Syntax:
operation ::= `ckks.relinearize` $input (`,` $keySwitchingKey^)? prop-dict attr-dict `:` functional-type(operands, 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: AlwaysSpeculatableImplTrait, InferTypeOpAdaptor
Interfaces: ConditionallySpeculatable, ElementwiseByOperandOpInterface, 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 |
keySwitchingKey | ranked tensor of lwe-ciphertext-like values |
Results:
| Result | Description |
|---|---|
output | lwe-ciphertext-like |
ckks.rescale (heir::ckks::RescaleOp)
Rescales the ciphertext, which is the CKKS version of modulus switching in BGV/BFV.
Syntax:
operation ::= `ckks.rescale` operands prop-dict attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface), ReducesLevelOpInterface
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 |
ckks.rotate (heir::ckks::RotateOp)
Rotate the coefficients of the ciphertext using a Galois automorphism.
Syntax:
operation ::= `ckks.rotate` $input (`,` $dynamic_shift^ `:` type($dynamic_shift))? prop-dict attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable
Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface), RotationOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
| Attribute | MLIR Type | Description |
|---|---|---|
static_shift | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
input | lwe-ciphertext-like |
dynamic_shift | signless-integer-like |
Results:
| Result | Description |
|---|---|
output | lwe-ciphertext-like |
ckks.sub (heir::ckks::SubOp)
Subtraction operation between ciphertexts.
Syntax:
operation ::= `ckks.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 |
ckks.sub_plain (heir::ckks::SubPlainOp)
Subtraction operation between ciphertext-plaintext.
Syntax:
operation ::= `ckks.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 |
CKKS additional definitions
CKKSEncryptionTechnique
An enum attribute representing an encryption technique
Cases:
| Symbol | Value | String |
|---|---|---|
| standard | 0 | standard |
| extended | 1 | extended |
CKKSEncryptionType
An enum attribute representing an encryption method
Cases:
| Symbol | Value | String |
|---|---|---|
| pk | 0 | pk |
| sk | 1 | sk |