Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
sumcheck_round.test.cpp
Go to the documentation of this file.
1#include "sumcheck_round.hpp"
5
6#include <gtest/gtest.h>
7
8using namespace bb;
9
14TEST(SumcheckRound, SumcheckTupleOfTuplesOfUnivariates)
15{
16 using Flavor = UltraFlavor;
17 using FF = typename Flavor::FF;
18 using SubrelationSeparators = typename Flavor::SubrelationSeparators;
19
20 // Define three linear univariates of different sizes
21 Univariate<FF, 3> univariate_1({ 1, 2, 3 });
22 Univariate<FF, 2> univariate_2({ 2, 4 });
23 Univariate<FF, 5> univariate_3({ 3, 4, 5, 6, 7 });
24 const size_t MAX_LENGTH = 5;
25
26 // Construct a tuple of tuples of the form { {univariate_1}, {univariate_2, univariate_3} }
27 auto tuple_of_tuples = flat_tuple::make_tuple(flat_tuple::make_tuple(univariate_1),
28 flat_tuple::make_tuple(univariate_2, univariate_3));
29
30 // Use scale_univariate_accumulators to scale by challenge powers
31 SubrelationSeparators challenge = {};
32 challenge[0] = 5;
33 challenge[1] = 25;
34 RelationUtils<Flavor>::scale_univariates(tuple_of_tuples, challenge);
35
36 // Use extend_and_batch_univariates to extend to MAX_LENGTH then accumulate
37 GateSeparatorPolynomial<FF> gate_separators({ 1 });
38 auto result = Univariate<FF, MAX_LENGTH>();
39 SumcheckProverRound<Flavor>::extend_and_batch_univariates(tuple_of_tuples, result, gate_separators);
40
41 // Repeat the batching process manually
42 auto result_expected = univariate_1.template extend_to<MAX_LENGTH>() +
43 univariate_2.template extend_to<MAX_LENGTH>() * challenge[0] +
44 univariate_3.template extend_to<MAX_LENGTH>() * challenge[1];
45
46 // Compare final batched univariates
47 EXPECT_EQ(result, result_expected);
48
49 // Reinitialize univariate accumulators to zero
51
52 // Check that reinitialization was successful
53 Univariate<FF, 3> expected_1({ 0, 0, 0 });
54 Univariate<FF, 2> expected_2({ 0, 0 });
55 Univariate<FF, 5> expected_3({ 0, 0, 0, 0, 0 });
56 EXPECT_EQ(std::get<0>(std::get<0>(tuple_of_tuples)), expected_1);
57 EXPECT_EQ(std::get<0>(std::get<1>(tuple_of_tuples)), expected_2);
58 EXPECT_EQ(std::get<1>(std::get<1>(tuple_of_tuples)), expected_3);
59}
60
65TEST(SumcheckRound, TuplesOfEvaluationArrays)
66{
67 using Flavor = UltraFlavor;
68 using Utils = RelationUtils<Flavor>;
69 using FF = typename Flavor::FF;
70 using SubrelationSeparators = typename Flavor::SubrelationSeparators;
71
72 // Define two arrays of arbitrary elements
73 std::array<FF, 2> evaluations_1 = { 4, 3 };
74 std::array<FF, 2> evaluations_2 = { 6, 2 };
75
76 // Construct a tuple
77 auto tuple_of_arrays = flat_tuple::make_tuple(evaluations_1, evaluations_2);
78
79 // Use scale_and_batch_elements to scale by challenge powers
80 SubrelationSeparators challenge{ 5, 25, 125 };
81
82 FF result = Utils::scale_and_batch_elements(tuple_of_arrays, challenge);
83
84 // Repeat the batching process manually
85 auto result_expected = evaluations_1[0] + evaluations_1[1] * challenge[0] + evaluations_2[0] * challenge[1] +
86 evaluations_2[1] * challenge[2];
87
88 // Compare batched result
89 EXPECT_EQ(result, result_expected);
90
91 // Reinitialize univariate accumulators to zero
92 Utils::zero_elements(tuple_of_arrays);
93
94 EXPECT_EQ(std::get<0>(tuple_of_arrays)[0], 0);
95 EXPECT_EQ(std::get<1>(tuple_of_arrays)[0], 0);
96 EXPECT_EQ(std::get<1>(tuple_of_arrays)[1], 0);
97}
98
103TEST(SumcheckRound, AddTuplesOfTuplesOfUnivariates)
104{
105 using Flavor = UltraFlavor;
106 using FF = typename Flavor::FF;
107
108 // Define some arbitrary univariates
109 Univariate<FF, 2> univariate_1({ 1, 2 });
110 Univariate<FF, 2> univariate_2({ 2, 4 });
111 Univariate<FF, 3> univariate_3({ 3, 4, 5 });
112
113 Univariate<FF, 2> univariate_4({ 3, 6 });
114 Univariate<FF, 2> univariate_5({ 8, 1 });
115 Univariate<FF, 3> univariate_6({ 3, 7, 1 });
116
117 Univariate<FF, 2> expected_sum_1 = univariate_1 + univariate_4;
118 Univariate<FF, 2> expected_sum_2 = univariate_2 + univariate_5;
119 Univariate<FF, 3> expected_sum_3 = univariate_3 + univariate_6;
120
121 // Construct two tuples of tuples of univariates
122 auto tuple_of_tuples_1 = flat_tuple::make_tuple(flat_tuple::make_tuple(univariate_1),
123 flat_tuple::make_tuple(univariate_2, univariate_3));
124 auto tuple_of_tuples_2 = flat_tuple::make_tuple(flat_tuple::make_tuple(univariate_4),
125 flat_tuple::make_tuple(univariate_5, univariate_6));
126
127 RelationUtils<Flavor>::add_nested_tuples(tuple_of_tuples_1, tuple_of_tuples_2);
128
129 EXPECT_EQ(std::get<0>(std::get<0>(tuple_of_tuples_1)), expected_sum_1);
130 EXPECT_EQ(std::get<0>(std::get<1>(tuple_of_tuples_1)), expected_sum_2);
131 EXPECT_EQ(std::get<1>(std::get<1>(tuple_of_tuples_1)), expected_sum_3);
132}
Curve::ScalarField FF
std::array< FF, NUM_SUBRELATIONS - 1 > SubrelationSeparators
static void scale_univariates(auto &tuple, const SubrelationSeparators &subrelation_separators)
Scale Univariates, each representing a subrelation, by different challenges.
Definition utils.hpp:76
static void zero_univariates(auto &tuple)
Set all coefficients of Univariates to zero.
Definition utils.hpp:61
static constexpr void add_nested_tuples(Tuple &tuple_1, const Tuple &tuple_2)
Componentwise addition of nested tuples (tuples of tuples)
Definition utils.hpp:117
static void extend_and_batch_univariates(const TupleOfTuplesOfUnivariates &tuple, ExtendedUnivariate &result, const bb::GateSeparatorPolynomial< FF > &gate_separators)
Extend Univariates then sum them multiplying by the current -contributions.
A univariate polynomial represented by its values on {domain_start, domain_start + 1,...
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
typename Flavor::FF FF
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
TUPLET_INLINE constexpr auto make_tuple(Ts &&... args)
Definition tuplet.hpp:1062
Implementation of the methods for the -polynomials used in Protogalaxy and -polynomials used in Sumch...