diff --git a/libiop/algebra/exponentiation.tcc b/libiop/algebra/exponentiation.tcc index a7777cf6..3bf46197 100644 --- a/libiop/algebra/exponentiation.tcc +++ b/libiop/algebra/exponentiation.tcc @@ -66,8 +66,8 @@ std::vector subspace_to_power_of_two(const affine_subspace &S, el = libiop::power(el, power_of_two); } - const FieldT offset_power = libiop::power(S.offset(), power_of_two); - return all_subset_sums(basis_powers, offset_power); + const FieldT shift_power = libiop::power(S.shift(), power_of_two); + return all_subset_sums(basis_powers, shift_power); } template diff --git a/libiop/algebra/fft.tcc b/libiop/algebra/fft.tcc index 5d8b9b62..929d47b8 100644 --- a/libiop/algebra/fft.tcc +++ b/libiop/algebra/fft.tcc @@ -52,7 +52,7 @@ std::vector additive_FFT(const std::vector &poly_coeffs, size_t recursed_betas_ptr = 0; std::vector betas2(domain.basis()); - FieldT shift2 = domain.offset(); + FieldT shift2 = domain.shift(); for (size_t j = 0; j < m; ++j) { FieldT beta = betas2[m-1-j]; @@ -135,7 +135,7 @@ std::vector additive_IFFT(const std::vector &evals, std::vector recursed_twists(m, FieldT(0)); std::vector betas2(domain.basis()); - FieldT shift2 = domain.offset(); + FieldT shift2 = domain.shift(); for (size_t j = 0; j < m; ++j) { const FieldT beta = betas2[m-1-j]; @@ -439,7 +439,7 @@ std::vector IFFT_of_known_degree_over_field_subset( field_subset domain) { /** We do an IFFT over the minimal subgroup needed for this known degree. - * We take the subgroup with the coset's offset as an element. + * We take the subgroup with the coset's shift as an element. * The evaluations in this coset are every nth element of the evaluations * over the entire domain, where n = |domain| / |degree| */ diff --git a/libiop/algebra/field_subset/field_subset.hpp b/libiop/algebra/field_subset/field_subset.hpp index 52bbc79a..bbcffd3d 100644 --- a/libiop/algebra/field_subset/field_subset.hpp +++ b/libiop/algebra/field_subset/field_subset.hpp @@ -64,7 +64,6 @@ class field_subset { FieldT generator() const; - const FieldT& offset() const; const FieldT shift() const; const std::vector& basis() const; diff --git a/libiop/algebra/field_subset/field_subset.tcc b/libiop/algebra/field_subset/field_subset.tcc index d4d0e264..77a5d489 100644 --- a/libiop/algebra/field_subset/field_subset.tcc +++ b/libiop/algebra/field_subset/field_subset.tcc @@ -226,7 +226,7 @@ field_subset field_subset::get_subset_of_order(const std::size_t input_subspace_basis.resize(subset_dim); return field_subset( affine_subspace(input_subspace_basis, - this->offset())); + this->shift())); } case multiplicative_coset_type: // Assumes this subgroup's generator is the default generator for a subgroup of that order. @@ -288,20 +288,12 @@ FieldT field_subset::generator() const return this->coset_->generator(); } -template -const FieldT& field_subset::offset() const -{ - assert(this->type_ == affine_subspace_type); - - return this->subspace_->offset(); -} - template const FieldT field_subset::shift() const { - assert(this->type_ == multiplicative_coset_type); - return this->coset_->shift(); + return this->type_ == multiplicative_coset_type? + this->coset_->shift() : this->subspace_->shift(); } template diff --git a/libiop/algebra/field_subset/subgroup.tcc b/libiop/algebra/field_subset/subgroup.tcc index 50533d64..63109db2 100644 --- a/libiop/algebra/field_subset/subgroup.tcc +++ b/libiop/algebra/field_subset/subgroup.tcc @@ -165,7 +165,7 @@ std::size_t multiplicative_subgroup_base::reindex_by_subgroup(const std: /** Let x be the number of elements in G \ S, for every element in S. Then x = (|G|/|S| - 1). * At index i in G \ S, the number of elements in S that appear before the index in G to which * i corresponds to, is floor(i / x) + 1. - * The +1 is because index 0 of G is S_0, so the position is offset by at least one. + * The +1 is because index 0 of G is S_0, so the position is shift by at least one. * The floor(i / x) term is because after x elements in G \ S, there is one more element from S * that will have appeared in G. */ const std::size_t x = order_g_over_s - 1; diff --git a/libiop/algebra/field_subset/subspace.hpp b/libiop/algebra/field_subset/subspace.hpp index e26e1e06..023f844d 100644 --- a/libiop/algebra/field_subset/subspace.hpp +++ b/libiop/algebra/field_subset/subspace.hpp @@ -50,15 +50,15 @@ class linear_subspace { template class affine_subspace : public linear_subspace { protected: - FieldT offset_; + FieldT shift_; public: affine_subspace() = default; - affine_subspace(const std::vector &basis, const FieldT &offset = FieldT(0)); - affine_subspace(const linear_subspace &base_space, const FieldT &offset = FieldT(0)); - affine_subspace(linear_subspace &&base_space, const FieldT &offset = FieldT(0)); + affine_subspace(const std::vector &basis, const FieldT &shift = FieldT(0)); + affine_subspace(const linear_subspace &base_space, const FieldT &shift = FieldT(0)); + affine_subspace(linear_subspace &&base_space, const FieldT &shift = FieldT(0)); - const FieldT& offset() const; + const FieldT shift() const; std::vector all_elements() const; FieldT element_by_index(const std::size_t index) const; @@ -68,7 +68,7 @@ class affine_subspace : public linear_subspace { static affine_subspace shifted_standard_basis( const std::size_t dimension, - const FieldT& offset); + const FieldT& shift); static affine_subspace random_affine_subspace(const std::size_t dimension); bool operator==(const affine_subspace &other) const; diff --git a/libiop/algebra/field_subset/subspace.tcc b/libiop/algebra/field_subset/subspace.tcc index bfc16f2f..30c57df7 100644 --- a/libiop/algebra/field_subset/subspace.tcc +++ b/libiop/algebra/field_subset/subspace.tcc @@ -128,58 +128,58 @@ bool linear_subspace::operator!=(const linear_subspace &other) c template affine_subspace::affine_subspace(const std::vector &basis, - const FieldT &offset) : - linear_subspace(basis), offset_(offset) + const FieldT &shift) : + linear_subspace(basis), shift_(shift) { } template affine_subspace::affine_subspace( const linear_subspace &base_space, - const FieldT &offset) : + const FieldT &shift) : linear_subspace(base_space), - offset_(offset) + shift_(shift) { } template affine_subspace::affine_subspace( linear_subspace &&base_space, - const FieldT &offset) : + const FieldT &shift) : linear_subspace(std::move(base_space)), - offset_(offset) + shift_(shift) { } template -const FieldT& affine_subspace::offset() const +const FieldT affine_subspace::shift() const { - return this->offset_; + return this->shift_; } template std::vector affine_subspace::all_elements() const { - return all_subset_sums(this->basis_, this->offset_); + return all_subset_sums(this->basis_, this->shift_); } template FieldT affine_subspace::element_by_index(const std::size_t index) const { - return (this->offset_ + (linear_subspace::element_by_index(index))); + return (this->shift_ + (linear_subspace::element_by_index(index))); } template bool internal_element_in_subset(const typename libiop::enable_if::value, FieldT>::type x, - FieldT offset, size_t dimension) + FieldT shift, size_t dimension) { throw std::invalid_argument("subspace.element_in_subset() is only supported for binary fields"); } template bool internal_element_in_subset(const typename libiop::enable_if::value, FieldT>::type x, - FieldT offset, size_t dimension) + FieldT shift, size_t dimension) { /** TODO: Implement this case */ if (dimension > 64) @@ -187,13 +187,13 @@ bool internal_element_in_subset(const typename libiop::enable_if= basis.dimension(), the coefficient of x^i is 0. * Due to the representation of field elements, * this corresponds to all but the first basis.dimension() bits being 0. * (using little endian ordering) */ - const std::vector words = (x + offset).as_words(); + const std::vector words = (x + shift).as_words(); /* Check that all but the least significant 64 bits are 0 */ for (size_t i = 1; i < words.size(); i++) { @@ -211,7 +211,7 @@ bool affine_subspace::element_in_subset(const FieldT x) const { if (this->is_standard_basis_) { - return internal_element_in_subset(x, this->offset_, this->dimension()); + return internal_element_in_subset(x, this->shift_, this->dimension()); } throw std::invalid_argument("subspace.element_in_subset() is only supported for standard basis"); } @@ -221,7 +221,7 @@ FieldT affine_subspace::element_outside_of_subset() const { if (this->is_standard_basis_) { - return this->offset() + FieldT(1ull << this->dimension()); + return this->shift() + FieldT(1ull << this->dimension()); } throw std::invalid_argument("subspace.element_outside_of_subset() is only supported for standard basis"); } @@ -255,11 +255,11 @@ linear_subspace standard_basis(const std::size_t dimension) template affine_subspace affine_subspace::shifted_standard_basis( const std::size_t dimension, - const FieldT& offset) + const FieldT& shift) { const linear_subspace basis = linear_subspace::standard_basis(dimension); - return affine_subspace(std::move(basis), offset); + return affine_subspace(std::move(basis), shift); } template @@ -267,14 +267,14 @@ affine_subspace affine_subspace::random_affine_subspace(const st { const linear_subspace basis = linear_subspace::standard_basis(dimension); - const FieldT offset = FieldT::random_element(); - return affine_subspace(std::move(basis), offset); + const FieldT shift = FieldT::random_element(); + return affine_subspace(std::move(basis), shift); } template bool affine_subspace::operator==(const affine_subspace &other) const { - return linear_subspace::operator==(other) && this->offset_ == other->offset_; + return linear_subspace::operator==(other) && this->shift_ == other->shift_; } } // namespace libiop diff --git a/libiop/algebra/lagrange.tcc b/libiop/algebra/lagrange.tcc index 246c5f1a..611e14a9 100644 --- a/libiop/algebra/lagrange.tcc +++ b/libiop/algebra/lagrange.tcc @@ -83,7 +83,7 @@ std::vector lagrange_cache::subspace_coefficients_for( * This already has c cached, which allows the shifted V to be calculated directly in one pass. */ const FieldT k = this->vp_.evaluation_at_point(interpolation_point) * this->c_; const std::vector V = - all_subset_sums(this->domain_.basis(), interpolation_point + this->domain_.offset()); + all_subset_sums(this->domain_.basis(), interpolation_point + this->domain_.shift()); // Handle check if interpolation point is in domain if (this->interpolation_domain_intersects_domain_ && k == FieldT::zero()) { std::vector result(this->domain_.num_elements(), FieldT::zero()); @@ -230,7 +230,7 @@ std::vector lagrange_coefficients(const affine_subspace &domain, Our computation below computes: k = (\prod_{i} \alpha - V[i]) = Zero_V(\alpha) - c = 1/{\prod_{j > 0} (V[j] - domain.offset()) = 1 / (Z_{V - offset} / X)(0) + c = 1/{\prod_{j > 0} (V[j] - domain.shift()) = 1 / (Z_{V - shift} / X)(0) and inverses of (\alpha - V[0]), ..., (\alpha - V[2^n-1]) @@ -238,13 +238,13 @@ std::vector lagrange_coefficients(const affine_subspace &domain, */ vanishing_polynomial Z(domain); - /* (Z_{V - offset} / X)(0) is the formal derivative of Z_V, + /* (Z_{V - shift} / X)(0) is the formal derivative of Z_V, * as the affine shift only affects the constant coefficient. */ const FieldT c = Z.formal_derivative_at_point(FieldT::zero()).inverse(); const FieldT k = Z.evaluation_at_point(interpolation_point); std::vector V = - all_subset_sums(domain.basis(), interpolation_point + domain.offset()); + all_subset_sums(domain.basis(), interpolation_point + domain.shift()); const std::vector V_inv = batch_inverse_and_mul(V, c * k); diff --git a/libiop/algebra/polynomials/lagrange_polynomial.tcc b/libiop/algebra/polynomials/lagrange_polynomial.tcc index f8db9cc9..d2e0ca56 100644 --- a/libiop/algebra/polynomials/lagrange_polynomial.tcc +++ b/libiop/algebra/polynomials/lagrange_polynomial.tcc @@ -71,7 +71,7 @@ std::vector lagrange_polynomial::evaluations_over_field_subset( * The additive case admits a faster method to create it, hence the separation */ if (this->S_.type() == affine_subspace_type) { - denominator = all_subset_sums(evaldomain.basis(), this->x_ + evaldomain.offset()); + denominator = all_subset_sums(evaldomain.basis(), this->x_ + evaldomain.shift()); } else if (this->S_.type() == multiplicative_coset_type) { diff --git a/libiop/algebra/polynomials/linearized_polynomial.tcc b/libiop/algebra/polynomials/linearized_polynomial.tcc index 99f0e6f5..314dcd28 100644 --- a/libiop/algebra/polynomials/linearized_polynomial.tcc +++ b/libiop/algebra/polynomials/linearized_polynomial.tcc @@ -68,7 +68,7 @@ std::vector linearized_polynomial::evaluations_over_subspace(con Therefore, evaluating over subspace below, we subtract constant term from evaluations over the basis, but include the constant - term in the offset calculation. */ + term in the shift calculation. */ std::vector eval_at_basis(S.basis()); std::for_each(eval_at_basis.begin(), eval_at_basis.end(), @@ -76,9 +76,9 @@ std::vector linearized_polynomial::evaluations_over_subspace(con el = (this->evaluation_at_point(el) - this->constant_coefficient()); }); - const FieldT offset = this->evaluation_at_point(S.offset()); + const FieldT shift = this->evaluation_at_point(S.shift()); - return all_subset_sums(eval_at_basis, offset); + return all_subset_sums(eval_at_basis, shift); } template @@ -191,17 +191,17 @@ bool linearized_polynomial::operator!=(const linearized_polynomial -void add_scalar_multiple_at_offset(std::vector &result, +void add_scalar_multiple_at_shift(std::vector &result, const std::vector &p, const FieldT &factor, - const size_t offset) { + const size_t shift) { // This is a helper method for linearized polynomial * polynomial - // It adds factor * p to result, starting at offset + // It adds factor * p to result, starting at shift if (factor == FieldT::zero()) { return; } for (std::size_t i = 0; i < p.size(); i++) { - result[i + offset] += p[i] * factor; + result[i + shift] += p[i] * factor; } } @@ -212,16 +212,16 @@ polynomial linearized_polynomial::operator*(const polynomial result(p.degree() + 1 + this->degree(), FieldT::zero()); const std::vector p_coeff = p.coefficients(); // set result to be L[0] * p - add_scalar_multiple_at_offset(result, p_coeff, this->coefficients_[0], 0); + add_scalar_multiple_at_shift(result, p_coeff, this->coefficients_[0], 0); for (std::size_t i = 1; i < this->coefficients_.size(); i++) { - std::size_t offset = 1 << (i - 1); - add_scalar_multiple_at_offset(result, p_coeff, this->coefficients_[i], offset); + std::size_t shift = 1 << (i - 1); + add_scalar_multiple_at_shift(result, p_coeff, this->coefficients_[i], shift); } return polynomial(std::move(result)); } diff --git a/libiop/algebra/polynomials/vanishing_polynomial.hpp b/libiop/algebra/polynomials/vanishing_polynomial.hpp index 5f3ad03e..412ccff2 100644 --- a/libiop/algebra/polynomials/vanishing_polynomial.hpp +++ b/libiop/algebra/polynomials/vanishing_polynomial.hpp @@ -34,7 +34,7 @@ class vanishing_polynomial : public polynomial_base { // subspace type linearized_polynomial linearized_polynomial_; // multiplicative coset type - FieldT vp_offset_; /* offset^|H| for cosets, 1 for subgroups */ + FieldT vp_shift_; /* shift^|H| for cosets, 1 for subgroups */ public: explicit vanishing_polynomial() {}; diff --git a/libiop/algebra/polynomials/vanishing_polynomial.tcc b/libiop/algebra/polynomials/vanishing_polynomial.tcc index 0b28a847..0f1a7c10 100644 --- a/libiop/algebra/polynomials/vanishing_polynomial.tcc +++ b/libiop/algebra/polynomials/vanishing_polynomial.tcc @@ -19,7 +19,7 @@ vanishing_polynomial::vanishing_polynomial(const field_subset &S if (this->type_ == affine_subspace_type) { this->linearized_polynomial_ = vanishing_polynomial_from_subspace(S.subspace()); } else if (this->type_ == multiplicative_coset_type) { - this->vp_offset_ = libiop::power(S.coset().shift(), this->vp_degree_); + this->vp_shift_ = libiop::power(S.coset().shift(), this->vp_degree_); } else { throw std::invalid_argument("field_subset type unsupported."); } @@ -38,7 +38,7 @@ vanishing_polynomial::vanishing_polynomial(const multiplicative_cosetvp_degree_ = S.num_elements(); - this->vp_offset_ = libiop::power(S.coset().shift(), this->vp_degree_); + this->vp_shift_ = libiop::power(S.coset().shift(), this->vp_degree_); } template @@ -46,7 +46,7 @@ FieldT vanishing_polynomial::evaluation_at_point(const FieldT &evalpoint if (this->type_ == affine_subspace_type) { return this->linearized_polynomial_.evaluation_at_point(evalpoint); } else if (this->type_ == multiplicative_coset_type) { - return libiop::power(evalpoint, this->vp_degree_) - this->vp_offset_; + return libiop::power(evalpoint, this->vp_degree_) - this->vp_shift_; } throw std::logic_error("vanishing_polynomial::evaluation_at_point: " " this shouldn't happen"); @@ -81,15 +81,15 @@ std::vector vanishing_polynomial::unique_evaluations_over_field_ std::vector evals = unique_domain.all_elements(); // In the additive case, the associated k to 1 map is the vanishing polynomial, // so the unique domain's evaluations is {Z_H(x) | x in S} - // In the multiplicative case, the associated k to 1 map is Z_H(x) + h_offset^|H| + // In the multiplicative case, the associated k to 1 map is Z_H(x) + h_shift^|H| // Hence te unique domain's evaluations are: - // {Z_H(x) + h_offset^|H| | x in S} - // So we subtract h^|H| from all evals. h^|H| is the vp offset + // {Z_H(x) + h_shift^|H| | x in S} + // So we subtract h^|H| from all evals. h^|H| is the vp shift if (S.type() == multiplicative_coset_type) { for (size_t i = 0; i < evals.size(); i++) { - evals[i] -= this->vp_offset_; + evals[i] -= this->vp_shift_; } } return evals; @@ -118,7 +118,7 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m if (this->type_ != multiplicative_coset_type) { throw std::invalid_argument("evaluations_over_coset can only be used on multiplicative_coset vanishing polynomials."); } - // P is of the form X^|G| - vp_offset + // P is of the form X^|G| - vp_shift const std::size_t order_s = S.num_elements(); const std::size_t order_g = this->vp_degree_; // points in S are of the form hg^i, where h is the shift of the coset, and g is its generator. @@ -130,8 +130,8 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m { // In this case |S| <= |G|, and |G| % |S| = 0. // Therefore g^{i|G|} = 1, consequently - // P(s) = h^|G| - vp_offset, for all s \in S - evals.resize(order_s, shift_to_order_g - this->vp_offset_); + // P(s) = h^|G| - vp_shift, for all s \in S + evals.resize(order_s, shift_to_order_g - this->vp_shift_); return evals; } size_t evaluation_repetitions = 1; @@ -151,7 +151,7 @@ std::vector vanishing_polynomial::evaluations_over_coset(const m FieldT cur = shift_to_order_g; for (std::size_t i = 0; i < number_of_distinct_evaluations; i++) { - evals.emplace_back(cur - this->vp_offset_); + evals.emplace_back(cur - this->vp_shift_); cur = cur * generator_to_order_g; } // Place these distinct evaluations in the remaining locations. @@ -174,7 +174,7 @@ FieldT vanishing_polynomial::constant_coefficient() const { return this->linearized_polynomial_.constant_coefficient(); } // subgroup / coset type - return -this->vp_offset_; + return -this->vp_shift_; } template @@ -189,13 +189,13 @@ std::shared_ptr> else if (this->type_ == multiplicative_coset_type) { /** This returns the polynomial x^{|H|}. - * It does this by altering vp_offset, making a copy of this vanishing polynomial, - * restoring the previous vp_offset, and returning the copy. */ - const FieldT vp_offset_copy = this->vp_offset_; - this->vp_offset_ = FieldT::zero(); + * It does this by altering vp_shift, making a copy of this vanishing polynomial, + * restoring the previous vp_shift, and returning the copy. */ + const FieldT vp_shift_copy = this->vp_shift_; + this->vp_shift_ = FieldT::zero(); std::shared_ptr> copy = std::static_pointer_cast>(std::make_shared>(*this)); - this->vp_offset_ = vp_offset_copy; + this->vp_shift_ = vp_shift_copy; return copy; } throw std::logic_error("should not happen"); @@ -243,13 +243,13 @@ field_subset vanishing_polynomial::associated_k_to_1_map_at_doma returned_basis.emplace_back(transformed_basis[i]); } } - const FieldT transformed_offset = k_to_1_map->evaluation_at_point(domain.offset()); - return field_subset(affine_subspace(returned_basis, transformed_offset)); + const FieldT transformed_shift = k_to_1_map->evaluation_at_point(domain.shift()); + return field_subset(affine_subspace(returned_basis, transformed_shift)); } else if (this->type_ == multiplicative_coset_type) { const FieldT new_shift = k_to_1_map->evaluation_at_point(domain.shift()); - /** The multiplicative vanishing polynomial with no offset is a + /** The multiplicative vanishing polynomial with no shift is a * k to 1 map over any domain of order divisible by k. */ if (domain.num_elements() % this->vp_degree_ == 0) { @@ -273,11 +273,11 @@ polynomial vanishing_polynomial::operator*(const polynomialtype_ == affine_subspace_type) { return this->linearized_polynomial_ * p; } - // in the multiplicative case just shift p, and subtract by p * this->vp_offset_ + // in the multiplicative case just shift p, and subtract by p * this->vp_shift_ std::vector result(p.degree() + this->vp_degree_ + 1, FieldT(0)); const std::vector p_coeff = p.coefficients(); - add_scalar_multiple_at_offset(result, p_coeff, FieldT(1), this->vp_degree_); - add_scalar_multiple_at_offset(result, p_coeff, FieldT(0) - this->vp_offset_, 0); + add_scalar_multiple_at_shift(result, p_coeff, FieldT(1), this->vp_degree_); + add_scalar_multiple_at_shift(result, p_coeff, FieldT(0) - this->vp_shift_, 0); return polynomial(std::move(result)); } @@ -313,7 +313,7 @@ template std::pair, polynomial > polynomial_over_multiplicative_vanishing_polynomial(const polynomial &P, - const FieldT vp_offset, + const FieldT vp_shift, const size_t vp_degree) { /* inverse of the leading term */ @@ -334,7 +334,7 @@ polynomial_over_multiplicative_vanishing_polynomial(const polynomial &P, std::vector remainder(P.coefficients().begin(), P.coefficients().begin() + vp_degree); - FieldT Z_0 = vp_offset; + FieldT Z_0 = vp_shift; for (std::size_t i = quotient.size(); i--; ) { // Z only has 2 terms, the leading term and the constant term. @@ -389,7 +389,7 @@ linearized_polynomial vanishing_polynomial_from_subspace(const affine_su poly = poly.squared() + (poly * poly_c); } - const FieldT poly_shift = poly.evaluation_at_point(S.offset()); + const FieldT poly_shift = poly.evaluation_at_point(S.shift()); poly[0] += poly_shift; return poly; diff --git a/libiop/algebra/trace_embedding/additive_successor_ordering.tcc b/libiop/algebra/trace_embedding/additive_successor_ordering.tcc index a14a8471..14609fe0 100644 --- a/libiop/algebra/trace_embedding/additive_successor_ordering.tcc +++ b/libiop/algebra/trace_embedding/additive_successor_ordering.tcc @@ -100,13 +100,13 @@ additive_successor_polynomial::additive_successor_polynomial(const affin * and the successor of x in (S' + g^(i - 1)) will be g*x + primitive_polynomial(g) * * The following code is calculating constituent terms for each partition polynomial. - * For the affine case, the partitions will account for the offset, but otherwise remain the same. + * For the affine case, the partitions will account for the shift, but otherwise remain the same. * In the below computations, the vanishing polynomials will be over the affine subspaces. */ - /** For partition {0}, the successor of {0} is 1 + affine_offset, and the indicator polynomial is + /** For partition {0}, the successor of {0} is 1 + affine_shift, and the indicator polynomial is * L_{S, 0}, which is the normalized lagrange basis polynomial for the 0th element of S. */ - const FieldT zeroth_element_of_S = this->subspace_.offset(); + const FieldT zeroth_element_of_S = this->subspace_.shift(); const bool is_normalized = true; this->lagrange_indicator_polynomial_ = lagrange_polynomial(zeroth_element_of_S, field_subset(this->subspace_), is_normalized); @@ -114,13 +114,13 @@ additive_successor_polynomial::additive_successor_polynomial(const affin /** S_truncated is the subspace of S with its final basis vector removed. * This is needed for the final two partitions. It is also denoted as S' in comments */ affine_subspace S_truncated = - affine_subspace::shifted_standard_basis(domain.dimension() - 1, domain.offset()); + affine_subspace::shifted_standard_basis(domain.dimension() - 1, domain.shift()); this->Z_S_truncated_ = vanishing_polynomial(S_truncated); /** For partitions S' / {0} and S' + x^(i - 1), - * we need polynomials L_c, for c \in [0,1] such that L_c(cZ_{S'}(g^{i - 1} + affine_offset)) = 1, - * and L_c((1 - c)Z_{S'}(g^{i - 1} + affine_offset)) = 0. */ + * we need polynomials L_c, for c \in [0,1] such that L_c(cZ_{S'}(g^{i - 1} + affine_shift)) = 1, + * and L_c((1 - c)Z_{S'}(g^{i - 1} + affine_shift)) = 0. */ const FieldT multiplicative_generator_to_i_minus_one = - libiop::power(this->multiplicative_generator_, domain.dimension() - 1) + this->subspace_.offset(); + libiop::power(this->multiplicative_generator_, domain.dimension() - 1) + this->subspace_.shift(); this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_ = this->Z_S_truncated_.evaluation_at_point(multiplicative_generator_to_i_minus_one); /** L_0 is the degree 1 polynomial that is 1 when the argument is 0, @@ -137,14 +137,14 @@ template FieldT additive_successor_polynomial::evaluation_at_point(const FieldT &evalpoint) const { /** Affine shift of the subspace. */ - const FieldT offset = this->subspace_.offset(); + const FieldT shift = this->subspace_.shift(); FieldT result = FieldT::zero(); FieldT Z_S_truncated_at_x = this->Z_S_truncated_.evaluation_at_point(evalpoint); /** Partition 0 at x is the lagrange_indicator_polynomial at x */ const FieldT partition_0_eval = this->lagrange_indicator_polynomial_.evaluation_at_point(evalpoint); - /** The value at this partition is (1 + offset) */ - result += partition_0_eval * (FieldT::one() + offset); + /** The value at this partition is (1 + shift) */ + result += partition_0_eval * (FieldT::one() + shift); /** L_0 is the polynomial that is the degree 1 polynomial that is 1 when the argument is 0, * and 0 when the argument is Z_S_at_multiplicative_generator_to_i_minus_one. @@ -153,18 +153,18 @@ FieldT additive_successor_polynomial::evaluation_at_point(const FieldT & const FieldT L_0_eval = this->L_0_coefficient_ * (Z_S_truncated_at_x - this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_); /** This partition is L_0 - partition 0, - * and has value: multiplicative_generator * (X - offset) + offset */ + * and has value: multiplicative_generator * (X - shift) + shift */ result += (L_0_eval - partition_0_eval) * - (this->multiplicative_generator_ * (evalpoint - offset) + offset); + (this->multiplicative_generator_ * (evalpoint - shift) + shift); /** L_1 is the polynomial that is the degree 1 polynomial that is 0 when the argument is 0, * and 1 when the argument is Z_S_at_multiplicative_generator_to_i_minus_one. * So L_1 = k * X * L_1 is evaluated at Z_S'(X) */ const FieldT L_1_eval = this->L_1_coefficient_ * Z_S_truncated_at_x; - /** This partition is L_1, and has value (g * (X - offset) + offset + (primitive polynomial at g)) */ + /** This partition is L_1, and has value (g * (X - shift) + shift + (primitive polynomial at g)) */ result += L_1_eval * - (this->multiplicative_generator_ * (evalpoint - offset) + - offset + this->primitive_polynomial_at_multiplicative_generator_); + (this->multiplicative_generator_ * (evalpoint - shift) + + shift + this->primitive_polynomial_at_multiplicative_generator_); return result; } @@ -173,12 +173,12 @@ template std::vector additive_successor_polynomial::evaluations_over_field_subset( const field_subset &U) const { - const FieldT S_offset = this->subspace_.offset(); + const FieldT S_shift = this->subspace_.shift(); std::vector Z_S_truncated_over_U = this->Z_S_truncated_.evaluations_over_field_subset(U); - /** We only need (x + S_offset) in the evaluation procedure, for x in U. - * Note that we are in a binary field, so (x + S_offset) = (x - S_offset) */ + /** We only need (x + S_shift) in the evaluation procedure, for x in U. + * Note that we are in a binary field, so (x + S_shift) = (x - S_shift) */ std::vector shifted_U_elements = - all_subset_sums(U.basis(), S_offset + U.offset()); + all_subset_sums(U.basis(), S_shift + U.shift()); // If we need to squeeze performance out of this method, // then the lagrange polynomial's evaluation over domain can be opened up here, @@ -189,27 +189,27 @@ std::vector additive_successor_polynomial::evaluations_over_fiel this->lagrange_indicator_polynomial_.evaluations_over_field_subset(U); std::vector result(U.num_elements(), FieldT::zero()); - const FieldT one_plus_S_offset = FieldT::one() + S_offset; + const FieldT one_plus_S_shift = FieldT::one() + S_shift; for (size_t i = 0; i < result.size(); i++) { // The partition 0 polynomial is the lagrange indicator polynomial - // Value at partition 0 is (1 + offset) - result[i] += lagrange_indicator_evaluations[i] * one_plus_S_offset; + // Value at partition 0 is (1 + shift) + result[i] += lagrange_indicator_evaluations[i] * one_plus_S_shift; // The partition 1 polynomial is: L_0(Z_S_truncated(X)) - partition_0(X) const FieldT L_0_eval = this->L_0_coefficient_ * (Z_S_truncated_over_U[i] - this->Z_S_truncated_at_multiplicative_generator_to_i_minus_one_); const FieldT partition_1_eval = L_0_eval - lagrange_indicator_evaluations[i]; - // Value at partition 1 is multiplicative_generator * (X - S_offset) + S_offset + // Value at partition 1 is multiplicative_generator * (X - S_shift) + S_shift result[i] += partition_1_eval * - (this->multiplicative_generator_ * shifted_U_elements[i] + S_offset); + (this->multiplicative_generator_ * shifted_U_elements[i] + S_shift); // The partition 2 polynomial is: L_1(Z_S_truncated(X)) const FieldT partition_2_eval = this->L_1_coefficient_ * Z_S_truncated_over_U[i]; - // Value at partition 2 is (multiplicative_generator * (X - S_offset) + S_offset + + // Value at partition 2 is (multiplicative_generator * (X - S_shift) + S_shift + // primitive_polynomial at multiplicative_generator) result[i] += partition_2_eval * - (this->multiplicative_generator_ * shifted_U_elements[i] + S_offset + + (this->multiplicative_generator_ * shifted_U_elements[i] + S_shift + this->primitive_polynomial_at_multiplicative_generator_); } return result; @@ -252,7 +252,7 @@ additive_successor_ordering::additive_successor_ordering(const field_sub template FieldT additive_successor_ordering::first_elem() const { - return this->subspace_.offset(); + return this->subspace_.shift(); } template diff --git a/libiop/profiling/boost_profile.cpp b/libiop/profiling/boost_profile.cpp new file mode 100644 index 00000000..8eaf8659 --- /dev/null +++ b/libiop/profiling/boost_profile.cpp @@ -0,0 +1,44 @@ +#ifndef CPPDEBUG /* Ubuntu's Boost does not provide binaries compatible with libstdc++'s debug mode so we just reduce functionality here */ +#include +#endif + +#include "libiop/bcs/bcs_common.hpp" + +namespace po = boost::program_options; +using namespace libiop; + +// The hash_enum field must be initialized from the hash_enum_val field, as opposed to via the command line. +struct options{ + std::size_t log_n_min = 8; + std::size_t log_n_max = 20; + std::size_t security_level = 128; + std::size_t field_size = 181; + std::size_t hash_enum_val = (size_t) libiop::blake2b_type; + bool heuristic_ldt_reducer_soundness = true; + bool is_multiplicative = true; + bool make_zk = false; + libiop::bcs_hash_type hash_enum = blake2b_type; +}; + + +po::options_description gen_options(options &options) +{ + po::options_description base("Usage"); + + + base.add_options() + ("help", "print this help message") + ("log_n_min", po::value(&options.log_n_min)->default_value(options.log_n_min)) + ("log_n_max", po::value(&options.log_n_max)->default_value(options.log_n_max)) + ("security_level", po::value(&options.security_level)->default_value(options.security_level)) + ("field_size", po::value(&options.field_size)->default_value(options.field_size)) + ("heuristic_ldt_reducer_soundness", po::value(&options.heuristic_ldt_reducer_soundness)->default_value(options.heuristic_ldt_reducer_soundness)) + ("is_multiplicative", po::value(&options.is_multiplicative)->default_value(options.is_multiplicative)) + ("make_zk", po::value(&options.make_zk)->default_value(false)) + ("hash_enum", po::value(&options.hash_enum_val)->default_value((size_t) blake2b_type)); + + + return base; +} + + diff --git a/libiop/profiling/instrument_algebra.cpp b/libiop/profiling/instrument_algebra.cpp index de7c8298..33695fd4 100644 --- a/libiop/profiling/instrument_algebra.cpp +++ b/libiop/profiling/instrument_algebra.cpp @@ -10,6 +10,7 @@ #include #endif +#include "boost_profile.cpp" #include "libiop/algebra/fft.hpp" #include "libiop/algebra/fields/gf64.hpp" #include "libiop/algebra/fields/gf128.hpp" diff --git a/libiop/profiling/instrument_aurora_snark.cpp b/libiop/profiling/instrument_aurora_snark.cpp index e9c20483..fd748af2 100644 --- a/libiop/profiling/instrument_aurora_snark.cpp +++ b/libiop/profiling/instrument_aurora_snark.cpp @@ -15,6 +15,8 @@ #include "libiop/algebra/fields/gf256.hpp" #include "libiop/algebra/fields/utils.hpp" + +#include "boost_profile.cpp" #include "libiop/snark/aurora_snark.hpp" #include "libiop/bcs/bcs_common.hpp" #include "libiop/protocols/aurora_iop.hpp" @@ -25,35 +27,17 @@ #ifndef CPPDEBUG bool process_prover_command_line(const int argc, const char** argv, - std::size_t &log_n_min, - std::size_t &log_n_max, - std::size_t &security_level, - std::size_t &field_size, - bool &heuristic_ldt_reducer_soundness, - bool &heuristic_fri_soundness, - bool &make_zk, - libiop::bcs_hash_type &hash_enum, - bool &is_multiplicative, - bool &optimize_localization) + options &options, bool heuristic_fri_soundness, bool optimize_localization) { namespace po = boost::program_options; try { - size_t hash_enum_val; - po::options_description desc("Usage"); + + po::options_description desc = gen_options(options); desc.add_options() - ("help", "print this help message") - ("log_n_min", po::value(&log_n_min)->default_value(8)) - ("log_n_max", po::value(&log_n_max)->default_value(20)) - ("security_level", po::value(&security_level)->default_value(128)) - ("field_size", po::value(&field_size)->default_value(192)) - ("heuristic_ldt_reducer_soundness", po::value(&heuristic_ldt_reducer_soundness)->default_value(true)) - ("heuristic_fri_soundness", po::value(&heuristic_fri_soundness)->default_value(true)) - ("make_zk", po::value(&make_zk)->default_value(false)) - ("hash_enum", po::value(&hash_enum_val)->default_value((size_t) libiop::blake2b_type)) /* Find a better solution for this in the future */ - ("is_multiplicative", po::value(&is_multiplicative)->default_value(false)) - ("optimize_localization", po::value(&optimize_localization)->default_value(false)); + ("optimize_localization", po::value(&optimize_localization)->default_value(false)) + ("heuristic_fri_soundness", po::value(&heuristic_fri_soundness)->default_value(true)); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -65,7 +49,7 @@ bool process_prover_command_line(const int argc, const char** argv, } po::notify(vm); - hash_enum = static_cast(hash_enum_val); + options.hash_enum = static_cast(options.hash_enum_val); } catch(std::exception& e) { @@ -103,25 +87,21 @@ void print_argument_size( } template -void instrument_aurora_snark(const std::size_t log_n_min, - const std::size_t log_n_max, - std::size_t security_level, - LDT_reducer_soundness_type ldt_reducer_soundness_type, - FRI_soundness_type fri_soundness_type, - const bcs_hash_type hash_enum, - const bool make_zk, - const bool is_multiplicative, - bool optimize_localization) +void instrument_aurora_snark(options &options, + LDT_reducer_soundness_type ldt_reducer_soundness_type, + FRI_soundness_type fri_soundness_type, + bool &optimize_localization) + { // TODO: Unhard code this - const size_t RS_extra_dimensions = 3 + (make_zk ? 0 : 2); + const size_t RS_extra_dimensions = 3 + (options.make_zk ? 0 : 2); const size_t fri_localization_parameter = 2; field_subset_type domain_type = affine_subspace_type; - if (is_multiplicative) { + if (options.is_multiplicative) { domain_type = multiplicative_coset_type; } - for (std::size_t log_n = log_n_min; log_n <= log_n_max; ++log_n) + for (std::size_t log_n = options.log_n_min; log_n <= options.log_n_max; ++log_n) { print_separator(); @@ -132,13 +112,13 @@ void instrument_aurora_snark(const std::size_t log_n_min, r1cs_example example = generate_r1cs_example(n, k, m); aurora_snark_parameters parameters( - security_level, + options.security_level, ldt_reducer_soundness_type, fri_soundness_type, - hash_enum, + options.hash_enum, fri_localization_parameter, RS_extra_dimensions, - make_zk, + options.make_zk, domain_type, example.constraint_system_.num_constraints(), example.constraint_system_.num_variables()); @@ -206,16 +186,11 @@ void instrument_aurora_snark(const std::size_t log_n_min, int main(int argc, const char * argv[]) { /* Set up R1CS */ - std::size_t log_n_min; - std::size_t log_n_max; - std::size_t security_level; - std::size_t field_size; - bool heuristic_ldt_reducer_soundness; - bool heuristic_fri_soundness; - bcs_hash_type hash_enum; - bool make_zk; - bool is_multiplicative; - bool optimize_localization; + + options default_vals; + + bool optimize_localization = false; + bool heuristic_fri_soundness = true; #ifdef CPPDEBUG /* set reasonable defaults */ @@ -226,25 +201,15 @@ int main(int argc, const char * argv[]) } libiop::UNUSED(argv); - log_n_min = 8; - log_n_max = 20; - security_level = 128; - field_size = 64; - heuristic_ldt_reducer_soundness = true; - heuristic_fri_soundness = true; - make_zk = false; - is_multiplicative = false; - optimize_localization = false; #else - if (!process_prover_command_line(argc, argv, log_n_min, log_n_max, security_level, field_size, - heuristic_ldt_reducer_soundness, heuristic_fri_soundness, make_zk, hash_enum, is_multiplicative, optimize_localization)) + if (!process_prover_command_line(argc, argv, default_vals, heuristic_fri_soundness, optimize_localization)) { return 1; } #endif /** TODO: eventually get a string from program options, and then have a from string methods in protocols */ LDT_reducer_soundness_type ldt_reducer_soundness_type = LDT_reducer_soundness_type::proven; - if (heuristic_ldt_reducer_soundness) + if (default_vals.heuristic_ldt_reducer_soundness) { ldt_reducer_soundness_type = LDT_reducer_soundness_type::optimistic_heuristic; } @@ -255,40 +220,38 @@ int main(int argc, const char * argv[]) start_profiling(); printf("Selected parameters:\n"); - printf("- log_n_min = %zu\n", log_n_min); - printf("- log_n_max = %zu\n", log_n_max); - printf("- security_level = %zu\n", security_level); + printf("- log_n_min = %zu\n", default_vals.log_n_min); + printf("- log_n_max = %zu\n", default_vals.log_n_max); + printf("- security_level = %zu\n", default_vals.security_level); printf("- LDT_reducer_soundness_type = %s\n", LDT_reducer_soundness_type_to_string(ldt_reducer_soundness_type)); printf("- FRI_soundness_type = %s\n", FRI_soundness_type_to_string(fri_soundness_type)); - printf("- is_multiplicative = %s\n", is_multiplicative ? "true" : "false"); - printf("- field_size = %zu\n", field_size); - printf("- make_zk = %s\n", make_zk ? "true" : "false"); - printf("- hash_enum = %s\n", bcs_hash_type_names[hash_enum]); + printf("- is_multiplicative = %s\n", default_vals.is_multiplicative ? "true" : "false"); + printf("- field_size = %zu\n", default_vals.field_size); + printf("- make_zk = %s\n", default_vals.make_zk ? "true" : "false"); + printf("- hash_enum = %s\n", bcs_hash_type_names[default_vals.hash_enum]); - if (is_multiplicative) { - switch (field_size) { + if (default_vals.is_multiplicative) { + switch (default_vals.field_size) { case 181: edwards_pp::init_public_params(); - instrument_aurora_snark(log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + instrument_aurora_snark( + default_vals, ldt_reducer_soundness_type, + fri_soundness_type, optimize_localization); break; case 256: libff::alt_bn128_pp::init_public_params(); - if (hash_enum == libiop::blake2b_type) + if (default_vals.hash_enum == libiop::blake2b_type) { instrument_aurora_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, + fri_soundness_type, optimize_localization); } else { instrument_aurora_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, + fri_soundness_type, optimize_localization); } break; default: @@ -296,27 +259,23 @@ int main(int argc, const char * argv[]) } } else { - switch (field_size) + switch (default_vals.field_size) { case 64: - instrument_aurora_snark(log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + instrument_aurora_snark( + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 128: - instrument_aurora_snark(log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + instrument_aurora_snark( + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 192: - instrument_aurora_snark(log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + instrument_aurora_snark( + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 256: - instrument_aurora_snark(log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + instrument_aurora_snark( + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; default: throw std::invalid_argument("Field size not supported."); diff --git a/libiop/profiling/instrument_fractal_snark.cpp b/libiop/profiling/instrument_fractal_snark.cpp index a51c97c1..069d6cff 100644 --- a/libiop/profiling/instrument_fractal_snark.cpp +++ b/libiop/profiling/instrument_fractal_snark.cpp @@ -9,6 +9,7 @@ #include #endif +#include "boost_profile.cpp" #include "libiop/algebra/fields/gf64.hpp" #include "libiop/algebra/fields/gf128.hpp" #include "libiop/algebra/fields/gf192.hpp" @@ -25,39 +26,21 @@ #ifndef CPPDEBUG bool process_prover_command_line(const int argc, const char** argv, - std::size_t &log_n_min, - std::size_t &log_n_max, - std::size_t &security_level, - std::size_t &field_size, - bool &heuristic_ldt_reducer_soundness, - bool &heuristic_fri_soundness, - bool &make_zk, - libiop::bcs_hash_type &hash_enum, - bool &is_multiplicative, - bool &optimize_localization) + options &options, bool heuristic_fri_soundness, bool optimize_localization) { namespace po = boost::program_options; try { - size_t hash_enum_val; - po::options_description desc("Usage"); + po::options_description desc = gen_options(options); desc.add_options() - ("help", "print this help message") - ("log_n_min", po::value(&log_n_min)->default_value(8)) - ("log_n_max", po::value(&log_n_max)->default_value(20)) - ("security_level", po::value(&security_level)->default_value(128)) - ("field_size", po::value(&field_size)->default_value(192)) - ("heuristic_ldt_reducer_soundness", po::value(&heuristic_ldt_reducer_soundness)->default_value(true)) - ("heuristic_fri_soundness", po::value(&heuristic_fri_soundness)->default_value(true)) - ("make_zk", po::value(&make_zk)->default_value(false)) - ("hash_enum", po::value(&hash_enum_val)->default_value((size_t) libiop::blake2b_type)) /* Find a better solution for this in the future */ - ("is_multiplicative", po::value(&is_multiplicative)->default_value(false)) - ("optimize_localization", po::value(&optimize_localization)->default_value(false)); + ("optimize_localization", po::value(&optimize_localization)->default_value(false)) + ("heuristic_fri_soundness", po::value(&heuristic_fri_soundness)->default_value(true)); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); + if (vm.count("help")) { std::cout << desc << "\n"; @@ -65,7 +48,7 @@ bool process_prover_command_line(const int argc, const char** argv, } po::notify(vm); - hash_enum = static_cast(hash_enum_val); + options.hash_enum = static_cast(options.hash_enum_val); } catch(std::exception& e) { @@ -103,26 +86,20 @@ void print_argument_size( } template -void instrument_fractal_snark( - const std::size_t log_n_min, - const std::size_t log_n_max, - std::size_t security_level, - LDT_reducer_soundness_type ldt_reducer_soundness_type, - FRI_soundness_type fri_soundness_type, - const bcs_hash_type hash_enum, - const bool make_zk, - const bool is_multiplicative, - bool optimize_localization) +void instrument_fractal_snark(options &options, + LDT_reducer_soundness_type ldt_reducer_soundness_type, + FRI_soundness_type fri_soundness_type, + bool &optimize_localization) { // TODO: Unhard code this const size_t RS_extra_dimensions = 3; const size_t fri_localization_parameter = 2; field_subset_type domain_type = affine_subspace_type; - if (is_multiplicative) { + if (options.is_multiplicative) { domain_type = multiplicative_coset_type; } - for (std::size_t log_n = log_n_min; log_n <= log_n_max; ++log_n) + for (std::size_t log_n = options.log_n_min; log_n <= options.log_n_max; ++log_n) { print_separator(); @@ -137,13 +114,13 @@ void instrument_fractal_snark( r1cs_example example = generate_r1cs_example(n, k, m); fractal_snark_parameters parameters( - security_level, + options.security_level, ldt_reducer_soundness_type, fri_soundness_type, - hash_enum, + options.hash_enum, fri_localization_parameter, RS_extra_dimensions, - make_zk, + options.make_zk, domain_type, std::make_shared>(example.constraint_system_)); @@ -202,13 +179,13 @@ void instrument_fractal_snark( parameters); parameters = fractal_snark_parameters( - security_level, + options.security_level, ldt_reducer_soundness_type, fri_soundness_type, - hash_enum, + options.hash_enum, fri_localization_parameter, RS_extra_dimensions, - make_zk, + options.make_zk, domain_type, std::make_shared>(example.constraint_system_)); if (optimize_localization) @@ -233,16 +210,10 @@ void instrument_fractal_snark( int main(int argc, const char * argv[]) { /* Set up R1CS */ - std::size_t log_n_min; - std::size_t log_n_max; - std::size_t security_level; - std::size_t field_size; - bool heuristic_ldt_reducer_soundness; - bool heuristic_fri_soundness; - bcs_hash_type hash_enum; - bool make_zk; - bool is_multiplicative; - bool optimize_localization; + options default_vals; + + bool optimize_localization = false; + bool heuristic_fri_soundness = true; #ifdef CPPDEBUG /* set reasonable defaults */ @@ -253,25 +224,15 @@ int main(int argc, const char * argv[]) } libiop::UNUSED(argv); - log_n_min = 8; - log_n_max = 20; - security_level = 128; - field_size = 64; - heuristic_ldt_reducer_soundness = true; - heuristic_fri_soundness = true; - make_zk = false; - is_multiplicative = false; - optimize_localization = false; #else - if (!process_prover_command_line(argc, argv, log_n_min, log_n_max, security_level, field_size, - heuristic_ldt_reducer_soundness, heuristic_fri_soundness, make_zk, hash_enum, is_multiplicative, optimize_localization)) + if (!process_prover_command_line(argc, argv, default_vals, heuristic_fri_soundness, optimize_localization)) { return 1; } #endif /** TODO: eventually get a string from program options, and then have a from string methods in protocols */ LDT_reducer_soundness_type ldt_reducer_soundness_type = LDT_reducer_soundness_type::proven; - if (heuristic_ldt_reducer_soundness) + if (default_vals.heuristic_ldt_reducer_soundness) { ldt_reducer_soundness_type = LDT_reducer_soundness_type::optimistic_heuristic; } @@ -282,40 +243,34 @@ int main(int argc, const char * argv[]) start_profiling(); printf("Selected parameters:\n"); - printf("- log_n_min = %zu\n", log_n_min); - printf("- log_n_max = %zu\n", log_n_max); - printf("- security_level = %zu\n", security_level); + printf("- log_n_min = %zu\n", default_vals.log_n_min); + printf("- log_n_max = %zu\n", default_vals.log_n_max); + printf("- security_level = %zu\n", default_vals.security_level); printf("- LDT_reducer_soundness_type = %s\n", LDT_reducer_soundness_type_to_string(ldt_reducer_soundness_type)); printf("- FRI_soundness_type = %s\n", FRI_soundness_type_to_string(fri_soundness_type)); - printf("- is_multiplicative = %s\n", is_multiplicative ? "true" : "false"); - printf("- field_size = %zu\n", field_size); - printf("- make_zk = %s\n", make_zk ? "true" : "false"); - printf("- hash_enum = %s\n", bcs_hash_type_names[hash_enum]); + printf("- is_multiplicative = %s\n", default_vals.is_multiplicative ? "true" : "false"); + printf("- field_size = %zu\n", default_vals.field_size); + printf("- make_zk = %s\n", default_vals.make_zk ? "true" : "false"); + printf("- hash_enum = %s\n", bcs_hash_type_names[default_vals.hash_enum]); - if (is_multiplicative) { - switch (field_size) { + if (default_vals.is_multiplicative) { + switch (default_vals.field_size) { case 181: edwards_pp::init_public_params(); instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 256: libff::alt_bn128_pp::init_public_params(); - if (hash_enum == libiop::blake2b_type) + if (default_vals.hash_enum == libiop::blake2b_type) { instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); } else { instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); } break; default: @@ -323,31 +278,23 @@ int main(int argc, const char * argv[]) } } else { - switch (field_size) + switch (default_vals.field_size) { case 64: instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 128: instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 192: instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; case 256: instrument_fractal_snark( - log_n_min, log_n_max, security_level, - ldt_reducer_soundness_type, fri_soundness_type, hash_enum, - make_zk, is_multiplicative, optimize_localization); + default_vals, ldt_reducer_soundness_type, fri_soundness_type, optimize_localization); break; default: throw std::invalid_argument("Field size not supported."); diff --git a/libiop/profiling/instrument_fri_snark.cpp b/libiop/profiling/instrument_fri_snark.cpp index c93ee495..55801d12 100644 --- a/libiop/profiling/instrument_fri_snark.cpp +++ b/libiop/profiling/instrument_fri_snark.cpp @@ -9,6 +9,7 @@ #include #endif +#include "boost_profile.cpp" #include "libff/algebra/curves/edwards/edwards_pp.hpp" #include "libff/algebra/curves/alt_bn128/alt_bn128_pp.hpp" @@ -26,35 +27,24 @@ #include "libiop/snark/fri_snark.hpp" #ifndef CPPDEBUG -bool process_prover_command_line(const int argc, const char** argv, - std::size_t &log_n_min, - std::size_t &log_n_max, - std::size_t &security_level, - std::size_t &field_size, - bool &is_multiplicative, - std::size_t &localization_parameter, - std::size_t &num_localization_steps, - std::size_t &num_oracles, - std::size_t &num_interactive_repetitions, - std::size_t &num_query_repetitions) +bool process_prover_command_line(const int argc, const char** argv, options &options, + std::size_t localization_parameter, + std::size_t num_localization_steps, + std::size_t num_oracles, + std::size_t num_interactive_repetitions, + std::size_t num_query_repetitions) { namespace po = boost::program_options; try { - po::options_description desc("Usage"); + po::options_description desc = gen_options(options); desc.add_options() - ("help", "print this help message") - ("log_n_min", po::value(&log_n_min)->default_value(8)) - ("log_n_max", po::value(&log_n_max)->default_value(20)) - ("security_level", po::value(&security_level)->default_value(128)) - ("field_size", po::value(&field_size)->default_value(64)) - ("is_multiplicative", po::value(&is_multiplicative)->default_value(false)) - ("localization_parameter", po::value(&localization_parameter)->default_value(2), "Only used when num_localization_steps is 0") - ("num_localization_steps", po::value(&num_localization_steps)->default_value(0)) - ("num_oracles", po::value(&num_oracles)->default_value(1)) - ("num_interactive_repetitions", po::value(&num_interactive_repetitions)->default_value(1)) - ("num_query_repetitions", po::value(&num_query_repetitions)->default_value(64)); + ("localization_parameter", po::value(&localization_parameter)->default_value(2), "Only used when num_localization_steps is 0") + ("num_localization_steps", po::value(&num_localization_steps)->default_value(0)) + ("num_oracles", po::value(&num_oracles)->default_value(1)) + ("num_interactive_repetitions", po::value(&num_interactive_repetitions)->default_value(1)) + ("num_query_repetitions", po::value(&num_query_repetitions)->default_value(64)); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -80,17 +70,14 @@ bool process_prover_command_line(const int argc, const char** argv, using namespace libiop; template -void instrument_FRI(std::size_t log_n_min, - std::size_t log_n_max, - std::size_t security_level, - bool is_multiplicative, +void instrument_FRI(options &options, std::size_t localization_parameter, std::size_t num_localization_steps, std::size_t num_oracles, std::size_t num_interactive_repetitions, std::size_t num_query_repetitions) { - for (std::size_t log_n = log_n_min; log_n <= log_n_max; ++log_n) + for (std::size_t log_n = options.log_n_min; log_n <= options.log_n_max; ++log_n) { print_separator(); const std::size_t poly_degree_bound = 1ull << log_n; @@ -121,8 +108,8 @@ void instrument_FRI(std::size_t log_n_min, FRI_snark_parameters params; params.codeword_domain_dim_ = codeword_domain_dim; - params.security_level_ = security_level; - params.hash_enum_ = blake2b_type; + params.security_level_ = options.security_level; + params.hash_enum_ = options.hash_enum; params.RS_extra_dimensions_ = RS_extra_dimensions; params.localization_parameter_array_ = localization_parameter_array; params.localization_parameter_ = localization_parameter; @@ -151,16 +138,13 @@ void instrument_FRI(std::size_t log_n_min, int main(int argc, const char * argv[]) { - std::size_t log_n_min; - std::size_t log_n_max; - std::size_t security_level; - std::size_t field_size; - bool is_multiplicative; - std::size_t localization_parameter; - std::size_t num_localization_steps; - std::size_t num_oracles; - std::size_t num_interactive_repetitions; - std::size_t num_query_repetitions; + options default_vals; + + std::size_t localization_parameter = 2; + std::size_t num_localization_steps = 0; + std::size_t num_oracles = 1; + std::size_t num_interactive_repetitions = 1; + std::size_t num_query_repetitions = 10; #ifdef CPPDEBUG /* set reasonable defaults */ @@ -171,71 +155,62 @@ int main(int argc, const char * argv[]) } libiop::UNUSED(argv); - log_n_min = 8; - log_n_max = 20; - security_level = 128; - field_size = 64; - is_multiplicative = false; - localization_parameter = 2; - num_localization_steps = 0; - num_oracles = 1; - num_interactive_repetitions = 1; - num_query_repetitions = 10; #else - if (!process_prover_command_line(argc, argv, log_n_min, log_n_max, security_level, - field_size, is_multiplicative, localization_parameter, num_localization_steps, - num_oracles, num_interactive_repetitions, num_query_repetitions)) + if (!process_prover_command_line(argc, argv, default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles)) { return 1; } + #endif start_profiling(); printf("Selected parameters:\n"); - printf("* log_n_min = %zu\n", log_n_min); - printf("* log_n_max = %zu\n", log_n_max); - printf("* security_level = %zu\n", security_level); + printf("* log_n_min = %zu\n", default_vals.log_n_min); + printf("* log_n_max = %zu\n", default_vals.log_n_max); + printf("* security_level = %zu\n", default_vals.security_level); - if (is_multiplicative) { - switch (field_size) { + if (default_vals.is_multiplicative) { + switch (default_vals.field_size) { case 181: edwards_pp::init_public_params(); - instrument_FRI(log_n_min, log_n_max, security_level, true, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; case 256: libff::alt_bn128_pp::init_public_params(); - instrument_FRI(log_n_min, log_n_max, security_level, true, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; default: throw std::invalid_argument("Field size not supported."); } } else { - switch (field_size) + switch (default_vals.field_size) { case 64: - instrument_FRI(log_n_min, log_n_max, security_level, false, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; case 128: - instrument_FRI(log_n_min, log_n_max, security_level, false, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; case 192: - instrument_FRI(log_n_min, log_n_max, security_level, false, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; case 256: - instrument_FRI(log_n_min, log_n_max, security_level, false, - localization_parameter, num_localization_steps, num_oracles, - num_interactive_repetitions, num_query_repetitions); + instrument_FRI(default_vals, localization_parameter, + num_interactive_repetitions, num_query_repetitions, + num_localization_steps, num_oracles); break; default: throw std::invalid_argument("Field size not supported."); diff --git a/libiop/profiling/instrument_ligero_snark.cpp b/libiop/profiling/instrument_ligero_snark.cpp index bbcc75f1..4ac601af 100644 --- a/libiop/profiling/instrument_ligero_snark.cpp +++ b/libiop/profiling/instrument_ligero_snark.cpp @@ -4,10 +4,12 @@ #include #include + #ifndef CPPDEBUG /* Ubuntu's Boost does not provide binaries compatible with libstdc++'s debug mode so we just reduce functionality here */ #include #endif +#include "boost_profile.cpp" #include #include @@ -23,35 +25,18 @@ #ifndef CPPDEBUG bool process_prover_command_line(const int argc, const char** argv, - std::size_t &log_n_min, - std::size_t &log_n_max, + options &options, float &height_width_ratio, - std::size_t &RS_extra_dimensions, - std::size_t &security_level, - std::size_t &field_size, - bool &heuristic_ldt_reducer_soundness, - bool &make_zk, - libiop::bcs_hash_type &hash_enum, - bool &is_multiplicative) + std::size_t &RS_extra_dimensions) { namespace po = boost::program_options; try { - size_t hash_enum_val; - po::options_description desc("Usage"); + po::options_description desc = gen_options(options); desc.add_options() - ("help", "print this help message") - ("log_n_min", po::value(&log_n_min)->default_value(8)) - ("log_n_max", po::value(&log_n_max)->default_value(20)) - ("security_level", po::value(&security_level)->default_value(128)) - ("heuristic_ldt_reducer_soundness", po::value(&heuristic_ldt_reducer_soundness)->default_value(true)) - ("height_width_ratio", po::value(&height_width_ratio)->default_value(0.1)) - ("RS_extra_dimensions", po::value(&RS_extra_dimensions)->default_value(2)) - ("field_size", po::value(&field_size)->default_value(192)) - ("make_zk", po::value(&make_zk)->default_value(true)) - ("hash_enum", po::value(&hash_enum_val)->default_value((size_t) libiop::blake2b_type)) /* Find a better solution for this in the future */ - ("is_multiplicative", po::value(&is_multiplicative)->default_value(false)); + ("height_width_ratio", po::value(&height_width_ratio)->default_value(0.1)) + ("RS_extra_dimensions", po::value(&RS_extra_dimensions)->default_value(2)); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -63,7 +48,7 @@ bool process_prover_command_line(const int argc, const char** argv, } po::notify(vm); - hash_enum = static_cast(hash_enum_val); + options.hash_enum = static_cast(options.hash_enum_val); } catch(std::exception& e) { @@ -78,27 +63,23 @@ bool process_prover_command_line(const int argc, const char** argv, using namespace libiop; template -void instrument_ligero_snark(const std::size_t log_n_min, - const std::size_t log_n_max, - const float height_width_ratio, - const std::size_t RS_extra_dimensions, - const std::size_t security_level, - const LDT_reducer_soundness_type ldt_reducer_soundness_type, - const bcs_hash_type hash_enum, - const bool make_zk, - const field_subset_type domain_type) +void instrument_ligero_snark(options &options, + LDT_reducer_soundness_type ldt_reducer_soundness_type, + const field_subset_type domain_type, + float height_width_ratio, + std::size_t RS_extra_dimensions) { ligero_snark_parameters parameters; - parameters.security_level_ = security_level; + parameters.security_level_ = options.security_level; parameters.LDT_reducer_soundness_type_ = ldt_reducer_soundness_type; parameters.height_width_ratio_ = height_width_ratio; parameters.RS_extra_dimensions_ = RS_extra_dimensions; - parameters.make_zk_ = make_zk; + parameters.make_zk_ = options.make_zk; parameters.domain_type_ = domain_type; - parameters.bcs_params_ = default_bcs_params(hash_enum, security_level, log_n_min); + parameters.bcs_params_ = default_bcs_params(options.hash_enum, options.security_level, options.log_n_min); parameters.describe(); - for (std::size_t log_n = log_n_min; log_n <= log_n_max; ++log_n) + for (std::size_t log_n = options.log_n_min; log_n <= options.log_n_max; ++log_n) { print_separator(); const std::size_t n = 1ul << log_n; @@ -106,7 +87,7 @@ void instrument_ligero_snark(const std::size_t log_n_min, const std::size_t k = 15; const std::size_t m = n - 1; r1cs_example example = generate_r1cs_example(n, k, m); - parameters.bcs_params_ = default_bcs_params(hash_enum, security_level, log_n); + parameters.bcs_params_ = default_bcs_params(options.hash_enum, options.security_level, log_n); enter_block("Check satisfiability of R1CS example"); const bool is_satisfied = example.constraint_system_.is_satisfied( @@ -155,35 +136,17 @@ void instrument_ligero_snark(const std::size_t log_n_min, int main(int argc, const char * argv[]) { - /* Set up R1CS */ - std::size_t log_n_min; - std::size_t log_n_max; - float height_width_ratio; - std::size_t RS_extra_dimensions; - std::size_t security_level; - std::size_t field_size; - bool heuristic_ldt_reducer_soundness; - bcs_hash_type hash_enum; - bool make_zk; - bool is_multiplicative; + + options default_vals; + + float height_width_ratio = 0.1; + std::size_t RS_extra_dimensions = 2; #ifdef CPPDEBUG /* set reasonable defaults */ - libiop::UNUSED(argc); - libiop::UNUSED(argv); - log_n_min = 8; - log_n_max = 20; - height_width_ratio = 0.1; - RS_extra_dimensions = 2; - security_level = 128; - field_size = 64; - heuristic_ldt_reducer_soundness = true; - make_zk = true; - is_multiplicative = false; + #else - if (!process_prover_command_line(argc, argv, log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, field_size, - heuristic_ldt_reducer_soundness, make_zk, hash_enum, is_multiplicative)) + if (!process_prover_command_line(argc, argv, default_vals, height_width_ratio, RS_extra_dimensions)) { return 1; } @@ -191,45 +154,45 @@ int main(int argc, const char * argv[]) /** TODO: eventually get a string from program options, and then have a from string method in LDT reducer */ LDT_reducer_soundness_type ldt_reducer_soundness_type = LDT_reducer_soundness_type::proven; - if (heuristic_ldt_reducer_soundness) + if (default_vals.heuristic_ldt_reducer_soundness) { ldt_reducer_soundness_type = LDT_reducer_soundness_type::optimistic_heuristic; } start_profiling(); printf("Selected parameters:\n"); - printf("- log_n_min = %zu\n", log_n_min); - printf("- log_n_max = %zu\n", log_n_max); + printf("- log_n_min = %zu\n", default_vals.log_n_min); + printf("- log_n_max = %zu\n", default_vals.log_n_max); printf("- height_width_ratio = %f\n", height_width_ratio); printf("- RS_extra_dimensions = %zu\n", RS_extra_dimensions); - printf("- security_level = %zu\n", security_level); + printf("- security_level = %zu\n", default_vals.security_level); printf("- LDT_reducer_soundness_type = %s\n", LDT_reducer_soundness_type_to_string(ldt_reducer_soundness_type)); - printf("- field_size = %zu\n", field_size); - printf("- make_zk = %d\n", make_zk); - printf("- hash_enum = %s\n", bcs_hash_type_names[hash_enum]); + printf("- field_size = %zu\n", default_vals.field_size); + printf("- make_zk = %d\n", default_vals.make_zk); + printf("- hash_enum = %s\n", bcs_hash_type_names[default_vals.hash_enum]); - if (is_multiplicative) + if (default_vals.is_multiplicative) { - switch (field_size) { + switch (default_vals.field_size) { case 181: edwards_pp::init_public_params(); - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - multiplicative_coset_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, multiplicative_coset_type, + height_width_ratio, RS_extra_dimensions); break; case 256: libff::alt_bn128_pp::init_public_params(); - if (hash_enum == blake2b_type) + if (default_vals.hash_enum == blake2b_type) { - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - multiplicative_coset_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, multiplicative_coset_type, + height_width_ratio, RS_extra_dimensions); } else { - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - multiplicative_coset_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, multiplicative_coset_type, + height_width_ratio, RS_extra_dimensions); } break; default: @@ -238,27 +201,27 @@ int main(int argc, const char * argv[]) } else { - switch (field_size) + switch (default_vals.field_size) { case 64: - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - affine_subspace_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, affine_subspace_type, + height_width_ratio, RS_extra_dimensions); break; case 128: - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - affine_subspace_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, affine_subspace_type, + height_width_ratio, RS_extra_dimensions); break; case 192: - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - affine_subspace_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, affine_subspace_type, + height_width_ratio, RS_extra_dimensions); break; case 256: - instrument_ligero_snark(log_n_min, log_n_max, height_width_ratio, RS_extra_dimensions, - security_level, ldt_reducer_soundness_type, hash_enum, make_zk, - affine_subspace_type); + instrument_ligero_snark( + default_vals, ldt_reducer_soundness_type, affine_subspace_type, + height_width_ratio, RS_extra_dimensions); break; default: throw std::invalid_argument("Field size not supported."); diff --git a/libiop/protocols/encoded/common/boundary_constraint.tcc b/libiop/protocols/encoded/common/boundary_constraint.tcc index 1b183855..1ae8fd8d 100644 --- a/libiop/protocols/encoded/common/boundary_constraint.tcc +++ b/libiop/protocols/encoded/common/boundary_constraint.tcc @@ -32,7 +32,7 @@ std::shared_ptr> single_boundary_constraint::evaluat { /** Creates a subspace with the correct shift */ field_subset shifted_subspace(this->codeword_domain_.num_elements(), - this->codeword_domain_.offset() + shift); + this->codeword_domain_.shift() + shift); all_shifted_elems = shifted_subspace.all_elements(); } else if (this->codeword_domain_.type() == multiplicative_coset_type) { diff --git a/libiop/protocols/encoded/lincheck/basic_lincheck_aux.hpp b/libiop/protocols/encoded/lincheck/basic_lincheck_aux.hpp index 920b87e6..4d0c00d5 100644 --- a/libiop/protocols/encoded/lincheck/basic_lincheck_aux.hpp +++ b/libiop/protocols/encoded/lincheck/basic_lincheck_aux.hpp @@ -56,6 +56,9 @@ class multi_lincheck_virtual_oracle : public virtual_oracle { lagrange_polynomial p_alpha_; std::vector p_alpha_evals_; std::vector p_alpha_ABC_evals_; + vanishing_polynomial variable_domain_vanishing_polynomial_; + vanishing_polynomial constraint_domain_vanishing_polynomial_; + std::shared_ptr > lagrange_coefficients_cache_; public: multi_lincheck_virtual_oracle( @@ -80,4 +83,4 @@ class multi_lincheck_virtual_oracle : public virtual_oracle { #include "libiop/protocols/encoded/lincheck/basic_lincheck_aux.tcc" -#endif // LIBIOP_PROTOCOLS_ENCODED_LINCHECK_BASIC_LINCHECK_AUX_HPP_ +#endif // LIBIOP_PROTOCOLS_ENCODED_LINCHECK_BASIC_LINCHECK_AUX_HPP_ \ No newline at end of file diff --git a/libiop/protocols/encoded/lincheck/basic_lincheck_aux.tcc b/libiop/protocols/encoded/lincheck/basic_lincheck_aux.tcc index 023d8366..d1b436d1 100644 --- a/libiop/protocols/encoded/lincheck/basic_lincheck_aux.tcc +++ b/libiop/protocols/encoded/lincheck/basic_lincheck_aux.tcc @@ -36,10 +36,11 @@ void multi_lincheck_virtual_oracle::set_challenge(const FieldT &alpha, c enter_block("multi_lincheck compute random polynomial evaluations"); - /* Set alpha polynomial, and its evaluations */ + /* Set alpha polynomial, variable and constraint domain polynomials, and their evaluations */ this->p_alpha_ = lagrange_polynomial(alpha, this->constraint_domain_); this->p_alpha_evals_ = this->p_alpha_.evaluations_over_field_subset(this->constraint_domain_); - + this->variable_domain_vanishing_polynomial_ = vanishing_polynomial(this->variable_domain_); + this->constraint_domain_vanishing_polynomial_ = vanishing_polynomial(this->constraint_domain_); leave_block("multi_lincheck compute random polynomial evaluations"); /* Set p_alpha_ABC_evals */ @@ -90,10 +91,33 @@ std::shared_ptr> multi_lincheck_virtual_oracle::eval } /* p_{alpha}^1 in [BCRSVW18], but now using the lagrange polynomial from - * [TODO: cite Succinct Aurora] instead of powers of alpha. */ + * [BCGGRS19] instead of powers of alpha. */ /* Compute p_alpha_prime. */ - std::vector p_alpha_prime_over_codeword_domain = + std::vector p_alpha_prime_over_codeword_domain; + + + /* If |variable_domain| > |constraint_domain|, we multiply the Lagrange sampled + polynomial (p_alpha_prime) by Z_{variable_domain}*Z_{constraint_domain}^-1*/ + if (this->variable_domain_.num_elements() < this->constraint_domain_.num_elements()){ + p_alpha_prime_over_codeword_domain = this->p_alpha_.evaluations_over_field_subset(this->codeword_domain_); + }else{ + /* inverses of the evaluations of constraint domain polynomial */ + std::vector constraint_domain_vanishing_polynomial_inverses; + std::vector variable_domain_vanishing_polynomial_evaluations; + p_alpha_prime_over_codeword_domain = this->p_alpha_.evaluations_over_field_subset(this->codeword_domain_); + + variable_domain_vanishing_polynomial_evaluations = this->variable_domain_vanishing_polynomial_ + .evaluations_over_field_subset(this->codeword_domain_); + constraint_domain_vanishing_polynomial_inverses = batch_inverse(this->constraint_domain_vanishing_polynomial_ + .evaluations_over_field_subset(this->codeword_domain_)); + + for (int i = 0; i < variable_domain_vanishing_polynomial_evaluations.size(); i++){ + p_alpha_prime_over_codeword_domain[i] *= variable_domain_vanishing_polynomial_evaluations[i] + * constraint_domain_vanishing_polynomial_inverses[i]; + } + + } /* p_{alpha}^2 in [BCRSVW18] */ const std::vector p_alpha_ABC_over_codeword_domain = @@ -133,13 +157,25 @@ FieldT multi_lincheck_virtual_oracle::evaluation_at_point( const std::vector &constituent_oracle_evaluations) const { UNUSED(evaluation_position); + FieldT p_alpha_prime_X; if (constituent_oracle_evaluations.size() != this->matrices_.size() + 1) { throw std::invalid_argument("multi_lincheck uses more constituent oracles than what was provided."); } - FieldT p_alpha_prime_X = this->p_alpha_.evaluation_at_point(evaluation_point);; + /* If |variable_domain| > |constraint_domain|, we multiply the Lagrange sampled + polynomial by Z_{variable_domain}*Z_{constraint_domain}^-1. + This is done for a single point rather than across a domain.*/ + + if (this->variable_domain_.num_elements() > this->constraint_domain_.num_elements()) + FieldT p_alpha_prime_X = this->p_alpha_.evaluation_at_point(evaluation_point) * + this->variable_domain_vanishing_polynomial_.evaluation_at_point(evaluation_point) * + this->constraint_domain_vanishing_polynomial_.evaluation_at_point(evaluation_point).inverse(); + else + FieldT p_alpha_prime_X = this->p_alpha_.evaluation_at_point(evaluation_point); + FieldT p_alpha_ABC_X = this->p_alpha_ABC_.evaluation_at_point(evaluation_point); + if (this->use_lagrange_) { const std::vector lagrange_coefficients = @@ -159,4 +195,4 @@ FieldT multi_lincheck_virtual_oracle::evaluation_at_point( return (f_combined_Mz_x * p_alpha_prime_X - fz_X * p_alpha_ABC_X); } -} // libiop +} // libiop \ No newline at end of file diff --git a/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc b/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc index 32756f5d..b2420d00 100644 --- a/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc +++ b/libiop/protocols/encoded/sumcheck/sumcheck_aux.tcc @@ -19,7 +19,7 @@ std::vector constant_times_subspace_to_order_H_minus_1( subspace_element_powers(subspace, order_H); /** TODO: If we make the codeword domain non-affine in the future, * then we should just remove the zero element before batch inversion. */ - const bool codeword_domain_contains_zero = (subspace.offset() == FieldT::zero()); + const bool codeword_domain_contains_zero = (subspace.shift() == FieldT::zero()); const std::vector x_inv_times_constant = batch_inverse_and_mul( subspace.all_elements(), constant, codeword_domain_contains_zero); std::vector constant_times_x_to_H_minus_1( diff --git a/libiop/protocols/ldt/fri/fri_aux.hpp b/libiop/protocols/ldt/fri/fri_aux.hpp index 2cf366ac..ff5398b9 100644 --- a/libiop/protocols/ldt/fri/fri_aux.hpp +++ b/libiop/protocols/ldt/fri/fri_aux.hpp @@ -32,7 +32,7 @@ template FieldT evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i); @@ -40,7 +40,7 @@ template FieldT additive_evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i); diff --git a/libiop/protocols/ldt/fri/fri_aux.tcc b/libiop/protocols/ldt/fri/fri_aux.tcc index a2735344..8ba3b43f 100644 --- a/libiop/protocols/ldt/fri/fri_aux.tcc +++ b/libiop/protocols/ldt/fri/fri_aux.tcc @@ -51,7 +51,7 @@ std::shared_ptr> additive_evaluate_next_f_i_over_entire_doma * As a consequence, we only need to calculate the vp_coset(x) and vp_coset[1] once. * We then just adjust the vp_coset(x) by the constant term when processing each coset. * TODO: Investigate if we can lower the number of inversions by taking advantage of - * v[k] = unshifted v[k % coset_size] + offset + * v[k] = unshifted v[k % coset_size] + shift */ const std::vector coset_basis = f_i_domain.get_subset_of_order(coset_size).basis(); @@ -70,9 +70,9 @@ std::shared_ptr> additive_evaluate_next_f_i_over_entire_doma { /** By definition of cosets, * shifted vp = unshifted vp - unshifted_vp(shift) */ - const FieldT coset_offset = all_elements[coset_size * j]; + const FieldT coset_shift = all_elements[coset_size * j]; const FieldT shifted_vp_x = unshifted_vp_x - - unshifted_vp.evaluation_at_point(coset_offset); + unshifted_vp.evaluation_at_point(coset_shift); const bool x_in_domain = shifted_vp_x == FieldT::zero(); FieldT interpolation = FieldT::zero(); @@ -252,17 +252,17 @@ template FieldT evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &unshifted_coset, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i) { if (unshifted_coset.type() == affine_subspace_type) { return additive_evaluate_next_f_i_at_coset( - f_i_evals_over_coset, unshifted_coset, offset, unshifted_vp, x_i); + f_i_evals_over_coset, unshifted_coset, shift, unshifted_vp, x_i); } else if (unshifted_coset.type() == multiplicative_coset_type) { const FieldT g = unshifted_coset.generator(); return multiplicative_evaluate_next_f_i_at_coset( - f_i_evals_over_coset, g, offset, x_i); + f_i_evals_over_coset, g, shift, x_i); } throw std::invalid_argument("unshifted_coset is of unsupported domain type"); } @@ -271,7 +271,7 @@ template FieldT additive_evaluate_next_f_i_at_coset( const std::vector &f_i_evals_over_coset, const field_subset &localizer_domain, - const FieldT offset, + const FieldT shift, const localizer_polynomial &unshifted_vp, const FieldT x_i) { @@ -279,12 +279,12 @@ FieldT additive_evaluate_next_f_i_at_coset( * the subspace lagrange coefficient generation, but with the interpolation being returned. */ /* TODO: Cache unshifted_vp(x_i) and c */ const FieldT vp_x = unshifted_vp.evaluation_at_point(x_i) - - unshifted_vp.evaluation_at_point(offset); + unshifted_vp.evaluation_at_point(shift); const FieldT c = unshifted_vp.get_linearized_polynomial().coefficients()[1].inverse(); const bool x_in_domain = vp_x == FieldT::zero(); /* In binary fields addition and subtraction are the same operation */ const std::vector coset_elems = - all_subset_sums(localizer_domain.basis(), x_i + offset); + all_subset_sums(localizer_domain.basis(), x_i + shift); if (x_in_domain) { for (size_t k = 0; k < f_i_evals_over_coset.size(); k++) diff --git a/libiop/protocols/ldt/fri/fri_ldt.tcc b/libiop/protocols/ldt/fri/fri_ldt.tcc index c1580ae9..e311c83e 100644 --- a/libiop/protocols/ldt/fri/fri_ldt.tcc +++ b/libiop/protocols/ldt/fri/fri_ldt.tcc @@ -313,7 +313,7 @@ void FRI_protocol::compute_domains() { const std::size_t current_localization_parameter = this->params_.get_localization_parameters()[i]; - const FieldT last_subspace_offset = this->domains_[i].offset(); + const FieldT last_subspace_shift = this->domains_[i].shift(); const std::vector& last_subspace_basis = this->domains_[i].basis(); const std::vector localizer_subspace_basis(last_subspace_basis.begin(), @@ -321,7 +321,7 @@ void FRI_protocol::compute_domains() const affine_subspace localizer_subspace(localizer_subspace_basis, FieldT::zero()); const localizer_polynomial localizer_poly(localizer_subspace); - const FieldT next_subspace_offset = localizer_poly.evaluation_at_point(last_subspace_offset); + const FieldT next_subspace_shift = localizer_poly.evaluation_at_point(last_subspace_shift); std::vector next_subspace_basis(last_subspace_basis.begin() + current_localization_parameter, last_subspace_basis.end()); for (size_t i = 0; i < next_subspace_basis.size(); i++) @@ -330,7 +330,7 @@ void FRI_protocol::compute_domains() next_subspace_basis[i] = localizer_poly.evaluation_at_point(el); } - const affine_subspace next_subspace(next_subspace_basis, next_subspace_offset); + const affine_subspace next_subspace(next_subspace_basis, next_subspace_shift); this->domains_.emplace_back(field_subset(next_subspace)); this->localizer_domains_.emplace_back(field_subset(localizer_subspace)); @@ -614,13 +614,13 @@ bool FRI_protocol::predicate_for_query_set(const FRI_query_set &Q) /* Now compute interpolant of f_i|S_i evaluated at x_i (for use in next round). */ - const size_t offset_position = + const size_t shift_position = this->domains_[i].position_by_coset_indices(si_j, 0, current_coset_size); - const FieldT offset = this->domains_[i].element_by_index(offset_position); + const FieldT shift = this->domains_[i].element_by_index(shift_position); FieldT interpolation = evaluate_next_f_i_at_coset( fi_on_si_coset, this->localizer_domains_[i], - offset, + shift, this->localizer_polynomials_[i], x_i); last_interpolation = interpolation;