Cheddar

‘cheddar’ Dialect

The cheddar dialect is an exit dialect for generating C++ code against the CHEDDAR GPU FHE library API.

CHEDDAR is a CKKS-only GPU-accelerated FHE library. It supports both 32-bit and 64-bit word types, with 32-bit being the primary fast path on GPUs.

See the Cheddar GitHub repository

Cheddar types

CiphertextType

Syntax: !cheddar.ciphertext

This type represents a CHEDDAR Ciphertext. Move-only, lives on GPU.

ConstantType

Syntax: !cheddar.constant

This type represents a CHEDDAR Constant. A scalar in RNS form, used for efficient ciphertext-scalar operations.

ContextType

Syntax: !cheddar.context

This type represents a CHEDDAR Context (or BootContext), which is the main server-side computation engine. Created via Context::Create(param) or BootContext::Create(param, boot_param).

EncoderType

Syntax: !cheddar.encoder

This type represents the CHEDDAR Encoder, accessed via context->encoder_. Used for encoding/decoding plaintext values.

EvalKeyType

Syntax: !cheddar.eval_key

This type represents a single CHEDDAR EvaluationKey.

EvkMapType

Syntax: !cheddar.evk_map

This type represents a CHEDDAR EvkMap, which bundles all evaluation keys (multiplication, rotation, conjugation, etc.) into a single map.

ParameterType

Syntax: !cheddar.parameter

This type represents a CHEDDAR Parameter object, constructed from a JSON file or programmatically.

PlaintextType

Syntax: !cheddar.plaintext

This type represents a CHEDDAR Plaintext. Contains an NTT-applied encoded message.

UserInterfaceType

Syntax: !cheddar.user_interface

This type represents the CHEDDAR UserInterface, used for key generation, encryption, and decryption. Note: this is for test purposes only and is not security-hardened.

Cheddar ops

cheddar.add (heir::cheddar::AddOp)

Add two ciphertexts

Syntax:

operation ::= `cheddar.add` operands attr-dict `:` functional-type(operands, results)

Calls context->Add(res, a, b).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
lhs
rhs

Results:

ResultDescription
output

cheddar.add_const (heir::cheddar::AddConstOp)

Add a constant to a ciphertext

Syntax:

operation ::= `cheddar.add_const` operands attr-dict `:` functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
ciphertext
constant

Results:

ResultDescription
output

cheddar.add_plain (heir::cheddar::AddPlainOp)

Add a plaintext to a ciphertext

Syntax:

operation ::= `cheddar.add_plain` operands attr-dict `:` functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
ciphertext
plaintext

Results:

ResultDescription
output

cheddar.boot (heir::cheddar::BootOp)

Bootstrap a ciphertext

Syntax:

operation ::= `cheddar.boot` operands attr-dict `:` functional-type(operands, results)

Calls boot_ctx->Boot(res, input, evk_map). Refreshes the ciphertext noise budget.

Interfaces: InferTypeOpInterface, ResetsMulDepthOpInterface

Operands:

OperandDescription
ctx
input
evkMap

Results:

ResultDescription
output

cheddar.create_context (heir::cheddar::CreateContextOp)

Create a CHEDDAR context from parameters

Syntax:

operation ::= `cheddar.create_context` operands attr-dict `:` functional-type(operands, results)

Creates a CHEDDAR Context from a Parameter object. The context is the main server-side computation engine.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
params

Results:

ResultDescription
ctx

cheddar.create_user_interface (heir::cheddar::CreateUserInterfaceOp)

Create a CHEDDAR UserInterface for key gen and encrypt/decrypt

Syntax:

operation ::= `cheddar.create_user_interface` operands attr-dict `:` functional-type(operands, results)

Creates a UserInterface from a context. The UserInterface handles key generation, encryption, and decryption. Note: for test purposes only.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx

Results:

ResultDescription
ui

cheddar.decode (heir::cheddar::DecodeOp)

Decode a CHEDDAR plaintext back to a message vector

Syntax:

operation ::= `cheddar.decode` operands attr-dict `:` functional-type(operands, results)

