diff --git a/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp b/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp index b04191041a..34e3cf4d13 100644 --- a/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp +++ b/cpp/src/barretenberg/honk/sumcheck/polynomials/multivariates.test.cpp @@ -68,7 +68,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial) FF expected_lo = v00 * (FF(1) - round_challenge_0) + v10 * round_challenge_0; FF expected_hi = v01 * (FF(1) - round_challenge_0) + v11 * round_challenge_0; - sumcheck.fold(full_polynomials, multivariate_n, round_challenge_0); + sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], round_challenge_0); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], FF(0)); @@ -76,7 +76,7 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsSpecial) FF round_challenge_1 = 2; FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } @@ -104,14 +104,14 @@ TYPED_TEST(MultivariatesTests, FoldTwoRoundsGeneric) FF expected_lo = v00 * (FF(1) - round_challenge_0) + v10 * round_challenge_0; FF expected_hi = v01 * (FF(1) - round_challenge_0) + v11 * round_challenge_0; - sumcheck.fold(full_polynomials, multivariate_n, round_challenge_0); + sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_1 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_1) + expected_hi * round_challenge_1; - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } @@ -167,7 +167,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial) FF expected_q3 = v001 * (FF(1) - round_challenge_0) + v101 * round_challenge_0; // 6 FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; // 8 - sumcheck.fold(full_polynomials, multivariate_n, round_challenge_0); + sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); @@ -178,13 +178,13 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsSpecial) FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; // 6 FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; // 10 - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_2 = 3; FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; // 18 - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } @@ -218,7 +218,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric) FF expected_q3 = v001 * (FF(1) - round_challenge_0) + v101 * round_challenge_0; FF expected_q4 = v011 * (FF(1) - round_challenge_0) + v111 * round_challenge_0; - sumcheck.fold(full_polynomials, multivariate_n, round_challenge_0); + sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_q1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_q2); @@ -229,13 +229,13 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGeneric) FF expected_lo = expected_q1 * (FF(1) - round_challenge_1) + expected_q2 * round_challenge_1; FF expected_hi = expected_q3 * (FF(1) - round_challenge_1) + expected_q4 * round_challenge_1; - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_lo); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][1], expected_hi); FF round_challenge_2 = FF::random_element(); FF expected_val = expected_lo * (FF(1) - round_challenge_2) + expected_hi * round_challenge_2; - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[0][0], expected_val); } @@ -286,7 +286,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys) expected_q4[i] = v011[i] * (FF(1) - round_challenge_0) + v111[i] * round_challenge_0; } - sumcheck.fold(full_polynomials, multivariate_n, round_challenge_0); + sumcheck.partially_evaluate(full_polynomials, multivariate_n, round_challenge_0); for (size_t i = 0; i < 3; i++) { EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_q1[i]); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_q2[i]); @@ -301,7 +301,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys) expected_lo[i] = expected_q1[i] * (FF(1) - round_challenge_1) + expected_q2[i] * round_challenge_1; expected_hi[i] = expected_q3[i] * (FF(1) - round_challenge_1) + expected_q4[i] * round_challenge_1; } - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 1, round_challenge_1); for (size_t i = 0; i < 3; i++) { EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_lo[i]); EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][1], expected_hi[i]); @@ -311,7 +311,7 @@ TYPED_TEST(MultivariatesTests, FoldThreeRoundsGenericMultiplePolys) for (size_t i = 0; i < 3; i++) { expected_val[i] = expected_lo[i] * (FF(1) - round_challenge_2) + expected_hi[i] * round_challenge_2; } - sumcheck.fold(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); + sumcheck.partially_evaluate(sumcheck.partially_evaluated_polynomials, multivariate_n >> 2, round_challenge_2); for (size_t i = 0; i < 3; i++) { EXPECT_EQ(sumcheck.partially_evaluated_polynomials[i][0], expected_val[i]); } diff --git a/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp b/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp index 0cb3f3b8aa..910a8488da 100644 --- a/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp +++ b/cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp @@ -39,9 +39,10 @@ template class... Relations ..., P_N. * At initialization, * we think of these as lying in a two-dimensional array, where each column records the value of one P_i on H^d. - * After the first round, the array will be updated ('folded'), so that the first n/2 rows will represent the + * After the first round, the array will be updated (partially evaluated), so that the first n/2 rows will represent + the * evaluations P_i(u0, X1, ..., X_{d-1}) as a low-degree extension on H^{d-1}. In reality, we elude copying all - * of the polynomial-defining data by only populating folded_multivariates after the first round. I.e.: + * of the polynomial-defining data by only populating partially_evaluated_polynomials after the first round. I.e.: We imagine all of the defining polynomial data in a matrix like this: | P_1 | P_2 | P_3 | P_4 | ... | P_N | N = number of multivariatesk @@ -55,7 +56,7 @@ template class... Relations \-| * | * | * | * | ... | * | vertex n-1 m = n/2 * - Each group consists of N edges |, and our construction of univariates and folding + Each group consists of N edges |, and our construction of univariates and partial evaluation * operations naturally operate on these groups of edges @@ -81,8 +82,8 @@ template class... Relations , round(std::tuple(Relations()...)){}; /** - * @brief Compute univariate restriction place in transcript, generate challenge, fold,... repeat until final round, - * then compute multivariate evaluations and place in transcript. + * @brief Compute univariate restriction place in transcript, generate challenge, partially evaluate,... repeat + * until final round, then compute multivariate evaluations and place in transcript. * * @details */ @@ -102,9 +103,10 @@ template class... Relations transcript.send_to_verifier("Sumcheck:univariate_0", round_univariate); FF round_challenge = transcript.get_challenge("Sumcheck:u_0"); multivariate_challenge.emplace_back(round_challenge); - fold(full_polynomials, multivariate_n, round_challenge); + partially_evaluate(full_polynomials, multivariate_n, round_challenge); pow_univariate.partially_evaluate(round_challenge); - round.round_size = round.round_size >> 1; // TODO(#224)(Cody): Maybe fold should do this and release memory? + round.round_size = + round.round_size >> 1; // TODO(#224)(Cody): Maybe partially_evaluate should do this and release memory? // All but final round // We operate on partially_evaluated_polynomials in place. @@ -115,7 +117,7 @@ template class... Relations transcript.send_to_verifier("Sumcheck:univariate_" + std::to_string(round_idx), round_univariate); FF round_challenge = transcript.get_challenge("Sumcheck:u_" + std::to_string(round_idx)); multivariate_challenge.emplace_back(round_challenge); - fold(partially_evaluated_polynomials, round.round_size, round_challenge); + partially_evaluate(partially_evaluated_polynomials, round.round_size, round_challenge); pow_univariate.partially_evaluate(round_challenge); round.round_size = round.round_size >> 1; } @@ -189,14 +191,12 @@ template class... Relations return SumcheckOutput{ multivariate_challenge, purported_evaluations }; }; - // TODO(#224)(Cody): Rename. fold is not descriptive, and it's already in use in the Gemini context. - // Probably just call it partial_evaluation? /** * @brief Evaluate at the round challenge and prepare class for next round. * Illustration of layout in example of first round when d==3 (showing just one Honk polynomial, * i.e., what happens in just one column of our two-dimensional array): * - * groups vertex terms collected vertex terms groups after folding + * groups vertex terms collected vertex terms groups after partial evaluation * g0 -- v0 (1-X0)(1-X1)(1-X2) --- (v0(1-X0) + v1 X0) (1-X1)(1-X2) ---- (v0(1-u0) + v1 u0) (1-X1)(1-X2) * \- v1 X0 (1-X1)(1-X2) --/ --- (v2(1-u0) + v3 u0) X1 (1-X2) * g1 -- v2 (1-X0) X1 (1-X2) --- (v2(1-X0) + v3 X0) X1 (1-X2)-/ -- (v4(1-u0) + v5 u0) (1-X1) X2 @@ -208,7 +208,7 @@ template class... Relations * * @param challenge */ - void fold(auto& polynomials, size_t round_size, FF round_challenge) + void partially_evaluate(auto& polynomials, size_t round_size, FF round_challenge) { // after the first round, operate in place on partially_evaluated_polynomials for (size_t j = 0; j < polynomials.size(); ++j) {