Skip to content

Commit

Permalink
Fix bug - bound must be larger than 0 && Add validation
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeho committed Mar 7, 2024
1 parent 851019e commit db83041
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/main/scala/fhetest/Generate/AbsProgram.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ case class AbsProgram(
mulDepthIsSmall(mulDepth, encParams.mulDepth) &&
firstModSizeIsLargest(libConfig.firstModSize, libConfig.scalingModSize) &&
modSizeIsUpto60bits(libConfig.firstModSize, libConfig.scalingModSize) &&
openFHEBFVModuli(
libConfig.scheme,
libConfig.firstModSize,
libConfig.scalingModSize,
) &&
ringDimIsPowerOfTwo(encParams.ringDim) &&
plainModIsPositive(encParams.plainMod) &&
plainModEnableBatching(encParams.plainMod, encParams.ringDim) &&
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/fhetest/Generate/LibConfigGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def generateLibConfig(encType: ENC_TYPE): LibConfig = {
val randomLenOpt: Option[Int] = Some(Random.between(1, 100000 + 1))
val randomBoundOpt: Option[Int | Double] = randomScheme match {
case Scheme.BFV | Scheme.BGV =>
Some(Random.nextInt(100000))
case Scheme.CKKS => Some(Random.between(0, math.pow(2, 64)))
Some(Random.between(1, 100000))
case Scheme.CKKS => Some(Random.between(1, math.pow(2, 64)))
}
LibConfig(
randomScheme,
Expand Down
9 changes: 9 additions & 0 deletions src/main/scala/fhetest/Generate/ValidFilter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ def firstModSizeIsLargest(firstModSize: Int, scalingModSize: Int): Boolean =
def modSizeIsUpto60bits(firstModSize: Int, scalingModSize: Int): Boolean =
(firstModSize <= 60) && (scalingModSize <= 60)

// OpenFHE/src/pke/lib/scheme/bfvrns/bfvrns-parametergeneration.cpp:53
// BFVrns.ParamsGen: Number of bits in CRT moduli should be in the range from 30 to 60
def openFHEBFVModuli(
scheme: Scheme,
firstModSize: Int,
scalingModSize: Int,
): Boolean =
!(scheme == Scheme.BFV) || ((30 <= firstModSize) && (30 <= scalingModSize))

def ringDimIsPowerOfTwo(n: Int): Boolean = (n > 0) && ((n & (n - 1)) == 0)

def plainModIsPositive(m: Int): Boolean = m > 0
Expand Down

0 comments on commit db83041

Please sign in to comment.