Calls encoder.Decode(message, pt). Returns a vector of complex numbers.

Operands:

OperandDescription
encoder
plaintext

Results:

ResultDescription
messageranked tensor of floating-point or complex-type values

cheddar.decrypt (heir::cheddar::DecryptOp)

Decrypt a ciphertext into a plaintext

Syntax:

operation ::= `cheddar.decrypt` operands attr-dict `:` functional-type(operands, results)

Calls ui.Decrypt(pt, ct). Test-only operation.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ui
ciphertext

Results:

ResultDescription
plaintext

cheddar.encode (heir::cheddar::EncodeOp)

Encode a message vector into a CHEDDAR plaintext

Syntax:

operation ::= `cheddar.encode` operands attr-dict `:` functional-type(operands, results)

Calls encoder.Encode(pt, level, scale, message). The message is a vector of complex numbers (or reals). scale is the C++ double value used by CHEDDAR’s Encoder.

Interfaces: InferTypeOpInterface

Attributes:

AttributeMLIR TypeDescription
level::mlir::IntegerAttrAn Attribute containing a integer value
scale::mlir::FloatAttr64-bit float attribute

Operands:

OperandDescription
encoder
messageranked tensor of floating-point or complex-type values

Results:

ResultDescription
plaintext

cheddar.encode_constant (heir::cheddar::EncodeConstantOp)

Encode a scalar double into a CHEDDAR constant

Syntax:

operation ::= `cheddar.encode_constant` operands attr-dict `:` functional-type(operands, results)

Calls encoder.EncodeConstant(constant, level, scale, number). The result is in RNS form for efficient ciphertext-scalar ops. scale is the C++ double value used by CHEDDAR’s Encoder.

Interfaces: InferTypeOpInterface

Attributes:

AttributeMLIR TypeDescription
level::mlir::IntegerAttrAn Attribute containing a integer value
scale::mlir::FloatAttr64-bit float attribute

Operands:

OperandDescription
encoder
valuefloating-point

Results:

ResultDescription
constant

cheddar.encrypt (heir::cheddar::EncryptOp)

Encrypt a plaintext into a ciphertext

Syntax:

operation ::= `cheddar.encrypt` operands attr-dict `:` functional-type(operands, results)

Calls ui.Encrypt(ct, pt). Test-only operation.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ui
plaintext

Results:

ResultDescription
ciphertext

cheddar.eval_poly (heir::cheddar::EvalPolyOp)

Evaluate a polynomial on a ciphertext

Syntax:

operation ::= `cheddar.eval_poly` operands attr-dict `:` functional-type(operands, results)

Evaluates a polynomial (e.g., Chebyshev approximation) on an encrypted input using CHEDDAR’s EvalPoly extension.

Interfaces: InferTypeOpInterface

Attributes:

AttributeMLIR TypeDescription
coefficients::mlir::ArrayAttrarray attribute
level::mlir::IntegerAttrAn Attribute containing a integer value

Operands:

OperandDescription
ctx
input
evkMap

Results:

ResultDescription
output

cheddar.get_encoder (heir::cheddar::GetEncoderOp)

Get the encoder from a CHEDDAR context

Syntax:

operation ::= `cheddar.get_encoder` operands attr-dict `:` functional-type(operands, results)

Returns a reference to the context’s encoder (context->encoder_).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx

Results:

ResultDescription
encoder

cheddar.get_evk_map (heir::cheddar::GetEvkMapOp)

Get the evaluation key map from a UserInterface

Syntax:

operation ::= `cheddar.get_evk_map` operands attr-dict `:` functional-type(operands, results)

Returns the EvkMap from the UserInterface (ui.GetEvkMap()).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ui

Results:

ResultDescription
evkMap

cheddar.get_mult_key (heir::cheddar::GetMultKeyOp)

Get the multiplication evaluation key

Syntax:

operation ::= `cheddar.get_mult_key` operands attr-dict `:` functional-type(operands, results)

Returns the multiplication key from the UserInterface (ui.GetMultiplicationKey()).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ui

Results:

ResultDescription
key

cheddar.hconj (heir::cheddar::HConjOp)

