5#include <gtest/gtest.h>
82 return in[2] ==
FF(1) || in[3] ==
FF(1);
92 return Accumulator(in[2]) + Accumulator(in[3]) - Accumulator(in[2]) * Accumulator(in[3]);
100 return std::forward_as_tuple(in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
105 return std::forward_as_tuple(in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
144 return in[2] ==
FF(1) || in[3] ==
FF(1);
149 return Accumulator(in[2]) + Accumulator(in[3]) - Accumulator(in[2]) * Accumulator(in[3]);
155 template <
typename Accumulator,
size_t ,
typename Parameters>
158 using View =
typename Accumulator::View;
159 auto f = Accumulator(View(in[4]));
166 template <
typename Accumulator,
size_t ,
typename Parameters>
169 using View =
typename Accumulator::View;
170 auto t = Accumulator(View(in[5]));
176 return std::forward_as_tuple(in[0], in[1], in[2], in[3], in[4], in[5]);
181 return std::forward_as_tuple(in[0], in[1], in[2], in[3], in[4], in[5]);
212 FF scaling_factor =
FF(1))
215 for (
const auto& row : rows) {
241 const FF beta = params.
beta;
244 auto construct_term = [&](
FF col1,
FF col2) {
return col1 * beta + col2 + gamma; };
249 const FF t1_row0 =
FF(3);
250 const FF t2_row0 =
FF(4);
251 const FF lookup_term0 = construct_term(f1, f2);
252 const FF table_term_row0 = construct_term(t1_row0, t2_row0);
255 row0[0] = (lookup_term0 * table_term_row0).invert();
263 const FF f1_row1 =
FF(9);
264 const FF f2_row1 =
FF(10);
265 const FF lookup_term_row1 = construct_term(f1_row1, f2_row1);
266 const FF table_term1 = construct_term(t1_row1, t2_row1);
269 row1[0] = (lookup_term_row1 * table_term1).invert();
270 row1[1] = read_count;
279 EXPECT_EQ(acc[0],
FF(0));
282 EXPECT_EQ(acc[0],
FF(0));
283 EXPECT_EQ(acc[1],
FF(1) / lookup_term0 - read_count / table_term1);
298 auto acc = eval_row(row, params);
299 EXPECT_EQ(acc[0],
FF(0));
300 EXPECT_EQ(acc[1],
FF(0));
314 const FF beta = params.
beta;
321 const FF t2 =
FF(11);
322 const FF lookup_term = f1 * beta + f2 + gamma;
323 const FF table_term = t1 * beta + t2 + gamma;
326 row[0] = (lookup_term * table_term).invert();
333 auto acc = eval_row(row, params);
334 EXPECT_EQ(acc[0],
FF(0));
348 const FF beta = params.
beta;
355 const FF lookup_term = f1 * beta + f2 + gamma;
356 const FF table_term = t1 * beta + t2 + gamma;
359 row[0] = (lookup_term * table_term).invert();
367 auto acc = eval_row(row, params);
368 EXPECT_EQ(acc[0],
FF(0));
380 check_two_row_sum(params,
FF(1),
FF(2),
FF(1));
391 const FF beta = params.
beta;
397 const FF t2 =
FF(11);
407 const FF lookup_term = f1 * beta + f2 + gamma;
408 const FF table_term = t1 * beta + t2 + gamma;
410 auto acc = eval_row(row, params);
414 const FF expected = lookup_term * table_term *
FF(42) -
FF(1);
415 EXPECT_EQ(acc[0], expected);
416 EXPECT_NE(acc[0],
FF(0));
426 check_two_row_sum(params,
FF(2),
FF(4),
FF(1));
436 check_two_row_sum(params,
FF(1),
FF(2),
FF(2));
439 check_two_row_sum(params,
FF(1),
FF(2),
FF(0));
460 auto construct_term = [&](
FF col) {
return col * col; };
463 const FF v_sq = construct_term(v);
466 const FF t_row0 =
FF(1);
468 row0[0] = (v_sq * t_row0).invert();
474 const FF f_row1 =
FF(5);
475 const FF lookup_term_row1 = construct_term(f_row1);
477 row1[0] = (lookup_term_row1 * table_t_value).invert();
478 row1[1] = read_count;
481 row1[5] = table_t_value;
485 EXPECT_EQ(acc[0],
FF(0));
488 EXPECT_EQ(acc[0],
FF(0));
489 EXPECT_EQ(acc[1],
FF(1) / v_sq - read_count / table_t_value);
500 auto acc = eval_row(row, params);
501 EXPECT_EQ(acc[0],
FF(0));
502 EXPECT_EQ(acc[1],
FF(0));
516 const FF t_val =
FF(7);
517 const FF lookup_term = f * f;
518 const FF table_term = t_val;
521 row[0] = (lookup_term * table_term).invert();
526 auto acc = eval_row(row, params);
527 EXPECT_EQ(acc[0],
FF(0));
541 const FF t_val =
FF(9);
542 const FF lookup_term = f * f;
543 const FF table_term = t_val;
546 row[0] = (lookup_term * table_term).invert();
552 auto acc = eval_row(row, params);
553 EXPECT_EQ(acc[0],
FF(0));
564 check_two_row_sum(params,
FF(9),
FF(1));
575 const FF t_val =
FF(7);
576 const FF lookup_term = f * f;
577 const FF table_term = t_val;
585 auto acc = eval_row(row, params);
587 const FF expected = lookup_term * table_term *
FF(13) -
FF(1);
588 EXPECT_EQ(acc[0], expected);
589 EXPECT_NE(acc[0],
FF(0));
598 check_two_row_sum(params,
FF(8),
FF(1));
607 check_two_row_sum(params,
FF(9),
FF(2));
610 check_two_row_sum(params,
FF(9),
FF(0));
671 return in[3] ==
FF(1) || in[5] ==
FF(1) || in[4] ==
FF(1) || in[6] ==
FF(1);
685 Accumulator(in[3]) + Accumulator(in[5]) - Accumulator(in[3]) * Accumulator(in[5]);
687 auto customized_term =
688 Accumulator(in[4]) + Accumulator(in[6]) - Accumulator(in[4]) * Accumulator(in[6]);
690 return basic_term + customized_term - basic_term * customized_term;
697 template <
typename Accumulator,
size_t ,
typename Parameters>
700 using View =
typename Accumulator::View;
701 auto f = Accumulator(View(in[13]));
708 template <
typename Accumulator,
size_t ,
typename Parameters>
711 using View =
typename Accumulator::View;
712 auto t = Accumulator(View(in[14]));
718 return std::forward_as_tuple(in[0],
737 return std::forward_as_tuple(in[0],
787 FF read_count =
FF(1),
788 FF custom_t_row0 =
FF(27),
789 FF read_count_customized =
FF(1))
791 const FF beta = params.
beta;
795 auto compute_basic_term = [&](
FF f1,
FF f2,
FF f3) {
return f1 * beta_sq + f2 * beta + f3 + gamma; };
796 auto compute_custom_term = [&](
FF f) {
return f * f * f; };
799 const FF valid_t1_row1 =
FF(1);
800 const FF valid_t2_row1 =
FF(2);
801 const FF valid_t3_row1 =
FF(3);
802 const FF valid_custom_f_row_1 =
FF(3);
805 const FF custom_f_row0 =
FF(2);
806 const FF dummy_t1_row0 =
FF(1);
807 const FF dummy_t2_row0 =
FF(1);
808 const FF dummy_t3_row0 =
FF(1);
811 const FF lookup_term_basic_row0 = compute_basic_term(valid_t1_row1, valid_t2_row1, valid_t3_row1);
812 const FF lookup_term_custom_row0 = compute_custom_term(custom_f_row0);
813 const FF table_term_basic_row0 = compute_basic_term(dummy_t1_row0, dummy_t2_row0, dummy_t3_row0);
814 const FF table_term_custom_row0 = custom_t_row0;
817 row0[0] = (lookup_term_basic_row0 * lookup_term_custom_row0 * table_term_basic_row0 * table_term_custom_row0)
819 row0[2] = read_count_customized;
822 row0[7] = valid_t1_row1;
823 row0[8] = valid_t2_row1;
824 row0[9] = valid_t3_row1;
825 row0[10] = dummy_t1_row0;
826 row0[11] = dummy_t2_row0;
827 row0[12] = dummy_t3_row0;
828 row0[13] = custom_f_row0;
829 row0[14] = table_term_custom_row0;
832 const FF dummy_f1_row1 =
FF(4);
833 const FF dummy_f2_row1 =
FF(5);
834 const FF dummy_f3_row1 =
FF(6);
835 const FF dummy_custom_t_row1 =
FF(1);
838 const FF lookup_term_basic_row1 = compute_basic_term(dummy_f1_row1, dummy_f2_row1, dummy_f3_row1);
839 const FF lookup_term_custom_row1 = compute_custom_term(valid_custom_f_row_1);
840 const FF table_term_basic_row1 = compute_basic_term(t1_row1, t2_row1, t3_row1);
841 const FF table_term_custom_row1 = dummy_custom_t_row1;
844 row1[0] = (lookup_term_basic_row1 * lookup_term_custom_row1 * table_term_basic_row1 * table_term_custom_row1)
846 row1[1] = read_count;
849 row1[7] = dummy_f1_row1;
850 row1[8] = dummy_f2_row1;
851 row1[9] = dummy_f3_row1;
855 row1[13] = valid_custom_f_row_1;
856 row1[14] = dummy_custom_t_row1;
860 EXPECT_EQ(acc[0],
FF(0));
863 EXPECT_EQ(acc[0],
FF(0));
865 FF(1) / lookup_term_basic_row0 - read_count / table_term_basic_row1 +
866 FF(1) / lookup_term_custom_row1 - read_count_customized / table_term_custom_row0);
883 auto acc = eval_row(row, params);
884 EXPECT_EQ(acc[0],
FF(0));
885 EXPECT_EQ(acc[1],
FF(0));
894 const FF beta = params.
beta;
898 auto validate_row = [&](
const size_t idx) {
902 const FF custom_f =
FF(2);
903 const FF t0_1 =
FF(1);
904 const FF t0_2 =
FF(1);
905 const FF t0_3 =
FF(1);
906 const FF custom_t =
FF(1);
907 const FF lookup_term_0 = f1 * beta_sq + f2 * beta + f3 + gamma;
908 const FF lookup_term_1 = custom_f * custom_f * custom_f;
909 const FF table_term_0 = t0_1 * beta_sq + t0_2 * beta + t0_3 + gamma;
910 const FF table_term_1 = custom_t;
913 row[0] = (lookup_term_0 * lookup_term_1 * table_term_0 * table_term_1).invert();
924 auto acc = eval_row(row, params);
925 EXPECT_EQ(acc[0],
FF(0));
941 const FF beta = params.
beta;
945 auto validate_row = [&](
const size_t idx) {
949 const FF custom_f =
FF(3);
950 const FF t0_1 =
FF(5);
951 const FF t0_2 =
FF(7);
952 const FF t0_3 =
FF(9);
953 const FF custom_t =
FF(1);
954 const FF lookup_term_0 = f1 * beta_sq + f2 * beta + f3 + gamma;
955 const FF lookup_term_1 = custom_f * custom_f * custom_f;
956 const FF table_term_0 = t0_1 * beta_sq + t0_2 * beta + t0_3 + gamma;
957 const FF table_term_1 = custom_t;
960 row[0] = (lookup_term_0 * lookup_term_1 * table_term_0 * table_term_1).invert();
971 auto acc = eval_row(row, params);
972 EXPECT_EQ(acc[0],
FF(0));
989 check_two_row_sum(params);
998 const FF beta = params.
beta;
1000 const FF gamma = params.
gamma;
1002 const FF f1 =
FF(3);
1003 const FF f2 =
FF(5);
1004 const FF f3 =
FF(7);
1005 const FF custom_f =
FF(2);
1006 const FF t0_1 =
FF(1);
1007 const FF t0_2 =
FF(1);
1008 const FF t0_3 =
FF(1);
1009 const FF custom_t =
FF(1);
1010 const FF lookup_term_0 = f1 * beta_sq + f2 * beta + f3 + gamma;
1011 const FF lookup_term_1 =
FF(8);
1012 const FF table_term_0 = t0_1 * beta_sq + t0_2 * beta + t0_3 + gamma;
1013 const FF table_term_1 = custom_t;
1027 auto acc = eval_row(row, params);
1029 const FF expected = lookup_term_0 * lookup_term_1 * table_term_0 * table_term_1 *
FF(42) -
FF(1);
1030 EXPECT_EQ(acc[0], expected);
1031 EXPECT_NE(acc[0],
FF(0));
1042 check_two_row_sum(params,
FF(2),
FF(4),
FF(6),
FF(1));
1045 check_two_row_sum(params,
FF(1),
FF(2),
FF(3),
FF(1),
FF(10));
1056 check_two_row_sum(params,
FF(1),
FF(2),
FF(3),
FF(2));
1059 check_two_row_sum(params,
FF(1),
FF(2),
FF(3),
FF(0));
1062 check_two_row_sum(params,
FF(1),
FF(2),
FF(3),
FF(1),
FF(27),
FF(2));
1065 check_two_row_sum(params,
FF(1),
FF(2),
FF(3),
FF(1),
FF(27),
FF(0));
static void check_two_row_sum(const RelationParameters< FF > ¶ms, FF t1_row1, FF t2_row1, FF read_count)
Build and evaluate a canonical two-row (lookup + table) trace.
static void check_two_row_sum(const RelationParameters< FF > ¶ms, FF table_t_value, FF read_count)
Build and evaluate a canonical two-row (lookup + table) trace.
static constexpr size_t NUM_SUBRELATIONS
std::array< FF, NUM_SUBRELATIONS > Accumulator
static Accumulator eval_trace(const std::vector< AllEntities > &rows, const RelationParameters< FF > ¶ms, FF scaling_factor=FF(1))
Accumulate multiple rows into one accumulator.
typename Settings::AllEntities AllEntities
static Accumulator eval_row(const AllEntities &row, const RelationParameters< FF > ¶ms, FF scaling_factor=FF(1))
Accumulate a single row into a fresh accumulator.
static void check_two_row_sum(const RelationParameters< FF > ¶ms, FF t1_row1=FF(1), FF t2_row1=FF(2), FF t3_row1=FF(3), FF read_count=FF(1), FF custom_t_row0=FF(27), FF read_count_customized=FF(1))
Build and evaluate a canonical two-row mixed trace.
Generic implementation of a log-derivative based lookup relation.
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters ¶ms, const FF &scaling_factor)
Compute generic log-derivative lookup subrelation accumulation.
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
static bool inverse_polynomial_is_computed_at_row(const AllEntities &in)
Returns true if either predicate is active, meaning inverse must be computed at this row.
static constexpr size_t NUM_LOOKUP_TERMS
static constexpr std::array< uint8_t, NUM_TABLE_TERMS > TABLE_TYPES
static constexpr std::array< uint8_t, NUM_LOOKUP_TERMS > LOOKUP_TYPES
std::array< FF, NUM_POLYS > AllEntities
static constexpr size_t LOOKUP_TUPLE_SIZE
static constexpr std::array< size_t, NUM_LOOKUP_TERMS > LOOKUP_TERM_DEGREES
static constexpr size_t NUM_TABLE_TERMS
static Accumulator compute_inverse_exists(const AllEntities &in)
OR(lookup_pred, table_pred) via the inclusion-exclusion formula A + B - A*B.
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE
static constexpr size_t NUM_POLYS
static constexpr std::array< size_t, NUM_TABLE_TERMS > TABLE_TERM_DEGREES
static auto get_nonconst_entities(AE &in)
static auto get_const_entities(const AE &in)
static constexpr std::array< uint8_t, NUM_TABLE_TERMS > TABLE_TYPES
static bool inverse_polynomial_is_computed_at_row(const AllEntities &in)
static auto get_const_entities(const AE &in)
static Accumulator compute_inverse_exists(const AllEntities &in)
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE
static constexpr size_t NUM_TABLE_TERMS
static constexpr std::array< uint8_t, NUM_LOOKUP_TERMS > LOOKUP_TYPES
static constexpr size_t LOOKUP_TUPLE_SIZE
static constexpr size_t NUM_LOOKUP_TERMS
std::array< FF, NUM_POLYS > AllEntities
static auto get_nonconst_entities(AE &in)
static constexpr std::array< size_t, NUM_LOOKUP_TERMS > LOOKUP_TERM_DEGREES
static constexpr size_t NUM_POLYS
static constexpr std::array< size_t, NUM_TABLE_TERMS > TABLE_TERM_DEGREES
static Accumulator compute_lookup_term(const AllEntities &in, const Parameters ¶ms)
Custom lookup term: f^2 (degree 2)
static Accumulator compute_table_term(const AllEntities &in, const Parameters ¶ms)
Custom table term: t (degree 1)
static constexpr std::array< uint8_t, NUM_TABLE_TERMS > TABLE_TYPES
static constexpr size_t LOOKUP_TUPLE_SIZE
static bool inverse_polynomial_is_computed_at_row(const AllEntities &in)
Returns true if any predicate is active, meaning the inverse must be computed at this row.
static constexpr std::array< size_t, NUM_LOOKUP_TERMS > LOOKUP_TERM_DEGREES
std::array< FF, NUM_POLYS > AllEntities
static auto get_nonconst_entities(AE &in)
static Accumulator compute_table_term(const AllEntities &in, const Parameters ¶ms)
Custom table term: t (degree 1)
static constexpr size_t INVERSE_EXISTS_POLYNOMIAL_DEGREE
static Accumulator compute_inverse_exists(const AllEntities &in)
OR of all four predicates via inclusion-exclusion.
static constexpr std::array< size_t, NUM_TABLE_TERMS > TABLE_TERM_DEGREES
static constexpr std::array< uint8_t, NUM_LOOKUP_TERMS > LOOKUP_TYPES
static constexpr size_t NUM_LOOKUP_TERMS
static constexpr size_t NUM_TABLE_TERMS
static constexpr size_t NUM_POLYS
static auto get_const_entities(const AE &in)
static Accumulator compute_lookup_term(const AllEntities &in, const Parameters ¶ms)
Custom lookup term: f^3 (degree 3), f = in[13]. Called only for the CUSTOMIZED_LOOKUP term (lookup_in...
Container for parameters used by the grand product (permutation, lookup) Honk relations.
static RelationParameters get_random()