Skip to content

Commit

Permalink
Fix overflowBound for Integer scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeho committed Mar 7, 2024
1 parent db83041 commit 8d53cbb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/scala/fhetest/Generate/LibConfigGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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.between(1, 100000))
Some(Random.between(1, 1000))
case Scheme.CKKS => Some(Random.between(1, math.pow(2, 64)))
}
LibConfig(
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/fhetest/Phase/Check.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ case object Check {
case Success(interpValue) => interpValue
case Failure(_) => InterpError
}
val overflowBound = program.libConfig.firstModSize
val overflowBound =
if program.libConfig.scheme == Scheme.CKKS then
math.pow(2, program.libConfig.firstModSize)
else program.libConfig.encParams.plainMod.toDouble
if !validCheck || notOverflow(result, overflowBound) then {
val encType = parsed._3
val interpResPair = BackendResultPair("CLEAR", result)
Expand Down Expand Up @@ -114,13 +117,12 @@ case object Check {
}

// TODO: Need to be revised
def notOverflow(interpResult: ExecuteResult, overflowBound: Int): Boolean =
val limit = math.pow(2, overflowBound)
def notOverflow(interpResult: ExecuteResult, overflowBound: Double): Boolean =
interpResult match {
case Normal(res) =>
res.split("\n").forall { line =>
val max = line.split(" ").map(_.toDouble).max
max < limit
max < overflowBound
}
case _ => true
}
Expand Down

0 comments on commit 8d53cbb

Please sign in to comment.