From b465f3f06a5d260ca70b9e4cb6bda1177e345a35 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Tue, 15 Oct 2024 11:47:45 +0000 Subject: [PATCH 1/6] Added relations --- .../translator_extra_relations.cpp | 3 + .../translator_extra_relations.hpp | 177 +++++++++++ .../translator_extra_relations_impl.hpp | 286 ++++++++++++++++++ .../translator_vm/translator_flavor.hpp | 6 +- 4 files changed, 470 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.cpp index 471fa8b77652..b0055bf11072 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.cpp @@ -1,9 +1,12 @@ +#include "barretenberg/relations/translator_vm/translator_extra_relations.hpp" #include "barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp" #include "barretenberg/translator_vm/translator_flavor.hpp" namespace bb { template class TranslatorOpcodeConstraintRelationImpl; template class TranslatorAccumulatorTransferRelationImpl; +template class TranslatorZeroConstraintsRelationImpl; DEFINE_ZK_SUMCHECK_RELATION_CLASS(TranslatorOpcodeConstraintRelationImpl, TranslatorFlavor); DEFINE_ZK_SUMCHECK_RELATION_CLASS(TranslatorAccumulatorTransferRelationImpl, TranslatorFlavor); +DEFINE_ZK_SUMCHECK_RELATION_CLASS(TranslatorZeroConstraintsRelationImpl, TranslatorFlavor); } // namespace bb \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp index c30ed383a4c2..244b8f610927 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp @@ -122,9 +122,186 @@ polynomials, const FF& scaling_factor); }; +template class TranslatorZeroConstraintsRelationImpl { + public: + using FF = FF_; + + // 1 + polynomial degree of this relation + static constexpr size_t RELATION_LENGTH = 3; // degree((some lagrange)(A)) = 2 + static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ + 3, // p_x_low_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // p_x_low_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // p_x_low_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // p_x_low_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // p_x_low_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_4 is zero outside of the minicircuit + 3, // relation_wide_limbs_range_constraint_0 is zero outside of the minicircuit + 3, // relation_wide_limbs_range_constraint_1 is zero outside of the minicircuit + 3, // relation_wide_limbs_range_constraint_2 is zero outside of the minicircuit + 3, // relation_wide_limbs_range_constraint_3 is zero outside of the minicircuit + 3, // p_x_low_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // p_x_high_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // p_y_low_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // p_y_high_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // z_low_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // z_high_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // accumulator_low_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // accumulator_high_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // quotient_low_limbs_range_constraint_tail is zero outside of the minicircuit + 3, // quotient_high_limbs_range_constraint_tail is zero outside of the minicircuit + + }; + /** + * @brief For ZK-Flavors: Upper bound on the degrees of subrelations considered as polynomials only in witness +polynomials, + * i.e. all selectors and public polynomials are treated as constants. The subrelation witness degree does not + * exceed the subrelation partial degree given by SUBRELATION_PARTIAL_LENGTH - 1. + */ + static constexpr std::array SUBRELATION_WITNESS_DEGREES{ + 2, // p_x_low_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // p_x_low_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // p_x_low_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // p_x_low_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // p_x_low_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_4 is zero outside of the minicircuit + 2, // relation_wide_limbs_range_constraint_0 is zero outside of the minicircuit + 2, // relation_wide_limbs_range_constraint_1 is zero outside of the minicircuit + 2, // relation_wide_limbs_range_constraint_2 is zero outside of the minicircuit + 2, // relation_wide_limbs_range_constraint_3 is zero outside of the minicircuit + 2, // p_x_low_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // p_x_high_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // p_y_low_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // p_y_high_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // z_low_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // z_high_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // accumulator_low_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // accumulator_high_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // quotient_low_limbs_range_constraint_tail is zero outside of the minicircuit + 2, // quotient_high_limbs_range_constraint_tail is zero outside of the minicircuit + + }; + /** + * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero + * + * @details This has a negligible chance of failing in sumcheck (not in the first round) because effectively + * transfrom original coefficients into a random linear combination. But checking each individually is noticeably + * slower. + * + */ + template inline static bool skip(const AllEntities& in) + { + static constexpr auto minus_one = -FF(1); + return (in.lagrange_even_in_minicircuit + in.lagrange_second_to_last_in_minicircuit + minus_one).is_zero(); + } + /** + * @brief Relation enforcing all the range-constraint polynomials to be zero after the minicircuit + * @details This relation ensures that while we are out of the minicircuit the range constraint polynomials are zero + * + * @param evals transformed to `evals + C(in(X)...)*scaling_factor` + * @param in an std::array containing the fully extended Univariate edges. + * @param parameters contains beta, gamma, and public_input_delta, .... + * @param scaling_factor optional term to scale the evaluation before adding to evals. + */ + template + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor); +}; + template using TranslatorOpcodeConstraintRelation = Relation>; template using TranslatorAccumulatorTransferRelation = Relation>; +template using TranslatorZeroConstraintsRelation = Relation>; + } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp index 63d6522238ea..db4e90a641c4 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp @@ -145,4 +145,290 @@ void TranslatorAccumulatorTransferRelationImpl::accumulate(ContainerOverSubr tmp_12 *= scaling_factor; std::get<11>(accumulators) += tmp_12; }; + +/** + * @brief Relation enforcing all the range-constraint polynomials to be zero after the minicircuit + * @details This relation ensures that while we are out of the minicircuit the range constraint polynomials are zero + * + * @param evals transformed to `evals + C(in(X)...)*scaling_factor` + * @param in an std::array containing the fully extended Univariate edges. + * @param parameters contains beta, gamma, and public_input_delta, .... + * @param scaling_factor optional term to scale the evaluation before adding to evals. + */ +template +template +void TranslatorZeroConstraintsRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) +{ + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + // Minus one + static auto minus_one = -FF(1); + + auto lagrange_even_in_minicircuit = View(in.lagrange_even_in_minicircuit); + auto lagrange_odd_in_minicircuit = View(in.lagrange_odd_in_minicircuit); + + auto p_x_low_limbs_range_constraint_0 = View(in.p_x_low_limbs_range_constraint_0); + auto p_x_low_limbs_range_constraint_1 = View(in.p_x_low_limbs_range_constraint_1); + auto p_x_low_limbs_range_constraint_2 = View(in.p_x_low_limbs_range_constraint_2); + auto p_x_low_limbs_range_constraint_3 = View(in.p_x_low_limbs_range_constraint_3); + auto p_x_low_limbs_range_constraint_4 = View(in.p_x_low_limbs_range_constraint_4); + auto p_x_high_limbs_range_constraint_0 = View(in.p_x_high_limbs_range_constraint_0); + auto p_x_high_limbs_range_constraint_1 = View(in.p_x_high_limbs_range_constraint_1); + auto p_x_high_limbs_range_constraint_2 = View(in.p_x_high_limbs_range_constraint_2); + auto p_x_high_limbs_range_constraint_3 = View(in.p_x_high_limbs_range_constraint_3); + auto p_x_high_limbs_range_constraint_4 = View(in.p_x_high_limbs_range_constraint_4); + auto p_y_low_limbs_range_constraint_0 = View(in.p_y_low_limbs_range_constraint_0); + auto p_y_low_limbs_range_constraint_1 = View(in.p_y_low_limbs_range_constraint_1); + auto p_y_low_limbs_range_constraint_2 = View(in.p_y_low_limbs_range_constraint_2); + auto p_y_low_limbs_range_constraint_3 = View(in.p_y_low_limbs_range_constraint_3); + auto p_y_low_limbs_range_constraint_4 = View(in.p_y_low_limbs_range_constraint_4); + auto p_y_high_limbs_range_constraint_0 = View(in.p_y_high_limbs_range_constraint_0); + auto p_y_high_limbs_range_constraint_1 = View(in.p_y_high_limbs_range_constraint_1); + auto p_y_high_limbs_range_constraint_2 = View(in.p_y_high_limbs_range_constraint_2); + auto p_y_high_limbs_range_constraint_3 = View(in.p_y_high_limbs_range_constraint_3); + auto p_y_high_limbs_range_constraint_4 = View(in.p_y_high_limbs_range_constraint_4); + auto z_low_limbs_range_constraint_0 = View(in.z_low_limbs_range_constraint_0); + auto z_low_limbs_range_constraint_1 = View(in.z_low_limbs_range_constraint_1); + auto z_low_limbs_range_constraint_2 = View(in.z_low_limbs_range_constraint_2); + auto z_low_limbs_range_constraint_3 = View(in.z_low_limbs_range_constraint_3); + auto z_low_limbs_range_constraint_4 = View(in.z_low_limbs_range_constraint_4); + auto z_high_limbs_range_constraint_0 = View(in.z_high_limbs_range_constraint_0); + auto z_high_limbs_range_constraint_1 = View(in.z_high_limbs_range_constraint_1); + auto z_high_limbs_range_constraint_2 = View(in.z_high_limbs_range_constraint_2); + auto z_high_limbs_range_constraint_3 = View(in.z_high_limbs_range_constraint_3); + auto z_high_limbs_range_constraint_4 = View(in.z_high_limbs_range_constraint_4); + auto accumulator_low_limbs_range_constraint_0 = View(in.accumulator_low_limbs_range_constraint_0); + auto accumulator_low_limbs_range_constraint_1 = View(in.accumulator_low_limbs_range_constraint_1); + auto accumulator_low_limbs_range_constraint_2 = View(in.accumulator_low_limbs_range_constraint_2); + auto accumulator_low_limbs_range_constraint_3 = View(in.accumulator_low_limbs_range_constraint_3); + auto accumulator_low_limbs_range_constraint_4 = View(in.accumulator_low_limbs_range_constraint_4); + auto accumulator_high_limbs_range_constraint_0 = View(in.accumulator_high_limbs_range_constraint_0); + auto accumulator_high_limbs_range_constraint_1 = View(in.accumulator_high_limbs_range_constraint_1); + auto accumulator_high_limbs_range_constraint_2 = View(in.accumulator_high_limbs_range_constraint_2); + auto accumulator_high_limbs_range_constraint_3 = View(in.accumulator_high_limbs_range_constraint_3); + auto accumulator_high_limbs_range_constraint_4 = View(in.accumulator_high_limbs_range_constraint_4); + auto quotient_low_limbs_range_constraint_0 = View(in.quotient_low_limbs_range_constraint_0); + auto quotient_low_limbs_range_constraint_1 = View(in.quotient_low_limbs_range_constraint_1); + auto quotient_low_limbs_range_constraint_2 = View(in.quotient_low_limbs_range_constraint_2); + auto quotient_low_limbs_range_constraint_3 = View(in.quotient_low_limbs_range_constraint_3); + auto quotient_low_limbs_range_constraint_4 = View(in.quotient_low_limbs_range_constraint_4); + auto quotient_high_limbs_range_constraint_0 = View(in.quotient_high_limbs_range_constraint_0); + auto quotient_high_limbs_range_constraint_1 = View(in.quotient_high_limbs_range_constraint_1); + auto quotient_high_limbs_range_constraint_2 = View(in.quotient_high_limbs_range_constraint_2); + auto quotient_high_limbs_range_constraint_3 = View(in.quotient_high_limbs_range_constraint_3); + auto quotient_high_limbs_range_constraint_4 = View(in.quotient_high_limbs_range_constraint_4); + auto relation_wide_limbs_range_constraint_0 = View(in.relation_wide_limbs_range_constraint_0); + auto relation_wide_limbs_range_constraint_1 = View(in.relation_wide_limbs_range_constraint_1); + auto relation_wide_limbs_range_constraint_2 = View(in.relation_wide_limbs_range_constraint_2); + auto relation_wide_limbs_range_constraint_3 = View(in.relation_wide_limbs_range_constraint_3); + auto p_x_low_limbs_range_constraint_tail = View(in.p_x_low_limbs_range_constraint_tail); + auto p_x_high_limbs_range_constraint_tail = View(in.p_x_high_limbs_range_constraint_tail); + auto p_y_low_limbs_range_constraint_tail = View(in.p_y_low_limbs_range_constraint_tail); + auto p_y_high_limbs_range_constraint_tail = View(in.p_y_high_limbs_range_constraint_tail); + auto z_low_limbs_range_constraint_tail = View(in.z_low_limbs_range_constraint_tail); + auto z_high_limbs_range_constraint_tail = View(in.z_high_limbs_range_constraint_tail); + auto accumulator_low_limbs_range_constraint_tail = View(in.accumulator_low_limbs_range_constraint_tail); + auto accumulator_high_limbs_range_constraint_tail = View(in.accumulator_high_limbs_range_constraint_tail); + auto quotient_low_limbs_range_constraint_tail = View(in.quotient_low_limbs_range_constraint_tail); + auto quotient_high_limbs_range_constraint_tail = View(in.quotient_high_limbs_range_constraint_tail); + + auto not_in_minicircuit_by_scaling = + (lagrange_odd_in_minicircuit + lagrange_even_in_minicircuit + minus_one) * scaling_factor; + + // Contribution 0, ensure p_x_low_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<0>(accumulators) += p_x_low_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 1, ensure p_x_low_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<1>(accumulators) += p_x_low_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 2, ensure p_x_low_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<2>(accumulators) += p_x_low_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 3, ensure p_x_low_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<3>(accumulators) += p_x_low_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 4, ensure p_x_low_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<4>(accumulators) += p_x_low_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 5, ensure p_x_high_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<5>(accumulators) += p_x_high_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 6, ensure p_x_high_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<6>(accumulators) += p_x_high_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 7, ensure p_x_high_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<7>(accumulators) += p_x_high_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 8, ensure p_x_high_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<8>(accumulators) += p_x_high_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 9, ensure p_x_high_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<9>(accumulators) += p_x_high_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 10, ensure p_y_low_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<10>(accumulators) += p_y_low_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 11, ensure p_y_low_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<11>(accumulators) += p_y_low_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 12, ensure p_y_low_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<12>(accumulators) += p_y_low_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 13, ensure p_y_low_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<13>(accumulators) += p_y_low_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 14, ensure p_y_low_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<14>(accumulators) += p_y_low_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 15, ensure p_y_high_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<15>(accumulators) += p_y_high_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 16, ensure p_y_high_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<16>(accumulators) += p_y_high_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 17, ensure p_y_high_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<17>(accumulators) += p_y_high_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 18, ensure p_y_high_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<18>(accumulators) += p_y_high_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 19, ensure p_y_high_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<19>(accumulators) += p_y_high_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 20, ensure z_low_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<20>(accumulators) += z_low_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 21, ensure z_low_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<21>(accumulators) += z_low_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 22, ensure z_low_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<22>(accumulators) += z_low_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 23, ensure z_low_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<23>(accumulators) += z_low_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 24, ensure z_low_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<24>(accumulators) += z_low_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 25, ensure z_high_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<25>(accumulators) += z_high_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 26, ensure z_high_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<26>(accumulators) += z_high_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 27, ensure z_high_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<27>(accumulators) += z_high_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 28, ensure z_high_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<28>(accumulators) += z_high_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 29, ensure z_high_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<29>(accumulators) += z_high_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 30, ensure accumulator_low_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<30>(accumulators) += accumulator_low_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 31, ensure accumulator_low_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<31>(accumulators) += accumulator_low_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 32, ensure accumulator_low_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<32>(accumulators) += accumulator_low_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 33, ensure accumulator_low_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<33>(accumulators) += accumulator_low_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 34, ensure accumulator_low_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<34>(accumulators) += accumulator_low_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 35, ensure accumulator_high_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<35>(accumulators) += accumulator_high_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 36, ensure accumulator_high_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<36>(accumulators) += accumulator_high_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 37, ensure accumulator_high_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<37>(accumulators) += accumulator_high_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 38, ensure accumulator_high_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<38>(accumulators) += accumulator_high_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 39, ensure accumulator_high_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<39>(accumulators) += accumulator_high_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 40, ensure quotient_low_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<40>(accumulators) += quotient_low_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 41, ensure quotient_low_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<41>(accumulators) += quotient_low_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 42, ensure quotient_low_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<42>(accumulators) += quotient_low_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 43, ensure quotient_low_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<43>(accumulators) += quotient_low_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 44, ensure quotient_low_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<44>(accumulators) += quotient_low_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 45, ensure quotient_high_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<45>(accumulators) += quotient_high_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 46, ensure quotient_high_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<46>(accumulators) += quotient_high_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 47, ensure quotient_high_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<47>(accumulators) += quotient_high_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 48, ensure quotient_high_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<48>(accumulators) += quotient_high_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 49, ensure quotient_high_limbs_range_constraint_4 is 0 outside of minicircuit + std::get<49>(accumulators) += quotient_high_limbs_range_constraint_4 * not_in_minicircuit_by_scaling; + + // Contribution 50, ensure relation_wide_limbs_range_constraint_0 is 0 outside of minicircuit + std::get<50>(accumulators) += relation_wide_limbs_range_constraint_0 * not_in_minicircuit_by_scaling; + + // Contribution 51, ensure relation_wide_limbs_range_constraint_1 is 0 outside of minicircuit + std::get<51>(accumulators) += relation_wide_limbs_range_constraint_1 * not_in_minicircuit_by_scaling; + + // Contribution 52, ensure relation_wide_limbs_range_constraint_2 is 0 outside of minicircuit + std::get<52>(accumulators) += relation_wide_limbs_range_constraint_2 * not_in_minicircuit_by_scaling; + + // Contribution 53, ensure relation_wide_limbs_range_constraint_3 is 0 outside of minicircuit + std::get<53>(accumulators) += relation_wide_limbs_range_constraint_3 * not_in_minicircuit_by_scaling; + + // Contribution 54, ensure p_x_low_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<54>(accumulators) += p_x_low_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 55, ensure p_x_high_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<55>(accumulators) += p_x_high_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 56, ensure p_y_low_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<56>(accumulators) += p_y_low_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 57, ensure p_y_high_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<57>(accumulators) += p_y_high_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 58, ensure z_low_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<58>(accumulators) += z_low_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 59, ensure z_high_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<59>(accumulators) += z_high_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 60, ensure accumulator_low_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<60>(accumulators) += accumulator_low_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 61, ensure accumulator_high_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<61>(accumulators) += accumulator_high_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 62, ensure quotient_low_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<62>(accumulators) += quotient_low_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; + + // Contribution 63, ensure quotient_high_limbs_range_constraint_tail is 0 outside of minicircuit + std::get<63>(accumulators) += quotient_high_limbs_range_constraint_tail * not_in_minicircuit_by_scaling; +}; } // namespace bb diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp index 5cb3f6a7003d..0a3d495b8900 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/translator_flavor.hpp @@ -90,7 +90,8 @@ class TranslatorFlavor { TranslatorOpcodeConstraintRelation, TranslatorAccumulatorTransferRelation, TranslatorDecompositionRelation, - TranslatorNonNativeFieldRelation>; + TranslatorNonNativeFieldRelation, + TranslatorZeroConstraintsRelation>; using Relations = Relations_; static constexpr size_t MAX_PARTIAL_RELATION_LENGTH = compute_max_partial_relation_length(); @@ -109,7 +110,8 @@ class TranslatorFlavor { typename TranslatorOpcodeConstraintRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations, typename TranslatorAccumulatorTransferRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations, typename TranslatorDecompositionRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations, - typename TranslatorNonNativeFieldRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations>; + typename TranslatorNonNativeFieldRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations, + typename TranslatorZeroConstraintsRelation::ZKSumcheckTupleOfUnivariatesOverSubrelations>; using TupleOfArraysOfValues = decltype(create_tuple_of_arrays_of_values()); /** From e14487a3d3fbafaa77788de3565531e3a2760c63 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 16 Oct 2024 10:03:59 +0000 Subject: [PATCH 2/6] Added correctness tests --- .../relation_correctness.test.cpp | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp index 2b9322ced97f..9b026d3c841e 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp @@ -1,8 +1,10 @@ +#include "barretenberg/common/thread.hpp" #include "barretenberg/honk/proof_system/permutation_library.hpp" #include "barretenberg/plonk_honk_shared/library/grand_product_library.hpp" #include "barretenberg/translator_vm/translator_flavor.hpp" #include +#include using namespace bb; /** @@ -24,6 +26,9 @@ template void check_relation(auto circuit_s // Evaluate each constraint in the relation and check that each is satisfied Relation::accumulate(result, polynomials.get_row(i), params, 1); for (auto& element : result) { + if (element != 0) { + info(i); + } ASSERT_EQ(element, 0); } } @@ -311,8 +316,9 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) } // Fill in lagrange even polynomial - for (size_t i = 2; i < mini_circuit_size; i += 2) { - prover_polynomials.lagrange_even_in_minicircuit.at(i) = 1; + for (size_t i = 1; i < mini_circuit_size - 1; i += 2) { + prover_polynomials.lagrange_odd_in_minicircuit.at(i) = 1; + prover_polynomials.lagrange_even_in_minicircuit.at(i + 1) = 1; } constexpr size_t NUMBER_OF_POSSIBLE_OPCODES = 6; constexpr std::array possible_opcode_values = { 0, 1, 2, 3, 4, 8 }; @@ -323,6 +329,23 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) possible_opcode_values[static_cast(engine.get_random_uint8() % NUMBER_OF_POSSIBLE_OPCODES)]; } + std::unordered_set range_constraint_polynomial_ids; + for (auto& concatenation_group : prover_polynomial_ids.get_groups_to_be_concatenated()) { + for (auto& id : concatenation_group) { + range_constraint_polynomial_ids.insert(id); + } + } + + // Assign random values to the mini-circuit part of the range constraint polynomials + + for (const auto& range_constraint_polynomial_id : range_constraint_polynomial_ids) { + parallel_for_range(mini_circuit_size - 2, [&](size_t start, size_t end) { + // We want to iterate from 1 to mini_circuit_size - 2 (inclusive) + for (size_t i = start + 1; i < end + 1; i++) { + polynomial_container[range_constraint_polynomial_id].at(i) = fr::random_element(); + } + }); + } // Initialize used lagrange polynomials prover_polynomials.lagrange_second.at(1) = 1; prover_polynomials.lagrange_second_to_last_in_minicircuit.at(mini_circuit_size - 2) = 1; @@ -352,6 +375,9 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) // Check that Accumulator Transfer relation is satisfied across each row of the prover polynomials check_relation>(circuit_size, prover_polynomials, params); + + // Check that Zero Constraint relation is satisfied across each row of the prover polynomials + check_relation>(circuit_size, prover_polynomials, params); } /** * @brief Test the correctness of TranslatorFlavor's Decomposition Relation From 25a057c2231113d43710905b614e0b121202b9a2 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 16 Oct 2024 10:45:27 +0000 Subject: [PATCH 3/6] Consistency tests --- .../translator_relation_consistency.test.cpp | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_relation_consistency.test.cpp index 4a7b8cdcde9b..ec94e7cfc07d 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_relation_consistency.test.cpp @@ -11,6 +11,7 @@ * satisfied in general by random inputs) only that the two implementations are equivalent. * */ +#include "barretenberg/relations/translator_vm/translator_extra_relations.hpp" #include "barretenberg/translator_vm/translator_flavor.hpp" #include @@ -792,6 +793,230 @@ TEST_F(TranslatorRelationConsistency, AccumulatorTransferRelation) run_test(/*random_inputs=*/true); }; +TEST_F(TranslatorRelationConsistency, ZeroConstraintsRelation) +{ + const auto run_test = [](bool random_inputs) { + using Relation = TranslatorZeroConstraintsRelation; + using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; + + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); + + // Get all the wires + const auto& p_x_low_limbs_range_constraint_0 = input_elements.p_x_low_limbs_range_constraint_0; + const auto& p_x_low_limbs_range_constraint_1 = input_elements.p_x_low_limbs_range_constraint_1; + const auto& p_x_low_limbs_range_constraint_2 = input_elements.p_x_low_limbs_range_constraint_2; + const auto& p_x_low_limbs_range_constraint_3 = input_elements.p_x_low_limbs_range_constraint_3; + const auto& p_x_low_limbs_range_constraint_4 = input_elements.p_x_low_limbs_range_constraint_4; + const auto& p_x_low_limbs_range_constraint_tail = input_elements.p_x_low_limbs_range_constraint_tail; + const auto& p_x_high_limbs_range_constraint_0 = input_elements.p_x_high_limbs_range_constraint_0; + const auto& p_x_high_limbs_range_constraint_1 = input_elements.p_x_high_limbs_range_constraint_1; + const auto& p_x_high_limbs_range_constraint_2 = input_elements.p_x_high_limbs_range_constraint_2; + const auto& p_x_high_limbs_range_constraint_3 = input_elements.p_x_high_limbs_range_constraint_3; + const auto& p_x_high_limbs_range_constraint_4 = input_elements.p_x_high_limbs_range_constraint_4; + const auto& p_x_high_limbs_range_constraint_tail = input_elements.p_x_high_limbs_range_constraint_tail; + const auto& p_y_low_limbs_range_constraint_0 = input_elements.p_y_low_limbs_range_constraint_0; + const auto& p_y_low_limbs_range_constraint_1 = input_elements.p_y_low_limbs_range_constraint_1; + const auto& p_y_low_limbs_range_constraint_2 = input_elements.p_y_low_limbs_range_constraint_2; + const auto& p_y_low_limbs_range_constraint_3 = input_elements.p_y_low_limbs_range_constraint_3; + const auto& p_y_low_limbs_range_constraint_4 = input_elements.p_y_low_limbs_range_constraint_4; + const auto& p_y_low_limbs_range_constraint_tail = input_elements.p_y_low_limbs_range_constraint_tail; + const auto& p_y_high_limbs_range_constraint_0 = input_elements.p_y_high_limbs_range_constraint_0; + const auto& p_y_high_limbs_range_constraint_1 = input_elements.p_y_high_limbs_range_constraint_1; + const auto& p_y_high_limbs_range_constraint_2 = input_elements.p_y_high_limbs_range_constraint_2; + const auto& p_y_high_limbs_range_constraint_3 = input_elements.p_y_high_limbs_range_constraint_3; + const auto& p_y_high_limbs_range_constraint_4 = input_elements.p_y_high_limbs_range_constraint_4; + const auto& p_y_high_limbs_range_constraint_tail = input_elements.p_y_high_limbs_range_constraint_tail; + const auto& z_low_limbs_range_constraint_0 = input_elements.z_low_limbs_range_constraint_0; + const auto& z_low_limbs_range_constraint_1 = input_elements.z_low_limbs_range_constraint_1; + const auto& z_low_limbs_range_constraint_2 = input_elements.z_low_limbs_range_constraint_2; + const auto& z_low_limbs_range_constraint_3 = input_elements.z_low_limbs_range_constraint_3; + const auto& z_low_limbs_range_constraint_4 = input_elements.z_low_limbs_range_constraint_4; + const auto& z_low_limbs_range_constraint_tail = input_elements.z_low_limbs_range_constraint_tail; + const auto& z_high_limbs_range_constraint_0 = input_elements.z_high_limbs_range_constraint_0; + const auto& z_high_limbs_range_constraint_1 = input_elements.z_high_limbs_range_constraint_1; + const auto& z_high_limbs_range_constraint_2 = input_elements.z_high_limbs_range_constraint_2; + const auto& z_high_limbs_range_constraint_3 = input_elements.z_high_limbs_range_constraint_3; + const auto& z_high_limbs_range_constraint_4 = input_elements.z_high_limbs_range_constraint_4; + const auto& z_high_limbs_range_constraint_tail = input_elements.z_high_limbs_range_constraint_tail; + const auto& accumulator_low_limbs_range_constraint_0 = input_elements.accumulator_low_limbs_range_constraint_0; + const auto& accumulator_low_limbs_range_constraint_1 = input_elements.accumulator_low_limbs_range_constraint_1; + const auto& accumulator_low_limbs_range_constraint_2 = input_elements.accumulator_low_limbs_range_constraint_2; + const auto& accumulator_low_limbs_range_constraint_3 = input_elements.accumulator_low_limbs_range_constraint_3; + const auto& accumulator_low_limbs_range_constraint_4 = input_elements.accumulator_low_limbs_range_constraint_4; + const auto& accumulator_low_limbs_range_constraint_tail = + input_elements.accumulator_low_limbs_range_constraint_tail; + const auto& accumulator_high_limbs_range_constraint_0 = + input_elements.accumulator_high_limbs_range_constraint_0; + const auto& accumulator_high_limbs_range_constraint_1 = + input_elements.accumulator_high_limbs_range_constraint_1; + const auto& accumulator_high_limbs_range_constraint_2 = + input_elements.accumulator_high_limbs_range_constraint_2; + const auto& accumulator_high_limbs_range_constraint_3 = + input_elements.accumulator_high_limbs_range_constraint_3; + const auto& accumulator_high_limbs_range_constraint_4 = + input_elements.accumulator_high_limbs_range_constraint_4; + const auto& accumulator_high_limbs_range_constraint_tail = + input_elements.accumulator_high_limbs_range_constraint_tail; + const auto& quotient_low_limbs_range_constraint_0 = input_elements.quotient_low_limbs_range_constraint_0; + const auto& quotient_low_limbs_range_constraint_1 = input_elements.quotient_low_limbs_range_constraint_1; + const auto& quotient_low_limbs_range_constraint_2 = input_elements.quotient_low_limbs_range_constraint_2; + const auto& quotient_low_limbs_range_constraint_3 = input_elements.quotient_low_limbs_range_constraint_3; + const auto& quotient_low_limbs_range_constraint_4 = input_elements.quotient_low_limbs_range_constraint_4; + const auto& quotient_low_limbs_range_constraint_tail = input_elements.quotient_low_limbs_range_constraint_tail; + const auto& quotient_high_limbs_range_constraint_0 = input_elements.quotient_high_limbs_range_constraint_0; + const auto& quotient_high_limbs_range_constraint_1 = input_elements.quotient_high_limbs_range_constraint_1; + const auto& quotient_high_limbs_range_constraint_2 = input_elements.quotient_high_limbs_range_constraint_2; + const auto& quotient_high_limbs_range_constraint_3 = input_elements.quotient_high_limbs_range_constraint_3; + const auto& quotient_high_limbs_range_constraint_4 = input_elements.quotient_high_limbs_range_constraint_4; + const auto& quotient_high_limbs_range_constraint_tail = + input_elements.quotient_high_limbs_range_constraint_tail; + const auto& relation_wide_limbs_range_constraint_0 = input_elements.relation_wide_limbs_range_constraint_0; + const auto& relation_wide_limbs_range_constraint_1 = input_elements.relation_wide_limbs_range_constraint_1; + const auto& relation_wide_limbs_range_constraint_2 = input_elements.relation_wide_limbs_range_constraint_2; + const auto& relation_wide_limbs_range_constraint_3 = input_elements.relation_wide_limbs_range_constraint_3; + + const auto& lagrange_odd_in_minicircuit = input_elements.lagrange_odd_in_minicircuit; + const auto& lagrange_even_in_minicircuit = input_elements.lagrange_even_in_minicircuit; + + RelationValues expected_values; + + const auto parameters = RelationParameters::get_random(); + + expected_values[0] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_0; + expected_values[1] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_1; + expected_values[2] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_2; + expected_values[3] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_3; + expected_values[4] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_4; + expected_values[5] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_0; + expected_values[6] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_1; + expected_values[7] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_2; + expected_values[8] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_3; + expected_values[9] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_4; + expected_values[10] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_0; + expected_values[11] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_1; + expected_values[12] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_2; + expected_values[13] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_3; + expected_values[14] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_4; + expected_values[15] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_0; + expected_values[16] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_1; + expected_values[17] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_2; + expected_values[18] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_3; + expected_values[19] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_4; + expected_values[20] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_0; + expected_values[21] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_1; + expected_values[22] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_2; + expected_values[23] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_3; + expected_values[24] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_4; + expected_values[25] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_0; + expected_values[26] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_1; + expected_values[27] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_2; + expected_values[28] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_3; + expected_values[29] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_4; + expected_values[30] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * accumulator_low_limbs_range_constraint_0; + expected_values[31] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * accumulator_low_limbs_range_constraint_1; + expected_values[32] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * accumulator_low_limbs_range_constraint_2; + expected_values[33] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * accumulator_low_limbs_range_constraint_3; + expected_values[34] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * accumulator_low_limbs_range_constraint_4; + expected_values[35] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_0; + expected_values[36] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_1; + expected_values[37] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_2; + expected_values[38] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_3; + expected_values[39] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_4; + expected_values[40] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_0; + expected_values[41] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_1; + expected_values[42] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_2; + expected_values[43] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_3; + expected_values[44] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_4; + expected_values[45] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_high_limbs_range_constraint_0; + expected_values[46] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_high_limbs_range_constraint_1; + expected_values[47] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_high_limbs_range_constraint_2; + expected_values[48] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_high_limbs_range_constraint_3; + expected_values[49] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_high_limbs_range_constraint_4; + expected_values[50] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * relation_wide_limbs_range_constraint_0; + expected_values[51] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * relation_wide_limbs_range_constraint_1; + expected_values[52] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * relation_wide_limbs_range_constraint_2; + expected_values[53] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * relation_wide_limbs_range_constraint_3; + expected_values[54] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_low_limbs_range_constraint_tail; + expected_values[55] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_x_high_limbs_range_constraint_tail; + expected_values[56] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_low_limbs_range_constraint_tail; + expected_values[57] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * p_y_high_limbs_range_constraint_tail; + expected_values[58] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_low_limbs_range_constraint_tail; + expected_values[59] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * z_high_limbs_range_constraint_tail; + expected_values[60] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_low_limbs_range_constraint_tail; + expected_values[61] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + accumulator_high_limbs_range_constraint_tail; + expected_values[62] = + (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * quotient_low_limbs_range_constraint_tail; + expected_values[63] = (lagrange_even_in_minicircuit + lagrange_odd_in_minicircuit - 1) * + quotient_high_limbs_range_constraint_tail; + + validate_relation_execution(expected_values, input_elements, parameters); + }; + run_test(/*random_inputs=*/false); + run_test(/*random_inputs=*/true); +}; + TEST_F(TranslatorRelationConsistency, NonNativeFieldRelation) { const auto run_test = [](bool random_inputs) { From 262d50230078c70692f8c3dc48f432c37d0529ee Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 30 Oct 2024 17:56:24 +0000 Subject: [PATCH 4/6] fix --- .../relations/translator_vm/translator_extra_relations.hpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp index 244b8f610927..2fdcaae4452e 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp @@ -128,6 +128,8 @@ template class TranslatorZeroConstraintsRelationImpl { // 1 + polynomial degree of this relation static constexpr size_t RELATION_LENGTH = 3; // degree((some lagrange)(A)) = 2 + + static constexpr size_t ZK_RELATION_LENGTH = 5; static constexpr std::array SUBRELATION_PARTIAL_LENGTHS{ 3, // p_x_low_limbs_range_constraint_0 is zero outside of the minicircuit 3, // p_x_low_limbs_range_constraint_1 is zero outside of the minicircuit From 12a155e9161e2cba0d1d1afedf5458e11c375675 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Wed, 30 Oct 2024 18:16:38 +0000 Subject: [PATCH 5/6] rephrase --- .../relations/translator_vm/translator_extra_relations.hpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp index 2fdcaae4452e..d114a4cabd85 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.hpp @@ -271,11 +271,8 @@ polynomials, }; /** - * @brief Returns true if the contribution from all subrelations for the provided inputs is identically zero + * @brief Might return true if the contribution from all subrelations for the provided inputs is identically zero * - * @details This has a negligible chance of failing in sumcheck (not in the first round) because effectively - * transfrom original coefficients into a random linear combination. But checking each individually is noticeably - * slower. * */ template inline static bool skip(const AllEntities& in) From 6e49ca546874eb2974d32afb7cdff5ed56bcb100 Mon Sep 17 00:00:00 2001 From: Rumata888 Date: Thu, 31 Oct 2024 12:34:55 +0000 Subject: [PATCH 6/6] fix --- .../translator_vm/translator_extra_relations_impl.hpp | 1 + .../barretenberg/translator_vm/relation_correctness.test.cpp | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp index db4e90a641c4..cddcb3af380a 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations_impl.hpp @@ -236,6 +236,7 @@ void TranslatorZeroConstraintsRelationImpl::accumulate(ContainerOverSubrelat auto quotient_low_limbs_range_constraint_tail = View(in.quotient_low_limbs_range_constraint_tail); auto quotient_high_limbs_range_constraint_tail = View(in.quotient_high_limbs_range_constraint_tail); + // 0 in the minicircuit, -1 outside auto not_in_minicircuit_by_scaling = (lagrange_odd_in_minicircuit + lagrange_even_in_minicircuit + minus_one) * scaling_factor; diff --git a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp index 9b026d3c841e..ca13448d383e 100644 --- a/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/translator_vm/relation_correctness.test.cpp @@ -26,9 +26,6 @@ template void check_relation(auto circuit_s // Evaluate each constraint in the relation and check that each is satisfied Relation::accumulate(result, polynomials.get_row(i), params, 1); for (auto& element : result) { - if (element != 0) { - info(i); - } ASSERT_EQ(element, 0); } } @@ -337,7 +334,6 @@ TEST_F(TranslatorRelationCorrectnessTests, TranslatorExtraRelationsCorrectness) } // Assign random values to the mini-circuit part of the range constraint polynomials - for (const auto& range_constraint_polynomial_id : range_constraint_polynomial_ids) { parallel_for_range(mini_circuit_size - 2, [&](size_t start, size_t end) { // We want to iterate from 1 to mini_circuit_size - 2 (inclusive)