This section contains the reference documentation for all of the dialects defined in HEIR.
This is the multi-page printable view of this section. Click here to print.
Dialects
- 1: BGV
- 2: CGGI
- 3: CKKS
- 4: Comb
- 5: Jaxite
- 6: Lattigo
- 7: LWE
- 8: Mgmt
- 9: ModArith
- 10: Openfhe
- 11: Polynomial
- 12: Random
- 13: RNS
- 14: Secret
- 15: TensorExt
- 16: TfheRust
- 17: TfheRustBool
1 - BGV
‘bgv’ Dialect
The BGV dialect defines the types and operations of the BGV cryptosystem.
BGV ops
bgv.add
(heir::bgv::AddOp)
Addition operation between ciphertexts.
Syntax:
operation ::= `bgv.add` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.add_plain
(heir::bgv::AddPlainOp)
Addition operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.add_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.extract
(heir::bgv::ExtractOp)
Extract the i-th element of a ciphertext.
Syntax:
operation ::= `bgv.extract` operands attr-dict `:` functional-type(operands, results)
While this operation is costly to compute in FHE, we represent it so we can implement efficient lowerings and folders.
This op can be implemented as a plaintext multiplication with a one-hot vector and a rotate into the zero-th index.
An extraction op’s input ciphertext type is asserted to have an underlying_type
corresponding to a ranked tensor type, and this op’s return type is
inferred to have the underlying_type
corresponding to the element type of
that tensor type.
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultRings
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
offset | signless integer or index |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.modulus_switch
(heir::bgv::ModulusSwitchOp)
Lower the modulus level of the ciphertext.
Syntax:
operation ::= `bgv.modulus_switch` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
to_ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring |
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.mul
(heir::bgv::MulOp)
Multiplication operation between ciphertexts.
Syntax:
operation ::= `bgv.mul` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, InferTypeOpAdaptor
, SameOperandsAndResultRings
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.mul_plain
(heir::bgv::MulPlainOp)
Multiplication operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.mul_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.negate
(heir::bgv::NegateOp)
Negate the coefficients of the ciphertext.
Syntax:
operation ::= `bgv.negate` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Involution
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.relinearize
(heir::bgv::RelinearizeOp)
Relinearize the ciphertext.
Syntax:
operation ::= `bgv.relinearize` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))
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: InferTypeOpAdaptor
, SameOperandsAndResultRings
Interfaces: InferTypeOpInterface
, OpAsmOpInterface
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 | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.rotate
(heir::bgv::RotateOp)
Rotate the coefficients of the ciphertext using a Galois automorphism.
Syntax:
operation ::= `bgv.rotate` operands attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
offset | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.sub
(heir::bgv::SubOp)
Subtraction operation between ciphertexts.
Syntax:
operation ::= `bgv.sub` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
bgv.sub_plain
(heir::bgv::SubPlainOp)
Subtraction operation between ciphertext-plaintext.
Syntax:
operation ::= `bgv.sub_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
2 - CGGI
‘cggi’ Dialect
A dialect for types and operations in the CGGI cryptosystem
CGGI attributes
CGGIBoolGatesAttr
An attribute containing an array of strings to store bool gates
Syntax:
#cggi.cggi_bool_gates<
::llvm::ArrayRef<::mlir::heir::cggi::CGGIBoolGateEnumAttr> # gates
>
This attributes stores a list of integer identifiers for Boolean gates.
Uses following mapping: AND_GATE = 0; NAND_GATE = 1; OR_GATE = 2; NOR_GATE = 3; XOR_GATE = 4; XNOR_GATE = 5; NOT_GATE = 6;
Parameters:
Parameter | C++ type | Description |
---|---|---|
gates | ::llvm::ArrayRef<::mlir::heir::cggi::CGGIBoolGateEnumAttr> |
CGGIParamsAttr
Syntax:
#cggi.cggi_params<
::mlir::heir::lwe::RLWEParamsAttr, # rlweParams
unsigned, # bsk_noise_variance
unsigned, # bsk_gadget_base_log
unsigned, # bsk_gadget_num_levels
unsigned, # ksk_noise_variance
unsigned, # ksk_gadget_base_log
unsigned # ksk_gadget_num_levels
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
rlweParams | ::mlir::heir::lwe::RLWEParamsAttr | |
bsk_noise_variance | unsigned | |
bsk_gadget_base_log | unsigned | |
bsk_gadget_num_levels | unsigned | |
ksk_noise_variance | unsigned | |
ksk_gadget_base_log | unsigned | |
ksk_gadget_num_levels | unsigned |
CGGI ops
cggi.add
(heir::cggi::AddOp)
Arithmetic addition of two ciphertexts.
Syntax:
operation ::= `cggi.add` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.and
(heir::cggi::AndOp)
Logical AND of two ciphertexts.
Syntax:
operation ::= `cggi.and` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.cast
(heir::cggi::CastOp)
Change the plaintext space of a CGGI ciphertext
Syntax:
operation ::= `cggi.cast` $input attr-dict `:` type($input) `to` type($output)
“cast” operation to change the plaintext size of a CGGI ciphertext. Note this operations is not a standard CGGI operation, but an mirror of the cast op implemented in TFHE-rs.
Examples:
`cggi.cast %c0 : !lwe.lwe_ciphertext<encoding = #unspecified_bit_field_encoding> to !lwe.lwe_ciphertext<encoding = #unspecified_bit_field_encoding1>`
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultShape
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.create_trivial
(heir::cggi::CreateTrivialOp)
Syntax:
operation ::= `cggi.create_trivial` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
value | ::mlir::IntegerAttr | An Attribute containing a integer value |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.lut2
(heir::cggi::Lut2Op)
A lookup table on two inputs.
Syntax:
operation ::= `cggi.lut2` operands attr-dict `:` qualified(type($output))
An op representing a lookup table applied to some number n
of ciphertexts
encrypting boolean input bits.
Over cleartext bits a, b, c
, using n = 3
for example, the operation
computed by this function can be interpreted as
truth_table >> {c, b, a}
where {c, b, a}
is the unsigned 3-bit integer with bits c, b, a
from most
significant bit to least-significant bit. The input are combined into a
single ciphertext input to the lookup table using products with plaintexts
and sums.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookup_table | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
b | ciphertext-like |
a | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.lut3
(heir::cggi::Lut3Op)
A lookup table on three inputs.
Syntax:
operation ::= `cggi.lut3` operands attr-dict `:` qualified(type($output))
An op representing a lookup table applied to some number n
of ciphertexts
encrypting boolean input bits.
Over cleartext bits a, b, c
, using n = 3
for example, the operation
computed by this function can be interpreted as
truth_table >> {c, b, a}
where {c, b, a}
is the unsigned 3-bit integer with bits c, b, a
from most
significant bit to least-significant bit. The input are combined into a
single ciphertext input to the lookup table using products with plaintexts
and sums.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookup_table | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
c | ciphertext-like |
b | ciphertext-like |
a | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.lut_lincomb
(heir::cggi::LutLinCombOp)
A variadic-input lookup table with inputs prepared via linear combination.
Syntax:
operation ::= `cggi.lut_lincomb` operands attr-dict `:` type($output)
An op representing a lookup table applied to an arbitrary number of input ciphertexts, which are combined according to a static linear combination attached to the op.
The user must ensure the chosen linear combination does not bleed error bits into the message space according to the underlying ciphertext’s encoding attributes. E.g., a bit_field_encoding with 3 cleartext bits cannot be multiplied by 16.
Example:
#encoding = #lwe.bit_field_encoding<cleartext_start=30, cleartext_bitwidth=3>
#params = #lwe.lwe_params<cmod=7917, dimension=4>
!ciphertext = !lwe.lwe_ciphertext<encoding = #encoding, lwe_params = #params>
%4 = cggi.lut_lincomb %c0, %c1, %c2, %c3 {coefficients = array<i32: 1, 2, 3, 2>, lookup_table = 68 : index} : !ciphertext
Represents applying the lut
68 >> (1 * c0 + 2 * c1 + 3 * c2 + 2 * c3)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
coefficients | ::mlir::DenseI32ArrayAttr | i32 dense array attribute |
lookup_table | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
inputs | variadic of any type |
Results:
Result | Description |
---|---|
output | any type |
cggi.mul
(heir::cggi::MulOp)
Arithmetic multiplication of two ciphertexts.
Syntax:
operation ::= `cggi.mul` operands attr-dict `:` qualified(type($output))
While CGGI does not have a native multiplication operation, some backend targets provide a multiplication operation that is implemented via a sequence of other atomic CGGI ops. When lowering to backends that do not have this, one must lower to this op the appropriate CGGI ops.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.multi_lut_lincomb
(heir::cggi::MultiLutLinCombOp)
A multi-output version of lut_lincomb with one LUT per output.
Syntax:
operation ::= `cggi.multi_lut_lincomb` operands attr-dict `:` functional-type($inputs, $outputs)
An op representing multiple lookup tables applied to a shared input, which
is prepared via a static linear combination. This is equivalent to
cggi.lut_lincomb
, but where the linear combination is given to multiple
lookup tables, each producing a separate output.
This can be achieved by a special implementation of blind rotate in the CGGI scheme. See AutoHoG.
Example:
#encoding = #lwe.bit_field_encoding<cleartext_start=30, cleartext_bitwidth=3>
#params = #lwe.lwe_params<cmod=7917, dimension=4>
!ciphertext = !lwe.lwe_ciphertext<encoding = #encoding, lwe_params = #params>
%4 = cggi.multi_lut_lincomb %c0, %c1, %c2, %c3 {
coefficients = array<i32: 1, 2, 3, 2>,
lookup_tables = array<index: 68, 70, 4, 8>
} : (!ciphertext, !ciphertext, !ciphertext, !ciphertext) -> (!ciphertext, !ciphertext, !ciphertext, !ciphertext)
Represents applying the following LUTs. Performance-wise, this is comparable to applying a single LUT to a linear combination.
x = (1 * c0 + 2 * c1 + 3 * c2 + 2 * c3)
return (
(68 >> x) & 1,
(70 >> x) & 1,
(4 >> x) & 1,
(8 >> x) & 1
)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
coefficients | ::mlir::DenseI32ArrayAttr | i32 dense array attribute |
lookup_tables | ::mlir::DenseI32ArrayAttr | i32 dense array attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of A type for LWE ciphertexts |
Results:
Result | Description |
---|---|
outputs | variadic of A type for LWE ciphertexts |
cggi.nand
(heir::cggi::NandOp)
Logical NAND of two ciphertexts.
Syntax:
operation ::= `cggi.nand` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.nor
(heir::cggi::NorOp)
Logical NOR of two ciphertexts.
Syntax:
operation ::= `cggi.nor` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.not
(heir::cggi::NotOp)
Logical NOT of two ciphertexts
Syntax:
operation ::= `cggi.not` 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 | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.or
(heir::cggi::OrOp)
Logical OR of two ciphertexts.
Syntax:
operation ::= `cggi.or` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.packed_lut3
(heir::cggi::PackedLut3Op)
Syntax:
operation ::= `cggi.packed_lut3` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookup_tables | ::mlir::ArrayAttr | Array of integers |
Operands:
Operand | Description |
---|---|
a | ciphertext-like |
b | ciphertext-like |
c | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.packed_gates
(heir::cggi::PackedOp)
Syntax:
operation ::= `cggi.packed_gates` operands attr-dict `:` functional-type(operands, results)
Operation to where different Boolean gates are executed pairwise between elements of two ciphertext arrays.
For example,
%0 = cggi.packed_gates %a, %b {gates = #cggi.cggi_gate<"and", "xor">} : tensor<2x!lwe.lwe_ciphertext>
applies an “and” gate to the first elements of %a and %b and an xor gate to the second elements.
Mapping is defined in the BooleanGates.td file.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
gates | ::mlir::heir::cggi::CGGIBoolGatesAttr | An attribute containing an array of strings to store bool gates |
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.programmable_bootstrap
(heir::cggi::ProgrammableBootstrapOp)
Programmable Bootstrap with a given lookup table.
Syntax:
operation ::= `cggi.programmable_bootstrap` operands attr-dict `:` qualified(type($output))
An op representing a programmable bootstrap applied to an LWE ciphertext.
This operation evaluates a univariate function homomorphically on the ciphertext by selecting the correct value from a lookup table. The bit size of the lookup table integer attribute should be equal to the plaintext space size. For example, if there ciphertext can hold 3 plaintext message bits, then the lookup table must be represented at most by an integer with 8 bits.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookup_table | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
input | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.shl
(heir::cggi::ShiftLeftOp)
Arithmetic shift to left of a ciphertext by an integer. Note this operations to mirror the TFHE-rs implmementation.
Syntax:
operation ::= `cggi.shl` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
shiftAmount | 8-bit integer |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.shr
(heir::cggi::ShiftRightOp)
Arithmetic shift to the right of a ciphertext by an integer. Note this operations to mirror the TFHE-rs implmementation.
Syntax:
operation ::= `cggi.shr` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
shiftAmount | 8-bit integer |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.sub
(heir::cggi::SubOp)
Subtraction of two ciphertexts.
Syntax:
operation ::= `cggi.sub` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.xnor
(heir::cggi::XNorOp)
Logical XNOR of two ciphertexts.
Syntax:
operation ::= `cggi.xnor` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
cggi.xor
(heir::cggi::XorOp)
Logical XOR of two ciphertexts.
Syntax:
operation ::= `cggi.xor` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | ciphertext-like |
rhs | ciphertext-like |
Results:
Result | Description |
---|---|
output | ciphertext-like |
CGGI additional definitions
CGGIBoolGateEnum
An enum attribute representing a CGGI boolean gate using u8 int
Cases:
Symbol | Value | String |
---|---|---|
AND | 0 | AND |
NAND | 1 | NAND |
OR | 2 | OR |
NOR | 3 | NOR |
XOR | 4 | XOR |
XNOR | 5 | XNOR |
NOT | 6 | NOT |
3 - CKKS
‘ckks’ Dialect
The CKKS dialect defines the types and operations of the CKKS cryptosystem.
CKKS ops
ckks.add
(heir::ckks::AddOp)
Addition operation between ciphertexts.
Syntax:
operation ::= `ckks.add` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.add_plain
(heir::ckks::AddPlainOp)
Addition operation between ciphertext-plaintext.
Syntax:
operation ::= `ckks.add_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
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
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.extract
(heir::ckks::ExtractOp)
Extract the i-th element of a ciphertext.
Syntax:
operation ::= `ckks.extract` operands attr-dict `:` functional-type(operands, results)
While this operation is costly to compute in FHE, we represent it so we can implement efficient lowerings and folders.
This op can be implemented as a plaintext multiplication with a one-hot vector and a rotate into the zero-th index.
An extraction op’s input ciphertext type is asserted to have an underlying_type
corresponding to a ranked tensor type, and this op’s return type is
inferred to have the underlying_type
corresponding to the element type of
that tensor type.
Traits: SameOperandsAndResultRings
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
offset | signless integer or index |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.mul
(heir::ckks::MulOp)
Multiplication operation between ciphertexts.
Syntax:
operation ::= `ckks.mul` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, InferTypeOpAdaptor
, SameOperandsAndResultRings
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
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
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.negate
(heir::ckks::NegateOp)
Negate the coefficients of the ciphertext.
Syntax:
operation ::= `ckks.negate` operands attr-dict `:` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
, Involution
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.relinearize
(heir::ckks::RelinearizeOp)
Relinearize the ciphertext.
Syntax:
operation ::= `ckks.relinearize` operands attr-dict `:` qualified(type($input)) `->` qualified(type($output))
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
, SameOperandsAndResultRings
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
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 | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
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
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
to_ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring |
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
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
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
offset | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.sub
(heir::ckks::SubOp)
Subtraction operation between ciphertexts.
Syntax:
operation ::= `ckks.sub` operands attr-dict `:` qualified(type($output))
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
, OpAsmOpInterface
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
ckks.sub_plain
(heir::ckks::SubPlainOp)
Subtraction operation between ciphertext-plaintext.
Syntax:
operation ::= `ckks.sub_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertextInput | A ciphertext type |
plaintextInput | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
4 - Comb
‘comb’ Dialect
Types and operations for comb dialect
This dialect defines the comb
dialect, which is intended to be a generic
representation of combinational logic outside of a particular use-case.
Operations
comb.add
(heir::comb::AddOp)
Syntax:
operation ::= `comb.add` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.and
(heir::comb::AndOp)
Syntax:
operation ::= `comb.and` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.concat
(heir::comb::ConcatOp)
Concatenate a variadic list of operands together.
Syntax:
operation ::= `comb.concat` $inputs attr-dict `:` qualified(type($inputs))
See the comb rationale document for details on operand ordering.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.extract
(heir::comb::ExtractOp)
Extract a range of bits into a smaller value, lowBit specifies the lowest bit included.
Syntax:
operation ::= `comb.extract` $input `from` $lowBit attr-dict `:` functional-type($input, $result)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lowBit | ::mlir::IntegerAttr | 32-bit signless integer attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.icmp
(heir::comb::ICmpOp)
Compare two integer values
Syntax:
operation ::= `comb.icmp` (`bin` $twoState^)? $predicate $lhs `,` $rhs attr-dict `:` qualified(type($lhs))
This operation compares two integers using a predicate. If the predicate is true, returns 1, otherwise returns 0. This operation always returns a one bit wide result.
%r = comb.icmp eq %a, %b : i4
Traits: AlwaysSpeculatableImplTrait
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
predicate | ::mlir::heir::comb::ICmpPredicateAttr | hw.icmp comparison predicate |
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
lhs | signless integer |
rhs | signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.inv
(heir::comb::InvOp)
Syntax:
operation ::= `comb.inv` (`bin` $twoState^)? $input attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.mul
(heir::comb::MulOp)
Syntax:
operation ::= `comb.mul` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.mux
(heir::comb::MuxOp)
Return one or the other operand depending on a selector bit
Syntax:
operation ::= `comb.mux` (`bin` $twoState^)? $cond `,` $trueValue `,` $falseValue attr-dict `:` qualified(type($result))
%0 = mux %pred, %tvalue, %fvalue : i4
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
cond | 1-bit signless integer |
trueValue | any type |
falseValue | any type |
Results:
Result | Description |
---|---|
result | any type |
comb.nand
(heir::comb::NandOp)
Syntax:
operation ::= `comb.nand` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.nor
(heir::comb::NorOp)
Syntax:
operation ::= `comb.nor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.or
(heir::comb::OrOp)
Syntax:
operation ::= `comb.or` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.parity
(heir::comb::ParityOp)
Syntax:
operation ::= `comb.parity` (`bin` $twoState^)? $input attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.replicate
(heir::comb::ReplicateOp)
Concatenate the operand a constant number of times
Syntax:
operation ::= `comb.replicate` $input attr-dict `:` functional-type($input, $result)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.truth_table
(heir::comb::TruthTableOp)
Return a true/false based on a lookup table
Syntax:
operation ::= `comb.truth_table` $inputs `->` $lookupTable attr-dict
%a = ... : i1
%b = ... : i1
%0 = comb.truth_table %a, %b -> 6 : ui4
This operation assumes that the lookup table is described as an integer of
2^n bits to fully specify the table. Inputs are sorted MSB -> LSB from left
to right and the offset into lookupTable
is computed from them. The
integer containing the truth table value’s LSB is the output for the input
“all false”, and the MSB is the output for the input “all true”.
No difference from array_get into an array of constants except for xprop behavior. If one of the inputs is unknown, but said input doesn’t make a difference in the output (based on the lookup table) the result should not be ‘x’ – it should be the well-known result.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookupTable | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
inputs | variadic of 1-bit signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.xnor
(heir::comb::XNorOp)
Syntax:
operation ::= `comb.xnor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.xor
(heir::comb::XorOp)
Syntax:
operation ::= `comb.xor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
Enums
ICmpPredicate
hw.icmp comparison predicate
Cases:
Symbol | Value | String |
---|---|---|
eq | 0 | eq |
ne | 1 | ne |
slt | 2 | slt |
sle | 3 | sle |
sgt | 4 | sgt |
sge | 5 | sge |
ult | 6 | ult |
ule | 7 | ule |
ugt | 8 | ugt |
uge | 9 | uge |
ceq | 10 | ceq |
cne | 11 | cne |
weq | 12 | weq |
wne | 13 | wne |
Comb types
Comb ops
comb.add
(heir::comb::AddOp)
Syntax:
operation ::= `comb.add` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.and
(heir::comb::AndOp)
Syntax:
operation ::= `comb.and` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.concat
(heir::comb::ConcatOp)
Concatenate a variadic list of operands together.
Syntax:
operation ::= `comb.concat` $inputs attr-dict `:` qualified(type($inputs))
See the comb rationale document for details on operand ordering.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.extract
(heir::comb::ExtractOp)
Extract a range of bits into a smaller value, lowBit specifies the lowest bit included.
Syntax:
operation ::= `comb.extract` $input `from` $lowBit attr-dict `:` functional-type($input, $result)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lowBit | ::mlir::IntegerAttr | 32-bit signless integer attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.icmp
(heir::comb::ICmpOp)
Compare two integer values
Syntax:
operation ::= `comb.icmp` (`bin` $twoState^)? $predicate $lhs `,` $rhs attr-dict `:` qualified(type($lhs))
This operation compares two integers using a predicate. If the predicate is true, returns 1, otherwise returns 0. This operation always returns a one bit wide result.
%r = comb.icmp eq %a, %b : i4
Traits: AlwaysSpeculatableImplTrait
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
predicate | ::mlir::heir::comb::ICmpPredicateAttr | hw.icmp comparison predicate |
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
lhs | signless integer |
rhs | signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.inv
(heir::comb::InvOp)
Syntax:
operation ::= `comb.inv` (`bin` $twoState^)? $input attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.mul
(heir::comb::MulOp)
Syntax:
operation ::= `comb.mul` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.mux
(heir::comb::MuxOp)
Return one or the other operand depending on a selector bit
Syntax:
operation ::= `comb.mux` (`bin` $twoState^)? $cond `,` $trueValue `,` $falseValue attr-dict `:` qualified(type($result))
%0 = mux %pred, %tvalue, %fvalue : i4
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
cond | 1-bit signless integer |
trueValue | any type |
falseValue | any type |
Results:
Result | Description |
---|---|
result | any type |
comb.nand
(heir::comb::NandOp)
Syntax:
operation ::= `comb.nand` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.nor
(heir::comb::NorOp)
Syntax:
operation ::= `comb.nor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.or
(heir::comb::OrOp)
Syntax:
operation ::= `comb.or` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.parity
(heir::comb::ParityOp)
Syntax:
operation ::= `comb.parity` (`bin` $twoState^)? $input attr-dict `:` qualified(type($input))
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.replicate
(heir::comb::ReplicateOp)
Concatenate the operand a constant number of times
Syntax:
operation ::= `comb.replicate` $input attr-dict `:` functional-type($input, $result)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.truth_table
(heir::comb::TruthTableOp)
Return a true/false based on a lookup table
Syntax:
operation ::= `comb.truth_table` $inputs `->` $lookupTable attr-dict
%a = ... : i1
%b = ... : i1
%0 = comb.truth_table %a, %b -> 6 : ui4
This operation assumes that the lookup table is described as an integer of
2^n bits to fully specify the table. Inputs are sorted MSB -> LSB from left
to right and the offset into lookupTable
is computed from them. The
integer containing the truth table value’s LSB is the output for the input
“all false”, and the MSB is the output for the input “all true”.
No difference from array_get into an array of constants except for xprop behavior. If one of the inputs is unknown, but said input doesn’t make a difference in the output (based on the lookup table) the result should not be ‘x’ – it should be the well-known result.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, LUTOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
lookupTable | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
inputs | variadic of 1-bit signless integer |
Results:
Result | Description |
---|---|
result | 1-bit signless integer |
comb.xnor
(heir::comb::XNorOp)
Syntax:
operation ::= `comb.xnor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
comb.xor
(heir::comb::XorOp)
Syntax:
operation ::= `comb.xor` (`bin` $twoState^)? $inputs attr-dict `:` qualified(type($result))
Traits: AlwaysSpeculatableImplTrait
, Commutative
, SameOperandsAndResultType
, SameTypeOperands
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
twoState | ::mlir::UnitAttr | unit attribute |
Operands:
Operand | Description |
---|---|
inputs | variadic of signless integer |
Results:
Result | Description |
---|---|
result | signless integer |
Comb additional definitions
ICmpPredicate
hw.icmp comparison predicate
Cases:
Symbol | Value | String |
---|---|---|
eq | 0 | eq |
ne | 1 | ne |
slt | 2 | slt |
sle | 3 | sle |
sgt | 4 | sgt |
sge | 5 | sge |
ult | 6 | ult |
ule | 7 | ule |
ugt | 8 | ugt |
uge | 9 | uge |
ceq | 10 | ceq |
cne | 11 | cne |
weq | 12 | weq |
wne | 13 | wne |
5 - Jaxite
‘jaxite’ Dialect
The jaxite
dialect is an exit dialect for generating py code against the jaxite library API,
using the jaxite parameters and encoding scheme.
See https://github.com/google/jaxite
Jaxite types
ParamsType
The jaxite security params required to perform homomorphic operations.
Syntax: !jaxite.params
PmapLut3TupleType
A tuple of pmap_lut3 args.
Syntax: !jaxite.pmap_lut3_tuple
ServerKeySetType
The jaxite server key set required to perform homomorphic operations.
Syntax: !jaxite.server_key_set
Jaxite ops
jaxite.constant
(heir::jaxite::ConstantOp)
Syntax:
operation ::= `jaxite.constant` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
value | 1-bit signless integer |
params | The jaxite security params required to perform homomorphic operations. |
Results:
Result | Description |
---|---|
output | A type for LWE ciphertexts |
jaxite.lut3_args
(heir::jaxite::Lut3ArgsOp)
Syntax:
operation ::= `jaxite.lut3_args` operands attr-dict `:` functional-type(operands, results)
The operation computed by this function is generating tuples for pmap_lut3.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
a | A type for LWE ciphertexts |
b | A type for LWE ciphertexts |
c | A type for LWE ciphertexts |
truth_table | 8-bit signless integer |
Results:
Result | Description |
---|---|
output | A tuple of pmap_lut3 args. |
jaxite.lut3
(heir::jaxite::Lut3Op)
Syntax:
operation ::= `jaxite.lut3` operands attr-dict `:` functional-type(operands, results)
The operation computed by this function can be interpreted as
truth_table » {c, b, a}
where {c, b, a} is the unsigned 3-bit integer with bits c, b, a from most significant bit to least-significant bit.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
a | A type for LWE ciphertexts |
b | A type for LWE ciphertexts |
c | A type for LWE ciphertexts |
truth_table | 8-bit signless integer |
serverKeySet | The jaxite server key set required to perform homomorphic operations. |
params | The jaxite security params required to perform homomorphic operations. |
Results:
Result | Description |
---|---|
output | A type for LWE ciphertexts |
jaxite.pmap_lut3
(heir::jaxite::PmapLut3Op)
Syntax:
operation ::= `jaxite.pmap_lut3` operands attr-dict `:` functional-type(operands, results)
The operation computed by this function is a bacthed Lut3Op.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lut3_args | pmap_lut3_tuples |
serverKeySet | The jaxite server key set required to perform homomorphic operations. |
params | The jaxite security params required to perform homomorphic operations. |
Results:
Result | Description |
---|---|
output | ciphertext-like |
6 - Lattigo
’lattigo’ Dialect
The lattigo
dialect is an exit dialect for generating GO code against the Lattigo library API.
See https://github.com/tuneinsight/lattigo
Lattigo attributes
BGVParametersLiteralAttr
Literal parameters for Lattigo BGV
Syntax:
#lattigo.bgv.parameters_literal<
int, # logN
DenseI64ArrayAttr, # Q
DenseI64ArrayAttr, # P
DenseI32ArrayAttr, # logQ
DenseI32ArrayAttr, # logP
int64_t # plaintextModulus
>
This attribute represents the literal parameters for Lattigo BGV.
This is in accordance with https://pkg.go.dev/github.com/tuneinsight/lattigo/v6@v6.1.0/schemes/bgv#ParametersLiteral where some field are not present in the current implementation.
Users must set the polynomial degree (LogN) and the coefficient modulus, by either setting the Q and P fields to the desired moduli chain, or by setting the LogQ and LogP fields to the desired moduli sizes.
Note that for Lattigo, Q/P requires []uint64, where this attribute only provides int64. We assume user should not select moduli so large to consider the signedness issue.
Users must also specify the coefficient modulus in plaintext-space (T). This modulus must be an NTT-friendly prime in the plaintext space: it must be equal to 1 modulo 2n where n is the plaintext ring degree (i.e., the plaintext space has n slots).
Parameters:
Parameter | C++ type | Description |
---|---|---|
logN | int | |
Q | DenseI64ArrayAttr | |
P | DenseI64ArrayAttr | |
logQ | DenseI32ArrayAttr | |
logP | DenseI32ArrayAttr | |
plaintextModulus | int64_t |
Lattigo types
BGVEncoderType
Syntax: !lattigo.bgv.encoder
This type represents the encoder for the BGV encryption scheme.
BGVEvaluatorType
Syntax: !lattigo.bgv.evaluator
This type represents the evaluator for the BGV encryption scheme.
BGVParameterType
Syntax: !lattigo.bgv.parameter
This type represents the parameters for the BGV encryption scheme.
RLWECiphertextType
Syntax: !lattigo.rlwe.ciphertext
This type represents the ciphertext for the RLWE encryption scheme.
RLWEDecryptorType
Syntax: !lattigo.rlwe.decryptor
This type represents the decryptor for the RLWE encryption scheme.
RLWEEncryptorType
Syntax: !lattigo.rlwe.encryptor
This type represents the encryptor for the RLWE encryption scheme.
RLWEEvaluationKeySetType
Syntax: !lattigo.rlwe.evaluation_key_set
This type represents the evaluation key set for the RLWE encryption scheme.
RLWEGaloisKeyType
Syntax:
!lattigo.rlwe.galois_key<
::mlir::IntegerAttr # galoisElement
>
This type represents the Galois key for the RLWE encryption scheme.
galoisElement: Enabling the automorphism X -> X^{galoisElement}.
Parameters:
Parameter | C++ type | Description |
---|---|---|
galoisElement | ::mlir::IntegerAttr | An Attribute containing a integer value |
RLWEKeyGeneratorType
Syntax: !lattigo.rlwe.key_generator
This type represents the key generator for the RLWE encryption scheme.
RLWEPlaintextType
Syntax: !lattigo.rlwe.plaintext
This type represents the plaintext for the RLWE encryption scheme.
RLWEPublicKeyType
Syntax: !lattigo.rlwe.public_key
This type represents the public key for the RLWE encryption scheme.
RLWERelinearizationKeyType
Syntax: !lattigo.rlwe.relinearization_key
This type represents the relinearization key for the RLWE encryption scheme.
RLWESecretKeyType
Syntax: !lattigo.rlwe.secret_key
This type represents the secret key for the RLWE encryption scheme.
Lattigo ops
lattigo.bgv.add
(heir::lattigo::BGVAddOp)
Add two ciphertexts in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.add` operands attr-dict `:` functional-type(operands, results)
This operation adds two ciphertext values in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
lhs | |
rhs | or |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.decode
(heir::lattigo::BGVDecodeOp)
Decode a plaintext value in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.decode` operands attr-dict `:` functional-type(operands, results)
This operation decodes a plaintext value using the specified encoder in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
encoder | |
plaintext | |
value | any type |
Results:
Result | Description |
---|---|
decoded | any type |
lattigo.bgv.encode
(heir::lattigo::BGVEncodeOp)
Encode a plaintext value in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.encode` operands attr-dict `:` functional-type(operands, results)
This operation encodes a plaintext value using the specified encoder in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
encoder | |
value | any type |
plaintext |
Results:
Result | Description |
---|---|
encoded |
lattigo.bgv.mul
(heir::lattigo::BGVMulOp)
Multiply two ciphertexts in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.mul` operands attr-dict `:` functional-type(operands, results)
This operation multiplies two ciphertext values in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
lhs | |
rhs | or |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.new_encoder
(heir::lattigo::BGVNewEncoderOp)
Create a new encoder in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.new_encoder` operands attr-dict `:` functional-type(operands, results)
This operation creates a new encoder for encoding plaintext values in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params |
Results:
Result | Description |
---|---|
encoder |
lattigo.bgv.new_evaluator
(heir::lattigo::BGVNewEvaluatorOp)
Create a new evaluator in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.new_evaluator` operands attr-dict `:` functional-type(operands, results)
This operation creates a new evaluator for performing operations on ciphertexts in the Lattigo BGV dialect.
By default, the evaluator is created with the provided parameters and could execute operations which does not relying on evaluation keys.
To support operations that require evaluation keys, the optional evaluation key set should be provided.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params | |
evaluationKeySet |
Results:
Result | Description |
---|---|
evaluator |
lattigo.bgv.new_parameters_from_literal
(heir::lattigo::BGVNewParametersFromLiteralOp)
Create new BGV parameters from a literal in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.new_parameters_from_literal` operands attr-dict `:` functional-type(operands, results)
This operation creates new BGV parameters from a given literal value in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
paramsLiteral | ::mlir::heir::lattigo::BGVParametersLiteralAttr | Literal parameters for Lattigo BGV |
Results:
Result | Description |
---|---|
params |
lattigo.bgv.new_plaintext
(heir::lattigo::BGVNewPlaintextOp)
Create a new plaintext in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.new_plaintext` operands attr-dict `:` functional-type(operands, results)
This operation creates a new plaintext value in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params |
Results:
Result | Description |
---|---|
plaintext |
lattigo.bgv.relinearize
(heir::lattigo::BGVRelinearizeOp)
Relinearize a ciphertext in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.relinearize` operands attr-dict `:` functional-type(operands, results)
This operation relinearizes a ciphertext value in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
input |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.rescale
(heir::lattigo::BGVRescaleOp)
Rescale a ciphertext in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.rescale` operands attr-dict `:` functional-type(operands, results)
This operation rescales a ciphertext value in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
input |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.rotate_columns
(heir::lattigo::BGVRotateColumnsOp)
Rotate columns of a ciphertext in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.rotate_columns` operands attr-dict `:` functional-type(operands, results)
This operation rotates the columns of a ciphertext value in the Lattigo BGV dialect.
Lattigo exposes the SIMD slot of BGV as a N/2 x 2 matrix, where N/2 is the column.
offset is valid in (-N/2, N/2).
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
offset | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
evaluator | |
input |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.rotate_rows
(heir::lattigo::BGVRotateRowsOp)
Rotate rows of a ciphertext in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.rotate_rows` operands attr-dict `:` functional-type(operands, results)
This operation swap the rows of a ciphertext value in the Lattigo BGV dialect.
Lattigo exposes the SIMD slot of BGV as a N/2 x 2 matrix, where 2 is the row.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
input |
Results:
Result | Description |
---|---|
output |
lattigo.bgv.sub
(heir::lattigo::BGVSubOp)
Subtract two ciphertexts in the Lattigo BGV dialect
Syntax:
operation ::= `lattigo.bgv.sub` operands attr-dict `:` functional-type(operands, results)
This operation subtracts one ciphertext value from another in the Lattigo BGV dialect.
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
evaluator | |
lhs | |
rhs | or |
Results:
Result | Description |
---|---|
output |
lattigo.rlwe.decrypt
(heir::lattigo::RLWEDecryptOp)
Decrypts a ciphertext using RLWE
Syntax:
operation ::= `lattigo.rlwe.decrypt` operands attr-dict `:` functional-type(operands, results)
This operation decrypts a ciphertext using RLWE
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
decryptor | |
ciphertext |
Results:
Result | Description |
---|---|
plaintext |
lattigo.rlwe.encrypt
(heir::lattigo::RLWEEncryptOp)
Encrypts a plaintext using RLWE
Syntax:
operation ::= `lattigo.rlwe.encrypt` operands attr-dict `:` functional-type(operands, results)
This operation encrypts a plaintext using RLWE
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
encryptor | |
plaintext |
Results:
Result | Description |
---|---|
ciphertext |
lattigo.rlwe.gen_galois_key
(heir::lattigo::RLWEGenGaloisKeyOp)
Generates a new RLWE Galois key
Syntax:
operation ::= `lattigo.rlwe.gen_galois_key` operands attr-dict `:` functional-type(operands, results)
This operation generates a new RLWE Galois key
galoisElement: Enabling the automorphism X -> X^{galoisElement}.
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
galoisElement | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
keyGenerator | |
secretKey |
Results:
Result | Description |
---|---|
galoisKey |
lattigo.rlwe.gen_key_pair
(heir::lattigo::RLWEGenKeyPairOp)
Generates a new RLWE key pair
Syntax:
operation ::= `lattigo.rlwe.gen_key_pair` operands attr-dict `:` functional-type(operands, results)
This operation generates a new RLWE key pair
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
keyGenerator |
Results:
Result | Description |
---|---|
secretKey | |
publicKey |
lattigo.rlwe.gen_relinearization_key
(heir::lattigo::RLWEGenRelinearizationKeyOp)
Generates a new RLWE relinearization key
Syntax:
operation ::= `lattigo.rlwe.gen_relinearization_key` operands attr-dict `:` functional-type(operands, results)
This operation generates a new RLWE relinearization key
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
keyGenerator | |
secretKey |
Results:
Result | Description |
---|---|
relinearizationKey |
lattigo.rlwe.new_decryptor
(heir::lattigo::RLWENewDecryptorOp)
Creates a new RLWE decryptor
Syntax:
operation ::= `lattigo.rlwe.new_decryptor` operands attr-dict `:` functional-type(operands, results)
This operation creates a new RLWE decryptor
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params | |
secretKey |
Results:
Result | Description |
---|---|
decryptor |
lattigo.rlwe.new_encryptor
(heir::lattigo::RLWENewEncryptorOp)
Creates a new RLWE encryptor
Syntax:
operation ::= `lattigo.rlwe.new_encryptor` operands attr-dict `:` functional-type(operands, results)
This operation creates a new RLWE encryptor
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params | |
publicKey |
Results:
Result | Description |
---|---|
encryptor |
lattigo.rlwe.new_evaluation_key_set
(heir::lattigo::RLWENewEvaluationKeySetOp)
Generates a new RLWE evaluation key set
Syntax:
operation ::= `lattigo.rlwe.new_evaluation_key_set` operands attr-dict `:` functional-type(operands, results)
This operation generates a new RLWE evaluation key set
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
relinearizationKey | |
galoisKeys | variadic of |
Results:
Result | Description |
---|---|
evaluationKeySet |
lattigo.rlwe.new_key_generator
(heir::lattigo::RLWENewKeyGeneratorOp)
Generates a new RLWE key generator
Syntax:
operation ::= `lattigo.rlwe.new_key_generator` operands attr-dict `:` functional-type(operands, results)
This operation generates a new RLWE key generator
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
params |
Results:
Result | Description |
---|---|
keyGenerator |
7 - LWE
’lwe’ Dialect
The lwe
dialect is a dialect for concepts related to cryptosystems
in the Learning With Errors (LWE) family.
See Wikipedia for an overview of LWE and the related RLWE problem.
While one might expect this dialect to contain types along the lines of LWE and RLWE ciphertexts, and operations like encryption, decryption, adding and multiplying ciphertexts, these concepts are not centralized here because they are too scheme-specific.
Instead, this dialect provides attributes that can be attached to tensors
of integer or poly.poly
types, which indicate that they are semantically
LWE and RLWE ciphertexts, respectively.
LWE attributes
ApplicationDataAttr
Syntax:
#lwe.application_data<
mlir::Type, # message_type
Attribute # overflow
>
An attribute describing the semantics of the underlying application data.
The messageType
parameter is used to describe the type and bits of the
original application data, e.g. i1, i32, f32. This type is later mapped
into the plaintext space of an FHE scheme by embedding, scaling, or other
techniques.
This attribute also contains information about the overflow semantics of the
data in the application. By default, we assume that the application program
was written so that the overflow is not expected and the overflow attribute
can can be no_overflow
. For LWE-based CGGI ciphertexts, the overflow
attribute will usually be preserve_overflow
, since messages will overflow
into padding bits.
Parameters:
Parameter | C++ type | Description |
---|---|---|
message_type | mlir::Type | |
overflow | Attribute |
BitFieldEncodingAttr
An attribute describing encoded LWE plaintexts using bit fields.
Syntax:
#lwe.bit_field_encoding<
unsigned, # cleartext_start
unsigned # cleartext_bitwidth
>
A bit field encoding of an integer describes which contiguous region of bits a small integer occupies within a larger integer.
The data describing the encoding consists of the starting bit positions of
the cleartext bit field and its width, where the LSB is bit 0 and the MSB
is bit bit_width-1
. So the above example would have starting bit 30
and
width 3
. The bits not specified for the message have semantics defined
by the scheme or lowering.
Note that this encoding does not specify the underlying bit width of the plaintext space. This is left for lowerings to decide.
The presence of this attribute as the encoding
attribute of a tensor
indicates that the tensor is an LWE ciphertext.
Example (CGGI):
#encoding = #lwe.bit_field_encoding<cleartext_start=30, cleartext_bitwidth=3>
!plaintext = !lwe.lwe_plaintext<encoding = #encoding>
%0 = arith.constant 4 : i3
%1 = lwe.encode %0 { encoding = #encoding }: i3 to !plaintext
The above represents an LWE plaintext encoding the 3-bit cleartext 4 as an
LWE ciphertext in a 32-bit integer, with a single bit of padding at the MSB.
This corresponds to the following, where 0 denotes a 0 bit, b
denotes a
bit of the cleartext, n
denotes a bit reserved for noise, and |
is a
visual aid to show where the bit fields begin and end.
0|bbb|nn...n
MSB^ ^LSB
Example (BGV):
Note: BGV uses the RLWE encodings, but they have the same bit-field encoding attributes as here. So this example serves mainly to show how this attribute can be used to specify storing bits in the LSB of a plaintext.
#encoding = #lwe.bit_field_encoding<cleartext_start=4, cleartext_bitwidth=4>
!plaintext = !lwe.lwe_plaintext<encoding = #encoding>
%0 = arith.constant 9 : i4
%1 = lwe.encode %0 { encoding = #encoding }: i4 to !plaintext
The above represents an LWE plaintext encoding a 4-bit cleartext as an LWE ciphertext in the least-significant bits of a larger integer. This corresponds to the following.
nn...n|bbbb
MSB^ ^LSB
Parameters:
Parameter | C++ type | Description |
---|---|---|
cleartext_start | unsigned | |
cleartext_bitwidth | unsigned |
CiphertextSpaceAttr
Syntax:
#lwe.ciphertext_space<
::mlir::heir::polynomial::RingAttr, # ring
::mlir::heir::lwe::LweEncryptionType, # encryption_type
unsigned # size
>
An attribute describing the ciphertext space and the transformation from plaintext space to ciphertext space of an FHE scheme.
The ciphertext space information includes the ring attribute, describing the space that the ciphertext elements belong to. The ring attribute contains a coefficient type attribute that describes the semantics of the coefficient. For example, a ring modulo $1 + x^1024$ with coefficients modulo $q = 298374$ will be described as
!ideal = !polynomial.int_polynomial<1 + x**1024>
!cmod = !mod_arith.mod_arith<modulus=298374 : i64>
#ring = #polynomial.ring<coefficientType = !cmod, modulus = !ideal>
#ciphertext_space = #lwe.ciphertext_space<ring = #ring, encryption_type = #encryption_type>
Ciphertexts using an RNS representation for $q$ will use an RNS type in their ring’s coefficient type attribute.
// TODO(#1085): Validate syntax of polynomial ring after coefficientType changes.
!ideal = !polynomial.int_polynomial<1 + x**1024>
!limb1 = !mod_arith.mod_arith<modulus=2251799814045697 : i64>
!limb2 = !mod_arith.mod_arith<modulus=65537 : i64>
#rns_mod = !rns.rns<!limb1, !limb2>
#ring = #polynomial.ring<coefficientType = #rns_mod, modulus = #ideal>
#ciphertext_space = #lwe.ciphertext_space<ring = #ring, encryption_type = #encryption_type>
Scalar LWE ciphertexts (like those used in CGGI) use an ideal polynomial of degree 1, $x$. CGGI ciphertexts will typically use a power of two modulus and may use a native integer type for its coefficient modulus.
!ideal = !polynomial.int_polynomial<1 + x**1024>
#ring = #polynomial.ring<coefficientType = i32, modulus = #ideal>
#ciphertext_space = #lwe.ciphertext_space<ring = #ring, encryption_type = #encryption_type>
The ciphertext encoding info is used to describe the way the plaintext data is encoded into the ciphertext (in the MSB, LSB, or mixed).
The size
parameter is used to describe the number of polynomials
comprising the ciphertext. This is typically 2 for RLWE ciphertexts that
are made up of an $(a, b)$ pair and greater than 2 for LWE instances. For
example, after an RLWE multiplication of two size 2 ciphertexts,
the ciphertext’s size will be 3.
Parameters:
Parameter | C++ type | Description |
---|---|---|
ring | ::mlir::heir::polynomial::RingAttr | |
encryption_type | ::mlir::heir::lwe::LweEncryptionType | |
size | unsigned |
CoefficientEncodingAttr
An encoding of cleartexts directly as coefficients.
Syntax:
#lwe.coefficient_encoding<
unsigned # scaling_factor
>
A coefficient encoding of a list of integers asserts that the coefficients
of the polynomials contain the integers, with the same semantics as
constant_coefficient_encoding
for per-coefficient encodings.
A scaling_factor
is optionally applied on the scalar when converting from
a rounded floating point to an integer.
Example:
#coeff_encoding = #lwe.coefficient_encoding<scaling_factor=10000>
Parameters:
Parameter | C++ type | Description |
---|---|---|
scaling_factor | unsigned |
ConstantCoefficientEncodingAttr
An encoding of a scalar in the constant coefficient
Syntax:
#lwe.constant_coefficient_encoding<
unsigned # scaling_factor
>
An encoding of a single scalar into the constant coefficient of the plaintext.
All other coefficients of the plaintext are set to be zero. This encoding is
used to encode scalar LWE ciphertexts where the plaintext space is viewed
as a polynomial ring modulo x
.
The scalar is first multiplied by the scaling_factor
and then rounded to
the nearest integer before encoding into the plaintext coefficient.
Example:
#coeff_encoding = #lwe.constant_coefficient_encoding<scaling_factor=10000>
Parameters:
Parameter | C++ type | Description |
---|---|---|
scaling_factor | unsigned |
FullCRTPackingEncodingAttr
An encoding of cleartexts via CRT slots.
Syntax:
#lwe.full_crt_packing_encoding<
unsigned # scaling_factor
>
This encoding maps a list of integers via the Chinese Remainder Theorem (CRT) into the plaintext space.
Given a ring with irreducible ideal polynomial f(x)
and coefficient
modulus q
, f(x)
can be decomposed modulo q
into a direct product of
lower-degree polynomials. This allows full SIMD-style homomorphic operations
across the slots formed from each factor.
This attribute can only be used in the context of on full CRT packing, where
the polynomial f(x)
splits completely (into linear factors) and the number
of slots equals the degree of f(x)
. This happens when q
is prime and q = 1 mod n
.
A scaling_factor
is optionally applied on the scalar when converting from
a rounded floating point to an integer.
Example:
#coeff_encoding = #lwe.full_crt_packing_encoding<scaling_factor=10000>
Parameters:
Parameter | C++ type | Description |
---|---|---|
scaling_factor | unsigned |
InverseCanonicalEncodingAttr
An encoding of cleartexts via the inverse canonical embedding.
Syntax:
#lwe.inverse_canonical_encoding<
unsigned # scaling_factor
>
Let $n$ be the degree of the polynomials in the plaintext space. An “inverse_canonical_encoding” of a list of real or complex values $v_1, \dots, v_{n/2}$ is (almost) the inverse of the following decoding map.
Define a map $\tau_N$ that maps a polynomial $p \in \mathbb{Z}[x] / (x^N + 1) \to \mathbb{C}^{N/2}$ by evaluating it at the following $N/2$ points, where $\omega = e^{2 \pi i / 2N}$ is the primitive $2N$th root of unity:
[ \omega, \omega^3, \omega^5, \dots, \omega^{N-1} ]
Then the complete decoding operation is $\textup{Decode}(p) = (1/\Delta)\tau_N(p)$, where $\Delta$ is a scaling parameter and $\tau_N$ is the truncated canonical embedding above. The encoding operation is the inverse of the decoding operation, with some caveats explained below.
The map $\tau_N$ is derived from the so-called canonical embedding $\tau$, though in the standard canonical embedding, we evaluate at all odd powers of the root of unity, $\omega, \omega^3, \dots, \omega^{2N-1}$. For polynomials in the slightly larger space $\mathbb{R}[x] / (x^N + 1)$, the image of the canonical embedding is the subspace $H \subset \mathbb{C}^N$ defined by tuples $(z_1, \dots, z_N)$ such that $\overline{z_i} = \overline{z_{N-i+1}}$. Note that this property holds because polynomial evaluation commutes with complex conjugates, and the second half of the roots of unity evaluate are complex conjugates of the first half. The converse, that any such tuple with complex conjugate symmetry has an inverse under $\tau$ with all real coefficients, makes $\tau$ is a bijection onto $H$. $\tau$ and its inverse are explicitly computable as discrete Fourier Transforms.
Because of the symmetry in canonical embedding for real polynomials, inputs to this encoding can be represented as a list of $N/2$ complex points, with the extra symmetric structure left implicit. $\tau_N$ and its inverse can also be explicitly computed without need to expand the vectors to length $N$.
The rounding step is required to invert the decoding because, while cleartexts must be (implicitly) in the subspace $H$, they need not be the output of $\tau_N$ for an integer polynomial. The rounding step ensures we can use integer polynomial plaintexts for the FHE operations. There are multiple rounding mechanisms, and this attribute does not specify which is used, because in theory two ciphertexts that have used different roundings are still compatible, though they may have different noise growth patterns.
The scaling parameter $\Delta$ is specified by the scaling_factor
, which
are applied coefficient-wise using the same semantics as the
constant_coefficient_encoding
.
A typical flow for the CKKS scheme using this encoding would be to apply an inverse FFT operation to invert the canonical embedding to be a polynomial with real coefficients, then encrypt scale the resulting polynomial’s coefficients according to the scaling parameters, then round to get integer coefficients.
Example:
#canonical_encoding = #lwe.inverse_canonical_encoding<scaling_factor=10000>
Parameters:
Parameter | C++ type | Description |
---|---|---|
scaling_factor | unsigned |
KeyAttr
Syntax:
#lwe.key<
int # slot_index
>
An attribute describing the key with which the message is currently encrypted.
The key attribute describes the key with which the message is currently encrypted and decryption can be performed. For example, if the decryption of a ciphertext $c = (c_0(x), c_1(x))$ is performed by computing the inner product $(c_0(x), c_1(x)) \cdot (1, s(x))$ then the key is $(1, s(x))$.
The slot_index
describes the key after using a Galois automorphism to
rotate the plaintext slots by slot_index
. This will correspond to an
action $\phi_k: x \rightarrow x^k$ for some k
that depends on the
structure of the Galois group for the chosen scheme parameters. The
corresponding key will have a new basis $(1, s(x^(k)))$.
Parameters:
Parameter | C++ type | Description |
---|---|---|
slot_index | int |
LWEParamsAttr
Syntax:
#lwe.lwe_params<
IntegerAttr, # cmod
unsigned # dimension
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
cmod | IntegerAttr | |
dimension | unsigned |
ModulusChainAttr
Syntax:
#lwe.modulus_chain<
::llvm::ArrayRef<mlir::IntegerAttr>, # elements
int # current
>
An attribute describing the elements of the modulus chain of an RLWE scheme.
Parameters:
Parameter | C++ type | Description |
---|---|---|
elements | ::llvm::ArrayRef<mlir::IntegerAttr> | |
current | int |
NoOverflowAttr
An attribute informing that application data never overflows.
Syntax: #lwe.no_overflow
This attribute informs lowerings that a program is written so that the message data will never overflow beyond the message type.
// FIXME: Have a separate WraparoundOverflow, which lowers the same as NoOverflow?
PlaintextSpaceAttr
Syntax:
#lwe.plaintext_space<
::mlir::heir::polynomial::RingAttr, # ring
Attribute # encoding
>
An attribute describing the plaintext space and the transformation from application data to plaintext space of an FHE scheme.
The plaintext space information is the ring structure, which contains the plaintext modulus $t$, which may be a power of two in the case of CGGI ciphertexts, or a prime power for RLWE. LWE ciphertexts use the ideal polynomial of degree 1 $x$. The plaintext modulus used in LWE-based CGGI plaintexts describes the full message space $\mathbb{Z}_p$ including the padding bits. The application data info attribute describes the space $\mathbb{Z}_p’$ where $p’ < p$ that the underlying message belongs to.
For RLWE schemes, this will include the type of encoding of application data
integers to a plaintext space Z_p[X]/X^N + 1
. This may be a constant
coefficient encoding, CRT-based packing for SIMD semantics, or other slot
packing. When using full CRT packing, the ring must split into linear
factors. The CKKS scheme will also include attributes describing the complex
encoding, including the scaling factor, which will change after
multiplication and rescaling.
Parameters:
Parameter | C++ type | Description |
---|---|---|
ring | ::mlir::heir::polynomial::RingAttr | |
encoding | Attribute | An encoding of a scalar in the constant coefficient or An encoding of cleartexts directly as coefficients. or An encoding of cleartexts via the inverse canonical embedding. or An encoding of cleartexts via CRT slots. |
PreserveOverflowAttr
An attribute informing that application data overflows in the message type.
Syntax: #lwe.preserve_overflow
This attribute informs lowerings that a program is written so that the message data may overflow beyond the message type.
RLWEParamsAttr
Syntax:
#lwe.rlwe_params<
unsigned, # dimension
::mlir::heir::polynomial::RingAttr # ring
>
An attribute describing classical RLWE parameters:
dimension
: the number of polynomials used in an RLWE sample, analogous to LWEParams.dimension.ring
: the polynomial ring to use.
Parameters:
Parameter | C++ type | Description |
---|---|---|
dimension | unsigned | |
ring | ::mlir::heir::polynomial::RingAttr |
UnspecifiedBitFieldEncodingAttr
An attribute describing unspecified bit field encodings.
Syntax:
#lwe.unspecified_bit_field_encoding<
unsigned # cleartext_bitwidth
>
See LWE_BitFieldEncoding for a description of bit field encodings.
This attribute describes an unspecified bit field encoding; this is where the starting bit position of the cleartext bit field is unspecified, but its width is fixed. A noise growth analysis should be performed to determine the optimal amount of bits needed for noise and padding to specify the bit field encodings starting bit position.
Example:
#lwe_encoding = #lwe.unspecified_bit_field_encoding<cleartext_bitwidth=3>
%lwe_ciphertext = arith.constant <[1,2,3,4]> : tensor<4xi32, #lwe_encoding>
Parameters:
Parameter | C++ type | Description |
---|---|---|
cleartext_bitwidth | unsigned |
LWE types
LWECiphertextType
A type for LWE ciphertexts
Syntax:
!lwe.lwe_ciphertext<
::mlir::Attribute, # encoding
LWEParamsAttr # lwe_params
>
A type for LWE ciphertexts.
This type keeps track of the plaintext integer encoding for the LWE Ciphertext to ensure proper decoding after decryption. It also keeps track of the ring where the LWE ciphertext is defined, which provides information on the ciphertext shape and the ring operations used in LWE operations.
Parameters:
Parameter | C++ type | Description |
---|---|---|
encoding | ::mlir::Attribute | |
lwe_params | LWEParamsAttr |
LWEPlaintextType
A type for LWE plaintexts
Syntax:
!lwe.lwe_plaintext<
::mlir::Attribute # encoding
>
A type for LWE plaintexts.
This type keeps track of the plaintext integer encoding for the LWE plaintext before it is encrypted.
Parameters:
Parameter | C++ type | Description |
---|---|---|
encoding | ::mlir::Attribute |
NewLWECiphertextType
A ciphertext type
Syntax:
!lwe.new_lwe_ciphertext<
ApplicationDataAttr, # application_data
PlaintextSpaceAttr, # plaintext_space
CiphertextSpaceAttr, # ciphertext_space
KeyAttr, # key
ModulusChainAttr # modulus_chain
>
An LWE ciphertext will always contain the application data, plaintext space, ciphertext space, and key information.
A modulus chain is optionally specified for parameter choices in RLWE schemes that use more than one of modulus. When no modulus chain is specified, the ciphertext modulus is always the ciphertext ring’s coefficient modulus.
Parameters:
Parameter | C++ type | Description |
---|---|---|
application_data | ApplicationDataAttr | |
plaintext_space | PlaintextSpaceAttr | |
ciphertext_space | CiphertextSpaceAttr | |
key | KeyAttr | |
modulus_chain | ModulusChainAttr |
NewLWEPlaintextType
A plaintext type
Syntax:
!lwe.new_lwe_plaintext<
ApplicationDataAttr, # application_data
PlaintextSpaceAttr # plaintext_space
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
application_data | ApplicationDataAttr | |
plaintext_space | PlaintextSpaceAttr |
NewLWEPublicKeyType
A public key for LWE
Syntax:
!lwe.new_lwe_public_key<
KeyAttr, # key
::mlir::heir::polynomial::RingAttr # ring
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
key | KeyAttr | |
ring | ::mlir::heir::polynomial::RingAttr |
NewLWESecretKeyType
A secret key for LWE
Syntax:
!lwe.new_lwe_secret_key<
KeyAttr, # key
::mlir::heir::polynomial::RingAttr # ring
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
key | KeyAttr | |
ring | ::mlir::heir::polynomial::RingAttr |
RLWECiphertextType
A type for RLWE ciphertexts
Syntax:
!lwe.rlwe_ciphertext<
::mlir::Attribute, # encoding
RLWEParamsAttr, # rlwe_params
Type # underlying_type
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
encoding | ::mlir::Attribute | |
rlwe_params | RLWEParamsAttr | |
underlying_type | Type |
RLWEPlaintextType
A type for RLWE plaintexts
Syntax:
!lwe.rlwe_plaintext<
::mlir::Attribute, # encoding
::mlir::heir::polynomial::RingAttr, # ring
Type # underlying_type
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
encoding | ::mlir::Attribute | |
ring | ::mlir::heir::polynomial::RingAttr | |
underlying_type | Type |
RLWEPublicKeyType
A public key for RLWE
Syntax:
!lwe.rlwe_public_key<
RLWEParamsAttr # rlwe_params
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
rlwe_params | RLWEParamsAttr |
RLWESecretKeyType
A secret key for RLWE
Syntax:
!lwe.rlwe_secret_key<
RLWEParamsAttr # rlwe_params
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
rlwe_params | RLWEParamsAttr |
LWE ops
lwe.add
(heir::lwe::AddOp)
Add two LWE ciphertexts
Syntax:
operation ::= `lwe.add` operands attr-dict `:` type($output)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A type for LWE ciphertexts |
rhs | A type for LWE ciphertexts |
Results:
Result | Description |
---|---|
output | A type for LWE ciphertexts |
lwe.encode
(heir::lwe::EncodeOp)
Encode an integer to yield an LWE plaintext
Syntax:
operation ::= `lwe.encode` $input attr-dict `:` qualified(type($input)) `to` qualified(type($output))
Encode an integer to yield an LWE plaintext.
This op uses a an encoding attribute to encode the bits of the integer into an LWE plaintext value that can then be encrypted.
Examples:
%Y = lwe.encode %value {encoding = #enc}: i1 to !lwe.lwe_plaintext<encoding = #enc>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
encoding | ::mlir::Attribute | An attribute describing encoded LWE plaintexts using bit fields. or An attribute describing unspecified bit field encodings. |
Operands:
Operand | Description |
---|---|
input | signless-integer-like or floating-point-like |
Results:
Result | Description |
---|---|
output | A type for LWE plaintexts |
lwe.mul_scalar
(heir::lwe::MulScalarOp)
Multiply an LWE ciphertext by a scalar
Syntax:
operation ::= `lwe.mul_scalar` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
ciphertext | ciphertext-like |
scalar | integer |
Results:
Result | Description |
---|---|
output | ciphertext-like |
lwe.radd
(heir::lwe::RAddOp)
Add two RLWE ciphertexts
Syntax:
operation ::= `lwe.radd` operands attr-dict `:` type($output)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
lwe.rlwe_decode
(heir::lwe::RLWEDecodeOp)
Decode an RLWE plaintext to an underlying type
Syntax:
operation ::= `lwe.rlwe_decode` $input attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
encoding | ::mlir::Attribute | An encoding of a scalar in the constant coefficient or An encoding of cleartexts directly as coefficients. or An encoding of cleartexts via the inverse canonical embedding. or An encoding of cleartexts via CRT slots. |
ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring |
Operands:
Operand | Description |
---|---|
input | A plaintext type |
Results:
Result | Description |
---|---|
output | signless-integer-like or floating-point-like |
lwe.rlwe_decrypt
(heir::lwe::RLWEDecryptOp)
Decrypt an RLWE ciphertext to a RLWE plaintext
Syntax:
operation ::= `lwe.rlwe_decrypt` operands attr-dict `:` functional-type(operands, results)
Decrypt an RLWE ciphertext to yield a RLWE plaintext
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
secret_key | A secret key for LWE |
Results:
Result | Description |
---|---|
output | A plaintext type |
lwe.rlwe_encode
(heir::lwe::RLWEEncodeOp)
Encode an integer to yield an RLWE plaintext
Syntax:
operation ::= `lwe.rlwe_encode` $input attr-dict `:` qualified(type($input)) `->` qualified(type($output))
Encode an integer to yield an RLWE plaintext.
This op uses a an encoding attribute to encode the bits of the integer into an RLWE plaintext value that can then be encrypted. CKKS cleartext inputs may be floating points, and a scaling factor described by the encoding will be applied.
Examples:
%Y = lwe.rlwe_encode %value {encoding = #enc, ring = #ring}: i1 to !lwe.rlwe_plaintext<encoding = #enc, ring = #ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
encoding | ::mlir::Attribute | An encoding of a scalar in the constant coefficient or An encoding of cleartexts directly as coefficients. or An encoding of cleartexts via the inverse canonical embedding. or An encoding of cleartexts via CRT slots. |
ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring |
Operands:
Operand | Description |
---|---|
input | signless-integer-like or floating-point-like |
Results:
Result | Description |
---|---|
output | A plaintext type |
lwe.rlwe_encrypt
(heir::lwe::RLWEEncryptOp)
Encrypt an RLWE plaintext to a RLWE ciphertext
Syntax:
operation ::= `lwe.rlwe_encrypt` operands attr-dict `:` functional-type(operands, results)
Encrypt an RLWE plaintext to yield a RLWE ciphertext.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A plaintext type |
key | A secret key for LWE or A public key for LWE |
Results:
Result | Description |
---|---|
output | A ciphertext type |
lwe.rmul
(heir::lwe::RMulOp)
Multiplies two RLWE ciphertexts
Syntax:
operation ::= `lwe.rmul` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, InferTypeOpAdaptor
, SameTypeOperands
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
lwe.rnegate
(heir::lwe::RNegateOp)
Negate a RLWE ciphertexts
Syntax:
operation ::= `lwe.rnegate` operands attr-dict `:` type($output)
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | new-lwe-ciphertext-like |
Results:
Result | Description |
---|---|
output | new-lwe-ciphertext-like |
lwe.rsub
(heir::lwe::RSubOp)
Subtract two RLWE ciphertexts
Syntax:
operation ::= `lwe.rsub` operands attr-dict `:` type($output)
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
lwe.trivial_encrypt
(heir::lwe::TrivialEncryptOp)
Create a trivial encryption of a plaintext.
Syntax:
operation ::= `lwe.trivial_encrypt` operands attr-dict `:` qualified(type(operands)) `to` qualified(type(results))
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
params | ::mlir::heir::lwe::LWEParamsAttr |
Operands:
Operand | Description |
---|---|
input | A type for LWE plaintexts |
Results:
Result | Description |
---|---|
output | A type for LWE ciphertexts |
lwe.reinterpret_underlying_type
(heir::lwe::ReinterpretUnderlyingTypeOp)
A placeholder cast from one ciphertext type to another
Syntax:
operation ::= `lwe.reinterpret_underlying_type` $input attr-dict `:` qualified(type($input)) `to` qualified(type($output))
The cast
op is thus used to translate underlying_type
between
ciphertexts in particular situations , such as when lowering to an API that
does not keep track of types for you.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
LWE additional definitions
LweEncryptionType
An enum attribute representing an encryption method
Cases:
Symbol | Value | String |
---|---|---|
msb | 0 | msb |
lsb | 1 | lsb |
mix | 2 | mix |
8 - Mgmt
‘mgmt’ Dialect
The mgmt
dialect contains scheme-agnostic ciphertext management ops
(like relinearize and mod reduce), to enable initial high-level compiler
passes to perform a first pass at parameter selection, while lower-level
passes may refine them with scheme-specific information.
Mgmt attributes
MgmtAttr
Container attribute for all mgmt parameter
Syntax:
#mgmt.mgmt<
int, # level
int # dimension
>
This attribute is used to store all mgmt parameters.
The attribute is a struct with the following fields:
level
: the level of the ciphertext, from L to 0dimension
: the dimension of the ciphertext, defaults to 2
Internally, this attribute is used by secret-to-
It should be populated by –secret-with-mgmt-
Example:
#mgmt = #mgmt.mgmt<level = 1> // dimension defaults to 2
#mgmt1 = #mgmt.mgmt<level = 1, dimension = 3>
%0 = secret.generic ins(%arg0, %arg1 : !secret.secret<i16>) attrs = {mgmt.mgmt = #mgmt} {
...
} -> !secret.secret<i16>
Parameters:
Parameter | C++ type | Description |
---|---|---|
level | int | |
dimension | int |
Mgmt ops
mgmt.bootstrap
(heir::mgmt::BootstrapOp)
Bootstrap the input ciphertext to refresh its noise budget
Syntax:
operation ::= `mgmt.bootstrap` operands attr-dict `:` type($output)
This is a scheme-agnostic operation that implies bootstrapping of the input ciphertext to refresh its noise budget.
Bootstrapping is a technique used in homomorphic encryption to reduce the noise in a ciphertext, allowing further operations to be performed on it without decryption.
When further lowered, it could be lowered to bgv.bootstrap or ckks.bootstrap depending on the scheme.
For the current backend, only ckks.bootstrap is supported. Further backend may include bgv.bootstrap.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | any type |
Results:
Result | Description |
---|---|
output | any type |
mgmt.modreduce
(heir::mgmt::ModReduceOp)
Modulus switch the input ciphertext down by one limb (RNS assumed)
Syntax:
operation ::= `mgmt.modreduce` operands attr-dict `:` type($output)
This is scheme-agonistic operation that implies modulus switching/rescaling by one limb.
Input ciphertext is assumed to be in RNS form when further lowered.
When further lowered, it could be lowered to bgv.modulus_switch or ckks.rescale depending on the scheme.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | any type |
Results:
Result | Description |
---|---|
output | any type |
mgmt.relinearize
(heir::mgmt::RelinearizeOp)
Relinearize the input ciphertext to be linear
Syntax:
operation ::= `mgmt.relinearize` operands attr-dict `:` type($output)
This is scheme-agonistic operation that implies relinearization of the input ciphertext to be linear (i.e. returns to dimension 2).
This is used solely by multiplication. For rotation, currently HEIR assumes relinearization is done internally and does not have a separate scheme-specific operation for it.
This accepts a ciphertext with dimension > 2 and returns a ciphertext with dimension 2. Note that the semantic includes the relinearization of higher dimension input like input with dimension 4 or higher, which when materialized should require multiple relinearization keys.
When further lowered, it could be lowered to bgv.relinearize or ckks.relinearize depending on the scheme.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | any type |
Results:
Result | Description |
---|---|
output | any type |
9 - ModArith
‘mod_arith’ Dialect
The mod_arith
dialect contains operations used for modulo arithmetic.
ModArith attributes
ModArithAttr
a typed mod_arith attribute
Syntax:
#mod_arith.int<
::mlir::heir::mod_arith::ModArithType, # type
mlir::IntegerAttr # value
>
Example:
#attr = 123:i32
#attr_verbose = #mod_arith.int<123:i32>
Parameters:
Parameter | C++ type | Description |
---|---|---|
type | ::mlir::heir::mod_arith::ModArithType | |
value | mlir::IntegerAttr |
ModArith types
ModArithType
Integer type with modular arithmetic
Syntax:
!mod_arith.int<
::mlir::IntegerAttr # modulus
>
mod_arith.int<p>
represents an element of the ring of integers modulo $p$.
The modulus
attribute is the ring modulus, and mod_arith
operations lower to
arith
operations that produce results in the range [0, modulus)
, often called
the canonical representative.
modulus
is specified with an integer type suffix, for example,
mod_arith.int<65537 : i32>
. This corresponds to the storage type for the
modulus, and is i64
by default.
It is required that the underlying integer type should be larger than
twice the modulus (have one extra bit of storage space) to avoid signedness
issues. For example, when modulus == 2 ** 32 - 1
, the underlying type
for the modulus should be at least i33
, though i64
is a natural choice.
Passes may allow intermediate values that do not always produce a
canonical representative in [0, modulus)
. For example, if the machine storage
type is i64
, but the modulus
fits within an i32
, a lowering could
allow intermediate arithmetic values to grow to as large as an i64
before
reducing them. However, all passes must ensure that values used outside
the local scope (e.g., function return values or arguments to calls to linked
functions) are appropriately reduced to the canonical representative.
modulus
is the modulus the arithmetic working with.
Examples:
!Zp1 = !mod_arith.int<7> // implicitly being i64
!Zp2 = !mod_arith.int<65537 : i32>
!Zp3 = !mod_arith.int<536903681 : i64>
Parameters:
Parameter | C++ type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr |
ModArith ops
mod_arith.add
(heir::mod_arith::AddOp)
Modular addition operation
Syntax:
operation ::= `mod_arith.add` operands attr-dict `:` type($output)
Computes modular addition.
Unless otherwise specified, the operation assumes both inputs are canonical representatives and guarantees the output being canonical representative.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | mod_arith-like |
rhs | mod_arith-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
mod_arith.barrett_reduce
(heir::mod_arith::BarrettReduceOp)
Compute the first step of the Barrett reduction.
Syntax:
operation ::= `mod_arith.barrett_reduce` operands attr-dict `:` qualified(type($input))
Let $q$ denote a statically known modulus and $b = 4^{w}$, where $w$ is the
smallest bit-width that contains the range $[0, q)$. The Barrett reduce
operation computes barret_reduce x = x - floor(x * floor(b / q) / b) * q
.
Given $0 <= x < q^2$, then this will compute $(x \mod q)$ or $(x \mod q) + q$.
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
modulus | ::mlir::IntegerAttr | arbitrary integer attribute |
Operands:
Operand | Description |
---|---|
input | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.constant
(heir::mod_arith::ConstantOp)
Define a constant value via an attribute.
Example:
%0 = mod_arith.constant 123 : !mod_arith.int<65537:i32>
Traits: AlwaysSpeculatableImplTrait
, InferTypeOpAdaptor
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
value | ::mlir::heir::mod_arith::ModArithAttr | a typed mod_arith attribute |
Results:
Result | Description |
---|---|
output | Integer type with modular arithmetic |
mod_arith.encapsulate
(heir::mod_arith::EncapsulateOp)
Encapsulate an integer into a mod_arith type
Syntax:
operation ::= `mod_arith.encapsulate` operands attr-dict `:` type($input) `->` type($output)
mod_arith.encapsulate
converts the integer to be of mod_arith type.
Examples:
mod_arith.encapsulate %c0 : i32 -> mod_arith.int<65537 : i32>
mod_arith.encapsulate %c1 : i64 -> mod_arith.int<65537>
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | signless-integer-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
mod_arith.extract
(heir::mod_arith::ExtractOp)
Extract the integer stored inside mod_arith type
Syntax:
operation ::= `mod_arith.extract` operands attr-dict `:` type($input) `->` type($output)
mod_arith.extract
extracts the integer inside the mod_arith type.
It is required that the bitwidth of the output integer type is the same as that of the storage type of the input mod_arith type.
Examples:
%m0 = mod_arith.encapsulate %c0 : i32 -> mod_arith.int<65537 : i32>
%m1 = mod_arith.encapsulate %c1 : i64 -> mod_arith.int<65537>
%c2 = mod_arith.extract %m0 : mod_arith.int<65537 : i32> -> i32
%c3 = mod_arith.extract %m1 : mod_arith.int<65537> -> i64
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | mod_arith-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.mac
(heir::mod_arith::MacOp)
Modular multiplication-and-accumulation operation
Syntax:
operation ::= `mod_arith.mac` operands attr-dict `:` type($output)
mod_arith.mac x, y, z
computes $(x * y) + z$
Unless otherwise specified, the operation assumes all inputs are canonical representatives and guarantees the output being canonical representative.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | mod_arith-like |
rhs | mod_arith-like |
acc | mod_arith-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
mod_arith.mod_switch
(heir::mod_arith::ModSwitchOp)
Change the modulus of a mod_arith
Syntax:
operation ::= `mod_arith.mod_switch` $input attr-dict `:` type($input) `to` type($output)
“mod_switch” operation to change the modulus of a mod_arith type to a bigger space.
Examples:
`mod_arith.mod_switch %c0 : mod_arith.int<65537 : i32> to mod_arith.int<65539 : i32>`
Traits: AlwaysSpeculatableImplTrait
, SameOperandsAndResultShape
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | Integer type with modular arithmetic |
Results:
Result | Description |
---|---|
output | Integer type with modular arithmetic |
mod_arith.mul
(heir::mod_arith::MulOp)
Modular multiplication operation
Syntax:
operation ::= `mod_arith.mul` operands attr-dict `:` type($output)
Computes modular multiplication.
Unless otherwise specified, the operation assumes both inputs are canonical representatives and guarantees the output being canonical representative.
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | mod_arith-like |
rhs | mod_arith-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
mod_arith.reduce
(heir::mod_arith::ReduceOp)
Reduce the mod arith type to its canonical representative
Syntax:
operation ::= `mod_arith.reduce` operands attr-dict `:` type($output)
mod_arith.reduce x
produces $y$, the canonical representative in $[0, q)$
such that $x \equiv y \mod q$.
Examples:
%c0 = arith.constant 65538 : i32
%m0 = mod_arith.encapsulate %c0 : i32 -> mod_arith.int<65537 : i32>
// mod_arith.extract %m0 produces 65538
%m1 = mod_arith.reduce %m0 : mod_arith.int<65537: i32>
// mod_arith.extract %m1 produces 1
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | mod_arith-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
mod_arith.subifge
(heir::mod_arith::SubIfGEOp)
Compute (x >= y) ? x - y : x.
Syntax:
operation ::= `mod_arith.subifge` operands attr-dict `:` qualified(type($output))
Traits: SameOperandsAndResultType
Interfaces: InferTypeOpInterface
Operands:
Operand | Description |
---|---|
lhs | signless-integer-like |
rhs | signless-integer-like |
Results:
Result | Description |
---|---|
output | signless-integer-like |
mod_arith.sub
(heir::mod_arith::SubOp)
Modular subtraction operation
Syntax:
operation ::= `mod_arith.sub` operands attr-dict `:` type($output)
Computes modular subtraction.
Unless otherwise specified, the operation assumes both inputs are canonical representatives and guarantees the output being canonical representative.
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | mod_arith-like |
rhs | mod_arith-like |
Results:
Result | Description |
---|---|
output | mod_arith-like |
10 - Openfhe
‘openfhe’ Dialect
The openfhe
dialect is an exit dialect for generating c++ code against the OpenFHE library API.
See https://github.com/openfheorg/openfhe-development
Openfhe types
CCParamsType
The CCParams required to create CryptoContext.
Syntax: !openfhe.cc_params
CryptoContextType
The CryptoContext required to perform homomorphic operations in OpenFHE.
Syntax: !openfhe.crypto_context
EvalKeyType
The evaluation key required to keyswitch/relinearize/rotate/automorphism operation in OpenFHE.
Syntax: !openfhe.eval_key
PrivateKeyType
The private key required to decrypt a ciphertext in OpenFHE.
Syntax: !openfhe.private_key
PublicKeyType
The public key required to encrypt plaintext in OpenFHE.
Syntax: !openfhe.public_key
Openfhe ops
openfhe.add
(heir::openfhe::AddOp)
OpenFHE add operation of two ciphertexts.
Syntax:
operation ::= `openfhe.add` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.add_plain
(heir::openfhe::AddPlainOp)
OpenFHE add operation of a ciphertext and a plaintext.
Syntax:
operation ::= `openfhe.add_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
plaintext | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.automorph
(heir::openfhe::AutomorphOp)
Syntax:
operation ::= `openfhe.automorph` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
evalKey | The evaluation key required to keyswitch/relinearize/rotate/automorphism operation in OpenFHE. |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.bootstrap
(heir::openfhe::BootstrapOp)
OpenFHE bootstrap operation of a ciphertext. (For CKKS)
Syntax:
operation ::= `openfhe.bootstrap` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.decrypt
(heir::openfhe::DecryptOp)
Syntax:
operation ::= `openfhe.decrypt` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
privateKey | The private key required to decrypt a ciphertext in OpenFHE. |
Results:
Result | Description |
---|---|
plaintext | A plaintext type |
openfhe.encrypt
(heir::openfhe::EncryptOp)
Syntax:
operation ::= `openfhe.encrypt` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
plaintext | A plaintext type |
publicKey | The public key required to encrypt plaintext in OpenFHE. |
Results:
Result | Description |
---|---|
ciphertext | A ciphertext type |
openfhe.gen_bootstrapkey
(heir::openfhe::GenBootstrapKeyOp)
Syntax:
operation ::= `openfhe.gen_bootstrapkey` operands attr-dict `:` functional-type(operands, results)
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
privateKey | The private key required to decrypt a ciphertext in OpenFHE. |
openfhe.gen_context
(heir::openfhe::GenContextOp)
Syntax:
operation ::= `openfhe.gen_context` operands attr-dict `:` functional-type(operands, results)
Interfaces: InferTypeOpInterface
, OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
supportFHE | ::mlir::BoolAttr | bool attribute |
Operands:
Operand | Description |
---|---|
params | The CCParams required to create CryptoContext. |
Results:
Result | Description |
---|---|
context | The CryptoContext required to perform homomorphic operations in OpenFHE. |
openfhe.gen_mulkey
(heir::openfhe::GenMulKeyOp)
Syntax:
operation ::= `openfhe.gen_mulkey` operands attr-dict `:` functional-type(operands, results)
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
privateKey | The private key required to decrypt a ciphertext in OpenFHE. |
openfhe.gen_params
(heir::openfhe::GenParamsOp)
Syntax:
operation ::= `openfhe.gen_params` operands attr-dict `:` functional-type(operands, results)
Generates the parameters for the OpenFHE scheme.
mulDepth
is the depth of the multiplication circuit,
including the bootstrapping depth.
plainMod
is the modulus of the plaintext space. If we
are using CKKS, this is 0.
insecure
is a flag that determines whether the parameters
are generated securely or not. This is mainly used for
testing purposes.
Interfaces: InferTypeOpInterface
, OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
mulDepth | ::mlir::IntegerAttr | 64-bit signless integer attribute |
plainMod | ::mlir::IntegerAttr | 64-bit signless integer attribute |
insecure | ::mlir::BoolAttr | bool attribute |
Results:
Result | Description |
---|---|
params | The CCParams required to create CryptoContext. |
openfhe.gen_rotkey
(heir::openfhe::GenRotKeyOp)
Syntax:
operation ::= `openfhe.gen_rotkey` operands attr-dict `:` functional-type(operands, results)
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
indices | ::mlir::DenseI64ArrayAttr | i64 dense array attribute |
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
privateKey | The private key required to decrypt a ciphertext in OpenFHE. |
openfhe.key_switch
(heir::openfhe::KeySwitchOp)
Syntax:
operation ::= `openfhe.key_switch` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
evalKey | The evaluation key required to keyswitch/relinearize/rotate/automorphism operation in OpenFHE. |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.level_reduce
(heir::openfhe::LevelReduceOp)
OpenFHE level_reduce operation of a ciphertext.
Syntax:
operation ::= `openfhe.level_reduce` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.make_ckks_packed_plaintext
(heir::openfhe::MakeCKKSPackedPlaintextOp)
Syntax:
operation ::= `openfhe.make_ckks_packed_plaintext` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
value | ranked tensor of floating-point or integer values |
Results:
Result | Description |
---|---|
plaintext | A plaintext type |
openfhe.make_packed_plaintext
(heir::openfhe::MakePackedPlaintextOp)
Syntax:
operation ::= `openfhe.make_packed_plaintext` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
value | ranked tensor of integer values |
Results:
Result | Description |
---|---|
plaintext | A plaintext type |
openfhe.mod_reduce
(heir::openfhe::ModReduceOp)
OpenFHE mod_reduce operation of a ciphertext. (used only for BGV/CKKS)
Syntax:
operation ::= `openfhe.mod_reduce` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.mul_const
(heir::openfhe::MulConstOp)
OpenFHE mul operation of a ciphertext and a constant.
Syntax:
operation ::= `openfhe.mul_const` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
constant | 64-bit signless integer |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.mul_no_relin
(heir::openfhe::MulNoRelinOp)
OpenFHE mul operation of two ciphertexts without relinearization.
Syntax:
operation ::= `openfhe.mul_no_relin` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.mul
(heir::openfhe::MulOp)
OpenFHE mul operation of two ciphertexts with relinearization.
Syntax:
operation ::= `openfhe.mul` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.mul_plain
(heir::openfhe::MulPlainOp)
OpenFHE mul operation of a ciphertext and a plaintext.
Syntax:
operation ::= `openfhe.mul_plain` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
plaintext | A plaintext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.negate
(heir::openfhe::NegateOp)
OpenFHE negate operation of a ciphertext.
Syntax:
operation ::= `openfhe.negate` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.relin
(heir::openfhe::RelinOp)
OpenFHE relinearize operation of a ciphertext.
Syntax:
operation ::= `openfhe.relin` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.rot
(heir::openfhe::RotOp)
Syntax:
operation ::= `openfhe.rot` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
index | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.setup_bootstrap
(heir::openfhe::SetupBootstrapOp)
Syntax:
operation ::= `openfhe.setup_bootstrap` operands attr-dict `:` functional-type(operands, results)
Interfaces: OpAsmOpInterface
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
levelBudgetEncode | ::mlir::IntegerAttr | An Attribute containing a integer value |
levelBudgetDecode | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
openfhe.square
(heir::openfhe::SquareOp)
OpenFHE square operation of a ciphertext.
Syntax:
operation ::= `openfhe.square` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
ciphertext | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
openfhe.sub
(heir::openfhe::SubOp)
OpenFHE sub operation of two ciphertexts.
Syntax:
operation ::= `openfhe.sub` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
, OpAsmOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cryptoContext | The CryptoContext required to perform homomorphic operations in OpenFHE. |
lhs | A ciphertext type |
rhs | A ciphertext type |
Results:
Result | Description |
---|---|
output | A ciphertext type |
11 - Polynomial
‘polynomial’ Dialect
The Polynomial dialect defines single-variable polynomial types and operations.
The simplest use of polynomial
is to represent mathematical operations in
a polynomial ring R[x]
, where R
is another MLIR type like i32
.
More generally, this dialect supports representing polynomial operations in a
quotient ring R[X]/(f(x))
for some statically fixed polynomial f(x)
.
Two polyomials p(x), q(x)
are considered equal in this ring if they have the
same remainder when dividing by f(x)
. When a modulus is given, ring operations
are performed with reductions modulo f(x)
and relative to the coefficient ring
R
.
Examples:
// A constant polynomial in a ring with i32 coefficients and no polynomial modulus
#ring = #polynomial.ring<coefficientType=i32>
%a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
// A constant polynomial in a ring with i32 coefficients, modulo (x^1024 + 1)
#modulus = #polynomial.int_polynomial<1 + x**1024>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#modulus>
%a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
// A constant polynomial in a ring with i32 coefficients, with a polynomial
// modulus of (x^1024 + 1) and a coefficient modulus of 17.
#modulus = #polynomial.int_polynomial<1 + x**1024>
!coeff_ty = !mod_arith.mod_arith<17:i32>
#ring = #polynomial.ring<coefficientType=!coeff_ty, polynomialModulus=#modulus>
%a = polynomial.constant <1 + x**2 - 3x**3> : polynomial.polynomial<#ring>
Polynomial attributes
FloatPolynomialAttr
an attribute containing a single-variable polynomial with double precision floating point coefficients
A polynomial attribute represents a single-variable polynomial with double precision floating point coefficients.
The polynomial must be expressed as a list of monomial terms, with addition or subtraction between them. The choice of variable name is arbitrary, but must be consistent across all the monomials used to define a single attribute. The order of monomial terms is arbitrary, each monomial degree must occur at most once.
Example:
#poly = #polynomial.float_polynomial<0.5 x**7 + 1.5>
Parameters:
Parameter | C++ type | Description |
---|---|---|
polynomial | FloatPolynomial |
IntPolynomialAttr
an attribute containing a single-variable polynomial with integer coefficients
A polynomial attribute represents a single-variable polynomial with integer
coefficients, which is used to define the modulus of a RingAttr
, as well
as to define constants and perform constant folding for polynomial
ops.
The polynomial must be expressed as a list of monomial terms, with addition or subtraction between them. The choice of variable name is arbitrary, but must be consistent across all the monomials used to define a single attribute. The order of monomial terms is arbitrary, each monomial degree must occur at most once.
Example:
#poly = #polynomial.int_polynomial<x**1024 + 1>
Parameters:
Parameter | C++ type | Description |
---|---|---|
polynomial | ::mlir::heir::polynomial::IntPolynomial |
PrimitiveRootAttr
an attribute containing an integer and its degree as a root of unity
Syntax:
#polynomial.primitive_root<
::mlir::IntegerAttr, # value
::mlir::IntegerAttr # degree
>
A primitive root attribute stores an integer root value
and an integer
degree
, corresponding to a primitive root of unity of the given degree in
an unspecified ring.
This is used as an attribute on polynomial.ntt
and polynomial.intt
ops
to specify the root of unity used in lowering the transform.
Example:
#poly = #polynomial.primitive_root<value=123 : i32, degree : 7 index>
Parameters:
Parameter | C++ type | Description |
---|---|---|
value | ::mlir::IntegerAttr | |
degree | ::mlir::IntegerAttr |
RingAttr
an attribute specifying a polynomial ring
Syntax:
#polynomial.ring<
Type, # coefficientType
::mlir::heir::polynomial::IntPolynomialAttr # polynomialModulus
>
A ring describes the domain in which polynomial arithmetic occurs. The ring
attribute in polynomial
represents the more specific case of polynomials
with a single indeterminate; whose coefficients can be represented by
another MLIR type (coefficientType
).
All semantics pertaining to arithmetic in the ring must be owned by the
coefficient type. For example, if the polynomials are with integer
coefficients taken modulo a prime $p$, then coefficientType
must be a
type that represents integers modulo $p$, such as mod_arith<p>
.
Additionally, a polynomial ring may specify a polynomialModulus
, which
converts polynomial arithmetic to the analogue of modular integer
arithmetic, where each polynomial is represented as its remainder when
dividing by the modulus. For single-variable polynomials, a polynomial
modulus is always specified via a single polynomial.
An expressive example is polynomials with i32 coefficients, whose
coefficients are taken modulo 2**32 - 5
, with a polynomial modulus of
x**1024 - 1
.
#poly_mod = #polynomial.int_polynomial<-1 + x**1024>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly_mod>
%0 = ... : polynomial.polynomial<#ring>
In this case, the value of a polynomial is always “converted” to a
canonical form by applying repeated reductions by setting x**1024 = 1
and simplifying.
Parameters:
Parameter | C++ type | Description |
---|---|---|
coefficientType | Type | |
polynomialModulus | ::mlir::heir::polynomial::IntPolynomialAttr |
TypedFloatPolynomialAttr
a typed float_polynomial
Syntax:
#polynomial.typed_float_polynomial<
::mlir::Type, # type
::mlir::heir::polynomial::FloatPolynomialAttr # value
>
Example:
!poly_ty = !polynomial.polynomial<ring=<coefficientType=f32>>
#poly = float<1.4 x**7 + 4.5> : !poly_ty
#poly_verbose = #polynomial.typed_float_polynomial<1.4 x**7 + 4.5> : !poly_ty
Parameters:
Parameter | C++ type | Description |
---|---|---|
type | ::mlir::Type | |
value | ::mlir::heir::polynomial::FloatPolynomialAttr |
TypedIntPolynomialAttr
a typed int_polynomial
Syntax:
#polynomial.typed_int_polynomial<
::mlir::Type, # type
::mlir::heir::polynomial::IntPolynomialAttr # value
>
Example:
!poly_ty = !polynomial.polynomial<ring=<coefficientType=i32>>
#poly = int<1 x**7 + 4> : !poly_ty
#poly_verbose = #polynomial.typed_int_polynomial<1 x**7 + 4> : !poly_ty
Parameters:
Parameter | C++ type | Description |
---|---|---|
type | ::mlir::Type | |
value | ::mlir::heir::polynomial::IntPolynomialAttr |
Polynomial types
PolynomialType
An element of a polynomial ring.
Syntax:
!polynomial.polynomial<
::mlir::heir::polynomial::RingAttr # ring
>
A type for polynomials in a polynomial quotient ring.
Parameters:
Parameter | C++ type | Description |
---|---|---|
ring | ::mlir::heir::polynomial::RingAttr | an attribute specifying a polynomial ring |
Polynomial ops
polynomial.add
(heir::polynomial::AddOp)
Addition operation between polynomials.
Syntax:
operation ::= `polynomial.add` operands attr-dict `:` type($result)
Performs polynomial addition on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
This op is defined to occur in the ring defined by the ring attribute of the two operands, meaning the arithmetic is taken modulo the polynomialModulus of the ring as well as modulo any semantics defined by the coefficient type.
Example:
// add two polynomials modulo x^1024 - 1
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%0 = polynomial.constant int<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant int<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.add %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results:
Result | Description |
---|---|
result | polynomial-like |
polynomial.constant
(heir::polynomial::ConstantOp)
Define a constant polynomial via an attribute.
Example:
!int_poly_ty = !polynomial.polynomial<ring=<coefficientType=i32>>
%0 = polynomial.constant int<1 + x**2> : !int_poly_ty
!float_poly_ty = !polynomial.polynomial<ring=<coefficientType=f32>>
%1 = polynomial.constant float<0.5 + 1.3e06 x**2> : !float_poly_ty
Traits: AlwaysSpeculatableImplTrait
, InferTypeOpAdaptor
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
value | ::mlir::Attribute | a typed float_polynomial or a typed int_polynomial |
Results:
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.from_tensor
(heir::polynomial::FromTensorOp)
Creates a polynomial from integer coefficients stored in a tensor.
Syntax:
operation ::= `polynomial.from_tensor` $input attr-dict `:` type($input) `->` type($output)
polynomial.from_tensor
creates a polynomial value from a tensor of coefficients.
The input tensor must list the coefficients in degree-increasing order.
The input one-dimensional tensor may have size at most the degree of the ring’s polynomialModulus generator polynomial, with smaller dimension implying that all higher-degree terms have coefficient zero.
Example:
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%two = arith.constant 2 : i32
%five = arith.constant 5 : i32
%coeffs = tensor.from_elements %two, %two, %five : tensor<3xi32>
%poly = polynomial.from_tensor %coeffs : tensor<3xi32> -> !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | ranked tensor of any type values |
Results:
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.intt
(heir::polynomial::INTTOp)
Computes the reverse integer Number Theoretic Transform (NTT).
Syntax:
operation ::= `polynomial.intt` $input attr-dict `:` qualified(type($input)) `->` type($output)
polynomial.intt
computes the reverse integer Number Theoretic Transform
(INTT) on the input tensor. This is the inverse operation of the
polynomial.ntt
operation.
The input tensor is interpreted as a point-value representation of the
output polynomial at powers of a primitive n
-th root of unity (see
polynomial.ntt
). The ring of the polynomial is taken from the required
encoding attribute of the tensor.
The choice of primitive root may be optionally specified.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
root | ::mlir::heir::polynomial::PrimitiveRootAttr | an attribute containing an integer and its degree as a root of unity |
Operands:
Operand | Description |
---|---|
input | ranked tensor of Integer type with modular arithmetic values |
Results:
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.leading_term
(heir::polynomial::LeadingTermOp)
Compute the leading term of the polynomial.
Syntax:
operation ::= `polynomial.leading_term` operands attr-dict `:` type($input) `->` `(` type($degree) `,` type($coefficient) `)`
The degree of a polynomial is the largest $k$ for which the coefficient
a_k
of x^k
is nonzero. The leading term is the term a_k * x^k
, which
this op represents as a pair of results. The first is the degree k
as an
index, and the second is the coefficient, whose type matches the
coefficient type of the polynomial’s ring attribute.
Example:
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%0 = polynomial.constant int<1 + x**2> : !polynomial.polynomial<#ring>
%1, %2 = polynomial.leading_term %0 : !polynomial.polynomial<#ring> -> (index, i32)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | An element of a polynomial ring. |
Results:
Result | Description |
---|---|
degree | index |
coefficient | any type |
polynomial.monic_monomial_mul
(heir::polynomial::MonicMonomialMulOp)
Multiply a polynomial by a monic monomial.
Syntax:
operation ::= `polynomial.monic_monomial_mul` operands attr-dict `:` functional-type(operands, results)
Multiply a polynomial by a monic monomial, meaning a polynomial of the form
1 * x^k
for an index operand k
.
In some special rings of polynomials, such as a ring of polynomials
modulo x^n - 1
, monomial_mul
can be interpreted as a cyclic shift of
the coefficients of the polynomial. For some rings, this results in
optimized lowerings that involve rotations and rescaling of the
coefficients of the input.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | polynomial-like |
monomialDegree | index |
Results:
Result | Description |
---|---|
output | polynomial-like |
polynomial.monomial
(heir::polynomial::MonomialOp)
Create a polynomial that consists of a single monomial.
Syntax:
operation ::= `polynomial.monomial` operands attr-dict `:` functional-type(operands, results)
Construct a polynomial that consists of a single monomial term, from its degree and coefficient as dynamic inputs.
The coefficient type of the output polynomial’s ring attribute must match
the coefficient
input type.
Example:
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%deg = arith.constant 1023 : index
%five = arith.constant 5 : i32
%0 = polynomial.monomial %five, %deg : (i32, index) -> !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
coefficient | any type |
degree | index |
Results:
Result | Description |
---|---|
output | An element of a polynomial ring. |
polynomial.mul
(heir::polynomial::MulOp)
Multiplication operation between polynomials.
Syntax:
operation ::= `polynomial.mul` operands attr-dict `:` type($result)
Performs polynomial multiplication on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
This op is defined to occur in the ring defined by the ring attribute of the two operands, meaning the arithmetic is taken modulo the polynomialModulus of the ring as well as modulo any semantics defined by the coefficient type.
Example:
// multiply two polynomials modulo x^1024 - 1
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%0 = polynomial.constant int<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant int<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.mul %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results:
Result | Description |
---|---|
result | polynomial-like |
polynomial.mul_scalar
(heir::polynomial::MulScalarOp)
Multiplication by a scalar of the field.
Syntax:
operation ::= `polynomial.mul_scalar` operands attr-dict `:` type($polynomial) `,` type($scalar)
Multiplies the polynomial operand’s coefficients by a given scalar value.
The scalar
input must have the same type as the polynomial ring’s
coefficientType.
Example:
// multiply two polynomials modulo x^1024 - 1
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%0 = polynomial.constant int<1 + x**2> : !polynomial.polynomial<#ring>
%1 = arith.constant 3 : i32
%2 = polynomial.mul_scalar %0, %1 : !polynomial.polynomial<#ring>, i32
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
polynomial | polynomial-like |
scalar | any type |
Results:
Result | Description |
---|---|
output | polynomial-like |
polynomial.ntt
(heir::polynomial::NTTOp)
Computes point-value tensor representation of a polynomial.
Syntax:
operation ::= `polynomial.ntt` $input attr-dict `:` qualified(type($input)) `->` type($output)
polynomial.ntt
computes the forward integer Number Theoretic Transform
(NTT) on the input polynomial. It returns a tensor containing a point-value
representation of the input polynomial. The output tensor has shape equal
to the degree of the ring’s polynomialModulus
. The polynomial’s RingAttr
is embedded as the encoding attribute of the output tensor.
Given an input polynomial F(x)
over a ring whose polynomialModulus
has
degree n
, and a primitive n
-th root of unity omega_n
, the output is
the list of $n$ evaluations
f[k] = F(omega[n]^k) ; k = {0, ..., n-1}
The choice of primitive root may be optionally specified.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
root | ::mlir::heir::polynomial::PrimitiveRootAttr | an attribute containing an integer and its degree as a root of unity |
Operands:
Operand | Description |
---|---|
input | An element of a polynomial ring. |
Results:
Result | Description |
---|---|
output | ranked tensor of Integer type with modular arithmetic values |
polynomial.sub
(heir::polynomial::SubOp)
Subtraction operation between polynomials.
Syntax:
operation ::= `polynomial.sub` operands attr-dict `:` type($result)
Performs polynomial subtraction on the operands. The operands may be single polynomials or containers of identically-typed polynomials, i.e., polynomials from the same underlying ring with the same coefficient types.
This op is defined to occur in the ring defined by the ring attribute of the two operands, meaning the arithmetic is taken modulo the polynomialModulus of the ring as well as modulo any semantics defined by the coefficient type.
Example:
// subtract two polynomials modulo x^1024 - 1
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%0 = polynomial.constant int<1 + x**2> : !polynomial.polynomial<#ring>
%1 = polynomial.constant int<x**5 - x + 1> : !polynomial.polynomial<#ring>
%2 = polynomial.sub %0, %1 : !polynomial.polynomial<#ring>
Traits: AlwaysSpeculatableImplTrait
, Elementwise
, SameOperandsAndResultType
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
lhs | polynomial-like |
rhs | polynomial-like |
Results:
Result | Description |
---|---|
result | polynomial-like |
polynomial.to_tensor
(heir::polynomial::ToTensorOp)
Creates a tensor containing the coefficients of a polynomial.
Syntax:
operation ::= `polynomial.to_tensor` $input attr-dict `:` type($input) `->` type($output)
polynomial.to_tensor
creates a dense tensor value containing the
coefficients of the input polynomial. The output tensor contains the
coefficients in degree-increasing order.
Operations that act on the coefficients of a polynomial, such as extracting
a specific coefficient or extracting a range of coefficients, should be
implemented by composing to_tensor
with the relevant tensor
dialect
ops.
The output tensor has shape equal to the degree of the polynomial ring attribute’s polynomialModulus, including zeroes.
Example:
#poly = #polynomial.int_polynomial<x**1024 - 1>
#ring = #polynomial.ring<coefficientType=i32, polynomialModulus=#poly>
%two = arith.constant 2 : i32
%five = arith.constant 5 : i32
%coeffs = tensor.from_elements %two, %two, %five : tensor<3xi32>
%poly = polynomial.from_tensor %coeffs : tensor<3xi32> -> !polynomial.polynomial<#ring>
%tensor = polynomial.to_tensor %poly : !polynomial.polynomial<#ring> -> tensor<1024xi32>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | An element of a polynomial ring. |
Results:
Result | Description |
---|---|
output | ranked tensor of any type values |
12 - Random
‘random’ Dialect
The random
dialect contains operations used to generate random numbers.
Random types
DistributionType
A random distribution type
Syntax:
!random.distribution<
::mlir::heir::random::Distribution # distribution_type
>
A generic type, representing a specific random distribution type of either uniform or gaussian as an attribute ($distribution_type).
Parameters:
Parameter | C++ type | Description |
---|---|---|
distribution_type | ::mlir::heir::random::Distribution |
PRNGType
A pseudorandom number generator type
Syntax: !random.prng
A type that provides pseudorandom number generator.
Random ops
random.discrete_gaussian_distribution
(heir::random::DiscreteGaussianDistributionOp)
Initializes the Discrete Gaussian Distribution
Syntax:
operation ::= `random.discrete_gaussian_distribution` operands attr-dict `:` functional-type(operands, results)
Initializes the Discrete Gaussian Distribution. The distribution is initialized with a mean and a standard deviation and pseudorandom generator that provides the source of the randomness.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
mean | ::mlir::IntegerAttr | An Attribute containing a integer value |
stddev | ::mlir::IntegerAttr | An Attribute containing a integer value whose value is non-negative |
Operands:
Operand | Description |
---|---|
input | A pseudorandom number generator type |
Results:
Result | Description |
---|---|
output | A random distribution type |
random.discrete_uniform_distribution
(heir::random::DiscreteUniformDistributionOp)
Initializes the Discrete Uniform Distribution
Syntax:
operation ::= `random.discrete_uniform_distribution` $input `{` `range` `=` `[` $min `,` $max `]` `}` attr-dict `:` `(` qualified(type($input)) `)` `->` type($output)
Initializes the Discrete Uniform Distribution. The distribution is initialized with a minimum and a maximum value and pseudo random generator that provides the source of the randomness. The distribution is inclusive of the minimum and exclusive of the maximum.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
min | ::mlir::IntegerAttr | An Attribute containing a integer value |
max | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
input | A pseudorandom number generator type |
Results:
Result | Description |
---|---|
output | A random distribution type |
random.init_prng
(heir::random::InitOp)
Initializes the pseudorandom number generator with a seed.
Syntax:
operation ::= `random.init_prng` operands attr-dict `:` functional-type(operands, results)
Initializes the PRNG with a seed. The seed is dynamically provided due to protocols that agree on shared randomness. The PRNG is used to initialized the random distributions such as the discrete gaussian distribution and the discrete uniform distribution. This initialization also takes as input a number of bits that are generated for each number value sampled (num_bits). For instance, a num_bits of 32 will mean that distributions will generate a 32-bit integer value. We expect that the seed initialization is done statically and globally once per thread for all distributions; however, if multiple threads are generating randomness, then seed initialization should be done per thread; otherwise there is no guarantee of consistent behavior. Thread safety is so far not considered.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
num_bits | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
seed | signless-integer-like |
Results:
Result | Description |
---|---|
output | A pseudorandom number generator type |
random.sample
(heir::random::SampleOp)
Samples from a distribution
Syntax:
operation ::= `random.sample` operands attr-dict `:` functional-type(operands, results)
Samples from the distribution to obtain a random value or tensor of values.
Operands:
Operand | Description |
---|---|
input | A random distribution type |
Results:
Result | Description |
---|---|
output | signless-integer-like |
Random additional definitions
Distribution
An enum attribute representing a random distribution
Cases:
Symbol | Value | String |
---|---|---|
uniform | 0 | uniform |
gaussian | 1 | gaussian |
13 - RNS
‘rns’ Dialect
The rns
dialect represents types and ops related to residue number
system (RNS) representations of ring-like types, such as integers or
polynomials decomposed from high-bit width to lower-bit-width prime
moduli. Sometimes RNS is referred to as CRT, for “Chinese Remainder
Theorem.”
This dialect is intended to be as generic as possible in terms of its
interaction with standard MLIR. However, because of upstream MLIR
constraints, we do not have the ability to override, say, arith.addi
to operate on an rns
type. So such situations require dedicated ops,
canonicalization patterns, etc.
RNS types
RNSType
A residue number system representation
Syntax:
!rns.rns<
::llvm::ArrayRef<mlir::Type> # basisTypes
>
Parameters:
Parameter | C++ type | Description |
---|---|---|
basisTypes | ::llvm::ArrayRef<mlir::Type> |
RNS ops
RNS additional definitions
TypeInterface definitions
RNSBasisTypeInterface (RNSBasisTypeInterface
)
This interface is required for a type to be used as a parameter
to an rns
type.
Methods:
isCompatibleWith
bool isCompatibleWith(::mlir::Type otherRnsBasisType);
Returns true if this type is compatible with another type in the same RNS basis. In particular, the set of types used for a single RNS basis are never equal as types, but instead have some common attribute that must be checked here. For example, an RNS type where the basis types are polynomials would return true if the two types are both polynomial types, even if they have different coefficient moduli.
Another example is using mod arith types as the basis types, where by the nature of chinese reminder theorem, it is required that the modulus of them must be mutually coprime.
isCompatibleWith
must be commutative, in the sense
that type1.isCompatibleWith(type2)
if and only if
type2.isCompatibleWith(type1)
.
NOTE: This method must be implemented by the user.
14 - Secret
‘secret’ Dialect
Secret is a dialect for computations that operate on encrypted data.
Secret is intended to serve as a scheme-agnostic front-end for the HEIR ecosystem of dialects. It is supposed to be fully interoperable with the rest of MLIR via secret.generic, while lower-level HEIR dialects would have custom types for arithmetic on secret integers of various bit widths.
Secret types
SecretType
A secret value
Syntax:
!secret.secret<
Type # valueType
>
A generic wrapper around another MLIR type, representing an encrypted value but not specifying the manner of encryption. This is useful in HEIR because the compiler may choose various details of the FHE scheme based on the properties of the input program, the backend target hardware, and cost models of the various passes.
Parameters:
Parameter | C++ type | Description |
---|---|---|
valueType | Type |
Secret ops
secret.cast
(heir::secret::CastOp)
A placeholder cast from one secret type to another
Syntax:
operation ::= `secret.cast` $input attr-dict `:` qualified(type($input)) `to` qualified(type($output))
A cast
operation represents a type cast from one secret type to another,
that is used to enable the intermixing of various equivalent secret types
before a lower-level FHE scheme has been chosen.
For example, secret.cast
can be used to convert a secret<i8>
to a
secret<tensor<8xi1>>
as a compatibility layer between boolean and
non-boolean parts of a program. The pass that later lowers the IR to
specific FHE schemes would need to replace these casts with appropriate
scheme-specific operations, and it is left to those later passes to
determine which casts are considered valid.
Example:
%result = secret.cast %0 : !secret.secret<i8> to !secret.secret<tensor<8xi1>>
%result2 = secret.cast %0 : !secret.secret<i8> to !secret.secret<tensor<2xi4>>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A secret value |
Results:
Result | Description |
---|---|
output | A secret value |
secret.conceal
(heir::secret::ConcealOp)
Convert a non-secret value into a secret
Syntax:
operation ::= `secret.conceal` $cleartext attr-dict `:` type($cleartext) `->` type($output)
Convert a value to a secret containing the same value.
This op represents a scheme-agnostic encryption operation, as well as a “trivial encryption” operation which is needed for some FHE schemes. This op is also useful for type materialization in the dialect conversion framework.
Examples:
%Y = secret.conceal %value : i32 -> !secret.secret<i32>
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
cleartext | any type |
Results:
Result | Description |
---|---|
output | A secret value |
secret.generic
(heir::secret::GenericOp)
Lift a plaintext computation to operate on secrets.
secret.generic
lifts a plaintext computation to operate on one or more
secrets. The lifted computation is represented as a region containing a
single block terminated by secret.yield
. The arguments of the secret.generic
may include one or more !secret.secret
types. The arguments of the block
in the op’s body correspond to the underlying plaintext types of the secrets.
secret.generic
is not isolated from above, so you may directly reference
values in the enclosing scope. This is required to support using
secret.generic
inside of ops with AffineScope
, while having the body
of the generic use the induction variables defined by the affine scope.
Basic examples:
Add two secret integers together
%Z = secret.generic ins(%X, %Y : !secret.secret<i32>, !secret.secret<i32>) {
^bb0(%x: i32, %y: i32):
%z = arith.addi %x, %y: i32
secret.yield %z : i32
} -> (!secret.secret<i32>)
Add a secret value with a plaintext value. I.e., not all arguments to the op need be secret.
%Z = secret.generic ins(%X, %Y : i32, !secret.secret<i32>) {
^bb0(%x: i32, %y: i32):
%z = arith.addi %x, %y: i32
secret.yield %z : i32
} -> (!secret.secret<i32>)
The same as above, but the plaintext op is not passed through the basic block.
%y = arith.constant 7: i32
%Z = secret.generic ins(%X : !secret.secret<i32>) {
^bb0(%x: i32):
%z = arith.addi %x, %y: i32
secret.yield %z : i32
} -> (!secret.secret<i32>)
Traits: SingleBlockImplicitTerminator<YieldOp>
, SingleBlock
Interfaces: OpAsmOpInterface
Operands:
Operand | Description |
---|---|
inputs | variadic of any type |
Results:
Result | Description |
---|---|
results | variadic of any type |
secret.reveal
(heir::secret::RevealOp)
Convert a secret value into a non-secret
Syntax:
operation ::= `secret.reveal` $input attr-dict `:` type($input) `->` type($cleartext)
Convert a secret into a non-secret containing the same value.
This op represents a scheme-agnostic decryption operation. This op is also useful for target materialization in the dialect conversion framework.
Examples:
%Y = secret.reveal %secret_value : !secret.secret<i32> -> i32
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
input | A secret value |
Results:
Result | Description |
---|---|
cleartext | any type |
secret.separator
(heir::secret::SeparatorOp)
Convert a non-secret value into a secret
Syntax:
operation ::= `secret.separator` attr-dict ($inputs^ `:` type($inputs))?
This operation is used as a separation boundary between logical subunits of
the module. This is used in conjunction with
--secret-distribute-generic=distribute-through=secret.separator
to break a
generic around these separators and allow for optimization passses to
analyze and optimize the sub-units locally.
In order to allow bufferization of modules with this operation, we must register a (bogus) memory effect that also prevents this operation from being trivially dead during operation folding.
This operation also accepts operands, which act as boundaries between the logical units. This enforces separation of memref and affine optimizations between the subunits, preventing optimizations from removing the operand and combining the two separated regions. The operand can be thought of as an return value of the logical subunit.
Interfaces: MemoryEffectOpInterface (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{MemoryEffects::Write on ::mlir::SideEffects::DefaultResource}
Operands:
Operand | Description |
---|---|
inputs | variadic of any type |
secret.yield
(heir::secret::YieldOp)
Secret yield operation
secret.yield
is a special terminator operation for blocks inside regions
in secret
generic ops. It returns the cleartext value of the
corresponding private computation to the immediately enclosing secret
generic op.
Traits: AlwaysSpeculatableImplTrait
, HasParent<GenericOp>
, ReturnLike
, Terminator
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
, RegionBranchTerminatorOpInterface
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
values | variadic of any type |
15 - TensorExt
’tensor_ext’ Dialect
The tensor_ext
dialect contains operations on plaintext tensors that
correspond to the computation model of certain FHE schemes, but are
unlikely to be upstreamed to MLIR due to their specificity to FHE.
TensorExt attributes
SIMDPackingAttr
An attribute describing the SIMD packing of a tensor.
Syntax:
#tensor_ext.simd_packing<
::mlir::DenseI64ArrayAttr, # in
::mlir::DenseI64ArrayAttr, # padding
::mlir::DenseI64ArrayAttr, # out
int64_t # padding_value
>
This attribute is used as the encoding attribute on a tensor. It describes the transformations that were applied to an input tensor to pack it into the given tensor.
The in
attribute describes the shape of the original tensor.
The following transformations are applied to the input tensor.
Padding is applied first. The
padding
attribute is an array with the same size as the input tensor shape. Padding is applied at the end of the array using thepadding_value
attribute (default zero). The result after zero padding should be a power of two.The padded result is replicated or split to fill the output tensor shape.
For example,
#packing = #tensor_ext.simd_packing<
in = [7],
padding = [1],
padding_value = 0,
out = [16],
>
may be used on a tensor type like
tensor<1x16xi32, #packing>
If the original tensor had values [1, 2, 3, 4, 5, 6, 7]
then a tensor with
this attribute contains the data [1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0]
.
Parameters:
Parameter | C++ type | Description |
---|---|---|
in | ::mlir::DenseI64ArrayAttr | |
padding | ::mlir::DenseI64ArrayAttr | |
out | ::mlir::DenseI64ArrayAttr | |
padding_value | int64_t |
TensorExt ops
tensor_ext.convert_layout
(heir::tensor_ext::ConvertLayoutOp)
Convert from one layout to another.
Syntax:
operation ::= `tensor_ext.convert_layout` operands attr-dict `:` type($output)
This op represents the conversion of a tensor from one packed layout to another. This is implemented via a “shift network” of ciphertext rotations, plaintext masks (ciphertext-plaintext multiplications), and additions.
This op is inserted by layout selection passes.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
from_layout | ::mlir::AffineMapAttr | An Attribute containing an AffineMap object |
to_layout | ::mlir::AffineMapAttr | An Attribute containing an AffineMap object |
Operands:
Operand | Description |
---|---|
tensor | ranked tensor of any type values |
Results:
Result | Description |
---|---|
output | ranked tensor of any type values |
tensor_ext.rotate
(heir::tensor_ext::RotateOp)
Rotate a tensor some number of indices left.
Syntax:
operation ::= `tensor_ext.rotate` operands attr-dict `:` qualified(type($tensor)) `,` type($shift)
This op represents a left-rotation of a tensor by given number of indices. Negative shift values are interpreted as right-rotations.
This corresponds to the rotate
operation in arithmetic FHE schemes like
BGV.
This operation’s current behavior allows rotating multi-dimensional tensors by rotating along the tensor’s only non-unit dimension. This assumes the tensor is packed along the non-unit dimension.
// In the future, the op will be adjusted to support rotations of general // multi-dimensional tensors with a vector of rotation indices for each // dimension. The lowering will implement the correct operations to rotate // the tensor along the indices given its packing.
Examples:
%0 = ... : tensor<16xi32>
%c7 = arith.constant 7 : i32
%1 = tensor_ext.rotate %0, %c7 : tensor<16xi32>, i32
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
tensor | tensor of any type values |
shift | signless-integer-like |
Results:
Result | Description |
---|---|
output | tensor of any type values |
16 - TfheRust
’tfhe_rust’ Dialect
The thfe_rust
dialect is an exit dialect for generating rust code against the tfhe-rs library API,
using the shortint parameters and encoding scheme.
See https://github.com/zama-ai/tfhe-rs
TfheRust types
EncryptedInt8Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type
Syntax: !tfhe_rust.ei8
EncryptedInt16Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type
Syntax: !tfhe_rust.ei16
EncryptedInt32Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type
Syntax: !tfhe_rust.ei32
EncryptedInt64Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type
Syntax: !tfhe_rust.ei64
EncryptedInt128Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type
Syntax: !tfhe_rust.ei128
EncryptedInt256Type
An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type
Syntax: !tfhe_rust.ei256
EncryptedUInt2Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type
Syntax: !tfhe_rust.eui2
EncryptedUInt3Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type
Syntax: !tfhe_rust.eui3
EncryptedUInt4Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type
Syntax: !tfhe_rust.eui4
EncryptedUInt8Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type
Syntax: !tfhe_rust.eui8
EncryptedUInt10Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type
Syntax: !tfhe_rust.eui10
EncryptedUInt12Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type
Syntax: !tfhe_rust.eui12
EncryptedUInt14Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type
Syntax: !tfhe_rust.eui14
EncryptedUInt16Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type
Syntax: !tfhe_rust.eui16
EncryptedUInt32Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type
Syntax: !tfhe_rust.eui32
EncryptedUInt64Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type
Syntax: !tfhe_rust.eui64
EncryptedUInt128Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type
Syntax: !tfhe_rust.eui128
EncryptedUInt256Type
An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type
Syntax: !tfhe_rust.eui256
LookupTableType
A univariate lookup table used for programmable bootstrapping.
Syntax: !tfhe_rust.lookup_table
ServerKeyType
The short int server key required to perform homomorphic operations.
Syntax: !tfhe_rust.server_key
TfheRust ops
tfhe_rust.add
(heir::tfhe_rust::AddOp)
Arithmetic add of two tfhe ciphertexts.
Syntax:
operation ::= `tfhe_rust.add` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
lhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
rhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.apply_lookup_table
(heir::tfhe_rust::ApplyLookupTableOp)
Syntax:
operation ::= `tfhe_rust.apply_lookup_table` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
input | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
lookupTable | A univariate lookup table used for programmable bootstrapping. |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.bitand
(heir::tfhe_rust::BitAndOp)
Logical AND of two tfhe ciphertexts.
Syntax:
operation ::= `tfhe_rust.bitand` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
lhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
rhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.cast
(heir::tfhe_rust::CastOp)
Syntax:
operation ::= `tfhe_rust.cast` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
ciphertext | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.create_trivial
(heir::tfhe_rust::CreateTrivialOp)
Syntax:
operation ::= `tfhe_rust.create_trivial` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
value | integer |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.generate_lookup_table
(heir::tfhe_rust::GenerateLookupTableOp)
Syntax:
operation ::= `tfhe_rust.generate_lookup_table` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
truthTable | ::mlir::IntegerAttr | An Attribute containing a integer value |
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
Results:
Result | Description |
---|---|
lookupTable | A univariate lookup table used for programmable bootstrapping. |
tfhe_rust.mul
(heir::tfhe_rust::MulOp)
Arithmetic mul of two tfhe ciphertexts.
Syntax:
operation ::= `tfhe_rust.mul` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
lhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
rhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.scalar_left_shift
(heir::tfhe_rust::ScalarLeftShiftOp)
Syntax:
operation ::= `tfhe_rust.scalar_left_shift` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
ciphertext | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
shiftAmount | 8-bit integer |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.scalar_right_shift
(heir::tfhe_rust::ScalarRightShiftOp)
Syntax:
operation ::= `tfhe_rust.scalar_right_shift` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
ciphertext | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
shiftAmount | 8-bit integer |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
tfhe_rust.sub
(heir::tfhe_rust::SubOp)
Arithmetic sub of two tfhe ciphertexts.
Syntax:
operation ::= `tfhe_rust.sub` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The short int server key required to perform homomorphic operations. |
lhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
rhs | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
Results:
Result | Description |
---|---|
output | An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint2 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint3 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint4 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint8 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint10 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint12 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint14 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint16 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint32 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint64 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint128 type or An encrypted unsigned integer corresponding to tfhe-rs’s FHEUint256 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt8 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt16 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt32 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt64 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt128 type or An encrypted signed integer corresponding to tfhe-rs’s FHEInt256 type |
17 - TfheRustBool
’tfhe_rust_bool’ Dialect
The tfhe_rust_bool
dialect is an exit dialect for generating rust code against the tfhe-rs library API,
using the boolean parameter set.
See https://github.com/zama-ai/tfhe-rs
TfheRustBool attributes
TfheRustBoolGatesAttr
An Attribute containing an array of strings to store bool gates
Syntax:
#tfhe_rust_bool.tfhe_rust_bool_gates<
::llvm::ArrayRef<::mlir::heir::tfhe_rust_bool::TfheRustBoolGateEnumAttr> # gates
>
This attributes stores a list of integer identifiers for Boolean gates.
Uses following mapping: AND_GATE = 0; NAND_GATE = 1; OR_GATE = 2; NOR_GATE = 3; XOR_GATE = 4; XNOR_GATE = 5; NOT_GATE = 6;
Parameters:
Parameter | C++ type | Description |
---|---|---|
gates | ::llvm::ArrayRef<::mlir::heir::tfhe_rust_bool::TfheRustBoolGateEnumAttr> |
TfheRustBool types
EncryptedBoolType
An encrypted Boolean corresponding to tfhe-rs’s FHEBool type
Syntax: !tfhe_rust_bool.eb
PackedServerKeyType
The Belfort packed API boolean server key.
Syntax: !tfhe_rust_bool.server_key_enum
ServerKeyType
The boolean server key required to perform homomorphic operations.
Syntax: !tfhe_rust_bool.server_key
TfheRustBool ops
tfhe_rust_bool.create_trivial
(heir::tfhe_rust_bool::CreateTrivialOp)
Syntax:
operation ::= `tfhe_rust_bool.create_trivial` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | tfhe rust bool server key |
value | 1-bit signless integer |
Results:
Result | Description |
---|---|
output | An encrypted Boolean corresponding to tfhe-rs’s FHEBool type |
tfhe_rust_bool.and
(heir::tfhe_rust_bool::AndOp)
Logical AND of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.and` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.mux
(heir::tfhe_rust_bool::MuxOp)
Syntax:
operation ::= `tfhe_rust_bool.mux` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
cnd | An encrypted Boolean corresponding to tfhe-rs’s FHEBool type |
lhs | An encrypted Boolean corresponding to tfhe-rs’s FHEBool type |
rhs | An encrypted Boolean corresponding to tfhe-rs’s FHEBool type |
Results:
Result | Description |
---|---|
output | An encrypted Boolean corresponding to tfhe-rs’s FHEBool type |
tfhe_rust_bool.nand
(heir::tfhe_rust_bool::NandOp)
Logical NAND of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.nand` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.nor
(heir::tfhe_rust_bool::NorOp)
Logical NOR of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.nor` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.not
(heir::tfhe_rust_bool::NotOp)
Syntax:
operation ::= `tfhe_rust_bool.not` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
input | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.or
(heir::tfhe_rust_bool::OrOp)
Logical OR of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.or` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.gates_packed
(heir::tfhe_rust_bool::PackedOp)
Syntax:
operation ::= `tfhe_rust_bool.gates_packed` operands attr-dict `:` functional-type(operands, results)
Operation to where different Boolean gates are executed pairwise between elements of two ciphertext arrays.
For example,
%0 = tfhe_rust_bool.packed_gates %a, %b {gates = #tfhe_rust_bool.tfhe_rust_bool_gates<0 : i32, 4 : i32>} :
(!tfhe_rust_bool.server_key,
tensor<2x!tfhe_rust_bool.eb>,
tensor<2x!tfhe_rust_bool.eb>) -> tensor<2x!tfhe_rust_bool.eb>
applies an “and” gate to the first elements of %a and %b and an xor gate to the second elements.
Mapping is defined in the BooleanGates.td file.
Traits: AlwaysSpeculatableImplTrait
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Attributes:
Attribute | MLIR Type | Description |
---|---|---|
gates | ::mlir::heir::tfhe_rust_bool::TfheRustBoolGatesAttr | An Attribute containing an array of strings to store bool gates |
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.xnor
(heir::tfhe_rust_bool::XnorOp)
Logical XNOR of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.xnor` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
tfhe_rust_bool.xor
(heir::tfhe_rust_bool::XorOp)
Logical XOR of two TFHE-rs Bool ciphertexts.
Syntax:
operation ::= `tfhe_rust_bool.xor` operands attr-dict `:` functional-type(operands, results)
Traits: AlwaysSpeculatableImplTrait
, Commutative
, Elementwise
, Scalarizable
, Tensorizable
, Vectorizable
Interfaces: ConditionallySpeculatable
, InferTypeOpInterface
, NoMemoryEffect (MemoryEffectOpInterface)
Effects: MemoryEffects::Effect{}
Operands:
Operand | Description |
---|---|
serverKey | The boolean server key required to perform homomorphic operations. or The Belfort packed API boolean server key. |
lhs | eb-like |
rhs | eb-like |
Results:
Result | Description |
---|---|
output | eb-like |
TfheRustBool additional definitions
TfheRustBoolGateEnum
An enum attribute representing a TFHE-rs boolean gate using u8 int
Cases:
Symbol | Value | String |
---|---|---|
AND | 0 | AND |
NAND | 1 | NAND |
OR | 2 | OR |
NOR | 3 | NOR |
XOR | 4 | XOR |
XNOR | 5 | XNOR |
NOT | 6 | NOT |