From 62044f6c0f8fcecd62f9b8f5b5531da29b017f52 Mon Sep 17 00:00:00 2001 From: dsuponitskiy Date: Wed, 6 Dec 2023 16:34:29 +0000 Subject: [PATCH] Validate multDepth as a cryptocontext parameter (#612) * Validate multDepth as a cryptocontext parameter * Rephrased the error message for multiplicative depth --------- Co-authored-by: Dmitriy Suponitskiy --- src/pke/include/scheme/gen-cryptocontext-params.h | 4 ++++ src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/src/pke/include/scheme/gen-cryptocontext-params.h b/src/pke/include/scheme/gen-cryptocontext-params.h index bc40400f1..61a553582 100644 --- a/src/pke/include/scheme/gen-cryptocontext-params.h +++ b/src/pke/include/scheme/gen-cryptocontext-params.h @@ -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) { @@ -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) { diff --git a/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp b/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp index e106ae9aa..b7066021b 100644 --- a/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp +++ b/src/pke/lib/scheme/gen-cryptocontext-params-impl.cpp @@ -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& vals) { if (getAllParamsDataMembers().size() != vals.size()) { std::string errMsg(std::string("The number of data members and the number of values do not match: ") +