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 to pk).
  • encryptionTechnique: The encryption technique (optional, defaults to standard).
  • moduliPerLevel: Optional array specifying how many moduli in Q belong to each level, ordered from level 0. I.e., if moduliPerLevel = {2, 3}, then the first level uses moduli Q[0], Q[1], and the second level uses moduli Q[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 equal Q.size().

Parameters:

ParameterC++ typeDescription
logNint
QDenseI64ArrayAttr
PDenseI64ArrayAttr
logDefaultScaleint
encryptionTypeCKKSEncryptionType
encryptionTechniqueCKKSEncryptionTechnique
moduliPerLevelDenseI32ArrayAttr

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:

OperandDescription
lhslwe-ciphertext-like
rhslwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
lhslwe-plaintext-or-ciphertext-like
rhslwe-plaintext-or-ciphertext-like

Results:

ResultDescription
outputlwe-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:

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

Operands:

OperandDescription
inputlwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

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

Operands:

OperandDescription
inputlwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
lhslwe-ciphertext-like
rhslwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
lhslwe-plaintext-or-ciphertext-like
rhslwe-plaintext-or-ciphertext-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
inputlwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

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

Operands:

OperandDescription
inputlwe-ciphertext-like
keySwitchingKeyranked tensor of lwe-ciphertext-like values

Results:

ResultDescription
outputlwe-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:

AttributeMLIR TypeDescription
to_ring::mlir::heir::polynomial::RingAttran attribute specifying a polynomial ring

Operands:

OperandDescription
inputlwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

AttributeMLIR TypeDescription
static_shift::mlir::IntegerAttrAn Attribute containing a integer value

Operands:

OperandDescription
inputlwe-ciphertext-like
dynamic_shiftsignless-integer-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
lhslwe-ciphertext-like
rhslwe-ciphertext-like

Results:

ResultDescription
outputlwe-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:

OperandDescription
lhslwe-plaintext-or-ciphertext-like
rhslwe-plaintext-or-ciphertext-like

Results:

ResultDescription
outputlwe-ciphertext-like

CKKS additional definitions

CKKSEncryptionTechnique

An enum attribute representing an encryption technique

Cases:

SymbolValueString
standard0standard
extended1extended

CKKSEncryptionType

An enum attribute representing an encryption method

Cases:

SymbolValueString
pk0pk
sk1sk