Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
gate_separator.test.cpp
Go to the documentation of this file.
1#include "gate_separator.hpp"
3#include <gtest/gtest.h>
4
5using namespace bb;
6
7TEST(GateSeparatorPolynomial, FullPowConsistency)
8{
9 constexpr size_t d = 5;
10 std::vector<fr> betas(d);
11 for (auto& beta : betas) {
12 beta = fr::random_element();
13 }
14
16 std::array<fr, d> variables{};
17 for (auto& u_i : variables) {
18 u_i = fr::random_element();
19 }
20
21 size_t beta_idx = 0;
22 fr expected_eval = 1;
23 for (auto& u_i : variables) {
24 poly.partially_evaluate(u_i);
25 expected_eval *= fr(1) - u_i + u_i * poly.betas[beta_idx];
26 beta_idx++;
27 // Check that current partial evaluation result is equal to the expected evaluation
28 EXPECT_EQ(poly.partial_evaluation_result, expected_eval);
29 }
30}
31
32TEST(GateSeparatorPolynomial, GateSeparatorPolynomialsOnPowers)
33{
34 std::vector<fr> betas{ 2, 4, 16 };
35 GateSeparatorPolynomial<fr> poly(betas, betas.size());
36 std::vector<fr> expected_values{ 1, 2, 4, 8, 16, 32, 64, 128 };
37 EXPECT_EQ(bb::Polynomial<fr>(expected_values), bb::Polynomial<fr>(poly.beta_products));
38}
39
40TEST(GateSeparatorPolynomial, GateSeparatorPolynomialsOnPowersWithDifferentBeta)
41{
42 constexpr size_t d = 5;
43 std::vector<fr> betas(d);
44 for (auto& beta : betas) {
45 beta = fr::random_element();
46 }
47 // Compute the beta products
48 std::vector<fr> expected_beta_products(1 << d);
49 for (size_t i = 0; i < (1 << d); i++) {
50 expected_beta_products[i] = 1;
51 for (size_t j = 0; j < d; j++) {
52 if (i & (1 << j)) {
53 expected_beta_products[i] *= betas[j];
54 }
55 }
56 }
57 GateSeparatorPolynomial<fr> poly(betas, betas.size());
58 EXPECT_EQ(bb::Polynomial<fr>(expected_beta_products), bb::Polynomial<fr>(poly.beta_products));
59}
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
field< Bn254FrParams > fr
Definition fr.hpp:174
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Implementation of the methods for the -polynomials used in in Sumcheck.
std::vector< FF > betas
The challenges .
void partially_evaluate(FF challenge)
Partially evaluate the -polynomial at the new challenge and update .
FF partial_evaluation_result
The value obtained by partially evaluating one variable in the power polynomial at each round....
Polynomial< FF > beta_products
The consecutive evaluations for identified with the integers .
static field random_element(numeric::RNG *engine=nullptr) noexcept