Fused key-switch + conjugation

Syntax:

operation ::= `cheddar.hconj` operands attr-dict `:` functional-type(operands, results)

Calls context->HConj(res, a, conj_key). The conjugation key is looked up from the enclosing function’s UserInterface.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input

Results:

ResultDescription
output

cheddar.hconj_add (heir::cheddar::HConjAddOp)

Fused conjugation + addition

Syntax:

operation ::= `cheddar.hconj_add` operands attr-dict `:` functional-type(operands, results)

Computes res = conj(a) + b in a single fused GPU kernel. Calls context->HConjAdd(res, a, b, conj_key). The conjugation key is looked up from the enclosing function’s UserInterface.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input
addend

Results:

ResultDescription
output

cheddar.hmult (heir::cheddar::HMultOp)

Fused multiply + relinearize (+ optional rescale)

Syntax:

operation ::= `cheddar.hmult` operands attr-dict `:` functional-type(operands, results)

Calls context->HMult(res, a, b, mult_key, rescale). Single fused GPU kernel launch. The rescale attribute controls whether rescaling is included (default: true).

Interfaces: IncreasesMulDepthOpInterface, InferTypeOpInterface

Attributes:

AttributeMLIR TypeDescription
rescale::mlir::BoolAttrbool attribute

Operands:

OperandDescription
ctx
lhs
rhs
multKey

Results:

ResultDescription
output

cheddar.hrot (heir::cheddar::HRotOp)

Fused key-switch + rotation

Syntax:

operation ::= `cheddar.hrot` operands attr-dict `:` functional-type(operands, results)

Calls context->HRot(res, a, rot_key, distance). The rotation key is looked up from the enclosing function’s UserInterface using distance. Single fused GPU kernel. Supports both static and dynamic distances.

Interfaces: InferTypeOpInterface, RotationOpInterface

Attributes:

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

Operands:

OperandDescription
ctx
input
dynamic_distancesignless integer or index

Results:

ResultDescription
output

cheddar.hrot_add (heir::cheddar::HRotAddOp)

Fused rotation + addition

Syntax:

operation ::= `cheddar.hrot_add` operands attr-dict `:` functional-type(operands, results)

Computes res = rotate(a, distance) + b in a single fused GPU kernel. Calls context->HRotAdd(res, a, b, rot_key, distance). The rotation key is looked up from the enclosing function’s UserInterface using distance.

Interfaces: InferTypeOpInterface, RotationOpInterface

Attributes:

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

Operands:

OperandDescription
ctx
input
addend

Results:

ResultDescription
output

cheddar.level_down (heir::cheddar::LevelDownOp)

Reduce ciphertext to a target level

Syntax:

operation ::= `cheddar.level_down` operands attr-dict `:` functional-type(operands, results)

Calls context->LevelDown(res, a, target_level).

Interfaces: InferTypeOpInterface

Attributes:

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

Operands:

OperandDescription
ctx
input

Results:

ResultDescription
output

cheddar.linear_transform (heir::cheddar::LinearTransformOp)

Apply a linear transform on a ciphertext

Syntax:

operation ::= `cheddar.linear_transform` operands attr-dict `:` functional-type(operands, results)

Applies a matrix-vector product using CHEDDAR’s LinearTransform extension with BSGS optimization and hoisting.

The diagonals input is a 2D tensor where each row is a non-zero diagonal. The diagonal_indices attribute specifies which diagonal each row represents. The level attribute specifies the modulus level for the operation.

Interfaces: InferTypeOpInterface, RotationOpInterface

Attributes:

AttributeMLIR TypeDescription
diagonal_indices::mlir::DenseI32ArrayAttri32 dense array attribute
level::mlir::IntegerAttrAn Attribute containing a integer value
logBabyStepGiantStepRatio::mlir::IntegerAttrAn Attribute containing a integer value

Operands:

OperandDescription
ctx
input
evkMap
diagonals2D tensor of floating-point values

Results:

ResultDescription
output

cheddar.mad_unsafe (heir::cheddar::MadUnsafeOp)

Fused multiply-accumulate with constant (no rescale)

