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
ConstantType
Syntax: !cheddar.constant
This type represents a CHEDDAR Constant
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
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
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:
| Operand | Description |
|---|---|
ctx | |
lhs | |
rhs |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
ciphertext | |
constant |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
ciphertext | |
plaintext |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input | |
evkMap |
Results:
| Result | Description |
|---|---|
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
Interfaces: InferTypeOpInterface
Operands:
| Operand | Description |
|---|---|
params |
Results:
| Result | Description |
|---|---|
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
Interfaces: InferTypeOpInterface
Operands:
| Operand | Description |
|---|---|
ctx |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
encoder | |
plaintext |
Results:
| Result | Description |
|---|---|
message | ranked 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:
| Operand | Description |
|---|---|
ui | |
ciphertext |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
level | ::mlir::IntegerAttr | An Attribute containing a integer value |
scale | ::mlir::FloatAttr | 64-bit float attribute |
Operands:
| Operand | Description |
|---|---|
encoder | |
message | ranked tensor of floating-point or complex-type values |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
level | ::mlir::IntegerAttr | An Attribute containing a integer value |
scale | ::mlir::FloatAttr | 64-bit float attribute |
Operands:
| Operand | Description |
|---|---|
encoder | |
value | floating-point |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ui | |
plaintext |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
coefficients | ::mlir::ArrayAttr | array attribute |
level | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
ctx | |
input | |
evkMap |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ui |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ui |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input | |
addend |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
rescale | ::mlir::BoolAttr | bool attribute |
Operands:
| Operand | Description |
|---|---|
ctx | |
lhs | |
rhs | |
multKey |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
static_distance | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
ctx | |
input | |
dynamic_distance | signless integer or index |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
distance | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
ctx | |
input | |
addend |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
targetLevel | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
ctx | |
input |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
diagonal_indices | ::mlir::DenseI32ArrayAttr | i32 dense array attribute |
level | ::mlir::IntegerAttr | An Attribute containing a integer value |
logBabyStepGiantStepRatio | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
ctx | |
input | |
evkMap | |
diagonals | 2D tensor of floating-point values |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
accumulator | |
input | |
constant |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
lhs | |
rhs |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
ciphertext | |
constant |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
ciphertext | |
plaintext |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input |
Results:
| Result | Description |
|---|---|
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:
| Attribute | MLIR Type | Description |
|---|---|---|
distance | ::mlir::IntegerAttr | An Attribute containing a integer value |
maxLevel | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
| Operand | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input | |
multKey |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input | |
multKey |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
input |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
lhs | |
rhs |
Results:
| Result | Description |
|---|---|
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:
| Operand | Description |
|---|---|
ctx | |
ciphertext | |
plaintext |
Results:
| Result | Description |
|---|---|
output |