diff --git a/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt index 16f375379bb..bfba40b03b4 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/CMakeLists.txt @@ -2,4 +2,5 @@ add_subdirectory(decrypt_bench) add_subdirectory(pippenger_bench) add_subdirectory(plonk_bench) add_subdirectory(honk_bench) -add_subdirectory(relations_bench) \ No newline at end of file +add_subdirectory(relations_bench) +add_subdirectory(widgets_bench) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt index 0db876053fb..31f4834f4bc 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/CMakeLists.txt @@ -2,16 +2,13 @@ set(BENCHMARK_SOURCES barycentric.bench.cpp relations.bench.cpp - widget.bench.cpp ) # Required libraries for benchmark suites set(LINKED_LIBRARIES - polynomials proof_system benchmark::benchmark transcript - stdlib_primitives ) # Add executable and custom target for each suite, e.g. ultra_honk_bench diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp index c98dae702c3..3300fb4bf8e 100644 --- a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp +++ b/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/relations.bench.cpp @@ -1,13 +1,6 @@ +#include "barretenberg/flavor/goblin_translator.hpp" #include "barretenberg/flavor/goblin_ultra.hpp" #include "barretenberg/flavor/ultra.hpp" -#include "barretenberg/relations/auxiliary_relation.hpp" -#include "barretenberg/relations/ecc_op_queue_relation.hpp" -#include "barretenberg/relations/elliptic_relation.hpp" -#include "barretenberg/relations/gen_perm_sort_relation.hpp" -#include "barretenberg/relations/lookup_relation.hpp" -#include "barretenberg/relations/permutation_relation.hpp" -#include "barretenberg/relations/relation_parameters.hpp" -#include "barretenberg/relations/ultra_arithmetic_relation.hpp" #include namespace { @@ -78,4 +71,40 @@ void ultra_arithmetic_relation(::benchmark::State& state) noexcept } BENCHMARK(ultra_arithmetic_relation); +void translator_decomposition_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_decomposition_relation); + +void translator_opcode_constraint_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_opcode_constraint_relation); + +void translator_accumulator_transfer_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_accumulator_transfer_relation); + +void translator_gen_perm_sort_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_gen_perm_sort_relation); + +void translator_non_native_field_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_non_native_field_relation); + +void translator_permutation_relation(::benchmark::State& state) noexcept +{ + execute_relation>(state); +} +BENCHMARK(translator_permutation_relation); + } // namespace proof_system::benchmark::relations diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt new file mode 100644 index 00000000000..35eebc6d27d --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/CMakeLists.txt @@ -0,0 +1,21 @@ +# Each source represents a separate benchmark suite +set(BENCHMARK_SOURCES + widget.bench.cpp +) + +# Required libraries for benchmark suites +set(LINKED_LIBRARIES + polynomials + proof_system + benchmark::benchmark + transcript + stdlib_primitives +) + +# Add executable and custom target for each suite, e.g. ultra_honk_bench +foreach(BENCHMARK_SOURCE ${BENCHMARK_SOURCES}) + get_filename_component(BENCHMARK_NAME ${BENCHMARK_SOURCE} NAME_WE) # extract name without extension + add_executable(${BENCHMARK_NAME}_bench main.bench.cpp ${BENCHMARK_SOURCE}) + target_link_libraries(${BENCHMARK_NAME}_bench ${LINKED_LIBRARIES}) + add_custom_target(run_${BENCHMARK_NAME} COMMAND ${BENCHMARK_NAME} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) +endforeach() \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp new file mode 100644 index 00000000000..71fefa04722 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/main.bench.cpp @@ -0,0 +1,3 @@ +#include + +BENCHMARK_MAIN(); diff --git a/barretenberg/cpp/src/barretenberg/benchmark/relations_bench/widget.bench.cpp b/barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp similarity index 100% rename from barretenberg/cpp/src/barretenberg/benchmark/relations_bench/widget.bench.cpp rename to barretenberg/cpp/src/barretenberg/benchmark/widgets_bench/widget.bench.cpp diff --git a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp index ae896765dd3..47cec70b76f 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/ecc_vm.hpp @@ -1284,28 +1284,28 @@ class ECCVMGrumpkin : public ECCVMBase; -extern template class ECCVMWnafRelationBase; -extern template class ECCVMPointTableRelationBase; -extern template class ECCVMMSMRelationBase; -extern template class ECCVMSetRelationBase; -extern template class ECCVMLookupRelationBase; +extern template class ECCVMTranscriptRelationImpl; +extern template class ECCVMWnafRelationImpl; +extern template class ECCVMPointTableRelationImpl; +extern template class ECCVMMSMRelationImpl; +extern template class ECCVMSetRelationImpl; +extern template class ECCVMLookupRelationImpl; -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVM); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVMGrumpkin); -DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM); -DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin); +DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM); +DECLARE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin); } // namespace sumcheck } // namespace proof_system::honk diff --git a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp index 9b0d5e20d57..e08eead4e42 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/goblin_translator.hpp @@ -6,6 +6,7 @@ #include "barretenberg/polynomials/univariate.hpp" #include "barretenberg/proof_system/arithmetization/arithmetization.hpp" #include "barretenberg/proof_system/circuit_builder/goblin_translator_circuit_builder.hpp" +#include "barretenberg/relations/relation_parameters.hpp" #include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp" #include "barretenberg/relations/translator_vm/translator_extra_relations.hpp" #include "barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp" @@ -1634,5 +1635,24 @@ template class GoblinTranslator_ { }; }; -using GoblinTranslatorBasic = GoblinTranslator_<2048>; +using GoblinTranslator = GoblinTranslator_<2048>; + } // namespace proof_system::honk::flavor + +namespace proof_system { + +extern template class GoblinTranslatorPermutationRelationImpl; +extern template class GoblinTranslatorGenPermSortRelationImpl; +extern template class GoblinTranslatorOpcodeConstraintRelationImpl; +extern template class GoblinTranslatorAccumulatorTransferRelationImpl; +extern template class GoblinTranslatorDecompositionRelationImpl; +extern template class GoblinTranslatorNonNativeFieldRelationImpl; + +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorPermutationRelationImpl, honk::flavor::GoblinTranslator); +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorGenPermSortRelationImpl, honk::flavor::GoblinTranslator); +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorOpcodeConstraintRelationImpl, honk::flavor::GoblinTranslator); +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorAccumulatorTransferRelationImpl, honk::flavor::GoblinTranslator); +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorDecompositionRelationImpl, honk::flavor::GoblinTranslator); +DECLARE_SUMCHECK_RELATION_CLASS(GoblinTranslatorNonNativeFieldRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/flavor/relation_definitions_fwd.hpp b/barretenberg/cpp/src/barretenberg/flavor/relation_definitions_fwd.hpp index af9e7a83bf3..8ebca000c94 100644 --- a/barretenberg/cpp/src/barretenberg/flavor/relation_definitions_fwd.hpp +++ b/barretenberg/cpp/src/barretenberg/flavor/relation_definitions_fwd.hpp @@ -7,44 +7,44 @@ #define EntityEdge(Flavor) Flavor::AllEntities #define ACCUMULATE(...) _ACCUMULATE(__VA_ARGS__) -#define _ACCUMULATE(Preface, RelationBase, Flavor, AccumulatorType, EdgeType) \ +#define _ACCUMULATE(Preface, RelationImpl, Flavor, AccumulatorType, EdgeType) \ Preface template void \ - RelationBase::accumulate>::AccumulatorType, \ + RelationImpl::accumulate>::AccumulatorType, \ EdgeType(Flavor)>( \ - proof_system::Relation>::AccumulatorType&, \ + proof_system::Relation>::AccumulatorType&, \ EdgeType(Flavor) const&, \ RelationParameters const&, \ Flavor::FF const&); #define PERMUTATION_METHOD(...) _PERMUTATION_METHOD(__VA_ARGS__) -#define _PERMUTATION_METHOD(Preface, MethodName, RelationBase, Flavor, AccumulatorType, EdgeType) \ - Preface template typename proof_system::Relation>::AccumulatorType \ - RelationBase::MethodName>::AccumulatorType, \ +#define _PERMUTATION_METHOD(Preface, MethodName, RelationImpl, Flavor, AccumulatorType, EdgeType) \ + Preface template typename proof_system::Relation>::AccumulatorType \ + RelationImpl::MethodName>::AccumulatorType, \ EdgeType(Flavor)>(EdgeType(Flavor) const&, \ RelationParameters const&); #define SUMCHECK_RELATION_CLASS(...) _SUMCHECK_RELATION_CLASS(__VA_ARGS__) -#define _SUMCHECK_RELATION_CLASS(Preface, RelationBase, Flavor) \ - ACCUMULATE(Preface, RelationBase, Flavor, SumcheckTupleOfUnivariatesOverSubrelations, ExtendedEdge) \ - ACCUMULATE(Preface, RelationBase, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge) \ - ACCUMULATE(Preface, RelationBase, Flavor, SumcheckArrayOfValuesOverSubrelations, EntityEdge) +#define _SUMCHECK_RELATION_CLASS(Preface, RelationImpl, Flavor) \ + ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckTupleOfUnivariatesOverSubrelations, ExtendedEdge) \ + ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EvaluationEdge) \ + ACCUMULATE(Preface, RelationImpl, Flavor, SumcheckArrayOfValuesOverSubrelations, EntityEdge) -#define DECLARE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(extern, RelationBase, Flavor) -#define DEFINE_SUMCHECK_RELATION_CLASS(RelationBase, Flavor) SUMCHECK_RELATION_CLASS(, RelationBase, Flavor) +#define DECLARE_SUMCHECK_RELATION_CLASS(RelationImpl, Flavor) SUMCHECK_RELATION_CLASS(extern, RelationImpl, Flavor) +#define DEFINE_SUMCHECK_RELATION_CLASS(RelationImpl, Flavor) SUMCHECK_RELATION_CLASS(, RelationImpl, Flavor) #define SUMCHECK_PERMUTATION_CLASS(...) _SUMCHECK_PERMUTATION_CLASS(__VA_ARGS__) -#define _SUMCHECK_PERMUTATION_CLASS(Preface, RelationBase, Flavor) \ +#define _SUMCHECK_PERMUTATION_CLASS(Preface, RelationImpl, Flavor) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_numerator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \ + Preface, compute_permutation_numerator, RelationImpl, Flavor, UnivariateAccumulator0, ExtendedEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \ - PERMUTATION_METHOD(Preface, compute_permutation_numerator, RelationBase, Flavor, ValueAccumulator0, EntityEdge) \ + Preface, compute_permutation_numerator, RelationImpl, Flavor, ValueAccumulator0, EvaluationEdge) \ + PERMUTATION_METHOD(Preface, compute_permutation_numerator, RelationImpl, Flavor, ValueAccumulator0, EntityEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_denominator, RelationBase, Flavor, UnivariateAccumulator0, ExtendedEdge) \ + Preface, compute_permutation_denominator, RelationImpl, Flavor, UnivariateAccumulator0, ExtendedEdge) \ PERMUTATION_METHOD( \ - Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EvaluationEdge) \ - PERMUTATION_METHOD(Preface, compute_permutation_denominator, RelationBase, Flavor, ValueAccumulator0, EntityEdge) + Preface, compute_permutation_denominator, RelationImpl, Flavor, ValueAccumulator0, EvaluationEdge) \ + PERMUTATION_METHOD(Preface, compute_permutation_denominator, RelationImpl, Flavor, ValueAccumulator0, EntityEdge) -#define DECLARE_SUMCHECK_PERMUTATION_CLASS(RelationBase, Flavor) \ - SUMCHECK_PERMUTATION_CLASS(extern, RelationBase, Flavor) -#define DEFINE_SUMCHECK_PERMUTATION_CLASS(RelationBase, Flavor) SUMCHECK_PERMUTATION_CLASS(, RelationBase, Flavor) +#define DECLARE_SUMCHECK_PERMUTATION_CLASS(RelationImpl, Flavor) \ + SUMCHECK_PERMUTATION_CLASS(extern, RelationImpl, Flavor) +#define DEFINE_SUMCHECK_PERMUTATION_CLASS(RelationImpl, Flavor) SUMCHECK_PERMUTATION_CLASS(, RelationImpl, Flavor) diff --git a/barretenberg/cpp/src/barretenberg/proof_system/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/proof_system/CMakeLists.txt index 68283003435..63d4af708eb 100644 --- a/barretenberg/cpp/src/barretenberg/proof_system/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/proof_system/CMakeLists.txt @@ -1 +1 @@ -barretenberg_module(proof_system relations polynomials crypto_pedersen_commitment crypto_pedersen_hash) \ No newline at end of file +barretenberg_module(proof_system relations crypto_pedersen_commitment crypto_pedersen_hash) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/CMakeLists.txt b/barretenberg/cpp/src/barretenberg/relations/CMakeLists.txt index 9e0da61e113..5f3aaaaa660 100644 --- a/barretenberg/cpp/src/barretenberg/relations/CMakeLists.txt +++ b/barretenberg/cpp/src/barretenberg/relations/CMakeLists.txt @@ -1 +1 @@ -barretenberg_module(relations proof_system) \ No newline at end of file +barretenberg_module(relations polynomials) \ No newline at end of file diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.cpp index 23fcaf324f9..66f2b4108e4 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.cpp @@ -20,18 +20,18 @@ namespace proof_system::honk::sumcheck { */ template template -void ECCVMLookupRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMLookupRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& params, [[maybe_unused]] const FF& scaling_factor) { - lookup_library::accumulate_logderivative_lookup_subrelation_contributions>( + lookup_library::accumulate_logderivative_lookup_subrelation_contributions>( accumulator, in, params, scaling_factor); } -template class ECCVMLookupRelationBase; -template class ECCVMLookupRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMLookupRelationImpl; +template class ECCVMLookupRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMLookupRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp index 1b5884db7a3..68f15aa2bd4 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_lookup_relation.hpp @@ -9,7 +9,7 @@ namespace proof_system::honk::sumcheck { -template class ECCVMLookupRelationBase { +template class ECCVMLookupRelationImpl { public: using FF = FF_; static constexpr size_t READ_TERMS = 4; @@ -222,6 +222,6 @@ template class ECCVMLookupRelationBase { const FF& scaling_factor); }; -template using ECCVMLookupRelation = Relation>; +template using ECCVMLookupRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.cpp index 9ab0db87e8b..b0efb52113c 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.cpp @@ -29,7 +29,7 @@ namespace proof_system::honk::sumcheck { * SKEW round: * If skew_i == 1, [Acc] = [Acc] - [P_i] for all i in [0, ..., k - 1] * - * The relations in ECCVMMSMRelationBase constrain the ADDITION, DOUBLE and SKEW rounds + * The relations in ECCVMMSMRelationImpl constrain the ADDITION, DOUBLE and SKEW rounds * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Accumulator edges. * @param parameters contains beta, gamma, and public_input_delta, .... @@ -37,7 +37,7 @@ namespace proof_system::honk::sumcheck { */ template template -void ECCVMMSMRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMMSMRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& /*unused*/, const FF& scaling_factor) @@ -159,7 +159,7 @@ void ECCVMMSMRelationBase::accumulate(ContainerOverSubrelations& accumulator /** * @brief Addition relation * - * All addition operations in ECCVMMSMRelationBase are conditional additions! + * All addition operations in ECCVMMSMRelationImpl are conditional additions! * This method returns two Accumulators that represent x/y coord of output. * Output is either an addition of inputs, or xa/ya dpeending on value of `selector`. * Additionally, we require `lambda = 0` if `selector = 0`. @@ -391,8 +391,8 @@ void ECCVMMSMRelationBase::accumulate(ContainerOverSubrelations& accumulator // perform lookups on (pc / slice_i / x / y) } -template class ECCVMMSMRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMMSMRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMMSMRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp index acc7006069c..c611ea752f7 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_msm_relation.hpp @@ -28,13 +28,13 @@ namespace proof_system::honk::sumcheck { * SKEW round: * If skew_i == 1, [Acc] = [Acc] - [P_i] for all i in [0, ..., k - 1] * - * The relations in ECCVMMSMRelationBase constrain the ADDITION, DOUBLE and SKEW rounds + * The relations in ECCVMMSMRelationImpl constrain the ADDITION, DOUBLE and SKEW rounds * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Accumulator edges. * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ -template class ECCVMMSMRelationBase { +template class ECCVMMSMRelationImpl { public: using FF = FF_; @@ -49,6 +49,6 @@ template class ECCVMMSMRelationBase { const FF& scaling_factor); }; -template using ECCVMMSMRelation = Relation>; +template using ECCVMMSMRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.cpp index 1b047e4e761..f846c265482 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.cpp @@ -5,11 +5,11 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMPointTableRelationBase + * @brief ECCVMPointTableRelationImpl * @details These relations define the set of point lookup tables we will use in `ecc_msm_relation.hpp`, to evaluate * multiscalar multiplication. For every point [P] = (Px, Py) involved in an MSM, we need to do define a lookup * table out of the following points: { -15[P], -13[P], -11[P], -9[P], -7[P], -5[P], -3[P], -[P] } - * ECCVMPointTableRelationBase defines relations that define the lookup table. + * ECCVMPointTableRelationImpl defines relations that define the lookup table. * * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Accumulator edges. @@ -18,7 +18,7 @@ namespace proof_system::honk::sumcheck { */ template template -void ECCVMPointTableRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMPointTableRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& /*unused*/, const FF& scaling_factor) @@ -172,8 +172,8 @@ void ECCVMPointTableRelationBase::accumulate(ContainerOverSubrelations& accu (-lagrange_first + 1) * (-precompute_point_transition + 1) * y_add_check * scaling_factor; } -template class ECCVMPointTableRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMPointTableRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMPointTableRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp index 8b1e0a1ce5b..4d78a80f0fb 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_point_table_relation.hpp @@ -4,18 +4,18 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMPointTableRelationBase + * @brief ECCVMPointTableRelationImpl * @details These relations define the set of point lookup tables we will use in `ecc_msm_relation.hpp`, to evaluate * multiscalar multiplication. For every point [P] = (Px, Py) involved in an MSM, we need to do define a lookup * table out of the following points: { -15[P], -13[P], -11[P], -9[P], -7[P], -5[P], -3[P], -[P] } - * ECCVMPointTableRelationBase defines relations that define the lookup table. + * ECCVMPointTableRelationImpl defines relations that define the lookup table. * * @param evals transformed to `evals + C(in(X)...)*scaling_factor` * @param in an std::array containing the fully extended Accumulator edges. * @param parameters contains beta, gamma, and public_input_delta, .... * @param scaling_factor optional term to scale the evaluation before adding to evals. */ -template class ECCVMPointTableRelationBase { +template class ECCVMPointTableRelationImpl { public: using FF = FF_; @@ -28,6 +28,6 @@ template class ECCVMPointTableRelationBase { const FF& scaling_factor); }; -template using ECCVMPointTableRelation = Relation>; +template using ECCVMPointTableRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.cpp index b882402cfaf..f9c9cd96cdd 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.cpp @@ -7,7 +7,7 @@ namespace proof_system::honk::sumcheck { /** * @brief Performs list-equivalence checks for the ECCVM * - * @details ECCVMSetRelationBase validates the correctness of the inputs/outputs of the three main algorithms evaluated + * @details ECCVMSetRelationImpl validates the correctness of the inputs/outputs of the three main algorithms evaluated * by the ECCVM. * * First term: tuple of (pc, round, wnaf_slice), computed when slicing scalar multipliers into slices, @@ -30,11 +30,11 @@ namespace proof_system::honk::sumcheck { * @param in * @param relation_params * @param index - * @return ECCVMSetRelationBase::template Accumulator + * @return ECCVMSetRelationImpl::template Accumulator */ template template -Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEntities& in, const Parameters& params) +Accumulator ECCVMSetRelationImpl::compute_permutation_numerator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -227,7 +227,7 @@ Accumulator ECCVMSetRelationBase::compute_permutation_numerator(const AllEnt template template -Accumulator ECCVMSetRelationBase::compute_permutation_denominator(const AllEntities& in, const Parameters& params) +Accumulator ECCVMSetRelationImpl::compute_permutation_denominator(const AllEntities& in, const Parameters& params) { using View = typename Accumulator::View; @@ -364,7 +364,7 @@ Accumulator ECCVMSetRelationBase::compute_permutation_denominator(const AllE */ template template -void ECCVMSetRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMSetRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& params, const FF& scaling_factor) @@ -393,10 +393,10 @@ void ECCVMSetRelationBase::accumulate(ContainerOverSubrelations& accumulator std::get<1>(accumulator) += (lagrange_last * z_perm_shift) * scaling_factor; } -template class ECCVMSetRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin); -DEFINE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMSetRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin); +DEFINE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_PERMUTATION_CLASS(ECCVMSetRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp index 879db1ff7fd..ca5a920eed4 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_set_relation.hpp @@ -9,7 +9,7 @@ namespace proof_system::honk::sumcheck { -template class ECCVMSetRelationBase { +template class ECCVMSetRelationImpl { public: using FF = FF_; @@ -44,6 +44,6 @@ template class ECCVMSetRelationBase { const FF& scaling_factor); }; -template using ECCVMSetRelation = Relation>; +template using ECCVMSetRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.cpp index 02660993402..85b18b65f7f 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.cpp @@ -8,7 +8,7 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMTranscriptRelationBase evaluates the correctness of the ECCVM transcript columns + * @brief ECCVMTranscriptRelationImpl evaluates the correctness of the ECCVM transcript columns * * @details The transcript relations directly evaluate the correctness of `add, eq, reset` operations. * `mul` operations are lazily evaluated. The output of multiscalar multiplications is present in @@ -31,7 +31,7 @@ namespace proof_system::honk::sumcheck { */ template template -void ECCVMTranscriptRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMTranscriptRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& /*unused*/, const FF& scaling_factor) @@ -255,8 +255,8 @@ void ECCVMTranscriptRelationBase::accumulate(ContainerOverSubrelations& accu std::get<34>(accumulator) += x_coordinate_collision_check * scaling_factor; } -template class ECCVMTranscriptRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMTranscriptRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMTranscriptRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp index bbbaf430ae6..2c89ecc16e0 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_transcript_relation.hpp @@ -7,7 +7,7 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMTranscriptRelationBase evaluates the correctness of the ECCVM transcript columns + * @brief ECCVMTranscriptRelationImpl evaluates the correctness of the ECCVM transcript columns * * @details The transcript relations directly evaluate the correctness of `add, eq, reset` operations. * `mul` operations are lazily evaluated. The output of multiscalar multiplications is present in @@ -26,7 +26,7 @@ namespace proof_system::honk::sumcheck { * prevents us doing redundant computation. * @tparam FF */ -template class ECCVMTranscriptRelationBase { +template class ECCVMTranscriptRelationImpl { public: using FF = FF_; @@ -53,6 +53,6 @@ template class ECCVMTranscriptRelationBase { } }; -template using ECCVMTranscriptRelation = Relation>; +template using ECCVMTranscriptRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.cpp index b0616a28595..56f84de6a87 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.cpp @@ -5,7 +5,7 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMWnafRelationBase evaluates relations that convert scalar multipliers into 4-bit WNAF slices + * @brief ECCVMWnafRelationImpl evaluates relations that convert scalar multipliers into 4-bit WNAF slices * @details Each WNAF slice is a 4-bit slice representing one of 16 integers { -15, -13, ..., 15 } * Each WNAF slice is represented via two 2-bit columns (precompute_s1hi, ..., precompute_s4lo) * One 128-bit scalar multiplier is processed across 8 rows, indexed by a round variable. @@ -36,7 +36,7 @@ namespace proof_system::honk::sumcheck { */ template template -void ECCVMWnafRelationBase::accumulate(ContainerOverSubrelations& accumulator, +void ECCVMWnafRelationImpl::accumulate(ContainerOverSubrelations& accumulator, const AllEntities& in, const Parameters& /*unused*/, const FF& scaling_factor) @@ -216,8 +216,8 @@ void ECCVMWnafRelationBase::accumulate(ContainerOverSubrelations& accumulato // the set equivalence relation } -template class ECCVMWnafRelationBase; -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVM); -DEFINE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationBase, flavor::ECCVMGrumpkin); +template class ECCVMWnafRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVM); +DEFINE_SUMCHECK_RELATION_CLASS(ECCVMWnafRelationImpl, flavor::ECCVMGrumpkin); } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp index 13aa4cd2aeb..2c66f7d4bd8 100644 --- a/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/ecc_vm/ecc_wnaf_relation.hpp @@ -3,7 +3,7 @@ namespace proof_system::honk::sumcheck { /** - * @brief ECCVMWnafRelationBase evaluates relations that convert scalar multipliers into 4-bit WNAF slices + * @brief ECCVMWnafRelationImpl evaluates relations that convert scalar multipliers into 4-bit WNAF slices * @details Each WNAF slice is a 4-bit slice representing one of 16 integers { -15, -13, ..., 15 } * Each WNAF slice is represented via two 2-bit columns (precompute_s1hi, ..., precompute_s4lo) * One 128-bit scalar multiplier is processed across 8 rows, indexed by a round variable. @@ -31,7 +31,7 @@ namespace proof_system::honk::sumcheck { * * @tparam FF */ -template class ECCVMWnafRelationBase { +template class ECCVMWnafRelationImpl { public: using FF = FF_; @@ -46,6 +46,6 @@ template class ECCVMWnafRelationBase { const FF& scaling_factor); }; -template using ECCVMWnafRelation = Relation>; +template using ECCVMWnafRelation = Relation>; } // namespace proof_system::honk::sumcheck diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp index 7ed763ba911..02710913aba 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/goblin_translator_relation_consistency.test.cpp @@ -11,226 +11,34 @@ * satisfied in general by random inputs) only that the two implementations are equivalent. * */ -#include "barretenberg/ecc/curves/bn254/fr.hpp" -#include "barretenberg/relations/relation_parameters.hpp" -#include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp" -#include "barretenberg/relations/translator_vm/translator_extra_relations.hpp" -#include "barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp" -#include "barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp" -#include "barretenberg/relations/translator_vm/translator_permutation_relation.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" #include using namespace proof_system; namespace proof_system::ultra_relation_consistency_tests { -using FF = barretenberg::fr; -struct InputElements { - static constexpr size_t NUM_ELEMENTS = 184; - std::array _data; +using Flavor = honk::flavor::GoblinTranslator; +using FF = typename Flavor::FF; +using InputElements = typename Flavor::AllValues; - static InputElements get_random() - { - InputElements result; - std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); - return result; - } +InputElements get_random_input() +{ + InputElements result; + std::generate(result._data.begin(), result._data.end(), [] { return FF::random_element(); }); + return result; +} - static InputElements get_special() // use non-random values - { - InputElements result; - FF idx = 0; - std::generate(result._data.begin(), result._data.end(), [&] { - idx += FF(1); - return idx; - }); - return result; - } - FF& op = std::get<0>(this->_data); - FF& x_lo_y_hi = std::get<1>(this->_data); - FF& x_hi_z_1 = std::get<2>(this->_data); - FF& y_lo_z_2 = std::get<3>(this->_data); - FF& p_x_low_limbs = std::get<4>(this->_data); - FF& p_x_low_limbs_range_constraint_0 = std::get<5>(this->_data); - FF& p_x_low_limbs_range_constraint_1 = std::get<6>(this->_data); - FF& p_x_low_limbs_range_constraint_2 = std::get<7>(this->_data); - FF& p_x_low_limbs_range_constraint_3 = std::get<8>(this->_data); - FF& p_x_low_limbs_range_constraint_4 = std::get<9>(this->_data); - FF& p_x_low_limbs_range_constraint_tail = std::get<10>(this->_data); - FF& p_x_high_limbs = std::get<11>(this->_data); - FF& p_x_high_limbs_range_constraint_0 = std::get<12>(this->_data); - FF& p_x_high_limbs_range_constraint_1 = std::get<13>(this->_data); - FF& p_x_high_limbs_range_constraint_2 = std::get<14>(this->_data); - FF& p_x_high_limbs_range_constraint_3 = std::get<15>(this->_data); - FF& p_x_high_limbs_range_constraint_4 = std::get<16>(this->_data); - FF& p_x_high_limbs_range_constraint_tail = std::get<17>(this->_data); - FF& p_y_low_limbs = std::get<18>(this->_data); - FF& p_y_low_limbs_range_constraint_0 = std::get<19>(this->_data); - FF& p_y_low_limbs_range_constraint_1 = std::get<20>(this->_data); - FF& p_y_low_limbs_range_constraint_2 = std::get<21>(this->_data); - FF& p_y_low_limbs_range_constraint_3 = std::get<22>(this->_data); - FF& p_y_low_limbs_range_constraint_4 = std::get<23>(this->_data); - FF& p_y_low_limbs_range_constraint_tail = std::get<24>(this->_data); - FF& p_y_high_limbs = std::get<25>(this->_data); - FF& p_y_high_limbs_range_constraint_0 = std::get<26>(this->_data); - FF& p_y_high_limbs_range_constraint_1 = std::get<27>(this->_data); - FF& p_y_high_limbs_range_constraint_2 = std::get<28>(this->_data); - FF& p_y_high_limbs_range_constraint_3 = std::get<29>(this->_data); - FF& p_y_high_limbs_range_constraint_4 = std::get<30>(this->_data); - FF& p_y_high_limbs_range_constraint_tail = std::get<31>(this->_data); - FF& z_low_limbs = std::get<32>(this->_data); - FF& z_low_limbs_range_constraint_0 = std::get<33>(this->_data); - FF& z_low_limbs_range_constraint_1 = std::get<34>(this->_data); - FF& z_low_limbs_range_constraint_2 = std::get<35>(this->_data); - FF& z_low_limbs_range_constraint_3 = std::get<36>(this->_data); - FF& z_low_limbs_range_constraint_4 = std::get<37>(this->_data); - FF& z_low_limbs_range_constraint_tail = std::get<38>(this->_data); - FF& z_high_limbs = std::get<39>(this->_data); - FF& z_high_limbs_range_constraint_0 = std::get<40>(this->_data); - FF& z_high_limbs_range_constraint_1 = std::get<41>(this->_data); - FF& z_high_limbs_range_constraint_2 = std::get<42>(this->_data); - FF& z_high_limbs_range_constraint_3 = std::get<43>(this->_data); - FF& z_high_limbs_range_constraint_4 = std::get<44>(this->_data); - FF& z_high_limbs_range_constraint_tail = std::get<45>(this->_data); - FF& accumulators_binary_limbs_0 = std::get<46>(this->_data); - FF& accumulators_binary_limbs_1 = std::get<47>(this->_data); - FF& accumulators_binary_limbs_2 = std::get<48>(this->_data); - FF& accumulators_binary_limbs_3 = std::get<49>(this->_data); - FF& accumulator_low_limbs_range_constraint_0 = std::get<50>(this->_data); - FF& accumulator_low_limbs_range_constraint_1 = std::get<51>(this->_data); - FF& accumulator_low_limbs_range_constraint_2 = std::get<52>(this->_data); - FF& accumulator_low_limbs_range_constraint_3 = std::get<53>(this->_data); - FF& accumulator_low_limbs_range_constraint_4 = std::get<54>(this->_data); - FF& accumulator_low_limbs_range_constraint_tail = std::get<55>(this->_data); - FF& accumulator_high_limbs_range_constraint_0 = std::get<56>(this->_data); - FF& accumulator_high_limbs_range_constraint_1 = std::get<57>(this->_data); - FF& accumulator_high_limbs_range_constraint_2 = std::get<58>(this->_data); - FF& accumulator_high_limbs_range_constraint_3 = std::get<59>(this->_data); - FF& accumulator_high_limbs_range_constraint_4 = std::get<60>(this->_data); - FF& accumulator_high_limbs_range_constraint_tail = std::get<61>(this->_data); - FF& quotient_low_binary_limbs = std::get<62>(this->_data); - FF& quotient_high_binary_limbs = std::get<63>(this->_data); - FF& quotient_low_limbs_range_constraint_0 = std::get<64>(this->_data); - FF& quotient_low_limbs_range_constraint_1 = std::get<65>(this->_data); - FF& quotient_low_limbs_range_constraint_2 = std::get<66>(this->_data); - FF& quotient_low_limbs_range_constraint_3 = std::get<67>(this->_data); - FF& quotient_low_limbs_range_constraint_4 = std::get<68>(this->_data); - FF& quotient_low_limbs_range_constraint_tail = std::get<69>(this->_data); - FF& quotient_high_limbs_range_constraint_0 = std::get<70>(this->_data); - FF& quotient_high_limbs_range_constraint_1 = std::get<71>(this->_data); - FF& quotient_high_limbs_range_constraint_2 = std::get<72>(this->_data); - FF& quotient_high_limbs_range_constraint_3 = std::get<73>(this->_data); - FF& quotient_high_limbs_range_constraint_4 = std::get<74>(this->_data); - FF& quotient_high_limbs_range_constraint_tail = std::get<75>(this->_data); - FF& relation_wide_limbs = std::get<76>(this->_data); - FF& relation_wide_limbs_range_constraint_0 = std::get<77>(this->_data); - FF& relation_wide_limbs_range_constraint_1 = std::get<78>(this->_data); - FF& relation_wide_limbs_range_constraint_2 = std::get<79>(this->_data); - FF& relation_wide_limbs_range_constraint_3 = std::get<80>(this->_data); - FF& concatenated_range_constraints_0 = std::get<81>(this->_data); - FF& concatenated_range_constraints_1 = std::get<82>(this->_data); - FF& concatenated_range_constraints_2 = std::get<83>(this->_data); - FF& concatenated_range_constraints_3 = std::get<84>(this->_data); - FF& ordered_range_constraints_0 = std::get<85>(this->_data); - FF& ordered_range_constraints_1 = std::get<86>(this->_data); - FF& ordered_range_constraints_2 = std::get<87>(this->_data); - FF& ordered_range_constraints_3 = std::get<88>(this->_data); - FF& ordered_range_constraints_4 = std::get<89>(this->_data); - FF& z_perm = std::get<90>(this->_data); - FF& x_lo_y_hi_shift = std::get<91>(this->_data); - FF& x_hi_z_1_shift = std::get<92>(this->_data); - FF& y_lo_z_2_shift = std::get<93>(this->_data); - FF& p_x_low_limbs_shift = std::get<94>(this->_data); - FF& p_x_low_limbs_range_constraint_0_shift = std::get<95>(this->_data); - FF& p_x_low_limbs_range_constraint_1_shift = std::get<96>(this->_data); - FF& p_x_low_limbs_range_constraint_2_shift = std::get<97>(this->_data); - FF& p_x_low_limbs_range_constraint_3_shift = std::get<98>(this->_data); - FF& p_x_low_limbs_range_constraint_4_shift = std::get<99>(this->_data); - FF& p_x_low_limbs_range_constraint_tail_shift = std::get<100>(this->_data); - FF& p_x_high_limbs_shift = std::get<101>(this->_data); - FF& p_x_high_limbs_range_constraint_0_shift = std::get<102>(this->_data); - FF& p_x_high_limbs_range_constraint_1_shift = std::get<103>(this->_data); - FF& p_x_high_limbs_range_constraint_2_shift = std::get<104>(this->_data); - FF& p_x_high_limbs_range_constraint_3_shift = std::get<105>(this->_data); - FF& p_x_high_limbs_range_constraint_4_shift = std::get<106>(this->_data); - FF& p_x_high_limbs_range_constraint_tail_shift = std::get<107>(this->_data); - FF& p_y_low_limbs_shift = std::get<108>(this->_data); - FF& p_y_low_limbs_range_constraint_0_shift = std::get<109>(this->_data); - FF& p_y_low_limbs_range_constraint_1_shift = std::get<110>(this->_data); - FF& p_y_low_limbs_range_constraint_2_shift = std::get<111>(this->_data); - FF& p_y_low_limbs_range_constraint_3_shift = std::get<112>(this->_data); - FF& p_y_low_limbs_range_constraint_4_shift = std::get<113>(this->_data); - FF& p_y_low_limbs_range_constraint_tail_shift = std::get<114>(this->_data); - FF& p_y_high_limbs_shift = std::get<115>(this->_data); - FF& p_y_high_limbs_range_constraint_0_shift = std::get<116>(this->_data); - FF& p_y_high_limbs_range_constraint_1_shift = std::get<117>(this->_data); - FF& p_y_high_limbs_range_constraint_2_shift = std::get<118>(this->_data); - FF& p_y_high_limbs_range_constraint_3_shift = std::get<119>(this->_data); - FF& p_y_high_limbs_range_constraint_4_shift = std::get<120>(this->_data); - FF& p_y_high_limbs_range_constraint_tail_shift = std::get<121>(this->_data); - FF& z_low_limbs_shift = std::get<122>(this->_data); - FF& z_low_limbs_range_constraint_0_shift = std::get<123>(this->_data); - FF& z_low_limbs_range_constraint_1_shift = std::get<124>(this->_data); - FF& z_low_limbs_range_constraint_2_shift = std::get<125>(this->_data); - FF& z_low_limbs_range_constraint_3_shift = std::get<126>(this->_data); - FF& z_low_limbs_range_constraint_4_shift = std::get<127>(this->_data); - FF& z_low_limbs_range_constraint_tail_shift = std::get<128>(this->_data); - FF& z_high_limbs_shift = std::get<129>(this->_data); - FF& z_high_limbs_range_constraint_0_shift = std::get<130>(this->_data); - FF& z_high_limbs_range_constraint_1_shift = std::get<131>(this->_data); - FF& z_high_limbs_range_constraint_2_shift = std::get<132>(this->_data); - FF& z_high_limbs_range_constraint_3_shift = std::get<133>(this->_data); - FF& z_high_limbs_range_constraint_4_shift = std::get<134>(this->_data); - FF& z_high_limbs_range_constraint_tail_shift = std::get<135>(this->_data); - FF& accumulators_binary_limbs_0_shift = std::get<136>(this->_data); - FF& accumulators_binary_limbs_1_shift = std::get<137>(this->_data); - FF& accumulators_binary_limbs_2_shift = std::get<138>(this->_data); - FF& accumulators_binary_limbs_3_shift = std::get<139>(this->_data); - FF& accumulator_low_limbs_range_constraint_0_shift = std::get<140>(this->_data); - FF& accumulator_low_limbs_range_constraint_1_shift = std::get<141>(this->_data); - FF& accumulator_low_limbs_range_constraint_2_shift = std::get<142>(this->_data); - FF& accumulator_low_limbs_range_constraint_3_shift = std::get<143>(this->_data); - FF& accumulator_low_limbs_range_constraint_4_shift = std::get<144>(this->_data); - FF& accumulator_low_limbs_range_constraint_tail_shift = std::get<145>(this->_data); - FF& accumulator_high_limbs_range_constraint_0_shift = std::get<146>(this->_data); - FF& accumulator_high_limbs_range_constraint_1_shift = std::get<147>(this->_data); - FF& accumulator_high_limbs_range_constraint_2_shift = std::get<148>(this->_data); - FF& accumulator_high_limbs_range_constraint_3_shift = std::get<149>(this->_data); - FF& accumulator_high_limbs_range_constraint_4_shift = std::get<150>(this->_data); - FF& accumulator_high_limbs_range_constraint_tail_shift = std::get<151>(this->_data); - FF& quotient_low_binary_limbs_shift = std::get<152>(this->_data); - FF& quotient_high_binary_limbs_shift = std::get<153>(this->_data); - FF& quotient_low_limbs_range_constraint_0_shift = std::get<154>(this->_data); - FF& quotient_low_limbs_range_constraint_1_shift = std::get<155>(this->_data); - FF& quotient_low_limbs_range_constraint_2_shift = std::get<156>(this->_data); - FF& quotient_low_limbs_range_constraint_3_shift = std::get<157>(this->_data); - FF& quotient_low_limbs_range_constraint_4_shift = std::get<158>(this->_data); - FF& quotient_low_limbs_range_constraint_tail_shift = std::get<159>(this->_data); - FF& quotient_high_limbs_range_constraint_0_shift = std::get<160>(this->_data); - FF& quotient_high_limbs_range_constraint_1_shift = std::get<161>(this->_data); - FF& quotient_high_limbs_range_constraint_2_shift = std::get<162>(this->_data); - FF& quotient_high_limbs_range_constraint_3_shift = std::get<163>(this->_data); - FF& quotient_high_limbs_range_constraint_4_shift = std::get<164>(this->_data); - FF& quotient_high_limbs_range_constraint_tail_shift = std::get<165>(this->_data); - FF& relation_wide_limbs_shift = std::get<166>(this->_data); - FF& relation_wide_limbs_range_constraint_0_shift = std::get<167>(this->_data); - FF& relation_wide_limbs_range_constraint_1_shift = std::get<168>(this->_data); - FF& relation_wide_limbs_range_constraint_2_shift = std::get<169>(this->_data); - FF& relation_wide_limbs_range_constraint_3_shift = std::get<170>(this->_data); - FF& ordered_range_constraints_0_shift = std::get<171>(this->_data); - FF& ordered_range_constraints_1_shift = std::get<172>(this->_data); - FF& ordered_range_constraints_2_shift = std::get<173>(this->_data); - FF& ordered_range_constraints_3_shift = std::get<174>(this->_data); - FF& ordered_range_constraints_4_shift = std::get<175>(this->_data); - FF& z_perm_shift = std::get<176>(this->_data); - FF& lagrange_first = std::get<177>(this->_data); - FF& lagrange_last = std::get<178>(this->_data); - FF& lagrange_odd_in_minicircuit = std::get<179>(this->_data); - FF& lagrange_even_in_minicircuit = std::get<180>(this->_data); - FF& lagrange_second = std::get<181>(this->_data); - FF& lagrange_second_to_last_in_minicircuit = std::get<182>(this->_data); - FF& ordered_extra_range_constraints_numerator = std::get<183>(this->_data); -}; +InputElements get_special_input() // use non-random values +{ + InputElements result; + FF idx = 0; + std::generate(result._data.begin(), result._data.end(), [&] { + idx += FF(1); + return idx; + }); + return result; +} class GoblinTranslatorRelationConsistency : public testing::Test { public: @@ -252,7 +60,7 @@ TEST_F(GoblinTranslatorRelationConsistency, PermutationRelation) using Relation = GoblinTranslatorPermutationRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); const auto& concatenated_range_constraints_0 = input_elements.concatenated_range_constraints_0; const auto& concatenated_range_constraints_1 = input_elements.concatenated_range_constraints_1; const auto& concatenated_range_constraints_2 = input_elements.concatenated_range_constraints_2; @@ -300,7 +108,7 @@ TEST_F(GoblinTranslatorRelationConsistency, GenPermSortRelation) using Relation = GoblinTranslatorGenPermSortRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); const auto& ordered_range_constraints_0 = input_elements.ordered_range_constraints_0; const auto& ordered_range_constraints_1 = input_elements.ordered_range_constraints_1; @@ -364,7 +172,7 @@ TEST_F(GoblinTranslatorRelationConsistency, DecompositionRelation) using Relation = GoblinTranslatorDecompositionRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + 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; @@ -913,7 +721,7 @@ TEST_F(GoblinTranslatorRelationConsistency, OpcodeConstraintRelation) using Relation = GoblinTranslatorOpcodeConstraintRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); const auto& op = input_elements.op; RelationValues expected_values; @@ -936,7 +744,7 @@ TEST_F(GoblinTranslatorRelationConsistency, AccumulatorTransferRelation) using Relation = GoblinTranslatorAccumulatorTransferRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); const auto& lagrange_even_in_minicircuit = input_elements.lagrange_even_in_minicircuit; const auto& lagrange_second = input_elements.lagrange_second; @@ -1005,7 +813,7 @@ TEST_F(GoblinTranslatorRelationConsistency, NonNativeFieldRelation) using Relation = GoblinTranslatorNonNativeFieldRelation; using RelationValues = typename Relation::SumcheckArrayOfValuesOverSubrelations; - const InputElements input_elements = random_inputs ? InputElements::get_random() : InputElements::get_special(); + const InputElements input_elements = random_inputs ? get_random_input() : get_special_input(); auto& op = input_elements.op; auto& p_x_low_limbs = input_elements.p_x_low_limbs; diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.cpp new file mode 100644 index 00000000000..aeaf1178c2c --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.cpp @@ -0,0 +1,622 @@ +#include "barretenberg/relations/translator_vm/translator_decomposition_relation.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" + +namespace proof_system { + +/** + * @brief Expression for decomposition of various values into smaller limbs or microlimbs. + * @details This relation enforces three types of subrelations: + * 1) A subrelation decomposing a value from the transcript (for example, z1) into 68-bit limbs. These relations + * will have the structure `lagrange_odd_in_minicircuit⋅(a - a_low - a_high⋅2⁶⁸)` + * 2) A subrelation decomposing a value of one of the limbs used in bigfield computation (for example, the lower + * wide relation limb) into 14-bit limbs. These relations will have the structure `lagrange_odd_in_minicircuit⋅(a - + * a_0 - a_1⋅2¹⁴ - + * ....)` 3) A subrelation making a microlimb range constraint more constraining. For example, we want to constrain + * some values to 12 bits instead of 14. So we add a constraint `lagrange_odd_in_minicircuit⋅(a_highest⋅4 - + * a_tail)`. In a separate relation both a_highest and a_tail are constrained to be 14 bits, but this relation + * changes the constraint on a_highest to be 12 bits. + * + * @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 GoblinTranslatorDecompositionRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) +{ + static constexpr size_t NUM_LIMB_BITS = 68; // Number of bits in a standard limb used for bigfield operations + static constexpr size_t NUM_MICRO_LIMB_BITS = 14; // Number of bits in a standard limb used for bigfield operations + + // Value to multiply an element by to perform an appropriate shift + static constexpr auto LIMB_SHIFT = FF(uint256_t(1) << NUM_LIMB_BITS); + + // Values to multiply an element by to perform an appropriate shift + static constexpr auto MICRO_LIMB_SHIFT = FF(uint256_t(1) << NUM_MICRO_LIMB_BITS); + static constexpr auto MICRO_LIMB_SHIFTx2 = MICRO_LIMB_SHIFT * MICRO_LIMB_SHIFT; + static constexpr auto MICRO_LIMB_SHIFTx3 = MICRO_LIMB_SHIFTx2 * MICRO_LIMB_SHIFT; + static constexpr auto MICRO_LIMB_SHIFTx4 = MICRO_LIMB_SHIFTx3 * MICRO_LIMB_SHIFT; + static constexpr auto MICRO_LIMB_SHIFTx5 = MICRO_LIMB_SHIFTx4 * MICRO_LIMB_SHIFT; + + // Shifts used to constrain ranges further + static constexpr auto SHIFT_12_TO_14 = + FF(4); // Shift used to range constrain the last microlimb of 68-bit limbs (standard limbs) + static constexpr auto SHIFT_10_TO_14 = + FF(16); // Shift used to range constrain the last microlimb of 52-bit limb (top quotient limb) + static constexpr auto SHIFT_8_TO_14 = FF(64); // Shift used to range constrain the last microlimb of 50-bit + // limbs (top limb of standard 254-bit value) + static constexpr auto SHIFT_4_TO_14 = + FF(1024); // Shift used to range constrain the last mircrolimb of 60-bit limbs from z scalars + + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + auto p_x_low_limbs = View(in.p_x_low_limbs); + 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_low_limbs_shift = View(in.p_x_low_limbs_shift); + auto p_x_low_limbs_range_constraint_0_shift = View(in.p_x_low_limbs_range_constraint_0_shift); + auto p_x_low_limbs_range_constraint_1_shift = View(in.p_x_low_limbs_range_constraint_1_shift); + auto p_x_low_limbs_range_constraint_2_shift = View(in.p_x_low_limbs_range_constraint_2_shift); + auto p_x_low_limbs_range_constraint_3_shift = View(in.p_x_low_limbs_range_constraint_3_shift); + auto p_x_low_limbs_range_constraint_4_shift = View(in.p_x_low_limbs_range_constraint_4_shift); + auto p_x_high_limbs = View(in.p_x_high_limbs); + 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_x_high_limbs_shift = View(in.p_x_high_limbs_shift); + auto p_x_high_limbs_range_constraint_0_shift = View(in.p_x_high_limbs_range_constraint_0_shift); + auto p_x_high_limbs_range_constraint_1_shift = View(in.p_x_high_limbs_range_constraint_1_shift); + auto p_x_high_limbs_range_constraint_2_shift = View(in.p_x_high_limbs_range_constraint_2_shift); + auto p_x_high_limbs_range_constraint_3_shift = View(in.p_x_high_limbs_range_constraint_3_shift); + auto p_y_low_limbs = View(in.p_y_low_limbs); + 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_low_limbs_shift = View(in.p_y_low_limbs_shift); + auto p_y_low_limbs_range_constraint_0_shift = View(in.p_y_low_limbs_range_constraint_0_shift); + auto p_y_low_limbs_range_constraint_1_shift = View(in.p_y_low_limbs_range_constraint_1_shift); + auto p_y_low_limbs_range_constraint_2_shift = View(in.p_y_low_limbs_range_constraint_2_shift); + auto p_y_low_limbs_range_constraint_3_shift = View(in.p_y_low_limbs_range_constraint_3_shift); + auto p_y_low_limbs_range_constraint_4_shift = View(in.p_y_low_limbs_range_constraint_4_shift); + auto p_y_high_limbs = View(in.p_y_high_limbs); + 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 p_y_high_limbs_shift = View(in.p_y_high_limbs_shift); + auto p_y_high_limbs_range_constraint_0_shift = View(in.p_y_high_limbs_range_constraint_0_shift); + auto p_y_high_limbs_range_constraint_1_shift = View(in.p_y_high_limbs_range_constraint_1_shift); + auto p_y_high_limbs_range_constraint_2_shift = View(in.p_y_high_limbs_range_constraint_2_shift); + auto p_y_high_limbs_range_constraint_3_shift = View(in.p_y_high_limbs_range_constraint_3_shift); + auto z_low_limbs = View(in.z_low_limbs); + 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_low_limbs_shift = View(in.z_low_limbs_shift); + auto z_low_limbs_range_constraint_0_shift = View(in.z_low_limbs_range_constraint_0_shift); + auto z_low_limbs_range_constraint_1_shift = View(in.z_low_limbs_range_constraint_1_shift); + auto z_low_limbs_range_constraint_2_shift = View(in.z_low_limbs_range_constraint_2_shift); + auto z_low_limbs_range_constraint_3_shift = View(in.z_low_limbs_range_constraint_3_shift); + auto z_low_limbs_range_constraint_4_shift = View(in.z_low_limbs_range_constraint_4_shift); + auto z_high_limbs = View(in.z_high_limbs); + 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 z_high_limbs_shift = View(in.z_high_limbs_shift); + auto z_high_limbs_range_constraint_0_shift = View(in.z_high_limbs_range_constraint_0_shift); + auto z_high_limbs_range_constraint_1_shift = View(in.z_high_limbs_range_constraint_1_shift); + auto z_high_limbs_range_constraint_2_shift = View(in.z_high_limbs_range_constraint_2_shift); + auto z_high_limbs_range_constraint_3_shift = View(in.z_high_limbs_range_constraint_3_shift); + auto z_high_limbs_range_constraint_4_shift = View(in.z_high_limbs_range_constraint_4_shift); + auto accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); + auto accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); + auto accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); + auto accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); + 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_low_limbs_range_constraint_0_shift = View(in.accumulator_low_limbs_range_constraint_0_shift); + auto accumulator_low_limbs_range_constraint_1_shift = View(in.accumulator_low_limbs_range_constraint_1_shift); + auto accumulator_low_limbs_range_constraint_2_shift = View(in.accumulator_low_limbs_range_constraint_2_shift); + auto accumulator_low_limbs_range_constraint_3_shift = View(in.accumulator_low_limbs_range_constraint_3_shift); + auto accumulator_low_limbs_range_constraint_4_shift = View(in.accumulator_low_limbs_range_constraint_4_shift); + 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 accumulator_high_limbs_range_constraint_0_shift = View(in.accumulator_high_limbs_range_constraint_0_shift); + auto accumulator_high_limbs_range_constraint_1_shift = View(in.accumulator_high_limbs_range_constraint_1_shift); + auto accumulator_high_limbs_range_constraint_2_shift = View(in.accumulator_high_limbs_range_constraint_2_shift); + auto accumulator_high_limbs_range_constraint_3_shift = View(in.accumulator_high_limbs_range_constraint_3_shift); + auto quotient_low_binary_limbs = View(in.quotient_low_binary_limbs); + 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_low_binary_limbs_shift = View(in.quotient_low_binary_limbs_shift); + auto quotient_low_limbs_range_constraint_0_shift = View(in.quotient_low_limbs_range_constraint_0_shift); + auto quotient_low_limbs_range_constraint_1_shift = View(in.quotient_low_limbs_range_constraint_1_shift); + auto quotient_low_limbs_range_constraint_2_shift = View(in.quotient_low_limbs_range_constraint_2_shift); + auto quotient_low_limbs_range_constraint_3_shift = View(in.quotient_low_limbs_range_constraint_3_shift); + auto quotient_low_limbs_range_constraint_4_shift = View(in.quotient_low_limbs_range_constraint_4_shift); + auto quotient_high_binary_limbs = View(in.quotient_high_binary_limbs); + 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 quotient_high_binary_limbs_shift = View(in.quotient_high_binary_limbs_shift); + auto quotient_high_limbs_range_constraint_0_shift = View(in.quotient_high_limbs_range_constraint_0_shift); + auto quotient_high_limbs_range_constraint_1_shift = View(in.quotient_high_limbs_range_constraint_1_shift); + auto quotient_high_limbs_range_constraint_2_shift = View(in.quotient_high_limbs_range_constraint_2_shift); + auto quotient_high_limbs_range_constraint_3_shift = View(in.quotient_high_limbs_range_constraint_3_shift); + auto relation_wide_limbs = View(in.relation_wide_limbs); + 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_high_limbs_range_constraint_tail_shift = View(in.p_x_high_limbs_range_constraint_tail_shift); + auto accumulator_high_limbs_range_constraint_tail_shift = + View(in.accumulator_high_limbs_range_constraint_tail_shift); + auto relation_wide_limbs_shift = View(in.relation_wide_limbs_shift); + auto relation_wide_limbs_range_constraint_0_shift = View(in.relation_wide_limbs_range_constraint_0_shift); + auto relation_wide_limbs_range_constraint_1_shift = View(in.relation_wide_limbs_range_constraint_1_shift); + auto relation_wide_limbs_range_constraint_2_shift = View(in.relation_wide_limbs_range_constraint_2_shift); + auto relation_wide_limbs_range_constraint_3_shift = View(in.relation_wide_limbs_range_constraint_3_shift); + auto p_y_high_limbs_range_constraint_tail_shift = View(in.p_y_high_limbs_range_constraint_tail_shift); + auto quotient_high_limbs_range_constraint_tail_shift = View(in.quotient_high_limbs_range_constraint_tail_shift); + auto p_x_low_limbs_range_constraint_tail = View(in.p_x_low_limbs_range_constraint_tail); + auto p_x_low_limbs_range_constraint_tail_shift = View(in.p_x_low_limbs_range_constraint_tail_shift); + auto p_x_high_limbs_range_constraint_tail = View(in.p_x_high_limbs_range_constraint_tail); + auto p_x_high_limbs_range_constraint_4_shift = View(in.p_x_high_limbs_range_constraint_4_shift); + auto p_y_low_limbs_range_constraint_tail = View(in.p_y_low_limbs_range_constraint_tail); + auto p_y_low_limbs_range_constraint_tail_shift = View(in.p_y_low_limbs_range_constraint_tail_shift); + auto p_y_high_limbs_range_constraint_tail = View(in.p_y_high_limbs_range_constraint_tail); + auto p_y_high_limbs_range_constraint_4_shift = View(in.p_y_high_limbs_range_constraint_4_shift); + auto z_low_limbs_range_constraint_tail = View(in.z_low_limbs_range_constraint_tail); + auto z_low_limbs_range_constraint_tail_shift = View(in.z_low_limbs_range_constraint_tail_shift); + auto z_high_limbs_range_constraint_tail = View(in.z_high_limbs_range_constraint_tail); + auto z_high_limbs_range_constraint_tail_shift = View(in.z_high_limbs_range_constraint_tail_shift); + auto accumulator_low_limbs_range_constraint_tail = View(in.accumulator_low_limbs_range_constraint_tail); + auto accumulator_low_limbs_range_constraint_tail_shift = View(in.accumulator_low_limbs_range_constraint_tail_shift); + auto accumulator_high_limbs_range_constraint_tail = View(in.accumulator_high_limbs_range_constraint_tail); + auto accumulator_high_limbs_range_constraint_4_shift = View(in.accumulator_high_limbs_range_constraint_4_shift); + auto quotient_low_limbs_range_constraint_tail = View(in.quotient_low_limbs_range_constraint_tail); + auto quotient_low_limbs_range_constraint_tail_shift = View(in.quotient_low_limbs_range_constraint_tail_shift); + auto quotient_high_limbs_range_constraint_tail = View(in.quotient_high_limbs_range_constraint_tail); + auto quotient_high_limbs_range_constraint_4_shift = View(in.quotient_high_limbs_range_constraint_4_shift); + auto x_lo_y_hi = View(in.x_lo_y_hi); + auto x_hi_z_1 = View(in.x_hi_z_1); + auto y_lo_z_2 = View(in.y_lo_z_2); + auto x_lo_y_hi_shift = View(in.x_lo_y_hi_shift); + auto x_hi_z_1_shift = View(in.x_hi_z_1_shift); + auto y_lo_z_2_shift = View(in.y_lo_z_2_shift); + auto lagrange_odd_in_minicircuit = View(in.lagrange_odd_in_minicircuit); + + // Contributions that decompose 50, 52, 68 or 84 bit limbs used for computation into range-constrained chunks + // Contribution 1 , P_x lowest limb decomposition + auto tmp_1 = ((p_x_low_limbs_range_constraint_0 + p_x_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + p_x_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + p_x_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + p_x_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + p_x_low_limbs); + tmp_1 *= lagrange_odd_in_minicircuit; + tmp_1 *= scaling_factor; + std::get<0>(accumulators) += tmp_1; + + // Contribution 2 , P_x second lowest limb decomposition + auto tmp_2 = ((p_x_low_limbs_range_constraint_0_shift + p_x_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + p_x_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + p_x_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + p_x_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + p_x_low_limbs_shift); + tmp_2 *= lagrange_odd_in_minicircuit; + tmp_2 *= scaling_factor; + std::get<1>(accumulators) += tmp_2; + + // Contribution 3 , P_x third limb decomposition + auto tmp_3 = ((p_x_high_limbs_range_constraint_0 + p_x_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + p_x_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + p_x_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + p_x_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + p_x_high_limbs); + tmp_3 *= lagrange_odd_in_minicircuit; + tmp_3 *= scaling_factor; + std::get<2>(accumulators) += tmp_3; + + // Contribution 4 , P_x highest limb decomposition + auto tmp_4 = + ((p_x_high_limbs_range_constraint_0_shift + p_x_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + p_x_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + p_x_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - + p_x_high_limbs_shift); + tmp_4 *= lagrange_odd_in_minicircuit; + tmp_4 *= scaling_factor; + std::get<3>(accumulators) += tmp_4; + + // Contribution 5 , P_y lowest limb decomposition + auto tmp_5 = ((p_y_low_limbs_range_constraint_0 + p_y_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + p_y_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + p_y_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + p_y_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + p_y_low_limbs); + tmp_5 *= lagrange_odd_in_minicircuit; + tmp_5 *= scaling_factor; + std::get<4>(accumulators) += tmp_5; + + // Contribution 6 , P_y second lowest limb decomposition + auto tmp_6 = ((p_y_low_limbs_range_constraint_0_shift + p_y_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + p_y_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + p_y_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + p_y_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + p_y_low_limbs_shift); + tmp_6 *= lagrange_odd_in_minicircuit; + tmp_6 *= scaling_factor; + std::get<5>(accumulators) += tmp_6; + + // Contribution 7 , P_y third limb decomposition + auto tmp_7 = ((p_y_high_limbs_range_constraint_0 + p_y_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + p_y_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + p_y_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + p_y_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + p_y_high_limbs); + tmp_7 *= lagrange_odd_in_minicircuit; + tmp_7 *= scaling_factor; + std::get<6>(accumulators) += tmp_7; + + // Contribution 8 , P_y highest limb decomposition + auto tmp_8 = + ((p_y_high_limbs_range_constraint_0_shift + p_y_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + p_y_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + p_y_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - + p_y_high_limbs_shift); + tmp_8 *= lagrange_odd_in_minicircuit; + tmp_8 *= scaling_factor; + std::get<7>(accumulators) += tmp_8; + + // Contribution 9 , z_1 low limb decomposition + auto tmp_9 = + ((z_low_limbs_range_constraint_0 + z_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + z_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + z_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + z_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + z_low_limbs); + tmp_9 *= lagrange_odd_in_minicircuit; + tmp_9 *= scaling_factor; + std::get<8>(accumulators) += tmp_9; + + // Contribution 10 , z_2 low limb decomposition + auto tmp_10 = ((z_low_limbs_range_constraint_0_shift + z_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + z_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + z_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + z_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + z_low_limbs_shift); + tmp_10 *= lagrange_odd_in_minicircuit; + tmp_10 *= scaling_factor; + std::get<9>(accumulators) += tmp_10; + + // Contribution 11 , z_1 high limb decomposition + auto tmp_11 = + ((z_high_limbs_range_constraint_0 + z_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + z_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + z_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + z_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + z_high_limbs); + tmp_11 *= lagrange_odd_in_minicircuit; + tmp_11 *= scaling_factor; + std::get<10>(accumulators) += tmp_11; + + // Contribution 12 , z_2 high limb decomposition + auto tmp_12 = ((z_high_limbs_range_constraint_0_shift + z_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + z_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + z_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + z_high_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + z_high_limbs_shift); + tmp_12 *= lagrange_odd_in_minicircuit; + tmp_12 *= scaling_factor; + std::get<11>(accumulators) += tmp_12; + + // Contribution 13 , accumulator lowest limb decomposition + auto tmp_13 = + ((accumulator_low_limbs_range_constraint_0 + accumulator_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + accumulator_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + accumulator_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + accumulator_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + accumulators_binary_limbs_0); + tmp_13 *= lagrange_odd_in_minicircuit; + tmp_13 *= scaling_factor; + std::get<12>(accumulators) += tmp_13; + // Contribution 14 , accumulator second limb decomposition + auto tmp_14 = ((accumulator_low_limbs_range_constraint_0_shift + + accumulator_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + accumulator_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + accumulator_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + accumulator_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + accumulators_binary_limbs_1); + tmp_14 *= lagrange_odd_in_minicircuit; + tmp_14 *= scaling_factor; + std::get<13>(accumulators) += tmp_14; + + // Contribution 15 , accumulator second highest limb decomposition + auto tmp_15 = + ((accumulator_high_limbs_range_constraint_0 + accumulator_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + accumulator_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + accumulator_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + accumulator_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + accumulators_binary_limbs_2); + tmp_15 *= lagrange_odd_in_minicircuit; + tmp_15 *= scaling_factor; + std::get<14>(accumulators) += tmp_15; + // Contribution 16 , accumulator highest limb decomposition + auto tmp_16 = ((accumulator_high_limbs_range_constraint_0_shift + + accumulator_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + accumulator_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + accumulator_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - + accumulators_binary_limbs_3); + tmp_16 *= lagrange_odd_in_minicircuit; + tmp_16 *= scaling_factor; + std::get<15>(accumulators) += tmp_16; + + // Contribution 15 , quotient lowest limb decomposition + auto tmp_17 = ((quotient_low_limbs_range_constraint_0 + quotient_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + quotient_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + quotient_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + quotient_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + quotient_low_binary_limbs); + tmp_17 *= lagrange_odd_in_minicircuit; + tmp_17 *= scaling_factor; + std::get<16>(accumulators) += tmp_17; + // Contribution 16 , quotient second lowest limb decomposition + auto tmp_18 = + ((quotient_low_limbs_range_constraint_0_shift + quotient_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + quotient_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + quotient_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + quotient_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - + quotient_low_binary_limbs_shift); + tmp_18 *= lagrange_odd_in_minicircuit; + tmp_18 *= scaling_factor; + std::get<17>(accumulators) += tmp_18; + + // Contribution 19 , quotient second highest limb decomposition + auto tmp_19 = ((quotient_high_limbs_range_constraint_0 + quotient_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + quotient_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + quotient_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + quotient_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - + quotient_high_binary_limbs); + tmp_19 *= lagrange_odd_in_minicircuit; + tmp_19 *= scaling_factor; + std::get<18>(accumulators) += tmp_19; + // Contribution 20 , quotient highest limb decomposition + auto tmp_20 = ((quotient_high_limbs_range_constraint_0_shift + + quotient_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + quotient_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + quotient_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - + quotient_high_binary_limbs_shift); + tmp_20 *= lagrange_odd_in_minicircuit; + tmp_20 *= scaling_factor; + std::get<19>(accumulators) += tmp_20; + + // Contribution 21 , decomposition of the low wide relation limb used for the bigfield relation. + // N.B. top microlimbs of relation wide limbs are stored in microlimbs for range constraints of P_x, P_y, + // accumulator and quotient. This is to save space and because these microlimbs are not used by their namesakes, + // since top limbs in 254/6-bit values use one less microlimb for the top 50/52-bit limb + auto tmp_21 = ((relation_wide_limbs_range_constraint_0 + relation_wide_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + + relation_wide_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + + relation_wide_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + + p_x_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx4 + + accumulator_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx5) - + relation_wide_limbs); + tmp_21 *= lagrange_odd_in_minicircuit; + tmp_21 *= scaling_factor; + std::get<20>(accumulators) += tmp_21; + + // Contribution 22 , decomposition of high relation limb + auto tmp_22 = ((relation_wide_limbs_range_constraint_0_shift + + relation_wide_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + + relation_wide_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + + relation_wide_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + + p_y_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx4 + + quotient_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx5) - + relation_wide_limbs_shift); + tmp_22 *= lagrange_odd_in_minicircuit; + tmp_22 *= scaling_factor; + std::get<21>(accumulators) += tmp_22; + + // Contributions enfocing a reduced range constraint on high limbs (these relation force the last microlimb in + // each limb to be more severely range constrained) + + // Contribution 23, range constrain the highest microlimb of lowest P.x limb to be 12 bits (68 % 14 = 12) + auto tmp_23 = p_x_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_x_low_limbs_range_constraint_tail; + tmp_23 *= lagrange_odd_in_minicircuit; + tmp_23 *= scaling_factor; + std::get<22>(accumulators) += tmp_23; + + // Contribution 24, range constrain the highest microlimb of second lowest P.x limb to be 12 bits + auto tmp_24 = p_x_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - p_x_low_limbs_range_constraint_tail_shift; + tmp_24 *= lagrange_odd_in_minicircuit; + tmp_24 *= scaling_factor; + std::get<23>(accumulators) += tmp_24; + + // Contribution 25, range constrain the highest microlimb of second highest P.x limb to be 12 bits + auto tmp_25 = p_x_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_x_high_limbs_range_constraint_tail; + tmp_25 *= lagrange_odd_in_minicircuit; + tmp_25 *= scaling_factor; + std::get<24>(accumulators) += tmp_25; + + // Contribution 26, range constrain the highest microilmb of highest P.x limb to be 8 bits (50 % 14 = 8) + auto tmp_26 = (p_x_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - p_x_high_limbs_range_constraint_4_shift); + + tmp_26 *= lagrange_odd_in_minicircuit; + tmp_26 *= scaling_factor; + std::get<25>(accumulators) += tmp_26; + + // Contribution 27, range constrain the highest microlimb of lowest P.y limb to be 12 bits (68 % 14 = 12) + auto tmp_27 = p_y_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_y_low_limbs_range_constraint_tail; + tmp_27 *= lagrange_odd_in_minicircuit; + tmp_27 *= scaling_factor; + std::get<26>(accumulators) += tmp_27; + + // Contribution 28, range constrain the highest microlimb of second lowest P.y limb to be 12 bits (68 % 14 = 12) + auto tmp_28 = p_y_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - p_y_low_limbs_range_constraint_tail_shift; + tmp_28 *= lagrange_odd_in_minicircuit; + tmp_28 *= scaling_factor; + std::get<27>(accumulators) += tmp_28; + + // Contribution 29, range constrain the highest microlimb of second highest P.y limb to be 12 bits (68 % 14 = + // 12) + auto tmp_29 = p_y_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_y_high_limbs_range_constraint_tail; + tmp_29 *= lagrange_odd_in_minicircuit; + tmp_29 *= scaling_factor; + std::get<28>(accumulators) += tmp_29; + + // Contribution 30, range constrain the highest microlimb of highest P.y limb to be 8 bits (50 % 14 = 8) + auto tmp_30 = (p_y_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - p_y_high_limbs_range_constraint_4_shift); + + tmp_30 *= lagrange_odd_in_minicircuit; + tmp_30 *= scaling_factor; + std::get<29>(accumulators) += tmp_30; + + // Contribution 31, range constrain the highest microlimb of low z1 limb to be 12 bits (68 % 14 = 12) + auto tmp_31 = (z_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - z_low_limbs_range_constraint_tail); + tmp_31 *= lagrange_odd_in_minicircuit; + tmp_31 *= scaling_factor; + std::get<30>(accumulators) += tmp_31; + + // Contribution 32, range constrain the highest microlimb of low z2 limb to be 12 bits (68 % 14 = 12) + auto tmp_32 = (z_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - z_low_limbs_range_constraint_tail_shift); + tmp_32 *= lagrange_odd_in_minicircuit; + tmp_32 *= scaling_factor; + std::get<31>(accumulators) += tmp_32; + + // Contribution 33, range constrain the highest microlimb of high z1 limb to be 4 bits (60 % 14 = 12) + auto tmp_33 = (z_high_limbs_range_constraint_4 * SHIFT_4_TO_14 - z_high_limbs_range_constraint_tail); + tmp_33 *= lagrange_odd_in_minicircuit; + tmp_33 *= scaling_factor; + std::get<32>(accumulators) += tmp_33; + + // Contribution 34, range constrain the highest microlimb of high z2 limb to be 4 bits (60 % 14 = 12) + auto tmp_34 = (z_high_limbs_range_constraint_4_shift * SHIFT_4_TO_14 - z_high_limbs_range_constraint_tail_shift); + tmp_34 *= lagrange_odd_in_minicircuit; + tmp_34 *= scaling_factor; + std::get<33>(accumulators) += tmp_34; + + // Contribution 35, range constrain the highest microlimb of lowest current accumulator limb to be 12 bits (68 % + // 14 = 12) + auto tmp_35 = + (accumulator_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - accumulator_low_limbs_range_constraint_tail); + tmp_35 *= lagrange_odd_in_minicircuit; + tmp_35 *= scaling_factor; + std::get<34>(accumulators) += tmp_35; + + // Contribution 36, range constrain the highest microlimb of second lowest current accumulator limb to be 12 + // bits (68 % 14 = 12) + auto tmp_36 = (accumulator_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - + accumulator_low_limbs_range_constraint_tail_shift); + tmp_36 *= lagrange_odd_in_minicircuit; + tmp_36 *= scaling_factor; + std::get<35>(accumulators) += tmp_36; + + // Contribution 37, range constrain the highest microlimb of second highest current accumulator limb to be 12 + // bits (68 % 14 = 12) + auto tmp_37 = + (accumulator_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - accumulator_high_limbs_range_constraint_tail); + tmp_37 *= lagrange_odd_in_minicircuit; + tmp_37 *= scaling_factor; + std::get<36>(accumulators) += tmp_37; + + // Contribution 38, range constrain the highest microlimb of highest current accumulator limb to be 8 bits (50 % + // 14 = 12) + auto tmp_38 = (accumulator_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - + accumulator_high_limbs_range_constraint_4_shift); + tmp_38 *= lagrange_odd_in_minicircuit; + tmp_38 *= scaling_factor; + std::get<37>(accumulators) += tmp_38; + + // Contribution 39, range constrain the highest microlimb of lowest quotient limb to be 12 bits (68 % 14 = 12) + auto tmp_39 = (quotient_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - quotient_low_limbs_range_constraint_tail); + tmp_39 *= lagrange_odd_in_minicircuit; + tmp_39 *= scaling_factor; + std::get<38>(accumulators) += tmp_39; + + // Contribution 40, range constrain the highest microlimb of second lowest quotient limb to be 12 bits (68 % 14 + // = 12) + auto tmp_40 = + (quotient_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - quotient_low_limbs_range_constraint_tail_shift); + tmp_40 *= lagrange_odd_in_minicircuit; + tmp_40 *= scaling_factor; + std::get<39>(accumulators) += tmp_40; + + // Contribution 41, range constrain the highest microlimb of second highest quotient limb to be 12 bits (68 % 14 + // = 12) + auto tmp_41 = (quotient_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - quotient_high_limbs_range_constraint_tail); + tmp_41 *= lagrange_odd_in_minicircuit; + tmp_41 *= scaling_factor; + std::get<40>(accumulators) += tmp_41; + + // Contribution 42, range constrain the highest microlimb of highest quotient limb to be 10 bits (52 % 14 = 12) + auto tmp_42 = + (quotient_high_limbs_range_constraint_3_shift * SHIFT_10_TO_14 - quotient_high_limbs_range_constraint_4_shift); + tmp_42 *= lagrange_odd_in_minicircuit; + tmp_42 *= scaling_factor; + std::get<41>(accumulators) += tmp_42; + + // Contributions where we decompose initial EccOpQueue values into 68-bit limbs + + // Contribution 43, decompose x_lo + auto tmp_43 = (p_x_low_limbs + p_x_low_limbs_shift * LIMB_SHIFT) - x_lo_y_hi; + tmp_43 *= lagrange_odd_in_minicircuit; + tmp_43 *= scaling_factor; + std::get<42>(accumulators) += tmp_43; + + // Contribution 44, decompose x_hi + auto tmp_44 = (p_x_high_limbs + p_x_high_limbs_shift * LIMB_SHIFT) - x_hi_z_1; + tmp_44 *= lagrange_odd_in_minicircuit; + tmp_44 *= scaling_factor; + std::get<43>(accumulators) += tmp_44; + // Contribution 45, decompose y_lo + auto tmp_45 = (p_y_low_limbs + p_y_low_limbs_shift * LIMB_SHIFT) - y_lo_z_2; + tmp_45 *= lagrange_odd_in_minicircuit; + tmp_45 *= scaling_factor; + std::get<44>(accumulators) += tmp_45; + + // Contribution 46, decompose y_hi + auto tmp_46 = (p_y_high_limbs + p_y_high_limbs_shift * LIMB_SHIFT) - x_lo_y_hi_shift; + tmp_46 *= lagrange_odd_in_minicircuit; + tmp_46 *= scaling_factor; + std::get<45>(accumulators) += tmp_46; + + // Contribution 47, decompose z1 + auto tmp_47 = (z_low_limbs + z_high_limbs * LIMB_SHIFT) - x_hi_z_1_shift; + tmp_47 *= lagrange_odd_in_minicircuit; + tmp_47 *= scaling_factor; + std::get<46>(accumulators) += tmp_47; + + // Contribution 48, decompose z2 + auto tmp_48 = (z_low_limbs_shift + z_high_limbs_shift * LIMB_SHIFT) - y_lo_z_2_shift; + tmp_48 *= lagrange_odd_in_minicircuit; + tmp_48 *= scaling_factor; + std::get<47>(accumulators) += tmp_48; +}; + +template class GoblinTranslatorDecompositionRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorDecompositionRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp index 7eaccc85380..5f12ead3613 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_decomposition_relation.hpp @@ -81,613 +81,10 @@ template class GoblinTranslatorDecompositionRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters&, - const FF& scaling_factor) - { - static constexpr size_t NUM_LIMB_BITS = 68; // Number of bits in a standard limb used for bigfield operations - static constexpr size_t NUM_MICRO_LIMB_BITS = - 14; // Number of bits in a standard limb used for bigfield operations - - // Value to multiply an element by to perform an appropriate shift - static constexpr auto LIMB_SHIFT = FF(uint256_t(1) << NUM_LIMB_BITS); - - // Values to multiply an element by to perform an appropriate shift - static constexpr auto MICRO_LIMB_SHIFT = FF(uint256_t(1) << NUM_MICRO_LIMB_BITS); - static constexpr auto MICRO_LIMB_SHIFTx2 = MICRO_LIMB_SHIFT * MICRO_LIMB_SHIFT; - static constexpr auto MICRO_LIMB_SHIFTx3 = MICRO_LIMB_SHIFTx2 * MICRO_LIMB_SHIFT; - static constexpr auto MICRO_LIMB_SHIFTx4 = MICRO_LIMB_SHIFTx3 * MICRO_LIMB_SHIFT; - static constexpr auto MICRO_LIMB_SHIFTx5 = MICRO_LIMB_SHIFTx4 * MICRO_LIMB_SHIFT; - - // Shifts used to constrain ranges further - static constexpr auto SHIFT_12_TO_14 = - FF(4); // Shift used to range constrain the last microlimb of 68-bit limbs (standard limbs) - static constexpr auto SHIFT_10_TO_14 = - FF(16); // Shift used to range constrain the last microlimb of 52-bit limb (top quotient limb) - static constexpr auto SHIFT_8_TO_14 = FF(64); // Shift used to range constrain the last microlimb of 50-bit - // limbs (top limb of standard 254-bit value) - static constexpr auto SHIFT_4_TO_14 = - FF(1024); // Shift used to range constrain the last mircrolimb of 60-bit limbs from z scalars - - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - auto p_x_low_limbs = View(in.p_x_low_limbs); - 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_low_limbs_shift = View(in.p_x_low_limbs_shift); - auto p_x_low_limbs_range_constraint_0_shift = View(in.p_x_low_limbs_range_constraint_0_shift); - auto p_x_low_limbs_range_constraint_1_shift = View(in.p_x_low_limbs_range_constraint_1_shift); - auto p_x_low_limbs_range_constraint_2_shift = View(in.p_x_low_limbs_range_constraint_2_shift); - auto p_x_low_limbs_range_constraint_3_shift = View(in.p_x_low_limbs_range_constraint_3_shift); - auto p_x_low_limbs_range_constraint_4_shift = View(in.p_x_low_limbs_range_constraint_4_shift); - auto p_x_high_limbs = View(in.p_x_high_limbs); - 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_x_high_limbs_shift = View(in.p_x_high_limbs_shift); - auto p_x_high_limbs_range_constraint_0_shift = View(in.p_x_high_limbs_range_constraint_0_shift); - auto p_x_high_limbs_range_constraint_1_shift = View(in.p_x_high_limbs_range_constraint_1_shift); - auto p_x_high_limbs_range_constraint_2_shift = View(in.p_x_high_limbs_range_constraint_2_shift); - auto p_x_high_limbs_range_constraint_3_shift = View(in.p_x_high_limbs_range_constraint_3_shift); - auto p_y_low_limbs = View(in.p_y_low_limbs); - 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_low_limbs_shift = View(in.p_y_low_limbs_shift); - auto p_y_low_limbs_range_constraint_0_shift = View(in.p_y_low_limbs_range_constraint_0_shift); - auto p_y_low_limbs_range_constraint_1_shift = View(in.p_y_low_limbs_range_constraint_1_shift); - auto p_y_low_limbs_range_constraint_2_shift = View(in.p_y_low_limbs_range_constraint_2_shift); - auto p_y_low_limbs_range_constraint_3_shift = View(in.p_y_low_limbs_range_constraint_3_shift); - auto p_y_low_limbs_range_constraint_4_shift = View(in.p_y_low_limbs_range_constraint_4_shift); - auto p_y_high_limbs = View(in.p_y_high_limbs); - 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 p_y_high_limbs_shift = View(in.p_y_high_limbs_shift); - auto p_y_high_limbs_range_constraint_0_shift = View(in.p_y_high_limbs_range_constraint_0_shift); - auto p_y_high_limbs_range_constraint_1_shift = View(in.p_y_high_limbs_range_constraint_1_shift); - auto p_y_high_limbs_range_constraint_2_shift = View(in.p_y_high_limbs_range_constraint_2_shift); - auto p_y_high_limbs_range_constraint_3_shift = View(in.p_y_high_limbs_range_constraint_3_shift); - auto z_low_limbs = View(in.z_low_limbs); - 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_low_limbs_shift = View(in.z_low_limbs_shift); - auto z_low_limbs_range_constraint_0_shift = View(in.z_low_limbs_range_constraint_0_shift); - auto z_low_limbs_range_constraint_1_shift = View(in.z_low_limbs_range_constraint_1_shift); - auto z_low_limbs_range_constraint_2_shift = View(in.z_low_limbs_range_constraint_2_shift); - auto z_low_limbs_range_constraint_3_shift = View(in.z_low_limbs_range_constraint_3_shift); - auto z_low_limbs_range_constraint_4_shift = View(in.z_low_limbs_range_constraint_4_shift); - auto z_high_limbs = View(in.z_high_limbs); - 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 z_high_limbs_shift = View(in.z_high_limbs_shift); - auto z_high_limbs_range_constraint_0_shift = View(in.z_high_limbs_range_constraint_0_shift); - auto z_high_limbs_range_constraint_1_shift = View(in.z_high_limbs_range_constraint_1_shift); - auto z_high_limbs_range_constraint_2_shift = View(in.z_high_limbs_range_constraint_2_shift); - auto z_high_limbs_range_constraint_3_shift = View(in.z_high_limbs_range_constraint_3_shift); - auto z_high_limbs_range_constraint_4_shift = View(in.z_high_limbs_range_constraint_4_shift); - auto accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); - auto accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); - auto accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); - auto accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); - 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_low_limbs_range_constraint_0_shift = View(in.accumulator_low_limbs_range_constraint_0_shift); - auto accumulator_low_limbs_range_constraint_1_shift = View(in.accumulator_low_limbs_range_constraint_1_shift); - auto accumulator_low_limbs_range_constraint_2_shift = View(in.accumulator_low_limbs_range_constraint_2_shift); - auto accumulator_low_limbs_range_constraint_3_shift = View(in.accumulator_low_limbs_range_constraint_3_shift); - auto accumulator_low_limbs_range_constraint_4_shift = View(in.accumulator_low_limbs_range_constraint_4_shift); - 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 accumulator_high_limbs_range_constraint_0_shift = View(in.accumulator_high_limbs_range_constraint_0_shift); - auto accumulator_high_limbs_range_constraint_1_shift = View(in.accumulator_high_limbs_range_constraint_1_shift); - auto accumulator_high_limbs_range_constraint_2_shift = View(in.accumulator_high_limbs_range_constraint_2_shift); - auto accumulator_high_limbs_range_constraint_3_shift = View(in.accumulator_high_limbs_range_constraint_3_shift); - auto quotient_low_binary_limbs = View(in.quotient_low_binary_limbs); - 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_low_binary_limbs_shift = View(in.quotient_low_binary_limbs_shift); - auto quotient_low_limbs_range_constraint_0_shift = View(in.quotient_low_limbs_range_constraint_0_shift); - auto quotient_low_limbs_range_constraint_1_shift = View(in.quotient_low_limbs_range_constraint_1_shift); - auto quotient_low_limbs_range_constraint_2_shift = View(in.quotient_low_limbs_range_constraint_2_shift); - auto quotient_low_limbs_range_constraint_3_shift = View(in.quotient_low_limbs_range_constraint_3_shift); - auto quotient_low_limbs_range_constraint_4_shift = View(in.quotient_low_limbs_range_constraint_4_shift); - auto quotient_high_binary_limbs = View(in.quotient_high_binary_limbs); - 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 quotient_high_binary_limbs_shift = View(in.quotient_high_binary_limbs_shift); - auto quotient_high_limbs_range_constraint_0_shift = View(in.quotient_high_limbs_range_constraint_0_shift); - auto quotient_high_limbs_range_constraint_1_shift = View(in.quotient_high_limbs_range_constraint_1_shift); - auto quotient_high_limbs_range_constraint_2_shift = View(in.quotient_high_limbs_range_constraint_2_shift); - auto quotient_high_limbs_range_constraint_3_shift = View(in.quotient_high_limbs_range_constraint_3_shift); - auto relation_wide_limbs = View(in.relation_wide_limbs); - 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_high_limbs_range_constraint_tail_shift = View(in.p_x_high_limbs_range_constraint_tail_shift); - auto accumulator_high_limbs_range_constraint_tail_shift = - View(in.accumulator_high_limbs_range_constraint_tail_shift); - auto relation_wide_limbs_shift = View(in.relation_wide_limbs_shift); - auto relation_wide_limbs_range_constraint_0_shift = View(in.relation_wide_limbs_range_constraint_0_shift); - auto relation_wide_limbs_range_constraint_1_shift = View(in.relation_wide_limbs_range_constraint_1_shift); - auto relation_wide_limbs_range_constraint_2_shift = View(in.relation_wide_limbs_range_constraint_2_shift); - auto relation_wide_limbs_range_constraint_3_shift = View(in.relation_wide_limbs_range_constraint_3_shift); - auto p_y_high_limbs_range_constraint_tail_shift = View(in.p_y_high_limbs_range_constraint_tail_shift); - auto quotient_high_limbs_range_constraint_tail_shift = View(in.quotient_high_limbs_range_constraint_tail_shift); - auto p_x_low_limbs_range_constraint_tail = View(in.p_x_low_limbs_range_constraint_tail); - auto p_x_low_limbs_range_constraint_tail_shift = View(in.p_x_low_limbs_range_constraint_tail_shift); - auto p_x_high_limbs_range_constraint_tail = View(in.p_x_high_limbs_range_constraint_tail); - auto p_x_high_limbs_range_constraint_4_shift = View(in.p_x_high_limbs_range_constraint_4_shift); - auto p_y_low_limbs_range_constraint_tail = View(in.p_y_low_limbs_range_constraint_tail); - auto p_y_low_limbs_range_constraint_tail_shift = View(in.p_y_low_limbs_range_constraint_tail_shift); - auto p_y_high_limbs_range_constraint_tail = View(in.p_y_high_limbs_range_constraint_tail); - auto p_y_high_limbs_range_constraint_4_shift = View(in.p_y_high_limbs_range_constraint_4_shift); - auto z_low_limbs_range_constraint_tail = View(in.z_low_limbs_range_constraint_tail); - auto z_low_limbs_range_constraint_tail_shift = View(in.z_low_limbs_range_constraint_tail_shift); - auto z_high_limbs_range_constraint_tail = View(in.z_high_limbs_range_constraint_tail); - auto z_high_limbs_range_constraint_tail_shift = View(in.z_high_limbs_range_constraint_tail_shift); - auto accumulator_low_limbs_range_constraint_tail = View(in.accumulator_low_limbs_range_constraint_tail); - auto accumulator_low_limbs_range_constraint_tail_shift = - View(in.accumulator_low_limbs_range_constraint_tail_shift); - auto accumulator_high_limbs_range_constraint_tail = View(in.accumulator_high_limbs_range_constraint_tail); - auto accumulator_high_limbs_range_constraint_4_shift = View(in.accumulator_high_limbs_range_constraint_4_shift); - auto quotient_low_limbs_range_constraint_tail = View(in.quotient_low_limbs_range_constraint_tail); - auto quotient_low_limbs_range_constraint_tail_shift = View(in.quotient_low_limbs_range_constraint_tail_shift); - auto quotient_high_limbs_range_constraint_tail = View(in.quotient_high_limbs_range_constraint_tail); - auto quotient_high_limbs_range_constraint_4_shift = View(in.quotient_high_limbs_range_constraint_4_shift); - auto x_lo_y_hi = View(in.x_lo_y_hi); - auto x_hi_z_1 = View(in.x_hi_z_1); - auto y_lo_z_2 = View(in.y_lo_z_2); - auto x_lo_y_hi_shift = View(in.x_lo_y_hi_shift); - auto x_hi_z_1_shift = View(in.x_hi_z_1_shift); - auto y_lo_z_2_shift = View(in.y_lo_z_2_shift); - auto lagrange_odd_in_minicircuit = View(in.lagrange_odd_in_minicircuit); - - // Contributions that decompose 50, 52, 68 or 84 bit limbs used for computation into range-constrained chunks - // Contribution 1 , P_x lowest limb decomposition - auto tmp_1 = ((p_x_low_limbs_range_constraint_0 + p_x_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - p_x_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - p_x_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - p_x_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - p_x_low_limbs); - tmp_1 *= lagrange_odd_in_minicircuit; - tmp_1 *= scaling_factor; - std::get<0>(accumulators) += tmp_1; - - // Contribution 2 , P_x second lowest limb decomposition - auto tmp_2 = - ((p_x_low_limbs_range_constraint_0_shift + p_x_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - p_x_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - p_x_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - p_x_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - p_x_low_limbs_shift); - tmp_2 *= lagrange_odd_in_minicircuit; - tmp_2 *= scaling_factor; - std::get<1>(accumulators) += tmp_2; - - // Contribution 3 , P_x third limb decomposition - auto tmp_3 = ((p_x_high_limbs_range_constraint_0 + p_x_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - p_x_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - p_x_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - p_x_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - p_x_high_limbs); - tmp_3 *= lagrange_odd_in_minicircuit; - tmp_3 *= scaling_factor; - std::get<2>(accumulators) += tmp_3; - - // Contribution 4 , P_x highest limb decomposition - auto tmp_4 = - ((p_x_high_limbs_range_constraint_0_shift + p_x_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - p_x_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - p_x_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - - p_x_high_limbs_shift); - tmp_4 *= lagrange_odd_in_minicircuit; - tmp_4 *= scaling_factor; - std::get<3>(accumulators) += tmp_4; - - // Contribution 5 , P_y lowest limb decomposition - auto tmp_5 = ((p_y_low_limbs_range_constraint_0 + p_y_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - p_y_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - p_y_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - p_y_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - p_y_low_limbs); - tmp_5 *= lagrange_odd_in_minicircuit; - tmp_5 *= scaling_factor; - std::get<4>(accumulators) += tmp_5; - - // Contribution 6 , P_y second lowest limb decomposition - auto tmp_6 = - ((p_y_low_limbs_range_constraint_0_shift + p_y_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - p_y_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - p_y_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - p_y_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - p_y_low_limbs_shift); - tmp_6 *= lagrange_odd_in_minicircuit; - tmp_6 *= scaling_factor; - std::get<5>(accumulators) += tmp_6; - - // Contribution 7 , P_y third limb decomposition - auto tmp_7 = ((p_y_high_limbs_range_constraint_0 + p_y_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - p_y_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - p_y_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - p_y_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - p_y_high_limbs); - tmp_7 *= lagrange_odd_in_minicircuit; - tmp_7 *= scaling_factor; - std::get<6>(accumulators) += tmp_7; - - // Contribution 8 , P_y highest limb decomposition - auto tmp_8 = - ((p_y_high_limbs_range_constraint_0_shift + p_y_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - p_y_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - p_y_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - - p_y_high_limbs_shift); - tmp_8 *= lagrange_odd_in_minicircuit; - tmp_8 *= scaling_factor; - std::get<7>(accumulators) += tmp_8; - - // Contribution 9 , z_1 low limb decomposition - auto tmp_9 = ((z_low_limbs_range_constraint_0 + z_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - z_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - z_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - z_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - z_low_limbs); - tmp_9 *= lagrange_odd_in_minicircuit; - tmp_9 *= scaling_factor; - std::get<8>(accumulators) += tmp_9; - - // Contribution 10 , z_2 low limb decomposition - auto tmp_10 = ((z_low_limbs_range_constraint_0_shift + z_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - z_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - z_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - z_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - z_low_limbs_shift); - tmp_10 *= lagrange_odd_in_minicircuit; - tmp_10 *= scaling_factor; - std::get<9>(accumulators) += tmp_10; - - // Contribution 11 , z_1 high limb decomposition - auto tmp_11 = ((z_high_limbs_range_constraint_0 + z_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - z_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - z_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - z_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - z_high_limbs); - tmp_11 *= lagrange_odd_in_minicircuit; - tmp_11 *= scaling_factor; - std::get<10>(accumulators) += tmp_11; - - // Contribution 12 , z_2 high limb decomposition - auto tmp_12 = - ((z_high_limbs_range_constraint_0_shift + z_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - z_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - z_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - z_high_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - z_high_limbs_shift); - tmp_12 *= lagrange_odd_in_minicircuit; - tmp_12 *= scaling_factor; - std::get<11>(accumulators) += tmp_12; - - // Contribution 13 , accumulator lowest limb decomposition - auto tmp_13 = - ((accumulator_low_limbs_range_constraint_0 + accumulator_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - accumulator_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - accumulator_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - accumulator_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - accumulators_binary_limbs_0); - tmp_13 *= lagrange_odd_in_minicircuit; - tmp_13 *= scaling_factor; - std::get<12>(accumulators) += tmp_13; - // Contribution 14 , accumulator second limb decomposition - auto tmp_14 = ((accumulator_low_limbs_range_constraint_0_shift + - accumulator_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - accumulator_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - accumulator_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - accumulator_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - accumulators_binary_limbs_1); - tmp_14 *= lagrange_odd_in_minicircuit; - tmp_14 *= scaling_factor; - std::get<13>(accumulators) += tmp_14; - - // Contribution 15 , accumulator second highest limb decomposition - auto tmp_15 = - ((accumulator_high_limbs_range_constraint_0 + accumulator_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - accumulator_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - accumulator_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - accumulator_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - accumulators_binary_limbs_2); - tmp_15 *= lagrange_odd_in_minicircuit; - tmp_15 *= scaling_factor; - std::get<14>(accumulators) += tmp_15; - // Contribution 16 , accumulator highest limb decomposition - auto tmp_16 = ((accumulator_high_limbs_range_constraint_0_shift + - accumulator_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - accumulator_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - accumulator_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - - accumulators_binary_limbs_3); - tmp_16 *= lagrange_odd_in_minicircuit; - tmp_16 *= scaling_factor; - std::get<15>(accumulators) += tmp_16; - - // Contribution 15 , quotient lowest limb decomposition - auto tmp_17 = - ((quotient_low_limbs_range_constraint_0 + quotient_low_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - quotient_low_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - quotient_low_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - quotient_low_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - quotient_low_binary_limbs); - tmp_17 *= lagrange_odd_in_minicircuit; - tmp_17 *= scaling_factor; - std::get<16>(accumulators) += tmp_17; - // Contribution 16 , quotient second lowest limb decomposition - auto tmp_18 = ((quotient_low_limbs_range_constraint_0_shift + - quotient_low_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - quotient_low_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - quotient_low_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - quotient_low_limbs_range_constraint_4_shift * MICRO_LIMB_SHIFTx4) - - quotient_low_binary_limbs_shift); - tmp_18 *= lagrange_odd_in_minicircuit; - tmp_18 *= scaling_factor; - std::get<17>(accumulators) += tmp_18; - - // Contribution 19 , quotient second highest limb decomposition - auto tmp_19 = - ((quotient_high_limbs_range_constraint_0 + quotient_high_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - quotient_high_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - quotient_high_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - quotient_high_limbs_range_constraint_4 * MICRO_LIMB_SHIFTx4) - - quotient_high_binary_limbs); - tmp_19 *= lagrange_odd_in_minicircuit; - tmp_19 *= scaling_factor; - std::get<18>(accumulators) += tmp_19; - // Contribution 20 , quotient highest limb decomposition - auto tmp_20 = ((quotient_high_limbs_range_constraint_0_shift + - quotient_high_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - quotient_high_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - quotient_high_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3) - - quotient_high_binary_limbs_shift); - tmp_20 *= lagrange_odd_in_minicircuit; - tmp_20 *= scaling_factor; - std::get<19>(accumulators) += tmp_20; - - // Contribution 21 , decomposition of the low wide relation limb used for the bigfield relation. - // N.B. top microlimbs of relation wide limbs are stored in microlimbs for range constraints of P_x, P_y, - // accumulator and quotient. This is to save space and because these microlimbs are not used by their namesakes, - // since top limbs in 254/6-bit values use one less microlimb for the top 50/52-bit limb - auto tmp_21 = - ((relation_wide_limbs_range_constraint_0 + relation_wide_limbs_range_constraint_1 * MICRO_LIMB_SHIFT + - relation_wide_limbs_range_constraint_2 * MICRO_LIMB_SHIFTx2 + - relation_wide_limbs_range_constraint_3 * MICRO_LIMB_SHIFTx3 + - p_x_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx4 + - accumulator_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx5) - - relation_wide_limbs); - tmp_21 *= lagrange_odd_in_minicircuit; - tmp_21 *= scaling_factor; - std::get<20>(accumulators) += tmp_21; - - // Contribution 22 , decomposition of high relation limb - auto tmp_22 = ((relation_wide_limbs_range_constraint_0_shift + - relation_wide_limbs_range_constraint_1_shift * MICRO_LIMB_SHIFT + - relation_wide_limbs_range_constraint_2_shift * MICRO_LIMB_SHIFTx2 + - relation_wide_limbs_range_constraint_3_shift * MICRO_LIMB_SHIFTx3 + - p_y_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx4 + - quotient_high_limbs_range_constraint_tail_shift * MICRO_LIMB_SHIFTx5) - - relation_wide_limbs_shift); - tmp_22 *= lagrange_odd_in_minicircuit; - tmp_22 *= scaling_factor; - std::get<21>(accumulators) += tmp_22; - - // Contributions enfocing a reduced range constraint on high limbs (these relation force the last microlimb in - // each limb to be more severely range constrained) - - // Contribution 23, range constrain the highest microlimb of lowest P.x limb to be 12 bits (68 % 14 = 12) - auto tmp_23 = p_x_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_x_low_limbs_range_constraint_tail; - tmp_23 *= lagrange_odd_in_minicircuit; - tmp_23 *= scaling_factor; - std::get<22>(accumulators) += tmp_23; - - // Contribution 24, range constrain the highest microlimb of second lowest P.x limb to be 12 bits - auto tmp_24 = - p_x_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - p_x_low_limbs_range_constraint_tail_shift; - tmp_24 *= lagrange_odd_in_minicircuit; - tmp_24 *= scaling_factor; - std::get<23>(accumulators) += tmp_24; - - // Contribution 25, range constrain the highest microlimb of second highest P.x limb to be 12 bits - auto tmp_25 = p_x_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_x_high_limbs_range_constraint_tail; - tmp_25 *= lagrange_odd_in_minicircuit; - tmp_25 *= scaling_factor; - std::get<24>(accumulators) += tmp_25; - - // Contribution 26, range constrain the highest microilmb of highest P.x limb to be 8 bits (50 % 14 = 8) - auto tmp_26 = - (p_x_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - p_x_high_limbs_range_constraint_4_shift); - - tmp_26 *= lagrange_odd_in_minicircuit; - tmp_26 *= scaling_factor; - std::get<25>(accumulators) += tmp_26; - - // Contribution 27, range constrain the highest microlimb of lowest P.y limb to be 12 bits (68 % 14 = 12) - auto tmp_27 = p_y_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_y_low_limbs_range_constraint_tail; - tmp_27 *= lagrange_odd_in_minicircuit; - tmp_27 *= scaling_factor; - std::get<26>(accumulators) += tmp_27; - - // Contribution 28, range constrain the highest microlimb of second lowest P.y limb to be 12 bits (68 % 14 = 12) - auto tmp_28 = - p_y_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - p_y_low_limbs_range_constraint_tail_shift; - tmp_28 *= lagrange_odd_in_minicircuit; - tmp_28 *= scaling_factor; - std::get<27>(accumulators) += tmp_28; - - // Contribution 29, range constrain the highest microlimb of second highest P.y limb to be 12 bits (68 % 14 = - // 12) - auto tmp_29 = p_y_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - p_y_high_limbs_range_constraint_tail; - tmp_29 *= lagrange_odd_in_minicircuit; - tmp_29 *= scaling_factor; - std::get<28>(accumulators) += tmp_29; - - // Contribution 30, range constrain the highest microlimb of highest P.y limb to be 8 bits (50 % 14 = 8) - auto tmp_30 = - (p_y_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - p_y_high_limbs_range_constraint_4_shift); - - tmp_30 *= lagrange_odd_in_minicircuit; - tmp_30 *= scaling_factor; - std::get<29>(accumulators) += tmp_30; - - // Contribution 31, range constrain the highest microlimb of low z1 limb to be 12 bits (68 % 14 = 12) - auto tmp_31 = (z_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - z_low_limbs_range_constraint_tail); - tmp_31 *= lagrange_odd_in_minicircuit; - tmp_31 *= scaling_factor; - std::get<30>(accumulators) += tmp_31; - - // Contribution 32, range constrain the highest microlimb of low z2 limb to be 12 bits (68 % 14 = 12) - auto tmp_32 = (z_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - z_low_limbs_range_constraint_tail_shift); - tmp_32 *= lagrange_odd_in_minicircuit; - tmp_32 *= scaling_factor; - std::get<31>(accumulators) += tmp_32; - - // Contribution 33, range constrain the highest microlimb of high z1 limb to be 4 bits (60 % 14 = 12) - auto tmp_33 = (z_high_limbs_range_constraint_4 * SHIFT_4_TO_14 - z_high_limbs_range_constraint_tail); - tmp_33 *= lagrange_odd_in_minicircuit; - tmp_33 *= scaling_factor; - std::get<32>(accumulators) += tmp_33; - - // Contribution 34, range constrain the highest microlimb of high z2 limb to be 4 bits (60 % 14 = 12) - auto tmp_34 = - (z_high_limbs_range_constraint_4_shift * SHIFT_4_TO_14 - z_high_limbs_range_constraint_tail_shift); - tmp_34 *= lagrange_odd_in_minicircuit; - tmp_34 *= scaling_factor; - std::get<33>(accumulators) += tmp_34; - - // Contribution 35, range constrain the highest microlimb of lowest current accumulator limb to be 12 bits (68 % - // 14 = 12) - auto tmp_35 = - (accumulator_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - accumulator_low_limbs_range_constraint_tail); - tmp_35 *= lagrange_odd_in_minicircuit; - tmp_35 *= scaling_factor; - std::get<34>(accumulators) += tmp_35; - - // Contribution 36, range constrain the highest microlimb of second lowest current accumulator limb to be 12 - // bits (68 % 14 = 12) - auto tmp_36 = (accumulator_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - - accumulator_low_limbs_range_constraint_tail_shift); - tmp_36 *= lagrange_odd_in_minicircuit; - tmp_36 *= scaling_factor; - std::get<35>(accumulators) += tmp_36; - - // Contribution 37, range constrain the highest microlimb of second highest current accumulator limb to be 12 - // bits (68 % 14 = 12) - auto tmp_37 = - (accumulator_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - accumulator_high_limbs_range_constraint_tail); - tmp_37 *= lagrange_odd_in_minicircuit; - tmp_37 *= scaling_factor; - std::get<36>(accumulators) += tmp_37; - - // Contribution 38, range constrain the highest microlimb of highest current accumulator limb to be 8 bits (50 % - // 14 = 12) - auto tmp_38 = (accumulator_high_limbs_range_constraint_3_shift * SHIFT_8_TO_14 - - accumulator_high_limbs_range_constraint_4_shift); - tmp_38 *= lagrange_odd_in_minicircuit; - tmp_38 *= scaling_factor; - std::get<37>(accumulators) += tmp_38; - - // Contribution 39, range constrain the highest microlimb of lowest quotient limb to be 12 bits (68 % 14 = 12) - auto tmp_39 = - (quotient_low_limbs_range_constraint_4 * SHIFT_12_TO_14 - quotient_low_limbs_range_constraint_tail); - tmp_39 *= lagrange_odd_in_minicircuit; - tmp_39 *= scaling_factor; - std::get<38>(accumulators) += tmp_39; - - // Contribution 40, range constrain the highest microlimb of second lowest quotient limb to be 12 bits (68 % 14 - // = 12) - auto tmp_40 = (quotient_low_limbs_range_constraint_4_shift * SHIFT_12_TO_14 - - quotient_low_limbs_range_constraint_tail_shift); - tmp_40 *= lagrange_odd_in_minicircuit; - tmp_40 *= scaling_factor; - std::get<39>(accumulators) += tmp_40; - - // Contribution 41, range constrain the highest microlimb of second highest quotient limb to be 12 bits (68 % 14 - // = 12) - auto tmp_41 = - (quotient_high_limbs_range_constraint_4 * SHIFT_12_TO_14 - quotient_high_limbs_range_constraint_tail); - tmp_41 *= lagrange_odd_in_minicircuit; - tmp_41 *= scaling_factor; - std::get<40>(accumulators) += tmp_41; - - // Contribution 42, range constrain the highest microlimb of highest quotient limb to be 10 bits (52 % 14 = 12) - auto tmp_42 = (quotient_high_limbs_range_constraint_3_shift * SHIFT_10_TO_14 - - quotient_high_limbs_range_constraint_4_shift); - tmp_42 *= lagrange_odd_in_minicircuit; - tmp_42 *= scaling_factor; - std::get<41>(accumulators) += tmp_42; - - // Contributions where we decompose initial EccOpQueue values into 68-bit limbs - - // Contribution 43, decompose x_lo - auto tmp_43 = (p_x_low_limbs + p_x_low_limbs_shift * LIMB_SHIFT) - x_lo_y_hi; - tmp_43 *= lagrange_odd_in_minicircuit; - tmp_43 *= scaling_factor; - std::get<42>(accumulators) += tmp_43; - - // Contribution 44, decompose x_hi - auto tmp_44 = (p_x_high_limbs + p_x_high_limbs_shift * LIMB_SHIFT) - x_hi_z_1; - tmp_44 *= lagrange_odd_in_minicircuit; - tmp_44 *= scaling_factor; - std::get<43>(accumulators) += tmp_44; - // Contribution 45, decompose y_lo - auto tmp_45 = (p_y_low_limbs + p_y_low_limbs_shift * LIMB_SHIFT) - y_lo_z_2; - tmp_45 *= lagrange_odd_in_minicircuit; - tmp_45 *= scaling_factor; - std::get<44>(accumulators) += tmp_45; - - // Contribution 46, decompose y_hi - auto tmp_46 = (p_y_high_limbs + p_y_high_limbs_shift * LIMB_SHIFT) - x_lo_y_hi_shift; - tmp_46 *= lagrange_odd_in_minicircuit; - tmp_46 *= scaling_factor; - std::get<45>(accumulators) += tmp_46; - - // Contribution 47, decompose z1 - auto tmp_47 = (z_low_limbs + z_high_limbs * LIMB_SHIFT) - x_hi_z_1_shift; - tmp_47 *= lagrange_odd_in_minicircuit; - tmp_47 *= scaling_factor; - std::get<46>(accumulators) += tmp_47; - - // Contribution 48, decompose z2 - auto tmp_48 = (z_low_limbs_shift + z_high_limbs_shift * LIMB_SHIFT) - y_lo_z_2_shift; - tmp_48 *= lagrange_odd_in_minicircuit; - tmp_48 *= scaling_factor; - std::get<47>(accumulators) += tmp_48; - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor); }; template 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 new file mode 100644 index 00000000000..9224f4966f8 --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_extra_relations.cpp @@ -0,0 +1,155 @@ +#include "barretenberg/relations/translator_vm/translator_extra_relations.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" + +namespace proof_system { + +/** + * @brief Expression for enforcing the value of the Opcode to be {0,1,2,3,4,8} + * @details This relation enforces the opcode to be one of described values. Since we don't care about even + * values in the opcode wire and usually just set them to zero, we don't use a lagrange polynomial to specify + * the relation to be enforced just at odd indices, which brings the degree down by 1. + * + * @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 GoblinTranslatorOpcodeConstraintRelationImpl::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; + + auto op = View(in.op); + static const FF minus_one = FF(-1); + static const FF minus_two = FF(-2); + static const FF minus_three = FF(-3); + static const FF minus_four = FF(-4); + static const FF minus_eight = FF(-8); + + // Contribution (1) (op(op-1)(op-2)(op-3)(op-4)(op-8)) + auto tmp_1 = op * (op + minus_one); + tmp_1 *= (op + minus_two); + tmp_1 *= (op + minus_three); + tmp_1 *= (op + minus_four); + tmp_1 *= (op + minus_eight); + tmp_1 *= scaling_factor; + std::get<0>(accumulators) += tmp_1; +}; + +/** + * @brief Relation enforcing non-arithmetic transitions of accumulator (value that is tracking the batched + * evaluation of polynomials in non-native field) + * @details This relation enforces three pieces of logic: + * 1) Accumulator starts as zero before we start accumulating stuff + * 2) Accumulator limbs stay the same if accumulation is not occurring (at even indices) + * 3) Accumulator limbs result in the values specified by relation parameters after accumulation + * + * @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 GoblinTranslatorAccumulatorTransferRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) +{ + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + // We use combination of lagrange polynomials at even indices in the minicircuit for copying the accumulator + auto lagrange_even_in_minicircuit = View(in.lagrange_even_in_minicircuit); + + // Lagrange at index 1 is used to confirm the accumulator result + auto lagrange_second = View(in.lagrange_second); + + // Lagrange at index (size of minicircuit - 2) is used to enforce that it starts with zero + auto lagrange_second_to_last_in_minicircuit = View(in.lagrange_second_to_last_in_minicircuit); + + auto accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); + auto accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); + auto accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); + auto accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); + auto accumulators_binary_limbs_0_shift = View(in.accumulators_binary_limbs_0_shift); + auto accumulators_binary_limbs_1_shift = View(in.accumulators_binary_limbs_1_shift); + auto accumulators_binary_limbs_2_shift = View(in.accumulators_binary_limbs_2_shift); + auto accumulators_binary_limbs_3_shift = View(in.accumulators_binary_limbs_3_shift); + + // Contribution (1) (1-4 ensure transfer of accumulator limbs at even indices of the minicircuit) + auto tmp_1 = accumulators_binary_limbs_0 - accumulators_binary_limbs_0_shift; + tmp_1 *= lagrange_even_in_minicircuit; + tmp_1 *= scaling_factor; + std::get<0>(accumulators) += tmp_1; + + // Contribution (2) + auto tmp_2 = accumulators_binary_limbs_1 - accumulators_binary_limbs_1_shift; + tmp_2 *= lagrange_even_in_minicircuit; + tmp_2 *= scaling_factor; + std::get<1>(accumulators) += tmp_2; + // Contribution (3) + auto tmp_3 = accumulators_binary_limbs_2 - accumulators_binary_limbs_2_shift; + tmp_3 *= lagrange_even_in_minicircuit; + tmp_3 *= scaling_factor; + std::get<2>(accumulators) += tmp_3; + // Contribution (4) + auto tmp_4 = accumulators_binary_limbs_3 - accumulators_binary_limbs_3_shift; + tmp_4 *= lagrange_even_in_minicircuit; + tmp_4 *= scaling_factor; + std::get<3>(accumulators) += tmp_4; + + // Contribution (5) (5-9 ensure that accumulator starts with zeroed-out limbs) + auto tmp_5 = accumulators_binary_limbs_0 * lagrange_second_to_last_in_minicircuit; + tmp_5 *= scaling_factor; + std::get<4>(accumulators) += tmp_5; + + // Contribution (6) + auto tmp_6 = accumulators_binary_limbs_1 * lagrange_second_to_last_in_minicircuit; + tmp_6 *= scaling_factor; + std::get<5>(accumulators) += tmp_6; + + // Contribution (7) + auto tmp_7 = accumulators_binary_limbs_2 * lagrange_second_to_last_in_minicircuit; + tmp_7 *= scaling_factor; + std::get<6>(accumulators) += tmp_7; + + // Contribution (8) + auto tmp_8 = accumulators_binary_limbs_3 * lagrange_second_to_last_in_minicircuit; + tmp_8 *= scaling_factor; + std::get<7>(accumulators) += tmp_8; + + // Contribution (9) (9-12 ensure the output is as stated, we basically use this to get the result out of the + // proof) + auto tmp_9 = (accumulators_binary_limbs_0 - params.accumulated_result[0]) * lagrange_second; + tmp_9 *= scaling_factor; + std::get<8>(accumulators) += tmp_9; + + // Contribution (10) + auto tmp_10 = (accumulators_binary_limbs_1 - params.accumulated_result[1]) * lagrange_second; + tmp_10 *= scaling_factor; + std::get<9>(accumulators) += tmp_10; + + // Contribution (11) + auto tmp_11 = (accumulators_binary_limbs_2 - params.accumulated_result[2]) * lagrange_second; + tmp_11 *= scaling_factor; + std::get<10>(accumulators) += tmp_11; + + // Contribution (12) + auto tmp_12 = (accumulators_binary_limbs_3 - params.accumulated_result[3]) * lagrange_second; + tmp_12 *= scaling_factor; + std::get<11>(accumulators) += tmp_12; +}; + +template class GoblinTranslatorOpcodeConstraintRelationImpl; +template class GoblinTranslatorAccumulatorTransferRelationImpl; + +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorOpcodeConstraintRelationImpl, honk::flavor::GoblinTranslator); +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorAccumulatorTransferRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system 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 652d0358853..ef93e9fc0ea 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 @@ -1,5 +1,4 @@ #pragma once -#include "barretenberg/numeric/uint256/uint256.hpp" #include "barretenberg/relations/relation_types.hpp" namespace proof_system { @@ -26,31 +25,10 @@ template class GoblinTranslatorOpcodeConstraintRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void 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; - - auto op = View(in.op); - static const FF minus_one = FF(-1); - static const FF minus_two = FF(-2); - static const FF minus_three = FF(-3); - static const FF minus_four = FF(-4); - static const FF minus_eight = FF(-8); - - // Contribution (1) (op(op-1)(op-2)(op-3)(op-4)(op-8)) - auto tmp_1 = op * (op + minus_one); - tmp_1 *= (op + minus_two); - tmp_1 *= (op + minus_three); - tmp_1 *= (op + minus_four); - tmp_1 *= (op + minus_eight); - tmp_1 *= scaling_factor; - std::get<0>(accumulators) += tmp_1; - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor); }; template class GoblinTranslatorAccumulatorTransferRelationImpl { @@ -89,95 +67,12 @@ template class GoblinTranslatorAccumulatorTransferRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters& params, - const FF& scaling_factor) - { - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - // We use combination of lagrange polynomials at even indices in the minicircuit for copying the accumulator - auto lagrange_even_in_minicircuit = View(in.lagrange_even_in_minicircuit); - - // Lagrange at index 1 is used to confirm the accumulator result - auto lagrange_second = View(in.lagrange_second); - - // Lagrange at index (size of minicircuit - 2) is used to enforce that it starts with zero - auto lagrange_second_to_last_in_minicircuit = View(in.lagrange_second_to_last_in_minicircuit); - - auto accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); - auto accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); - auto accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); - auto accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); - auto accumulators_binary_limbs_0_shift = View(in.accumulators_binary_limbs_0_shift); - auto accumulators_binary_limbs_1_shift = View(in.accumulators_binary_limbs_1_shift); - auto accumulators_binary_limbs_2_shift = View(in.accumulators_binary_limbs_2_shift); - auto accumulators_binary_limbs_3_shift = View(in.accumulators_binary_limbs_3_shift); - - // Contribution (1) (1-4 ensure transfer of accumulator limbs at even indices of the minicircuit) - auto tmp_1 = accumulators_binary_limbs_0 - accumulators_binary_limbs_0_shift; - tmp_1 *= lagrange_even_in_minicircuit; - tmp_1 *= scaling_factor; - std::get<0>(accumulators) += tmp_1; - - // Contribution (2) - auto tmp_2 = accumulators_binary_limbs_1 - accumulators_binary_limbs_1_shift; - tmp_2 *= lagrange_even_in_minicircuit; - tmp_2 *= scaling_factor; - std::get<1>(accumulators) += tmp_2; - // Contribution (3) - auto tmp_3 = accumulators_binary_limbs_2 - accumulators_binary_limbs_2_shift; - tmp_3 *= lagrange_even_in_minicircuit; - tmp_3 *= scaling_factor; - std::get<2>(accumulators) += tmp_3; - // Contribution (4) - auto tmp_4 = accumulators_binary_limbs_3 - accumulators_binary_limbs_3_shift; - tmp_4 *= lagrange_even_in_minicircuit; - tmp_4 *= scaling_factor; - std::get<3>(accumulators) += tmp_4; - - // Contribution (5) (5-9 ensure that accumulator starts with zeroed-out limbs) - auto tmp_5 = accumulators_binary_limbs_0 * lagrange_second_to_last_in_minicircuit; - tmp_5 *= scaling_factor; - std::get<4>(accumulators) += tmp_5; - - // Contribution (6) - auto tmp_6 = accumulators_binary_limbs_1 * lagrange_second_to_last_in_minicircuit; - tmp_6 *= scaling_factor; - std::get<5>(accumulators) += tmp_6; - - // Contribution (7) - auto tmp_7 = accumulators_binary_limbs_2 * lagrange_second_to_last_in_minicircuit; - tmp_7 *= scaling_factor; - std::get<6>(accumulators) += tmp_7; - - // Contribution (8) - auto tmp_8 = accumulators_binary_limbs_3 * lagrange_second_to_last_in_minicircuit; - tmp_8 *= scaling_factor; - std::get<7>(accumulators) += tmp_8; - - // Contribution (9) (9-12 ensure the output is as stated, we basically use this to get the result out of the - // proof) - auto tmp_9 = (accumulators_binary_limbs_0 - params.accumulated_result[0]) * lagrange_second; - tmp_9 *= scaling_factor; - std::get<8>(accumulators) += tmp_9; - - // Contribution (10) - auto tmp_10 = (accumulators_binary_limbs_1 - params.accumulated_result[1]) * lagrange_second; - tmp_10 *= scaling_factor; - std::get<9>(accumulators) += tmp_10; - - // Contribution (11) - auto tmp_11 = (accumulators_binary_limbs_2 - params.accumulated_result[2]) * lagrange_second; - tmp_11 *= scaling_factor; - std::get<10>(accumulators) += tmp_11; - - // Contribution (12) - auto tmp_12 = (accumulators_binary_limbs_3 - params.accumulated_result[3]) * lagrange_second; - tmp_12 *= scaling_factor; - std::get<11>(accumulators) += tmp_12; - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor); }; + template using GoblinTranslatorOpcodeConstraintRelation = Relation>; diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.cpp new file mode 100644 index 00000000000..8cbb0ea995e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.cpp @@ -0,0 +1,132 @@ +#include "barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" + +namespace proof_system { + +/** + * @brief Expression for the generalized permutation sort relation + * + * @details The relation enforces 2 constraints on each of the ordered_range_constraints wires: + * 1) 2 sequential values are non-descending and have a difference of at most 3, except for the value at last index + * 2) The value at last index is 2¹⁴ - 1 + * + * @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 GoblinTranslatorGenPermSortRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor) +{ + static const FF minus_one = FF(-1); + static const FF minus_two = FF(-2); + static const FF minus_three = FF(-3); + static const size_t micro_limb_bits = 14; + static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1); + + [&]() { + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); + auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); + auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); + auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); + auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); + auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift); + auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift); + auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift); + auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift); + auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift); + auto lagrange_last = View(in.lagrange_last); + + // Compute wire differences + auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0; + auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1; + auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2; + auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3; + auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4; + + // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3}) + auto tmp_1 = delta_1; + tmp_1 *= (delta_1 + minus_one); + tmp_1 *= (delta_1 + minus_two); + tmp_1 *= (delta_1 + minus_three); + tmp_1 *= (lagrange_last + minus_one); + tmp_1 *= scaling_factor; + std::get<0>(accumulators) += tmp_1; + + // Contribution (2) + auto tmp_2 = delta_2; + tmp_2 *= (delta_2 + minus_one); + tmp_2 *= (delta_2 + minus_two); + tmp_2 *= (delta_2 + minus_three); + tmp_2 *= (lagrange_last + minus_one); + tmp_2 *= scaling_factor; + + std::get<1>(accumulators) += tmp_2; + + // Contribution (3) + auto tmp_3 = delta_3; + tmp_3 *= (delta_3 + minus_one); + tmp_3 *= (delta_3 + minus_two); + tmp_3 *= (delta_3 + minus_three); + tmp_3 *= (lagrange_last + minus_one); + tmp_3 *= scaling_factor; + std::get<2>(accumulators) += tmp_3; + + // Contribution (4) + auto tmp_4 = delta_4; + tmp_4 *= (delta_4 + minus_one); + tmp_4 *= (delta_4 + minus_two); + tmp_4 *= (delta_4 + minus_three); + tmp_4 *= (lagrange_last + minus_one); + tmp_4 *= scaling_factor; + std::get<3>(accumulators) += tmp_4; + + // Contribution (5) + auto tmp_5 = delta_5; + tmp_5 *= (delta_5 + minus_one); + tmp_5 *= (delta_5 + minus_two); + tmp_5 *= (delta_5 + minus_three); + tmp_5 *= (lagrange_last + minus_one); + tmp_5 *= scaling_factor; + std::get<4>(accumulators) += tmp_5; + }(); + + [&]() { + using Accumulator = std::tuple_element_t<5, ContainerOverSubrelations>; + using View = typename Accumulator::View; + auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); + auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); + auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); + auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); + auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); + auto lagrange_last = View(in.lagrange_last); + + // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't + // need to constrain the first value to be 0, because the shift mechanic does this for us) + std::get<5>(accumulators) += + lagrange_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor; + // Contribution (7) + std::get<6>(accumulators) += + lagrange_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor; + // Contribution (8) + std::get<7>(accumulators) += + lagrange_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor; + // Contribution (9) + std::get<8>(accumulators) += + lagrange_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor; + // Contribution (10) + std::get<9>(accumulators) += + lagrange_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor; + }(); +}; + +template class GoblinTranslatorGenPermSortRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorGenPermSortRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp index b63ebe29a8d..7966dda83fb 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_gen_perm_sort_relation.hpp @@ -37,101 +37,12 @@ template class GoblinTranslatorGenPermSortRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void 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; - auto ordered_range_constraints_0 = View(in.ordered_range_constraints_0); - auto ordered_range_constraints_1 = View(in.ordered_range_constraints_1); - auto ordered_range_constraints_2 = View(in.ordered_range_constraints_2); - auto ordered_range_constraints_3 = View(in.ordered_range_constraints_3); - auto ordered_range_constraints_4 = View(in.ordered_range_constraints_4); - auto ordered_range_constraints_0_shift = View(in.ordered_range_constraints_0_shift); - auto ordered_range_constraints_1_shift = View(in.ordered_range_constraints_1_shift); - auto ordered_range_constraints_2_shift = View(in.ordered_range_constraints_2_shift); - auto ordered_range_constraints_3_shift = View(in.ordered_range_constraints_3_shift); - auto ordered_range_constraints_4_shift = View(in.ordered_range_constraints_4_shift); - auto lagrange_last = View(in.lagrange_last); - - static const FF minus_one = FF(-1); - static const FF minus_two = FF(-2); - static const FF minus_three = FF(-3); - static const size_t micro_limb_bits = 14; - static const auto maximum_sort_value = -FF((1 << micro_limb_bits) - 1); - // Compute wire differences - auto delta_1 = ordered_range_constraints_0_shift - ordered_range_constraints_0; - auto delta_2 = ordered_range_constraints_1_shift - ordered_range_constraints_1; - auto delta_3 = ordered_range_constraints_2_shift - ordered_range_constraints_2; - auto delta_4 = ordered_range_constraints_3_shift - ordered_range_constraints_3; - auto delta_5 = ordered_range_constraints_4_shift - ordered_range_constraints_4; - - // Contribution (1) (contributions 1-5 ensure that the sequential values have a difference of {0,1,2,3}) - auto tmp_1 = delta_1; - tmp_1 *= (delta_1 + minus_one); - tmp_1 *= (delta_1 + minus_two); - tmp_1 *= (delta_1 + minus_three); - tmp_1 *= (lagrange_last + minus_one); - tmp_1 *= scaling_factor; - std::get<0>(accumulators) += tmp_1; - - // Contribution (2) - auto tmp_2 = delta_2; - tmp_2 *= (delta_2 + minus_one); - tmp_2 *= (delta_2 + minus_two); - tmp_2 *= (delta_2 + minus_three); - tmp_2 *= (lagrange_last + minus_one); - tmp_2 *= scaling_factor; - - std::get<1>(accumulators) += tmp_2; - - // Contribution (3) - auto tmp_3 = delta_3; - tmp_3 *= (delta_3 + minus_one); - tmp_3 *= (delta_3 + minus_two); - tmp_3 *= (delta_3 + minus_three); - tmp_3 *= (lagrange_last + minus_one); - tmp_3 *= scaling_factor; - std::get<2>(accumulators) += tmp_3; - - // Contribution (4) - auto tmp_4 = delta_4; - tmp_4 *= (delta_4 + minus_one); - tmp_4 *= (delta_4 + minus_two); - tmp_4 *= (delta_4 + minus_three); - tmp_4 *= (lagrange_last + minus_one); - tmp_4 *= scaling_factor; - std::get<3>(accumulators) += tmp_4; - - // Contribution (5) - auto tmp_5 = delta_5; - tmp_5 *= (delta_5 + minus_one); - tmp_5 *= (delta_5 + minus_two); - tmp_5 *= (delta_5 + minus_three); - tmp_5 *= (lagrange_last + minus_one); - tmp_5 *= scaling_factor; - std::get<4>(accumulators) += tmp_5; - - // Contribution (6) (Contributions 6-10 ensure that the last value is the designated maximum value. We don't - // need to constrain the first value to be 0, because the shift mechanic does this for us) - std::get<5>(accumulators) += - lagrange_last * (ordered_range_constraints_0 + maximum_sort_value) * scaling_factor; - // Contribution (7) - std::get<6>(accumulators) += - lagrange_last * (ordered_range_constraints_1 + maximum_sort_value) * scaling_factor; - // Contribution (8) - std::get<7>(accumulators) += - lagrange_last * (ordered_range_constraints_2 + maximum_sort_value) * scaling_factor; - // Contribution (9) - std::get<8>(accumulators) += - lagrange_last * (ordered_range_constraints_3 + maximum_sort_value) * scaling_factor; - // Contribution (10) - std::get<9>(accumulators) += - lagrange_last * (ordered_range_constraints_4 + maximum_sort_value) * scaling_factor; - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters&, + const FF& scaling_factor); }; + template using GoblinTranslatorGenPermSortRelation = Relation>; diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.cpp new file mode 100644 index 00000000000..9a4722593cf --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.cpp @@ -0,0 +1,283 @@ +#include "barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" + +namespace proof_system { +/** + * @brief Expression for the computation of Goblin Translator accumulator in integers through 68-bit limbs and + * native field (prime) limb + * @details This relation is a part of system of relations that enforce a formula in non-native field (base field of + * bn254 curve Fp (p - modulus of Fp)). We are trying to compute: + * + * `current_accumulator = previous_accumulator ⋅ x + op + P.x ⋅ v + P.y ⋅ v² +z1 ⋅ v³ + z2 ⋅ v⁴ mod p`. + * + * However, we can only operate in Fr (scalar field of bn254) with + * modulus r. To emulate arithmetic in Fp we rephrase the equation in integers: + * + * `previous_accumulator ⋅ x + op + P.x ⋅ v + P.y ⋅ v² +z1 ⋅ v³ + z2 ⋅ v⁴ - quotient⋅p - current_accumulator = 0` + * + * We can't operate over unbounded integers, but since we know the maximum value of each element (we also treat + * powers of v as new constants constrained to 254 bits) we know that the maximum values of the sum of the positive + * products is ~2⁵¹⁴, so we only need to make sure that no overflow happens till that bound. We calculate integer + * logic until the bound 2²⁷²⋅r (which is more than 2⁵¹⁴) by using the representations modulo 2²⁷² (requires limb + * computation over native scalar field) and r (native scalar field computation). + * + * We perform modulo 2²⁷² computations by separating each of values into 4 68-bit limbs (z1 and z2 are just two + * since they represent the values < 2¹²⁸ and op is just itself). Then we compute the first subrelation (index means + * sublimb and we use 2²⁷² - p instead of -p): + * ` previous_accumulator[0]⋅x[0] + op + P.x[0]⋅v[0] + P.y[0]⋅v²[0] + z1[0] ⋅ v³[0] + z2[0] ⋅ v⁴[0] + * + quotient[0]⋅(-p)[0] - current_accumulator[0] + * + 2⁶⁸⋅(previous_accumulator[1]⋅x[0] + P.x[1]⋅v[0] + P.y[1]⋅v²[0] + z1[1] ⋅ v³[0] + z2[1] ⋅ v⁴[0] + * + quotient[1]⋅(-p)[0] + + * previous_accumulator[0]⋅x[1] + P.x[0]⋅v[1] + P.y[0]⋅v²[1] + z1[0] ⋅ v³[1] + z2[0] ⋅ v⁴[1] + * + quotient[0]⋅(-p)[1] - current_accumulator[1]) + * - 2¹³⁶⋅relation_wide_lower_limb + * == 0` + * + * We use 2 relation wide limbs which are called wide, because they contain the results of products (like you needed + * EDX:EAX in x86 to hold the product results of two standard 32-bit registers) and because they are constrained to + * 84 bits instead of 68 or lower by other relations. + * + * We show that the evaluation in 2 lower limbs results in relation_wide_lower_limb multiplied by 2¹³⁶. If + * relation_wide_lower_limb is propertly constrained (this is performed in other relations), then that means that + * the lower 136 bits of the result are 0. This is the first subrelation. + * + * We then use the relation_wide_lower_limb as carry and add it to the next expression, computing the evaluation in + * higher bits (carry + combinations of limbs (0,2), (1,1), (2,0), (0,3), (2,1), (1,2), (0,3)) and checking that it + * results in 2¹³⁶⋅relation_wide_higher_limb. This ensures that the logic was sound modulo 2²⁷². This is the second + * subrelation. + * + * Finally, we check that the relation holds in the native field. For this we reconstruct each value, for example: + * `previous_accumulator_native = previous_accumulator[0] + 2⁶⁸ ⋅previous_accumulator[1] + * + 2¹³⁶⋅previous_accumulator[2] + 2²⁰⁴⋅previous accumulator[3] mod r` + * + * Then the last subrelation is simply checking the integer equation in this native form + * + * All of these subrelations are multiplied by lagrange_odd_in_minicircuit, which is a polynomial with 1 at each odd + * index less than the size of the mini-circuit (16 times smaller than the final circuit and the only part over + * which we need to calculate non-permutation relations). All other indices are set to zero. Each EccOpQueue entry + * (operation) occupies 2 rows in bn254 transcripts. So the Goblin Translator VM has a 2-row cycle and we need to + * switch the checks being performed depending on which row we are at right now. We have half a cycle of + * accumulation, where we perform this computation, and half a cycle where we just copy accumulator data. + * + * @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 GoblinTranslatorNonNativeFieldRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) +{ + + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + static constexpr size_t NUM_LIMB_BITS = 68; + static constexpr FF shift = FF(uint256_t(1) << NUM_LIMB_BITS); + static constexpr FF shiftx2 = FF(uint256_t(1) << (NUM_LIMB_BITS * 2)); + static constexpr FF shiftx3 = FF(uint256_t(1) << (NUM_LIMB_BITS * 3)); + static constexpr uint512_t MODULUS_U512 = uint512_t(curve::BN254::BaseField::modulus); + static constexpr uint512_t BINARY_BASIS_MODULUS = uint512_t(1) << (NUM_LIMB_BITS << 2); + static constexpr uint512_t NEGATIVE_PRIME_MODULUS = BINARY_BASIS_MODULUS - MODULUS_U512; + static constexpr std::array NEGATIVE_MODULUS_LIMBS = { + FF(NEGATIVE_PRIME_MODULUS.slice(0, NUM_LIMB_BITS).lo), + FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2).lo), + FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3).lo), + FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4).lo), + -FF(curve::BN254::BaseField::modulus) + }; + + const auto& evaluation_input_x_0 = params.evaluation_input_x[0]; + const auto& evaluation_input_x_1 = params.evaluation_input_x[1]; + const auto& evaluation_input_x_2 = params.evaluation_input_x[2]; + const auto& evaluation_input_x_3 = params.evaluation_input_x[3]; + const auto& evaluation_input_x_4 = params.evaluation_input_x[4]; + // for j < 4, v_i_j is the j-th limb of v^{1+i} + // v_i_4 is v^{1+i} in the native field + const auto& v_0_0 = params.batching_challenge_v[0][0]; + const auto& v_0_1 = params.batching_challenge_v[0][1]; + const auto& v_0_2 = params.batching_challenge_v[0][2]; + const auto& v_0_3 = params.batching_challenge_v[0][3]; + const auto& v_0_4 = params.batching_challenge_v[0][4]; + const auto& v_1_0 = params.batching_challenge_v[1][0]; + const auto& v_1_1 = params.batching_challenge_v[1][1]; + const auto& v_1_2 = params.batching_challenge_v[1][2]; + const auto& v_1_3 = params.batching_challenge_v[1][3]; + const auto& v_1_4 = params.batching_challenge_v[1][4]; + const auto& v_2_0 = params.batching_challenge_v[2][0]; + const auto& v_2_1 = params.batching_challenge_v[2][1]; + const auto& v_2_2 = params.batching_challenge_v[2][2]; + const auto& v_2_3 = params.batching_challenge_v[2][3]; + const auto& v_2_4 = params.batching_challenge_v[2][4]; + const auto& v_3_0 = params.batching_challenge_v[3][0]; + const auto& v_3_1 = params.batching_challenge_v[3][1]; + const auto& v_3_2 = params.batching_challenge_v[3][2]; + const auto& v_3_3 = params.batching_challenge_v[3][3]; + const auto& v_3_4 = params.batching_challenge_v[3][4]; + + const auto& op = View(in.op); + const auto& p_x_low_limbs = View(in.p_x_low_limbs); + const auto& p_y_low_limbs = View(in.p_y_low_limbs); + const auto& p_x_high_limbs = View(in.p_x_high_limbs); + const auto& p_y_high_limbs = View(in.p_y_high_limbs); + const auto& accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); + const auto& accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); + const auto& accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); + const auto& accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); + const auto& z_low_limbs = View(in.z_low_limbs); + const auto& z_high_limbs = View(in.z_high_limbs); + const auto& quotient_low_binary_limbs = View(in.quotient_low_binary_limbs); + const auto& quotient_high_binary_limbs = View(in.quotient_high_binary_limbs); + const auto& p_x_low_limbs_shift = View(in.p_x_low_limbs_shift); + const auto& p_y_low_limbs_shift = View(in.p_y_low_limbs_shift); + const auto& p_x_high_limbs_shift = View(in.p_x_high_limbs_shift); + const auto& p_y_high_limbs_shift = View(in.p_y_high_limbs_shift); + const auto& accumulators_binary_limbs_0_shift = View(in.accumulators_binary_limbs_0_shift); + const auto& accumulators_binary_limbs_1_shift = View(in.accumulators_binary_limbs_1_shift); + const auto& accumulators_binary_limbs_2_shift = View(in.accumulators_binary_limbs_2_shift); + const auto& accumulators_binary_limbs_3_shift = View(in.accumulators_binary_limbs_3_shift); + const auto& z_low_limbs_shift = View(in.z_low_limbs_shift); + const auto& z_high_limbs_shift = View(in.z_high_limbs_shift); + const auto& quotient_low_binary_limbs_shift = View(in.quotient_low_binary_limbs_shift); + const auto& quotient_high_binary_limbs_shift = View(in.quotient_high_binary_limbs_shift); + const auto& relation_wide_limbs = View(in.relation_wide_limbs); + const auto& relation_wide_limbs_shift = View(in.relation_wide_limbs_shift); + const auto& lagrange_odd_in_minicircuit = View(in.lagrange_odd_in_minicircuit); + + // Contribution (1) Computing the mod 2²⁷² relation over lower 136 bits + // clang-format off + // the index-0 limb + auto tmp = accumulators_binary_limbs_0_shift * evaluation_input_x_0 + + op + + p_x_low_limbs * v_0_0 + + p_y_low_limbs * v_1_0 + + z_low_limbs * v_2_0 + + z_low_limbs_shift * v_3_0 + + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[0] + - accumulators_binary_limbs_0; + + // the index-1 limb + tmp += (accumulators_binary_limbs_1_shift * evaluation_input_x_0 + + accumulators_binary_limbs_0_shift * evaluation_input_x_1 + + p_x_low_limbs * v_0_1 + + p_x_low_limbs_shift * v_0_0 + + p_y_low_limbs * v_1_1 + + p_y_low_limbs_shift * v_1_0 + + z_low_limbs * v_2_1 + + z_high_limbs * v_2_0 + + z_low_limbs_shift * v_3_1 + + z_high_limbs_shift * v_3_0 + + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[1] + + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[0] + - accumulators_binary_limbs_1) + * shift ; + // clang-format on + // subtract large value; vanishing shows the desired relation holds on low 136-bit limb + tmp -= relation_wide_limbs * shiftx2; + tmp *= lagrange_odd_in_minicircuit; + tmp *= scaling_factor; + std::get<0>(accumulators) += tmp; + + // Contribution (2) Computing the 2²⁷² relation over higher 136 bits + // why declare another temporary? + // clang-format off + // the index-2 limb, with a carry from the previous calculation + tmp = relation_wide_limbs + + accumulators_binary_limbs_2_shift * evaluation_input_x_0 + + accumulators_binary_limbs_1_shift * evaluation_input_x_1 + + accumulators_binary_limbs_0_shift * evaluation_input_x_2 + + p_x_high_limbs * v_0_0 + + p_x_low_limbs_shift * v_0_1 + + p_x_low_limbs * v_0_2 + + p_y_high_limbs * v_1_0 + + p_y_low_limbs_shift * v_1_1 + + p_y_low_limbs * v_1_2 + + z_high_limbs * v_2_1 + + z_low_limbs * v_2_2 + + z_high_limbs_shift * v_3_1 + + z_low_limbs_shift * v_3_2 + + quotient_high_binary_limbs * NEGATIVE_MODULUS_LIMBS[0] + + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[1] + + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[2] + - accumulators_binary_limbs_2; + + // the index-2 limb + tmp += (accumulators_binary_limbs_3_shift * evaluation_input_x_0 + + accumulators_binary_limbs_2_shift * evaluation_input_x_1 + + accumulators_binary_limbs_1_shift * evaluation_input_x_2 + + accumulators_binary_limbs_0_shift * evaluation_input_x_3 + + p_x_high_limbs_shift * v_0_0 + + p_x_high_limbs * v_0_1 + + p_x_low_limbs_shift * v_0_2 + + p_x_low_limbs * v_0_3 + + p_y_high_limbs_shift * v_1_0 + + p_y_high_limbs * v_1_1 + + p_y_low_limbs_shift * v_1_2 + + p_y_low_limbs * v_1_3 + + z_high_limbs * v_2_2 + + z_low_limbs * v_2_3 + + z_high_limbs_shift * v_3_2 + + z_low_limbs_shift * v_3_3 + + quotient_high_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[0] + + quotient_high_binary_limbs * NEGATIVE_MODULUS_LIMBS[1] + + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[2] + + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[3] + - accumulators_binary_limbs_3) + * shift; + // clang-format on + // subtract large value; vanishing shows the desired relation holds on high 136-bit limb + tmp -= relation_wide_limbs_shift * shiftx2; + tmp *= lagrange_odd_in_minicircuit; + tmp *= scaling_factor; + std::get<1>(accumulators) += tmp; + + const auto reconstruct_from_two = [](const auto& l0, const auto& l1) { return l0 + l1 * shift; }; + + const auto reconstruct_from_four = [](const auto& l0, const auto& l1, const auto& l2, const auto& l3) { + return l0 + l1 * shift + l2 * shiftx2 + l3 * shiftx3; + }; + + // Reconstructing native versions of values + auto reconstructed_p_x = + reconstruct_from_four(p_x_low_limbs, p_x_low_limbs_shift, p_x_high_limbs, p_x_high_limbs_shift); + auto reconstructed_p_y = + reconstruct_from_four(p_y_low_limbs, p_y_low_limbs_shift, p_y_high_limbs, p_y_high_limbs_shift); + auto reconstructed_previous_accumulator = reconstruct_from_four(accumulators_binary_limbs_0_shift, + accumulators_binary_limbs_1_shift, + accumulators_binary_limbs_2_shift, + accumulators_binary_limbs_3_shift); + auto reconstructed_current_accumulator = reconstruct_from_four(accumulators_binary_limbs_0, + accumulators_binary_limbs_1, + accumulators_binary_limbs_2, + accumulators_binary_limbs_3); + auto reconstructed_z1 = reconstruct_from_two(z_low_limbs, z_high_limbs); + auto reconstructed_z2 = reconstruct_from_two(z_low_limbs_shift, z_high_limbs_shift); + auto reconstructed_quotient = reconstruct_from_four(quotient_low_binary_limbs, + quotient_low_binary_limbs_shift, + quotient_high_binary_limbs, + quotient_high_binary_limbs_shift); + + // Contribution (3). Evaluating integer relation over native field + // clang-format off + // the native limb index is 4 + tmp = reconstructed_previous_accumulator * evaluation_input_x_4 + + op + + reconstructed_p_x * v_0_4 + + reconstructed_p_y * v_1_4 + + reconstructed_z1 * v_2_4 + + reconstructed_z2 * v_3_4 + + reconstructed_quotient * NEGATIVE_MODULUS_LIMBS[4] + - reconstructed_current_accumulator; + // clang-format on + tmp *= lagrange_odd_in_minicircuit; + tmp *= scaling_factor; + std::get<2>(accumulators) += tmp; +}; + +template class GoblinTranslatorNonNativeFieldRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorNonNativeFieldRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp index 134c5e28aab..33bd9cf32b4 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_non_native_field_relation.hpp @@ -1,6 +1,5 @@ #pragma once #include "barretenberg/ecc/curves/bn254/bn254.hpp" -#include "barretenberg/numeric/uintx/uintx.hpp" #include "barretenberg/relations/relation_types.hpp" namespace proof_system { @@ -79,216 +78,10 @@ template class GoblinTranslatorNonNativeFieldRelationImpl { * @param scaling_factor optional term to scale the evaluation before adding to evals. */ template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters& params, - const FF& scaling_factor) - { - - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - static constexpr size_t NUM_LIMB_BITS = 68; - static constexpr FF shift = FF(uint256_t(1) << NUM_LIMB_BITS); - static constexpr FF shiftx2 = FF(uint256_t(1) << (NUM_LIMB_BITS * 2)); - static constexpr FF shiftx3 = FF(uint256_t(1) << (NUM_LIMB_BITS * 3)); - static constexpr uint512_t MODULUS_U512 = uint512_t(curve::BN254::BaseField::modulus); - static constexpr uint512_t BINARY_BASIS_MODULUS = uint512_t(1) << (NUM_LIMB_BITS << 2); - static constexpr uint512_t NEGATIVE_PRIME_MODULUS = BINARY_BASIS_MODULUS - MODULUS_U512; - static constexpr std::array NEGATIVE_MODULUS_LIMBS = { - FF(NEGATIVE_PRIME_MODULUS.slice(0, NUM_LIMB_BITS).lo), - FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS, NUM_LIMB_BITS * 2).lo), - FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS * 2, NUM_LIMB_BITS * 3).lo), - FF(NEGATIVE_PRIME_MODULUS.slice(NUM_LIMB_BITS * 3, NUM_LIMB_BITS * 4).lo), - -FF(curve::BN254::BaseField::modulus) - }; - - const auto& evaluation_input_x_0 = params.evaluation_input_x[0]; - const auto& evaluation_input_x_1 = params.evaluation_input_x[1]; - const auto& evaluation_input_x_2 = params.evaluation_input_x[2]; - const auto& evaluation_input_x_3 = params.evaluation_input_x[3]; - const auto& evaluation_input_x_4 = params.evaluation_input_x[4]; - // for j < 4, v_i_j is the j-th limb of v^{1+i} - // v_i_4 is v^{1+i} in the native field - const auto& v_0_0 = params.batching_challenge_v[0][0]; - const auto& v_0_1 = params.batching_challenge_v[0][1]; - const auto& v_0_2 = params.batching_challenge_v[0][2]; - const auto& v_0_3 = params.batching_challenge_v[0][3]; - const auto& v_0_4 = params.batching_challenge_v[0][4]; - const auto& v_1_0 = params.batching_challenge_v[1][0]; - const auto& v_1_1 = params.batching_challenge_v[1][1]; - const auto& v_1_2 = params.batching_challenge_v[1][2]; - const auto& v_1_3 = params.batching_challenge_v[1][3]; - const auto& v_1_4 = params.batching_challenge_v[1][4]; - const auto& v_2_0 = params.batching_challenge_v[2][0]; - const auto& v_2_1 = params.batching_challenge_v[2][1]; - const auto& v_2_2 = params.batching_challenge_v[2][2]; - const auto& v_2_3 = params.batching_challenge_v[2][3]; - const auto& v_2_4 = params.batching_challenge_v[2][4]; - const auto& v_3_0 = params.batching_challenge_v[3][0]; - const auto& v_3_1 = params.batching_challenge_v[3][1]; - const auto& v_3_2 = params.batching_challenge_v[3][2]; - const auto& v_3_3 = params.batching_challenge_v[3][3]; - const auto& v_3_4 = params.batching_challenge_v[3][4]; - - const auto& op = View(in.op); - const auto& p_x_low_limbs = View(in.p_x_low_limbs); - const auto& p_y_low_limbs = View(in.p_y_low_limbs); - const auto& p_x_high_limbs = View(in.p_x_high_limbs); - const auto& p_y_high_limbs = View(in.p_y_high_limbs); - const auto& accumulators_binary_limbs_0 = View(in.accumulators_binary_limbs_0); - const auto& accumulators_binary_limbs_1 = View(in.accumulators_binary_limbs_1); - const auto& accumulators_binary_limbs_2 = View(in.accumulators_binary_limbs_2); - const auto& accumulators_binary_limbs_3 = View(in.accumulators_binary_limbs_3); - const auto& z_low_limbs = View(in.z_low_limbs); - const auto& z_high_limbs = View(in.z_high_limbs); - const auto& quotient_low_binary_limbs = View(in.quotient_low_binary_limbs); - const auto& quotient_high_binary_limbs = View(in.quotient_high_binary_limbs); - const auto& p_x_low_limbs_shift = View(in.p_x_low_limbs_shift); - const auto& p_y_low_limbs_shift = View(in.p_y_low_limbs_shift); - const auto& p_x_high_limbs_shift = View(in.p_x_high_limbs_shift); - const auto& p_y_high_limbs_shift = View(in.p_y_high_limbs_shift); - const auto& accumulators_binary_limbs_0_shift = View(in.accumulators_binary_limbs_0_shift); - const auto& accumulators_binary_limbs_1_shift = View(in.accumulators_binary_limbs_1_shift); - const auto& accumulators_binary_limbs_2_shift = View(in.accumulators_binary_limbs_2_shift); - const auto& accumulators_binary_limbs_3_shift = View(in.accumulators_binary_limbs_3_shift); - const auto& z_low_limbs_shift = View(in.z_low_limbs_shift); - const auto& z_high_limbs_shift = View(in.z_high_limbs_shift); - const auto& quotient_low_binary_limbs_shift = View(in.quotient_low_binary_limbs_shift); - const auto& quotient_high_binary_limbs_shift = View(in.quotient_high_binary_limbs_shift); - const auto& relation_wide_limbs = View(in.relation_wide_limbs); - const auto& relation_wide_limbs_shift = View(in.relation_wide_limbs_shift); - const auto& lagrange_odd_in_minicircuit = View(in.lagrange_odd_in_minicircuit); - - // Contribution (1) Computing the mod 2²⁷² relation over lower 136 bits - // clang-format off - // the index-0 limb - auto tmp = accumulators_binary_limbs_0_shift * evaluation_input_x_0 - + op - + p_x_low_limbs * v_0_0 - + p_y_low_limbs * v_1_0 - + z_low_limbs * v_2_0 - + z_low_limbs_shift * v_3_0 - + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[0] - - accumulators_binary_limbs_0; - - // the index-1 limb - tmp += shift - * (accumulators_binary_limbs_1_shift * evaluation_input_x_0 - + accumulators_binary_limbs_0_shift * evaluation_input_x_1 - + p_x_low_limbs * v_0_1 - + p_x_low_limbs_shift * v_0_0 - + p_y_low_limbs * v_1_1 - + p_y_low_limbs_shift * v_1_0 - + z_low_limbs * v_2_1 - + z_high_limbs * v_2_0 - + z_low_limbs_shift * v_3_1 - + z_high_limbs_shift * v_3_0 - + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[1] - + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[0] - - accumulators_binary_limbs_1); - // clang-format on - // subtract large value; vanishing shows the desired relation holds on low 136-bit limb - tmp -= relation_wide_limbs * shiftx2; - tmp *= lagrange_odd_in_minicircuit; - tmp *= scaling_factor; - std::get<0>(accumulators) += tmp; - - // Contribution (2) Computing the 2²⁷² relation over higher 136 bits - // why declare another temporary? - // clang-format off - // the index-2 limb, with a carry from the previous calculation - tmp = relation_wide_limbs - + accumulators_binary_limbs_2_shift * evaluation_input_x_0 - + accumulators_binary_limbs_1_shift * evaluation_input_x_1 - + accumulators_binary_limbs_0_shift * evaluation_input_x_2 - + p_x_high_limbs * v_0_0 - + p_x_low_limbs_shift * v_0_1 - + p_x_low_limbs * v_0_2 - + p_y_high_limbs * v_1_0 - + p_y_low_limbs_shift * v_1_1 - + p_y_low_limbs * v_1_2 - + z_high_limbs * v_2_1 - + z_low_limbs * v_2_2 - + z_high_limbs_shift * v_3_1 - + z_low_limbs_shift * v_3_2 - + quotient_high_binary_limbs * NEGATIVE_MODULUS_LIMBS[0] - + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[1] - + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[2] - - accumulators_binary_limbs_2; - - // the index-2 limb - tmp += shift - * (accumulators_binary_limbs_3_shift * evaluation_input_x_0 - + accumulators_binary_limbs_2_shift * evaluation_input_x_1 - + accumulators_binary_limbs_1_shift * evaluation_input_x_2 - + accumulators_binary_limbs_0_shift * evaluation_input_x_3 - + p_x_high_limbs_shift * v_0_0 - + p_x_high_limbs * v_0_1 - + p_x_low_limbs_shift * v_0_2 - + p_x_low_limbs * v_0_3 - + p_y_high_limbs_shift * v_1_0 - + p_y_high_limbs * v_1_1 - + p_y_low_limbs_shift * v_1_2 - + p_y_low_limbs * v_1_3 - + z_high_limbs * v_2_2 - + z_low_limbs * v_2_3 - + z_high_limbs_shift * v_3_2 - + z_low_limbs_shift * v_3_3 - + quotient_high_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[0] - + quotient_high_binary_limbs * NEGATIVE_MODULUS_LIMBS[1] - + quotient_low_binary_limbs_shift * NEGATIVE_MODULUS_LIMBS[2] - + quotient_low_binary_limbs * NEGATIVE_MODULUS_LIMBS[3] - - accumulators_binary_limbs_3); - // clang-format on - // subtract large value; vanishing shows the desired relation holds on high 136-bit limb - tmp -= relation_wide_limbs_shift * shiftx2; - tmp *= lagrange_odd_in_minicircuit; - tmp *= scaling_factor; - std::get<1>(accumulators) += tmp; - - const auto reconstruct_from_two = [](const auto& l0, const auto& l1) { return l0 + l1 * shift; }; - - const auto reconstruct_from_four = [](const auto& l0, const auto& l1, const auto& l2, const auto& l3) { - return l0 + l1 * shift + l2 * shiftx2 + l3 * shiftx3; - }; - - // Reconstructing native versions of values - auto reconstructed_p_x = - reconstruct_from_four(p_x_low_limbs, p_x_low_limbs_shift, p_x_high_limbs, p_x_high_limbs_shift); - auto reconstructed_p_y = - reconstruct_from_four(p_y_low_limbs, p_y_low_limbs_shift, p_y_high_limbs, p_y_high_limbs_shift); - auto reconstructed_previous_accumulator = reconstruct_from_four(accumulators_binary_limbs_0_shift, - accumulators_binary_limbs_1_shift, - accumulators_binary_limbs_2_shift, - accumulators_binary_limbs_3_shift); - auto reconstructed_current_accumulator = reconstruct_from_four(accumulators_binary_limbs_0, - accumulators_binary_limbs_1, - accumulators_binary_limbs_2, - accumulators_binary_limbs_3); - auto reconstructed_z1 = reconstruct_from_two(z_low_limbs, z_high_limbs); - auto reconstructed_z2 = reconstruct_from_two(z_low_limbs_shift, z_high_limbs_shift); - auto reconstructed_quotient = reconstruct_from_four(quotient_low_binary_limbs, - quotient_low_binary_limbs_shift, - quotient_high_binary_limbs, - quotient_high_binary_limbs_shift); - - // Contribution (3). Evaluating integer relation over native field - // clang-format off - // the native limb index is 4 - tmp = reconstructed_previous_accumulator * evaluation_input_x_4 - + op - + reconstructed_p_x * v_0_4 - + reconstructed_p_y * v_1_4 - + reconstructed_z1 * v_2_4 - + reconstructed_z2 * v_3_4 - + reconstructed_quotient * NEGATIVE_MODULUS_LIMBS[4] - - reconstructed_current_accumulator; - // clang-format on - tmp *= lagrange_odd_in_minicircuit; - tmp *= scaling_factor; - std::get<2>(accumulators) += tmp; - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor); }; template diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.cpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.cpp new file mode 100644 index 00000000000..508fd95ca2e --- /dev/null +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.cpp @@ -0,0 +1,65 @@ +#include "barretenberg/relations/translator_vm/translator_permutation_relation.hpp" +#include "barretenberg/flavor/goblin_translator.hpp" + +namespace proof_system { + +/** + * @brief Compute contribution of the goblin translator permutation relation for a given edge (internal function) + * + * @details There are 2 relations associated with enforcing the set permutation relation + * This file handles the relation that confirms faithful calculation of the grand + * product polynomial Z_perm. + * + * C(in(X)...) = + * ( z_perm(X) + lagrange_first(X) )*P(X) + * - ( z_perm_shift(X) + lagrange_last(X))*Q(X), + * where P(X) = Prod_{i=0:4} numerator_polynomial_i(X) + γ + * Q(X) = Prod_{i=0:4} ordered_range_constraint_i(X) + γ + * the first 4 numerator polynomials are concatenated range constraint polynomials and the last one is the constant + * extra numerator + * + * @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 GoblinTranslatorPermutationRelationImpl::accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor) +{ + [&]() { + using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + auto z_perm = View(in.z_perm); + auto z_perm_shift = View(in.z_perm_shift); + auto lagrange_first = View(in.lagrange_first); + auto lagrange_last = View(in.lagrange_last); + + // Contribution (1) + std::get<0>(accumulators) += + (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - + ((z_perm_shift + lagrange_last) * compute_grand_product_denominator(in, params))) * + scaling_factor; + }(); + + [&]() { + using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; + using View = typename Accumulator::View; + + auto z_perm_shift = View(in.z_perm_shift); + auto lagrange_last = View(in.lagrange_last); + + // Contribution (2) + std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; + }(); +}; + +template class GoblinTranslatorPermutationRelationImpl; +DEFINE_SUMCHECK_RELATION_CLASS(GoblinTranslatorPermutationRelationImpl, honk::flavor::GoblinTranslator); + +} // namespace proof_system diff --git a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp index 7f11672ba7c..ac53a2fca69 100644 --- a/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp +++ b/barretenberg/cpp/src/barretenberg/relations/translator_vm/translator_permutation_relation.hpp @@ -74,38 +74,10 @@ template class GoblinTranslatorPermutationRelationImpl { */ template - inline static void accumulate(ContainerOverSubrelations& accumulators, - const AllEntities& in, - const Parameters& params, - const FF& scaling_factor) - { - [&]() { - using Accumulator = std::tuple_element_t<0, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - auto z_perm = View(in.z_perm); - auto z_perm_shift = View(in.z_perm_shift); - auto lagrange_first = View(in.lagrange_first); - auto lagrange_last = View(in.lagrange_last); - - // Contribution (1) - std::get<0>(accumulators) += - (((z_perm + lagrange_first) * compute_grand_product_numerator(in, params)) - - ((z_perm_shift + lagrange_last) * compute_grand_product_denominator(in, params))) * - scaling_factor; - }(); - - [&]() { - using Accumulator = std::tuple_element_t<1, ContainerOverSubrelations>; - using View = typename Accumulator::View; - - auto z_perm_shift = View(in.z_perm_shift); - auto lagrange_last = View(in.lagrange_last); - - // Contribution (2) - std::get<1>(accumulators) += (lagrange_last * z_perm_shift) * scaling_factor; - }(); - }; + static void accumulate(ContainerOverSubrelations& accumulators, + const AllEntities& in, + const Parameters& params, + const FF& scaling_factor); }; template diff --git a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp index a40555af5b4..7e515a42823 100644 --- a/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp +++ b/barretenberg/cpp/src/barretenberg/ultra_honk/relation_correctness.test.cpp @@ -327,7 +327,7 @@ TEST_F(RelationCorrectnessTests, GoblinUltraRelationCorrectness) */ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) { - using Flavor = flavor::GoblinTranslatorBasic; + using Flavor = flavor::GoblinTranslator; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using Polynomial = barretenberg::Polynomial; @@ -448,7 +448,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorPermutationRelationCorrectness) TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) { - using Flavor = flavor::GoblinTranslatorBasic; + using Flavor = flavor::GoblinTranslator; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using Polynomial = barretenberg::Polynomial; @@ -537,7 +537,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorGenPermSortRelationCorrectness) */ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) { - using Flavor = flavor::GoblinTranslatorBasic; + using Flavor = flavor::GoblinTranslator; using FF = typename Flavor::FF; using ProverPolynomials = typename Flavor::ProverPolynomials; using ProverPolynomialIds = typename Flavor::ProverPolynomialIds; @@ -637,7 +637,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorExtraRelationsCorrectness) */ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectness) { - using Flavor = flavor::GoblinTranslatorBasic; + using Flavor = flavor::GoblinTranslator; using FF = typename Flavor::FF; using BF = typename Flavor::BF; using ProverPolynomials = typename Flavor::ProverPolynomials; @@ -1008,7 +1008,7 @@ TEST_F(RelationCorrectnessTests, GoblinTranslatorDecompositionRelationCorrectnes */ TEST_F(RelationCorrectnessTests, GoblinTranslatorNonNativeRelationCorrectness) { - using Flavor = flavor::GoblinTranslatorBasic; + using Flavor = flavor::GoblinTranslator; using FF = typename Flavor::FF; using BF = typename Flavor::BF; using ProverPolynomials = typename Flavor::ProverPolynomials;