Syntax:

operation ::= `cheddar.mad_unsafe` operands attr-dict `:` functional-type(operands, results)

Computes res += a * constant (in-place accumulation). Calls context->MadUnsafe(res, a, constant).

Note: this op would typically be called mac, the current name reflects the spelling in Cheddar (MadUnsafe).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
accumulator
input
constant

Results:

ResultDescription
output

cheddar.mult (heir::cheddar::MultOp)

Multiply two ciphertexts (tensor product, no relin/rescale)

Syntax:

operation ::= `cheddar.mult` operands attr-dict `:` functional-type(operands, results)

Calls context->Mult(res, a, b). Produces a degree-3 ciphertext. Does NOT include relinearization or rescaling.

Interfaces: IncreasesMulDepthOpInterface, InferTypeOpInterface

Operands:

OperandDescription
ctx
lhs
rhs

Results:

ResultDescription
output

cheddar.mult_const (heir::cheddar::MultConstOp)

Multiply a ciphertext by a constant (no rescale)

Syntax:

operation ::= `cheddar.mult_const` operands attr-dict `:` functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
ciphertext
constant

Results:

ResultDescription
output

cheddar.mult_plain (heir::cheddar::MultPlainOp)

Multiply a ciphertext by a plaintext (no rescale)

Syntax:

operation ::= `cheddar.mult_plain` operands attr-dict `:` functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
ciphertext
plaintext

Results:

ResultDescription
output

cheddar.neg (heir::cheddar::NegOp)

Negate a ciphertext

Syntax:

operation ::= `cheddar.neg` operands attr-dict `:` functional-type(operands, results)

Calls context->Neg(res, a).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input

Results:

ResultDescription
output

cheddar.prepare_rot_key (heir::cheddar::PrepareRotKeyOp)

Generate a rotation key for a given distance

Syntax:

operation ::= `cheddar.prepare_rot_key` operands attr-dict `:` functional-type(operands, results)

Calls ui.PrepareRotationKey(distance, max_level) to generate a rotation key. Must be called before using rotation with that distance. The max_level parameter specifies the maximum ciphertext level at which this rotation key will be used.

Attributes:

AttributeMLIR TypeDescription
distance::mlir::IntegerAttrAn Attribute containing a integer value
maxLevel::mlir::IntegerAttrAn Attribute containing a integer value

Operands:

OperandDescription
ui

cheddar.relinearize (heir::cheddar::RelinearizeOp)

Relinearize a ciphertext (without rescale)

Syntax:

operation ::= `cheddar.relinearize` operands attr-dict `:` functional-type(operands, results)

Calls context->Relinearize(res, a, mult_key).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input
multKey

Results:

ResultDescription
output

cheddar.relinearize_rescale (heir::cheddar::RelinearizeRescaleOp)

Fused relinearize + rescale

Syntax:

operation ::= `cheddar.relinearize_rescale` operands attr-dict `:` functional-type(operands, results)

Calls context->RelinearizeRescale(res, a, mult_key). Faster than separate Relinearize + Rescale.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input
multKey

Results:

ResultDescription
output

cheddar.rescale (heir::cheddar::RescaleOp)

Rescale a ciphertext (drop one level)

Syntax:

operation ::= `cheddar.rescale` operands attr-dict `:` functional-type(operands, results)

Calls context->Rescale(res, a). Reduces the ciphertext level by 1.

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
input

Results:

ResultDescription
output

cheddar.sub (heir::cheddar::SubOp)

Subtract two ciphertexts

Syntax:

operation ::= `cheddar.sub` operands attr-dict `:` functional-type(operands, results)

Calls context->Sub(res, a, b).

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
lhs
rhs

Results:

ResultDescription
output

cheddar.sub_plain (heir::cheddar::SubPlainOp)

Subtract a plaintext from a ciphertext

Syntax:

operation ::= `cheddar.sub_plain` operands attr-dict `:` functional-type(operands, results)

Interfaces: InferTypeOpInterface

Operands:

OperandDescription
ctx
ciphertext
plaintext

Results:

ResultDescription
output