13#include <gtest/gtest.h>
22using Fr =
typename G1::Fr;
38 &polys.msm_size_of_msm,
50 &polys.msm_collision_x1,
51 &polys.msm_collision_x2,
52 &polys.msm_collision_x3,
53 &polys.msm_collision_x4,
63 &polys.msm_transition,
67 &polys.msm_accumulator_x,
68 &polys.msm_accumulator_y,
81 auto generators = G1::derive_generators(
"test generators", 3);
82 auto a = generators[0];
83 auto b = generators[1];
88 op_queue->mul_accumulate(
a, x);
89 op_queue->mul_accumulate(
b, y);
90 op_queue->eq_and_reset();
106 const FF beta_sqr = beta.
sqr();
107 const FF beta_cube = beta_sqr * beta;
108 auto eccvm_set_permutation_delta =
109 gamma * (gamma + beta_sqr) * (gamma + beta_sqr + beta_sqr) * (gamma + beta_sqr + beta_sqr + beta_sqr);
110 eccvm_set_permutation_delta = eccvm_set_permutation_delta.
invert();
116 .public_input_delta = 0,
117 .beta_sqr = beta_sqr,
118 .beta_cube = beta_cube,
119 .eccvm_set_permutation_delta = eccvm_set_permutation_delta,
122 compute_logderivative_inverse<FF, ECCVMLookupRelation<FF>>(polynomials, params,
Flavor::TRACE_OFFSET);
123 compute_grand_product<Flavor, ECCVMSetRelation<FF>>(polynomials, params);
124 polynomials.z_perm_shift =
Polynomial(polynomials.z_perm.shifted());
134 const size_t num_rows = polynomials.get_polynomial_size();
136 if (polynomials.transcript_add[i] ==
FF(0) && polynomials.transcript_mul[i] ==
FF(0) &&
137 polynomials.transcript_eq[i] ==
FF(0) && polynomials.transcript_reset_accumulator[i] ==
FF(0) &&
138 polynomials.lagrange_first[i] ==
FF(0) && polynomials.lagrange_last[i] ==
FF(0)) {
163 auto polynomials = build_valid_eccvm_msm_state();
168 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
172 ASSERT_EQ(polynomials.msm_add[first_msm_row],
FF(1)) <<
"First MSM row should be an active MSM add row";
173 ASSERT_EQ(polynomials.msm_transition[first_msm_row],
FF(1)) <<
"First MSM row should have msm_transition=1";
178 polynomials.set_shifted();
182 EXPECT_TRUE(failures.empty()) <<
"MSM relation should STILL PASS — acc is unused when msm_transition=1";
201 auto polynomials = build_valid_eccvm_msm_state();
205 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
208 const size_t num_rows = polynomials.get_polynomial_size();
209 size_t active_row = 0;
211 if (polynomials.msm_add[i] ==
FF(1) && polynomials.msm_transition[i] ==
FF(0)) {
216 ASSERT_NE(active_row, 0) <<
"Should find an interior active MSM add row";
220 polynomials.set_shifted();
224 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after active-row accumulator corruption";
229 auto polynomials = build_valid_eccvm_msm_state();
232 const size_t num_rows = polynomials.get_polynomial_size();
233 size_t no_op_row = 0;
235 if (polynomials.msm_add[i] ==
FF(0) && polynomials.msm_double[i] ==
FF(0) &&
236 polynomials.msm_skew[i] ==
FF(0) && polynomials.msm_transition[i] ==
FF(0) &&
237 polynomials.lagrange_first[i] ==
FF(0)) {
242 ASSERT_NE(no_op_row, 0) <<
"Should find a no-op row in the MSM table";
246 polynomials.set_shifted();
250 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after no-op accumulator corruption";
253 bool found_noop_subrelation_failure = failures.contains(45) || failures.contains(46);
254 EXPECT_TRUE(found_noop_subrelation_failure)
255 <<
"Failure should be detected by subrelations 45/46 (no-op accumulator preservation)";
276 auto polynomials = build_valid_eccvm_msm_state();
282 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
284 auto msm_polys = get_msm_polynomials(polynomials);
288 for (
auto* poly : msm_polys) {
289 for (
size_t k = poly->end_index() - 1; k >= ofs + 2; k--) {
290 poly->at(k) = (*poly)[k - 1];
292 poly->at(ofs + 1) =
FF(0);
296 polynomials.msm_size_of_msm.at(ofs + 1) = polynomials.msm_pc[ofs + 1] - polynomials.msm_pc[ofs + 2];
299 polynomials.set_shifted();
303 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after shifting MSM table by one row";
306 for (
const auto& [subrelation_idx, row_idx] : failures) {
307 info(
"Shifted MSM table: subrelation ", subrelation_idx,
" first failed at row ", row_idx);
311 EXPECT_EQ(failures.size(), 2U) <<
"Exactly two subrelations should fail (45 and 46)";
312 EXPECT_TRUE(failures.contains(45)) <<
"Subrelation 45 (no-op acc_x preservation) should fail";
313 EXPECT_TRUE(failures.contains(46)) <<
"Subrelation 46 (no-op acc_y preservation) should fail";
318 auto full_params = compute_full_relation_params(polynomials);
323 EXPECT_TRUE(transcript_failures.empty()) <<
"ECCVMTranscriptRelation should still pass";
327 EXPECT_TRUE(point_table_failures.empty()) <<
"ECCVMPointTableRelation should still pass";
331 EXPECT_TRUE(wnaf_failures.empty()) <<
"ECCVMWnafRelation should still pass";
335 EXPECT_TRUE(bools_failures.empty()) <<
"ECCVMBoolsRelation should still pass";
343 EXPECT_FALSE(set_failures.empty()) <<
"ECCVMSetRelation should also fail (MSM output tuples are shifted)";
350 EXPECT_TRUE(lookup_failures.empty()) <<
"ECCVMLookupRelation should still pass (inverse computed post-shift)";
362 auto polynomials = build_valid_eccvm_msm_state();
367 EXPECT_TRUE(baseline.empty()) <<
"Baseline transcript relation should pass";
369 size_t noop_row = find_transcript_noop_row(polynomials);
370 ASSERT_NE(noop_row, 0) <<
"Should find a transcript no-op row";
374 polynomials.transcript_accumulator_not_empty.at(noop_row + 1) =
FF(1);
375 polynomials.set_shifted();
379 EXPECT_FALSE(failures.empty()) <<
"Transcript relation should fail after corrupting accumulator_not_empty on "
380 "the row following a no-op";
381 EXPECT_TRUE(failures.contains(22)) <<
"Subrelation 22 (accumulator_infinity) should catch the corruption";
396 auto polynomials = build_valid_eccvm_msm_state();
397 auto params = compute_full_relation_params(polynomials);
402 EXPECT_TRUE(baseline.empty()) <<
"Baseline set relation should pass";
405 ASSERT_TRUE(polynomials.z_perm.is_shiftable());
409 const auto& lagrange_first = polynomials.lagrange_first;
410 size_t scanned_first_row = 0;
412 for (
size_t i = lagrange_first.start_index(); i < lagrange_first.end_index(); ++i) {
413 if (lagrange_first[i] !=
FF(0)) {
414 scanned_first_row = i;
419 ASSERT_TRUE(found) <<
"lagrange_first has no non-zero entry";
420 ASSERT_EQ(structural_first_row, scanned_first_row)
421 <<
"lagrange_first position doesn't match z_perm shiftable structure";
423 const size_t first_row = scanned_first_row;
426 polynomials.z_perm = polynomials.z_perm.full();
427 polynomials.z_perm_shift = polynomials.z_perm_shift.full();
429 ASSERT_EQ(polynomials.z_perm[first_row],
FF(0));
432 polynomials.z_perm.at(first_row) =
FF(1);
435 polynomials, params,
"ECCVMSetRelation - After setting z_perm != 0 at lagrange_first",
Flavor::TRACE_OFFSET);
436 EXPECT_FALSE(failures.empty()) <<
"Set relation should fail after z_perm init corruption";
438 <<
"Sub-relation Z_PERM_INIT should catch the corruption";
440 <<
"Failure should be at lagrange_first row";
static void SetUpTestSuite()
A container for the prover polynomials.
typename Curve::ScalarField FF
bb::Polynomial< FF > Polynomial
static constexpr size_t TRACE_OFFSET
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
A debugging utility for checking whether a set of polynomials satisfies the relations for a given Fla...
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
typename ECCVMFlavor::ProverPolynomials ProverPolynomials
void add_hiding_op_for_test(const std::shared_ptr< ECCOpQueue > &op_queue)
Set a hiding op on the op_queue for testing.
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
group< fq, fr, Bn254G1Params > g1
TEST_F(IPATest, ChallengesAreZero)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Container for parameters used by the grand product (permutation, lookup) Honk relations.
constexpr field invert() const noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr field sqr() const noexcept