13#include <gtest/gtest.h>
22using Fr =
typename G1::Fr;
29void expand_shiftable_to_virtual_size(
Polynomial& polynomial)
43 &polys.msm_size_of_msm,
55 &polys.msm_collision_x1,
56 &polys.msm_collision_x2,
57 &polys.msm_collision_x3,
58 &polys.msm_collision_x4,
68 &polys.msm_transition,
72 &polys.msm_accumulator_x,
73 &polys.msm_accumulator_y,
86 auto generators = G1::derive_generators(
"test generators", 3);
87 auto a = generators[0];
88 auto b = generators[1];
93 op_queue->mul_accumulate(
a, x);
94 op_queue->mul_accumulate(
b, y);
95 op_queue->eq_and_reset();
111 const FF beta_sqr = beta.
sqr();
112 const FF beta_cube = beta_sqr * beta;
113 auto eccvm_set_permutation_delta =
114 gamma * (gamma + beta_sqr) * (gamma + beta_sqr + beta_sqr) * (gamma + beta_sqr + beta_sqr + beta_sqr);
115 eccvm_set_permutation_delta = eccvm_set_permutation_delta.
invert();
121 .public_input_delta = 0,
122 .beta_sqr = beta_sqr,
123 .beta_cube = beta_cube,
124 .eccvm_set_permutation_delta = eccvm_set_permutation_delta,
127 compute_logderivative_inverse<FF, ECCVMLookupRelation<FF>>(polynomials, params,
Flavor::TRACE_OFFSET);
128 compute_grand_product<Flavor, ECCVMSetRelation<FF>>(polynomials, params);
129 polynomials.z_perm_shift =
Polynomial(polynomials.z_perm.shifted());
139 const size_t num_rows = polynomials.get_polynomial_size();
141 if (polynomials.transcript_add.get(i) ==
FF(0) && polynomials.transcript_mul.get(i) ==
FF(0) &&
142 polynomials.transcript_eq.get(i) ==
FF(0) && polynomials.transcript_reset_accumulator.get(i) ==
FF(0) &&
143 polynomials.lagrange_first.get(i) ==
FF(0) && polynomials.lagrange_last.get(i) ==
FF(0)) {
168 auto polynomials = build_valid_eccvm_msm_state();
173 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
177 ASSERT_EQ(polynomials.msm_add.get(first_msm_row),
FF(1)) <<
"First MSM row should be an active MSM add row";
178 ASSERT_EQ(polynomials.msm_transition.get(first_msm_row),
FF(1)) <<
"First MSM row should have msm_transition=1";
183 polynomials.set_shifted();
187 EXPECT_TRUE(failures.empty()) <<
"MSM relation should STILL PASS — acc is unused when msm_transition=1";
206 auto polynomials = build_valid_eccvm_msm_state();
210 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
213 const size_t num_rows = polynomials.get_polynomial_size();
214 size_t active_row = 0;
216 if (polynomials.msm_add.get(i) ==
FF(1) && polynomials.msm_transition.get(i) ==
FF(0)) {
221 ASSERT_NE(active_row, 0) <<
"Should find an interior active MSM add row";
225 polynomials.set_shifted();
229 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after active-row accumulator corruption";
234 auto polynomials = build_valid_eccvm_msm_state();
237 const size_t num_rows = polynomials.get_polynomial_size();
238 size_t no_op_row = 0;
240 if (polynomials.msm_add.get(i) ==
FF(0) && polynomials.msm_double.get(i) ==
FF(0) &&
241 polynomials.msm_skew.get(i) ==
FF(0) && polynomials.msm_transition.get(i) ==
FF(0) &&
242 polynomials.lagrange_first.get(i) ==
FF(0)) {
247 ASSERT_NE(no_op_row, 0) <<
"Should find a no-op row in the MSM table";
249 expand_shiftable_to_virtual_size(polynomials.msm_accumulator_x);
250 expand_shiftable_to_virtual_size(polynomials.msm_accumulator_y);
253 polynomials.set_shifted();
257 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after no-op accumulator corruption";
260 bool found_noop_subrelation_failure = failures.contains(45) || failures.contains(46);
261 EXPECT_TRUE(found_noop_subrelation_failure)
262 <<
"Failure should be detected by subrelations 45/46 (no-op accumulator preservation)";
283 auto polynomials = build_valid_eccvm_msm_state();
289 EXPECT_TRUE(baseline.empty()) <<
"Baseline MSM relation should pass";
291 auto msm_polys = get_msm_polynomials(polynomials);
295 for (
auto* poly : msm_polys) {
296 for (
size_t k = poly->end_index() - 1; k >= ofs + 2; k--) {
297 poly->at(k) = (*poly)[k - 1];
299 poly->at(ofs + 1) =
FF(0);
303 polynomials.msm_size_of_msm.at(ofs + 1) = polynomials.msm_pc.get(ofs + 1) - polynomials.msm_pc.get(ofs + 2);
306 polynomials.set_shifted();
310 EXPECT_FALSE(failures.empty()) <<
"MSM relation should fail after shifting MSM table by one row";
313 for (
const auto& [subrelation_idx, row_idx] : failures) {
314 info(
"Shifted MSM table: subrelation ", subrelation_idx,
" first failed at row ", row_idx);
317 EXPECT_TRUE(failures.contains(45)) <<
"Subrelation 45 (no-op acc_x preservation) should fail";
318 EXPECT_TRUE(failures.contains(46)) <<
"Subrelation 46 (no-op acc_y preservation) should fail";
323 auto full_params = compute_full_relation_params(polynomials);
328 EXPECT_TRUE(transcript_failures.empty()) <<
"ECCVMTranscriptRelation should still pass";
332 EXPECT_TRUE(point_table_failures.empty()) <<
"ECCVMPointTableRelation should still pass";
336 EXPECT_TRUE(wnaf_failures.empty()) <<
"ECCVMWnafRelation should still pass";
340 EXPECT_TRUE(bools_failures.empty()) <<
"ECCVMBoolsRelation should still pass";
348 EXPECT_FALSE(set_failures.empty()) <<
"ECCVMSetRelation should also fail (MSM output tuples are shifted)";
355 EXPECT_TRUE(lookup_failures.empty()) <<
"ECCVMLookupRelation should still pass (inverse computed post-shift)";
368 auto polynomials = build_valid_eccvm_msm_state();
373 EXPECT_TRUE(baseline.empty()) <<
"Baseline transcript relation should pass";
375 size_t noop_row = find_transcript_noop_row(polynomials);
376 ASSERT_NE(noop_row, 0) <<
"Should find a transcript no-op row";
380 expand_shiftable_to_virtual_size(polynomials.transcript_accumulator_not_empty);
381 polynomials.transcript_accumulator_not_empty.at(noop_row + 1) =
FF(1);
382 polynomials.set_shifted();
386 EXPECT_FALSE(failures.empty()) <<
"Transcript relation should fail after corrupting accumulator_not_empty on "
387 "the row following a no-op";
389 <<
"ACCUMULATOR_EMPTY_UPDATE subrelation should catch the corruption";
404 auto polynomials = build_valid_eccvm_msm_state();
405 auto params = compute_full_relation_params(polynomials);
410 EXPECT_TRUE(baseline.empty()) <<
"Baseline set relation should pass";
413 ASSERT_TRUE(polynomials.z_perm.is_shiftable());
417 const auto& lagrange_first = polynomials.lagrange_first;
418 size_t scanned_first_row = 0;
420 for (
size_t i = lagrange_first.start_index(); i < lagrange_first.end_index(); ++i) {
421 if (lagrange_first[i] !=
FF(0)) {
422 scanned_first_row = i;
427 ASSERT_TRUE(found) <<
"lagrange_first has no non-zero entry";
428 ASSERT_EQ(structural_first_row, scanned_first_row)
429 <<
"lagrange_first position doesn't match z_perm shiftable structure";
431 const size_t first_row = scanned_first_row;
434 polynomials.z_perm = polynomials.z_perm.full();
435 polynomials.z_perm_shift = polynomials.z_perm_shift.full();
437 ASSERT_EQ(polynomials.z_perm.get(first_row),
FF(0));
440 polynomials.z_perm.at(first_row) =
FF(1);
443 polynomials, params,
"ECCVMSetRelation - After setting z_perm != 0 at lagrange_first",
Flavor::TRACE_OFFSET);
444 EXPECT_FALSE(failures.empty()) <<
"Set relation should fail after z_perm init corruption";
446 <<
"Sub-relation Z_PERM_INIT should catch the corruption";
448 <<
"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
ECCVMTranscriptRelationImpl evaluates the correctness of the ECCVM transcript columns.
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
size_t start_index() const
std::size_t virtual_size() const
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