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
>
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.intlogDefaultScale: The log of the default scale.
Parameters:
| Parameter | C++ type | Description |
|---|---|---|
| logN | int | |
| Q | DenseI64ArrayAttr | |
| P | DenseI64ArrayAttr | |
| logDefaultScale | int | |
| encryptionType | CKKSEncryptionType | |
| encryptionTechnique | CKKSEncryptionTechnique |
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 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)
Effects: MemoryEffects::Effect{}
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 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 |
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^)? 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, SameOperandsAndResultPlaintextTypes, SameOperandsAndResultRings
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 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 |
ckks.rotate (heir::ckks::RotateOp)
Rotate the coefficients of the ciphertext using a Galois automorphism.
Syntax:
operation ::= `ckks.rotate` operands attr-dict `:` qualified(type($input))
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 |
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 |