def full_sieve_kernel(arg0, params=None, seed=None): # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 pump_params = pop_prefixed_params("pump", params) workout_params = pop_prefixed_params("workout", params) verbose = params.pop("verbose") load_matrix = params.pop("load_matrix") pre_bkz = params.pop("pre_bkz") trace = params.pop("trace") reserved_n = n params = params.new(reserved_n=reserved_n, otf_lift=False) if load_matrix is None: A, bkz = load_svpchallenge_and_randomize(n, s=0, seed=seed) if verbose: print("Loaded challenge dim %d" % n) if pre_bkz is not None: par = BKZ_FPYLLL.Param(pre_bkz, strategies=BKZ_FPYLLL.DEFAULT_STRATEGY, max_loops=1) bkz(par) else: A, _ = load_matrix_file(load_matrix, doLLL=False, high_prec=False) if verbose: print("Loaded file '%s'" % load_matrix) g6k = Siever(A, params, seed=seed) if trace: tracer = SieveTreeTracer(g6k, root_label=("full-sieve", n), start_clocks=True) else: tracer = dummy_tracer # Actually runs a workout with very large decrements, so that the basis is kind-of reduced # for the final full-sieve workout(g6k, tracer, 0, n, dim4free_min=0, dim4free_dec=15, pump_params=pump_params, verbose=verbose, **workout_params) g6k.output_bench() tracer.exit() if hasattr(tracer, "trace"): return tracer.trace else: return None
def asvp_kernel(arg0, params=None, seed=None): logger = logging.getLogger('asvp') # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) load_matrix = params.pop("load_matrix") pump_params = pop_prefixed_params("pump", params) workout_params = pop_prefixed_params("workout", params) verbose = params.pop("verbose") if verbose: workout_params["verbose"] = True challenge_seed = params.pop("challenge_seed") if load_matrix is None: A, _ = load_svpchallenge_and_randomize(n, s=challenge_seed, seed=seed) if verbose: print(("Loaded challenge dim %d" % n)) else: A, _ = load_matrix_file(load_matrix) if verbose: print(("Loaded file '%s'" % load_matrix)) g6k = Siever(A, params, seed=seed) tracer = SieveTreeTracer(g6k, root_label=("svp-challenge", n), start_clocks=True) gh = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(n)]) goal_r0 = (1.05**2) * gh if verbose: print(("gh = %f, goal_r0/gh = %f, r0/gh = %f" % (gh, goal_r0 / gh, sum([x * x for x in A[0]]) / gh))) flast = workout(g6k, tracer, 0, n, goal_r0=goal_r0, pump_params=pump_params, **workout_params) tracer.exit() stat = tracer.trace stat.data["flast"] = flast if verbose: logger.info("sol %d, %s" % (n, A[0])) norm = sum([x * x for x in A[0]]) if verbose: logger.info("norm %.1f ,hf %.5f" % (norm**.5, (norm / gh)**.5)) return tracer.trace
def find_norm_kernel_trial(arg0, params=None, seed=None, goal_r0=None): # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) dim4free_dec = params.pop("workout/dim4free_dec") pump_params = pop_prefixed_params("pump", params) load_matrix = params.pop("load_matrix") verbose = params.pop("verbose") A, _ = load_matrix_file(load_matrix, randomize=True, seed=None, float_type="double") if A.nrows != n: raise ValueError( f"wrong dimension:: Expected dim(A) = {A.nrows}, got n = {n}") g6k = Siever(A, params, seed=seed) tracer = SieveTreeTracer(g6k, root_label=("svp-challenge", n), start_clocks=True) gh = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(n)]) ds = list(range(0, n - 40, dim4free_dec))[::-1] + 10 * [0] if goal_r0 is None: goal_r0 = 1.1 * gh if verbose and n < 90: verbose = False for d in ds: workout(g6k, tracer, 0, n, dim4free_dec=dim4free_dec, goal_r0=goal_r0 * 1.001, pump_params=pump_params, verbose=verbose) tracer.exit() return int(g6k.M.get_r(0, 0)), gh
def asvp_kernel(arg0, params=None, seed=None): logger = logging.getLogger('asvp') # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) load_matrix = params.pop("load_matrix") pump_params = pop_prefixed_params("pump", params) workout_params = pop_prefixed_params("workout", params) verbose = params.pop("verbose") if verbose: workout_params["verbose"] = True challenge_seed = params.pop("challenge_seed") if load_matrix is None: A, _ = load_svpchallenge_and_randomize(n, s=challenge_seed, seed=seed) if verbose: print("Loaded challenge dim %d" % n) else: A, _ = load_matrix_file(load_matrix) if verbose: print("Loaded file '%s'" % load_matrix) g6k = Siever(A, params, seed=seed) tracer = SieveTreeTracer(g6k, root_label=("svp-challenge", n), start_clocks=True) gh = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(n)]) flast = workout(g6k, tracer, 0, n, pump_params=pump_params, **workout_params) tracer.exit() stat = tracer.trace f = workout_params["dim4free_min"] gh2 = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(f, n)]) quality = (gh * (n - f)) / (gh2 * n) stat.data["quality"] = quality print >> sys.stderr, g6k.M.B return tracer.trace
def asvp_kernel(arg0, params=None, seed=None): # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) load_matrix = params.pop("load_matrix") goal_r0__gh = params.pop('goal_r0__gh') pump_params = pop_prefixed_params("pump", params) workout_params = pop_prefixed_params("workout", params) verbose = params.pop("verbose") if verbose: workout_params["verbose"] = True A, _ = load_matrix_file(load_matrix, randomize=False, seed=None, float_type="double") if verbose: print(("Loaded file '%s'" % load_matrix)) g6k = Siever(A, params, seed=seed) tracer = SieveTreeTracer(g6k, root_label=("svp-challenge", n), start_clocks=True) gh = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(n)]) goal_r0 = (goal_r0__gh**2) * gh if verbose: print(("gh = %f, goal_r0/gh = %f, r0/gh = %f" % (gh, goal_r0/gh, sum([x*x for x in A[0]])/gh))) flast = workout(g6k, tracer, 0, n, goal_r0=goal_r0, **workout_params) tracer.exit() stat = tracer.trace sol = tuple(A[0]) stat.data["flast"] = flast tracer.trace.data['res'] = A if verbose: print(f"svp: sol {sol}") norm = sum([x*x for x in sol]) if verbose: print("svp: norm %.1f ,hf %.5f" % (norm**.5, (norm/gh)**.5)) return tracer.trace
def asvp_kernel(arg0, params=None, seed=None): logger = logging.getLogger('asvp') # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) load_matrix = params.pop("load_matrix") pre_bkz = params.pop("pre_bkz") pump_params = pop_prefixed_params("pump", params) workout_params = pop_prefixed_params("workout", params) verbose = params.pop("verbose") if verbose: workout_params["verbose"] = True challenge_seed = params.pop("challenge_seed") high_prec = params.pop("high_prec") trace = params.pop("trace") if load_matrix is None: A, bkz = load_svpchallenge_and_randomize(n, s=challenge_seed, seed=seed) if verbose: print("Loaded challenge dim %d" % n) if pre_bkz is not None: par = BKZ_FPYLLL.Param(pre_bkz, strategies=BKZ_FPYLLL.DEFAULT_STRATEGY, max_loops=1) bkz(par) else: A, _ = load_matrix_file(load_matrix, doLLL=False, high_prec=high_prec) if verbose: print("Loaded file '%s'" % load_matrix) g6k = Siever(A, params, seed=seed) if trace: tracer = SieveTreeTracer(g6k, root_label=("svp-challenge", n), start_clocks=True) else: tracer = dummy_tracer gh = gaussian_heuristic([g6k.M.get_r(i, i) for i in range(n)]) gamma = params.pop("gamma") if gamma is None: goal_r0 = (1.05**2) * gh else: goal_r0 = gamma**2 * gh if verbose: print("gh = %f, goal_r0/gh = %f, r0/gh = %f" % (gh, goal_r0 / gh, sum([x * x for x in A[0]]) / gh)) flast = workout(g6k, tracer, 0, n, goal_r0=goal_r0, pump_params=pump_params, **workout_params) if verbose: logger.info("sol %d, %s" % (n, A[0])) norm = sum([x * x for x in A[0]]) if verbose: logger.info("norm %.1f ,hf %.5f" % (norm**.5, (norm / gh)**.5)) tracer.exit() if hasattr(tracer, "trace"): stat = tracer.trace stat.data["flast"] = flast return stat else: return None
def svp_kernel(arg0, params=None, seed=None): # Pool.map only supports a single parameter if params is None and seed is None: n, params, seed = arg0 else: n = arg0 params = copy.copy(params) load_matrix = params.pop("load_matrix") alg = params.pop("svp/alg") goal_r0 = 1.001 * params.pop('goal_r0') workout_params = pop_prefixed_params("workout/", params) pump_params = pop_prefixed_params("pump/", params) verbose = params.pop("verbose") if verbose and alg == "workout": workout_params["verbose"] = True A, bkz = load_matrix_file(load_matrix, randomize=True, seed=seed, float_type="double") if verbose: print(("Loaded file '%s'" % load_matrix)) g6k = Siever(A, params, seed=seed) tracer = SieveTreeTracer(g6k, root_label=("svp-exact", n), start_clocks=True) if alg == "enum": assert len(workout_params) + len(pump_params) == 0 bkz_params = fplll_bkz.Param(block_size=n, max_loops=1, strategies=fplll_bkz.DEFAULT_STRATEGY, flags=fplll_bkz.GH_BND) svp_enum(bkz, bkz_params, goal_r0) flast = -1 elif alg == "duc18": assert len(workout_params) + len(pump_params) == 0 flast = ducas18(g6k, tracer, goal=goal_r0) elif alg == "workout": flast = workout(g6k, tracer, 0, n, goal_r0=goal_r0, pump_params=pump_params, **workout_params) else: raise ValueError("Unrecognized algorithm for SVP") r0 = bkz.M.get_r(0, 0) if alg == "enum" else g6k.M.get_r(0, 0) if r0 > goal_r0: raise ValueError('Did not reach the goal') if 1.002 * r0 < goal_r0: raise ValueError( 'Found a vector(%d) shorter than the goal(%d) for n=%d.' % (r0, goal_r0, n)) if verbose: print("sol %d, %s" % (n, A[0])) tracer.exit() stat = tracer.trace stat.data["flast"] = flast tracer.trace.data['res'] = A return stat