Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
relation_types.test.cpp
Go to the documentation of this file.
1#include "relation_types.hpp"
5
6#include <gtest/gtest.h>
7
8using namespace bb;
9
10TEST(RelationTypes, CreateSumcheckTupleOfTuplesOfUnivariates)
11{
12 using FF = fr;
13
14 struct Relation1 {
15 using SumcheckTupleOfUnivariatesOverSubrelations =
16 TupleOfUnivariates<FF, /*SUBRELATION_PARTIAL_LENGTHS=*/std::array<size_t, 1>{ 3 }>;
17 };
18 struct Relation2 {
19 using SumcheckTupleOfUnivariatesOverSubrelations =
20 TupleOfUnivariates<FF, /*SUBRELATION_PARTIAL_LENGTHS=*/std::array<size_t, 2>{ 2, 5 }>;
21 };
22 using RelationsTuple = flat_tuple::tuple<Relation1, Relation2>;
23 auto tuple_of_tuples = create_sumcheck_tuple_of_tuples_of_univariates<RelationsTuple>();
24
25 Univariate<FF, 3> expected_zero_1({ 0, 0, 0 });
26 Univariate<FF, 2> expected_zero_2({ 0, 0 });
27 Univariate<FF, 5> expected_zero_3({ 0, 0, 0, 0, 0 });
28 EXPECT_EQ(std::get<0>(std::get<0>(tuple_of_tuples)), expected_zero_1);
29 EXPECT_EQ(std::get<0>(std::get<1>(tuple_of_tuples)), expected_zero_2);
30 EXPECT_EQ(std::get<1>(std::get<1>(tuple_of_tuples)), expected_zero_3);
31
32 // Now test it when creating it from the type.
33 using SumcheckTupleOfTuplesOfUnivariates =
34 decltype(create_sumcheck_tuple_of_tuples_of_univariates<RelationsTuple>());
35 // Note: {} is required to initialize the tuple contents. Otherwise the univariates contain garbage.
36 SumcheckTupleOfTuplesOfUnivariates tuple_of_tuples_from_type{};
37
38 EXPECT_EQ(std::get<0>(std::get<0>(tuple_of_tuples_from_type)), expected_zero_1);
39 EXPECT_EQ(std::get<0>(std::get<1>(tuple_of_tuples_from_type)), expected_zero_2);
40 EXPECT_EQ(std::get<1>(std::get<1>(tuple_of_tuples_from_type)), expected_zero_3);
41}
42
43// This class needs to be outside the test because of the templated skip.
45 struct AllEntities {
46 int input;
47 };
48 template <typename Entities> static bool skip(const Entities&) { return false; }
49};
50
51TEST(RelationTypes, IsSkippableConcept)
52{
53 // Works with a non-templated skip function.
54 struct Relation1 {
55 struct AllEntities {
56 int input;
57 };
58 static bool skip(const AllEntities&) { return false; }
59 };
60 static_assert(isSkippable<Relation1, Relation1::AllEntities>);
61
62 // Works with a templated skip function.
63 static_assert(isSkippable<RelationWithTemplatedSkip, RelationWithTemplatedSkip::AllEntities>);
64
65 // False when the skip function is not there.
66 struct Relation2 {
67 struct AllEntities {
68 int input;
69 };
70 };
71 static_assert(!isSkippable<Relation2, Relation2::AllEntities>);
72
73 struct Relation3 {};
74}
75
76TEST(RelationParameters, GetRandomSetsBetaQuartic)
77{
78 const auto params = RelationParameters<fr>::get_random();
79
80 EXPECT_NE(params.beta_quartic, fr(0));
81 EXPECT_EQ(params.beta_quartic, params.beta_cube * params.beta);
82
83 // eccvm_set_permutation_delta uses first_term_tag = FIRST_TERM_TAG (= 1) * beta_quartic.
84 const fr g = params.gamma;
85 const fr b2 = params.beta_sqr;
86 const fr tag = params.beta_quartic;
87 const fr expected = (g + tag) * (g + b2 + tag) * (g + b2 + b2 + tag) * (g + b2 + b2 + b2 + tag);
88 EXPECT_EQ(params.eccvm_set_permutation_delta, expected);
89
90 const fr wrong_zero_tag = g * (g + b2) * (g + b2 + b2) * (g + b2 + b2 + b2);
91 EXPECT_NE(params.eccvm_set_permutation_delta, wrong_zero_tag);
92}
bb::field< bb::Bn254FrParams > FF
Definition field.cpp:24
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
field< Bn254FrParams > fr
Definition fr.hpp:155
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
typename TupleOfContainersOverArray< bb::Univariate, FF, LENGTHS >::type TupleOfUnivariates
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static bool skip(const Entities &)
Container for parameters used by the grand product (permutation, lookup) Honk relations.
static RelationParameters get_random()