Skip to content

Commit

Permalink
run some basic sanity checks on outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
malb committed Apr 6, 2022
1 parent 7c886bf commit 8cd0c51
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 10 additions & 0 deletions estimator/cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,3 +256,13 @@ def __le__(self, other):
return self["rop"] <= other["rop"]
except AttributeError:
return self["rop"] <= other

def sanity_check(self):
"""
Perform basic checks.
"""
if self.get("beta", 0) > self.get("d", 0):
raise RuntimeError(f"β = {self['beta']} > d = {self['d']}")
if self.get("eta", 0) > self.get("d", 0):
raise RuntimeError(f"η = {self['eta']} > d = {self['d']}")
return self
12 changes: 8 additions & 4 deletions estimator/lwe_dual.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,9 @@ def fft_solver(params, success_probability, t=0):

sigma = params.Xe.stddev / params.q
m_required = RR(
4 * exp(4 * pi * pi * sigma * sigma) * (log(size_fft * size) - log(log(1 / probability)))
4
* exp(4 * pi * pi * sigma * sigma)
* (log(size_fft * size) - log(log(1 / probability)))
)

if params.m < m_required:
Expand Down Expand Up @@ -278,11 +280,13 @@ def optimize_blocksize(
)

if fft:

def f(beta):
with local_minimum(0, params.n - zeta) as it:
for t in it:
it.update(f_t(beta=beta, t=t))
return it.y

else:
f = f_t

Expand Down Expand Up @@ -429,7 +433,7 @@ def _optimize_blocksize(
red_cost_model=red_cost_model_default,
use_lll=True,
log_level=None,
fft=False
fft=False,
):
h = params.Xs.get_hamming_weight(params.n)
h1_min = max(0, h - (params.n - zeta))
Expand Down Expand Up @@ -473,7 +477,7 @@ def _optimize_blocksize(
cost = it.y

cost["problem"] = params
return cost
return cost.sanity_check()


DH = DualHybrid()
Expand Down Expand Up @@ -583,7 +587,7 @@ def dual_hybrid(
red_cost_model=red_cost_model,
use_lll=use_lll,
opt_step=opt_step,
fft=fft
fft=fft,
)
if mitm_optimization:
ret["tag"] = "dual_mitm_hybrid"
Expand Down
6 changes: 3 additions & 3 deletions estimator/lwe_primal.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def __call__(
cost = it.y
cost["tag"] = "usvp"
cost["problem"] = params
return cost
return cost.sanity_check()

try:
red_shape_model = simulator_normalize(red_shape_model)
Expand Down Expand Up @@ -237,7 +237,7 @@ def __call__(

cost["tag"] = "usvp"
cost["problem"] = params
return cost
return cost.sanity_check()

__name__ = "primal_usvp"

Expand Down Expand Up @@ -574,7 +574,7 @@ def __call__(
except KeyError:
pass

return cost
return cost.sanity_check()

__name__ = "primal_hybrid"

Expand Down

0 comments on commit 8cd0c51

Please sign in to comment.