3#include <gtest/gtest.h>
42 for (
auto [polynomial, commitment] :
zip_view(proving_key->polynomials.get_precomputed(),
vk.get_all())) {
43 commitment = proving_key->commitment_key.commit(polynomial);
55 for (
const auto&
fr : frs) {
56 elements.push_back(
fr);
67 static const bool grumpkin_srs_initialized = []() {
71 static_cast<void>(grumpkin_srs_initialized);
97 op_queue->add_accumulate(
a);
98 op_queue->mul_accumulate(
a, x);
99 op_queue->mul_accumulate(
b, x);
100 op_queue->mul_accumulate(
b, y);
101 op_queue->add_accumulate(
a);
102 op_queue->mul_accumulate(
b, x);
103 op_queue->eq_and_reset();
104 op_queue->add_accumulate(c);
105 op_queue->mul_accumulate(
a, x);
106 op_queue->mul_accumulate(
b, x);
107 op_queue->eq_and_reset();
108 op_queue->mul_accumulate(
a, x);
109 op_queue->mul_accumulate(
b, x);
110 op_queue->mul_accumulate(c, x);
112 add_hiding_op_for_test(op_queue);
128 for (
auto i = 0; i < 8; i++) {
130 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, x);
133 for (
auto i = 0; i < 8; i++) {
135 op_queue->mul_accumulate(g, 0);
139 add_hiding_op_for_test(op_queue);
147 std::vector<FF>& gate_challenges)
153 const FF beta_sqr = beta * beta;
154 const FF beta_quartic = beta_sqr * beta_sqr;
155 relation_parameters.
gamma = gamma;
156 relation_parameters.
beta = beta;
157 relation_parameters.
beta_sqr = beta_sqr;
158 relation_parameters.
beta_cube = beta_sqr * beta;
160 auto first_term_tag = beta_quartic;
162 (gamma + beta_sqr + beta_sqr + first_term_tag) *
163 (gamma + beta_sqr + beta_sqr + beta_sqr + first_term_tag);
168 compute_logderivative_inverse<FF, ECCVMFlavor::LookupRelation, ECCVMFlavor::ProverPolynomials, true>(
170 compute_grand_products<ECCVMFlavor>(pk->polynomials, relation_parameters);
173 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
189 ASSERT_TRUE(eccvm_result.reduction_succeeded);
198 EXPECT_THROW(op_queue->get_eccvm_ops(), std::runtime_error);
205 add_hiding_op_for_test(op_queue);
215 ASSERT_TRUE(eccvm_result.reduction_succeeded);
230 ASSERT_TRUE(eccvm_result.reduction_succeeded);
252 ECCVMVerifier::TripleIPA::reduce_verify(ipa_vk, eccvm_result.triple_ipa_claim, ipa_verifier_transcript);
254 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
263 for (
auto& edge :
result.get_all()) {
275template <
typename ShortRelation>
278 const FF& scaling_factor)
280 typename ShortRelation::SumcheckTupleOfUnivariatesOverSubrelations accumulators{};
281 ShortRelation::accumulate(accumulators, in, params, scaling_factor);
288template <
size_t Offset,
typename FullTuple,
typename ShortTuple,
size_t... Js>
293 constexpr size_t full_idx = Offset + Js;
294 constexpr size_t full_length = std::tuple_element_t<full_idx, FullTuple>::LENGTH;
301template <
size_t Offset,
typename FullTuple>
void compare_short_blocks(
const FullTuple&)
304 "short relations must cover exactly the legacy relation's subrelations");
310template <
size_t Offset,
typename FullTuple,
typename ShortHead,
typename... ShortTail>
311void compare_short_blocks(
const FullTuple& full_acc,
const ShortHead& head,
const ShortTail&... tail)
315 compare_short_blocks<Offset + head_size>(full_acc, tail...);
318template <
typename FullRelation,
typename... ShortRelations>
321 const FF& scaling_factor)
324 for (
auto [extended_edge, short_edge] :
zip_view(extended_edges.get_all(), in.get_all())) {
325 extended_edge = short_edge.template extend_to<ECCVMFlavor::MAX_PARTIAL_RELATION_LENGTH>();
328 typename FullRelation::SumcheckTupleOfUnivariatesOverSubrelations full_acc{};
329 FullRelation::accumulate(full_acc, extended_edges, params, scaling_factor);
331 compare_short_blocks<0>(full_acc, accumulate_short_relation<ShortRelations>(in, params, scaling_factor)...);
341 const auto run_test = [&](
bool random_inputs) {
342 const auto input = get_short_edge_input(random_inputs);
346 expect_short_relations_match_full_edges<ECCVMTranscriptRelation<FF>,
349 input, params, scaling_factor);
350 expect_short_relations_match_full_edges<ECCVMPointTableRelation<FF>,
354 input, params, scaling_factor);
355 expect_short_relations_match_full_edges<ECCVMMSMRelation<FF>,
361 input, params, scaling_factor);
363 input, params, scaling_factor);
364 expect_short_relations_match_full_edges<ECCVMBoolsRelation<FF>,
383 op_queue->eq_and_reset();
385 add_hiding_op_for_test(op_queue);
396 ASSERT_TRUE(eccvm_result.reduction_succeeded);
429 ASSERT_TRUE(eccvm_result.reduction_succeeded);
436 builder.op_queue->add_erroneous_equality_op_for_testing();
448 ASSERT_FALSE(eccvm_result.reduction_succeeded);
460 std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
485 ZKData zk_sumcheck_data = ZKData(CONST_ECCVM_LOG_N, prover_transcript);
486 auto prover_output = sumcheck_prover.
prove(zk_sumcheck_data);
496 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
497 FF true_eval_at_the_challenge = prover_output.round_univariates[idx].evaluate(prover_output.challenge[idx]);
499 EXPECT_TRUE(true_eval_at_the_challenge == verifier_eval_at_the_challenge);
503 FF prover_target_sum = zk_sumcheck_data.libra_challenge * zk_sumcheck_data.libra_total_sum;
508 EXPECT_TRUE(verifier_output.
verified);
532 auto generators = Curve::Group::derive_generators(
"base_infinity_regression", 2);
533 G1 a = generators[0];
534 G1 b = generators[1];
539 G1 honest_result =
a * x +
b * y;
540 G1 forged_result =
a * x;
541 ASSERT_NE(honest_result, forged_result) <<
"Need b*y != 0 for a meaningful attack";
547 op_queue->mul_accumulate(
a, x);
548 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, y);
549 op_queue->eq_and_reset();
551 add_hiding_op_for_test(op_queue);
560 auto& polys = prover.
key->polynomials;
561 const size_t num_rows = polys.get_polynomial_size();
562 size_t forged_row = 0;
563 for (
size_t i = 0; i < num_rows; i++) {
564 if (polys.transcript_op[i] ==
FF(4) && polys.transcript_base_infinity[i] ==
FF(1)) {
569 ASSERT_GT(forged_row,
size_t(0)) <<
"Could not find infinity mul row";
574 auto b_affine = Curve::Group::affine_element(
b);
575 polys.transcript_Px.at(forged_row) = b_affine.x;
576 polys.transcript_Py.at(forged_row) = b_affine.y;
588 EXPECT_FALSE(proof_verified)
589 <<
"REGRESSION: Forged ECCVM proof must NOT verify after base_infinity coordinate constraints";
614 const auto& labels = bb::ECCVMFlavor::VerificationKey::get_labels();
616 for (
auto [vk_commitment, fixed_commitment] :
zip_view(vk_computed_by_prover.get_all(), fixed_vk.get_all())) {
617 EXPECT_EQ(vk_commitment, fixed_commitment)
618 <<
"Mismatch between vk_commitment and fixed_commitment at label: " << labels[
index];
623 EXPECT_EQ(fixed_vk, vk_computed_by_prover);
628 if (computed_hash != hardcoded_hash) {
629 info(
"VK hash mismatch! Update ECCVMHardcodedVKAndHash::vk_hash() with:");
630 info(
"0x", computed_hash);
632 EXPECT_EQ(computed_hash, hardcoded_hash) <<
"Hardcoded VK hash does not match computed hash";
646 auto check_masked = [](
const auto& poly,
const std::string&
label) {
647 bool has_masking =
false;
648 for (
size_t j = 0; j < NUM_MASKED_ROWS; j++) {
649 has_masking |= !poly[NUM_ZERO_ROWS + j].is_zero();
651 EXPECT_TRUE(has_masking) <<
label <<
" should be masked but has all zeros in masking region";
655 for (
auto [poly,
label] :
zip_view(polynomials.get_wires(), labels.get_wires())) {
656 check_masked(poly,
label);
658 check_masked(polynomials.z_perm,
"z_perm");
659 check_masked(polynomials.lookup_inverses,
"lookup_inverses");
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
A base class labelling all entities (for instance, all of the polynomials used by the prover during s...
A container for commitment labels.
A container for the prover polynomials.
The proving key is responsible for storing the polynomials used by the prover.
static constexpr size_t ECCVM_FIXED_SIZE
typename Curve::ScalarField FF
typename Curve::BaseField BF
static constexpr size_t PROOF_LENGTH
BaseTranscript< Codec, HashFunction > Transcript
static constexpr size_t TRACE_OFFSET
static std::vector< Commitment > get_all()
std::shared_ptr< ProvingKey > key
Unified ECCVM verifier class for both native and recursive verification.
ReductionResult reduce_to_triple_ipa_claim()
Reduce the ECCVM proof to a compact TripleIPA verifier claim.
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
static std::vector< fr > serialize_to_fields(const T &val)
Conversion from transcript values to bb::frs.
IPA (inner product argument) commitment scheme class.
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
The implementation of the sumcheck Prover for statements of the form for multilinear polynomials .
SumcheckOutput< Flavor > prove()
Non-ZK version: Compute round univariate, place it in transcript, compute challenge,...
Implementation of the sumcheck Verifier for statements of the form for multilinear polynomials .
SumcheckOutput< Flavor > verify(const bb::RelationParameters< FF > &relation_parameters, const std::vector< FF > &gate_challenges)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
A univariate polynomial represented by its values on {0, 1,..., domain_end - 1}.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
typename Group::element Element
void complete_proving_key_for_test(bb::RelationParameters< FF > &relation_parameters, std::shared_ptr< PK > &pk, std::vector< FF > &gate_challenges)
ECCVMFlavor::VerificationKey create_vk_from_proving_key(const std::shared_ptr< PK > &proving_key)
ECCVMFlavor::BF compute_eccvm_vk_hash()
ECCVMCircuitBuilder generate_zero_circuit(numeric::RNG *engine=nullptr, bool zero_scalars=1)
ECCVMCircuitBuilder generate_circuit(numeric::RNG *engine=nullptr)
Adds operations in BN254 to the op_queue and then constructs and ECCVM circuit from the op_queue.
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()
std::vector< grumpkin::g1::affine_element > generate_grumpkin_srs(size_t num_points)
Generates a monomial basis Grumpkin SRS on-the-fly.
void init_file_crs_factory(const std::filesystem::path &path)
void init_grumpkin_mem_crs_factory(std::vector< curve::Grumpkin::AffineElement > const &points)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Container for parameters used by the grand product (permutation, lookup) Honk relations.
T eccvm_set_permutation_delta
static RelationParameters get_random()
Contains the evaluations of multilinear polynomials at the challenge point . These are computed by S...
std::vector< std::array< FF, 3 > > round_univariate_evaluations
This structure is created to contain various polynomials and constants required by ZK Sumcheck.
static field random_element(numeric::RNG *engine=nullptr) noexcept