Skip to content

Commit

Permalink
Validate multDepth as a cryptocontext parameter (openfheorg#612)
Browse files Browse the repository at this point in the history
* Validate multDepth as a cryptocontext parameter

* Rephrased the error message for multiplicative depth

---------

Co-authored-by: Dmitriy Suponitskiy <dsuponitskiy@dualitytech.com>
  • Loading branch information
dsuponitskiy and dsuponitskiy-duality authored Dec 6, 2023
1 parent 1f90f06 commit c02bfe2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/pke/include/scheme/gen-cryptocontext-params.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class Params {
void SetToDefaults(SCHEME scheme);

void ValidateRingDim(usint ringDim);
void ValidateMultiplicativeDepth(usint multiplicativeDepth);

public:
explicit Params(SCHEME scheme0 = INVALID_SCHEME) {
Expand Down Expand Up @@ -387,6 +388,9 @@ class Params {
numLargeDigits = numLargeDigits0;
}
void SetMultiplicativeDepth(usint multiplicativeDepth0) {
// TODO (dsuponit): move the check below ValidateMultiplicativeDepth() to a separate validating function. see
// https://github.com/openfheorg/openfhe-development/issues/400
ValidateMultiplicativeDepth(multiplicativeDepth0);
multiplicativeDepth = multiplicativeDepth0;
}
void SetScalingModSize(usint scalingModSize0) {
Expand Down
9 changes: 9 additions & 0 deletions src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ void Params::ValidateRingDim(usint ringDim) {
}
}
//====================================================================================================================
void Params::ValidateMultiplicativeDepth(usint multiplicativeDepth) {
constexpr usint maxMultiplicativeDepthValue = 1000;
if (multiplicativeDepth > maxMultiplicativeDepthValue) {
std::string errorMsg(std::string("The provided multiplicative depth [") + std::to_string(multiplicativeDepth) +
"] is not computationally feasible. Use a smaller value.");
OPENFHE_THROW(config_error, errorMsg);
}
}
//====================================================================================================================
Params::Params(const std::vector<std::string>& vals) {
if (getAllParamsDataMembers().size() != vals.size()) {
std::string errMsg(std::string("The number of data members and the number of values do not match: ") +
Expand Down

0 comments on commit c02bfe2

Please sign in to comment.