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:

  • int logN: The log of the degree of the polynomial modulus.
  • DenseI64ArrayAttr Q: The array of primes in the ciphertext modulus.
  • DenseI64ArrayAttr P: The array of primes in the special modulus, used for key switching.
  • int logDefaultScale: The log of the default scale.

Parameters:

ParameterC++ typeDescription
logNint
QDenseI64ArrayAttr
PDenseI64ArrayAttr
logDefaultScaleint
encryptionTypeCKKSEncryptionType
encryptionTechniqueCKKSEncryptionTechnique

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 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), 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.key_switch_inner (heir::ckks::KeySwitchInnerOp)

Fundamental key-switching kernel.

Syntax:

operation ::= `ckks.key_switch_inner` operands attr-dict `:`  functional-type(operands, results)

The key-switching key is the encryption of a key s_{in} under the key s_{out}. The input value is a ring element of a ciphertext that gets multiplied with s_{in}. KeySwitchInner outputs a linear ciphertext ct' such that decrypting ct' under s_{out} is value * s_{in}. By adding ct' to the components of the original ciphertext that do are not multiplied by s_{in}, we obtain a ciphertext that encrypts the same message as the original ciphertext, but under s_{out}.

Concretely, for relinearization, a ciphertext [c_0, c_1, c_2] decrypts as c_0 + c_1*s + c_2*s^2, and the key-switch key is an encryption of s^2 under s. Then we apply KeySwitchInner to c_2, which produces [c_0', c_1'], where c_0'+c_1'*s = c_2 * s^2. Then relinearization outputs [c_0+c_0', c_1+c_1'].

This operation is intended to be an internal implementation detail of higher-level ciphertext operations such as ckks.relinearize, isolated here for reuse among multiple op lowerings.

Traits: AlwaysSpeculatableImplTrait

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

Effects: MemoryEffects::Effect{}

Operands:

OperandDescription
valueA ring element
keySwitchingKeyranked tensor of A ciphertext type values

Results:

ResultDescription
constTermA ring element
linearTermA ring element

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, InferTypeOpAdaptor, SameOperandsAndResultPlaintextTypes, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

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^)? 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 attr-dict `:` qualified(type($input)) `->` qualified(type($output))

Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, NoMemoryEffect (MemoryEffectOpInterface)

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))? attr-dict `:` qualified(type($input))

Traits: AlwaysSpeculatableImplTrait, Elementwise, Scalarizable, Tensorizable, Vectorizable

Interfaces: ConditionallySpeculatable, InferTypeOpInterface, NoMemoryEffect (MemoryEffectOpInterface)

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