-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LWE: add evaluation key type and technique #1067
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -281,20 +281,25 @@ def LWE_KeyAttr : AttrDef<LWE_Dialect, "Key"> { | |||||
$1$ for LWE instances. A ciphertext encrypted with a `key_size` of $k$ will | ||||||
have size $k+1$. | ||||||
|
||||||
The key basis describes the inner product used in the phase calculation in | ||||||
decryption. This attribute is only supported for RLWE ciphertexts whose | ||||||
The key basis/power describes the inner product used in the phase calculation | ||||||
in decryption. This attribute is only supported for RLWE ciphertexts whose | ||||||
`key_size` is $1$. An RLWE 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]`. | ||||||
corresponds to `[0, 2]`. The array that represents the key rotate is constructed | ||||||
by listing the powers of `X` at each position of the array. For example, | ||||||
`(1, s, s(X^2))` corresponds to `[0, 1, 2]`. Combining the basis/rotate array | ||||||
together, we can express `(1, s, s^2, s(X^2), s^2(X^2))` as `[0, 1, 2, 1, 2]` | ||||||
and `[0, 1, 1, 2, 2]`. | ||||||
}]; | ||||||
|
||||||
let parameters = (ins | ||||||
"::mlir::StringAttr":$id, | ||||||
DefaultValuedParameter<"unsigned", "1">:$size, | ||||||
OptionalArrayRefParameter<"unsigned int">:$basis | ||||||
OptionalArrayRefParameter<"unsigned int">:$basis, | ||||||
OptionalArrayRefParameter<"unsigned int">:$rotate | ||||||
); | ||||||
|
||||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||||
|
@@ -348,4 +353,60 @@ def LWE_ModulusChainAttr : AttrDef<LWE_Dialect, "ModulusChain"> { | |||||
// let genVerifyDecl = 1; // Verify index into list | ||||||
} | ||||||
|
||||||
def LWE_BVKeySwitchAttr : AttrDef<LWE_Dialect, "BVKeySwitch"> { | ||||||
let mnemonic = "bv_keyswitch_technique"; | ||||||
let description = [{ | ||||||
An attribute describing the BV technique for keyswitch. | ||||||
|
||||||
`base` is the radix base used in decomposition of the coefficient modulus | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
`Q` (non-RNS case) / `qi` (RNS case). | ||||||
|
||||||
`dnum` is the number of large digits for the RNS case. It takes effect | ||||||
only when `base` equals 0. | ||||||
|
||||||
Check Appendix A of https://eprint.iacr.org/2021/204.pdf for more detail. | ||||||
}]; | ||||||
|
||||||
let parameters = (ins | ||||||
"IntegerAttr":$base, | ||||||
"IntegerAttr":$dnum | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thank you for considering the RNS variants! I understand it's important to know the dnums so that the type converter knows the type / shape of the key switching key. For the lowering, we'll need the actual RNS moduli, which we'll pull from the RNS modulus of the ring in the keyswitching key, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OptionalParameter? (can also update the assembly format for an optional print) |
||||||
); | ||||||
|
||||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||||
|
||||||
// let genVerifyDecl = 1; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could implement the type constraint here. |
||||||
} | ||||||
|
||||||
|
||||||
def LWE_GHSKeySwitchAttr : AttrDef<LWE_Dialect, "GHSKeySwitch"> { | ||||||
let mnemonic = "ghs_keyswitch_technique"; | ||||||
let description = [{ | ||||||
An attribute describing the GHS technique for keyswitch. | ||||||
|
||||||
`extra_modulus` is the extra modulus `P` needed by the technique. | ||||||
In RNS case, it is a chain of modulus. | ||||||
|
||||||
Check Appendix A of https://eprint.iacr.org/2021/204.pdf for more detail. | ||||||
}]; | ||||||
|
||||||
let parameters = (ins | ||||||
"ModulusChainAttr":$extra_modulus | ||||||
); | ||||||
|
||||||
let assemblyFormat = "`<` struct(params) `>`"; | ||||||
|
||||||
// let genVerifyDecl = 1; | ||||||
} | ||||||
|
||||||
def LWE_AnyKeySwitchAttr : AttrDef<LWE_Dialect, "KeySwitch"> { | ||||||
let mnemonic = "keyswitch_technique"; | ||||||
let returnType = "Attribute"; | ||||||
let convertFromStorage = "$_self"; | ||||||
string cppType = "Attribute"; | ||||||
let predicate = Or<[ | ||||||
LWE_BVKeySwitchAttr.predicate, | ||||||
LWE_GHSKeySwitchAttr.predicate | ||||||
]>; | ||||||
} | ||||||
|
||||||
#endif // LIB_DIALECT_LWE_IR_NEWLWEATTRIBUTES_TD_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,17 @@ def NewLWEPublicKey : LWE_Type<"NewLWEPublicKey", "new_lwe_public_key"> { | |
); | ||
} | ||
|
||
def NewLWEEvaluationKey : LWE_Type<"NewLWEEvaluationKey", "new_lwe_evaluation_key"> { | ||
let summary = "A evaluation key for LWE"; | ||
let parameters = (ins | ||
"KeyAttr":$from_key, | ||
"KeyAttr":$to_key, | ||
"::mlir::polynomial::RingAttr":$ring, | ||
// can not be ArrayRefParameter<"KeySwitchAttr"> | ||
ArrayRefParameter<"Attribute">:$keyswitch_techniques | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this an array ref parameter? Wouldn't only a sinlgle technique apply to a given key? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I intentionally left the HYBRID keyswitching technique as a combination of BV attr and GHS attr, so that we do not have to define another |
||
); | ||
} | ||
|
||
def NewLWESecretOrPublicKey : AnyTypeOf<[NewLWESecretKey, NewLWEPublicKey]>; | ||
|
||
def NewLWEPlaintext : LWE_Type<"NewLWEPlaintext", "new_lwe_plaintext"> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: just remove the
_technique
here and below