3#include <gtest/gtest.h>
33 for (
auto [polynomial, commitment] :
zip_view(proving_key->polynomials.get_precomputed(),
vk.get_all())) {
34 commitment = proving_key->commitment_key.commit(polynomial);
46 for (
const auto&
fr : frs) {
47 elements.push_back(
fr);
80 op_queue->add_accumulate(
a);
81 op_queue->mul_accumulate(
a, x);
82 op_queue->mul_accumulate(
b, x);
83 op_queue->mul_accumulate(
b, y);
84 op_queue->add_accumulate(
a);
85 op_queue->mul_accumulate(
b, x);
86 op_queue->eq_and_reset();
87 op_queue->add_accumulate(c);
88 op_queue->mul_accumulate(
a, x);
89 op_queue->mul_accumulate(
b, x);
90 op_queue->eq_and_reset();
91 op_queue->mul_accumulate(
a, x);
92 op_queue->mul_accumulate(
b, x);
93 op_queue->mul_accumulate(c, x);
95 add_hiding_op_for_test(op_queue);
111 for (
auto i = 0; i < 8; i++) {
113 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, x);
116 for (
auto i = 0; i < 8; i++) {
118 op_queue->mul_accumulate(g, 0);
122 add_hiding_op_for_test(op_queue);
130 std::vector<FF>& gate_challenges)
136 const FF beta_sqr = beta * beta;
137 relation_parameters.
gamma = gamma;
138 relation_parameters.
beta = beta;
139 relation_parameters.
beta_sqr = beta_sqr;
140 relation_parameters.
beta_cube = beta_sqr * beta;
142 gamma * (gamma + beta_sqr) * (gamma + beta_sqr + beta_sqr) * (gamma + beta_sqr + beta_sqr + beta_sqr);
145 const size_t unmasked_witness_size = pk->circuit_size - NUM_DISABLED_ROWS_IN_SUMCHECK;
147 compute_logderivative_inverse<FF, ECCVMFlavor::LookupRelation, ECCVMFlavor::ProverPolynomials, true>(
148 pk->polynomials, relation_parameters, unmasked_witness_size);
149 compute_grand_products<ECCVMFlavor>(pk->polynomials, relation_parameters, unmasked_witness_size);
152 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
166 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
177 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
185 EXPECT_THROW(op_queue->get_eccvm_ops(), std::runtime_error);
192 add_hiding_op_for_test(op_queue);
200 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
211 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
223 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
233 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
245 op_queue->eq_and_reset();
247 add_hiding_op_for_test(op_queue);
255 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
265 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
293 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
303 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
310 builder.op_queue->add_erroneous_equality_op_for_testing();
319 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
329 ASSERT_FALSE(ipa_verified && eccvm_result.reduction_succeeded);
341 std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
366 ZKData zk_sumcheck_data = ZKData(CONST_ECCVM_LOG_N, prover_transcript);
368 auto prover_output = sumcheck_prover.
prove(zk_sumcheck_data);
374 std::vector<FF> padding_indicator_array(CONST_ECCVM_LOG_N,
FF(1));
376 sumcheck_verifier.
verify(relation_parameters, gate_challenges, padding_indicator_array);
380 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
381 FF true_eval_at_the_challenge = prover_output.round_univariates[idx].evaluate(prover_output.challenge[idx]);
383 EXPECT_TRUE(true_eval_at_the_challenge == verifier_eval_at_the_challenge);
387 FF prover_target_sum = zk_sumcheck_data.libra_challenge * zk_sumcheck_data.libra_total_sum;
392 EXPECT_TRUE(verifier_output.
verified);
416 auto generators = Curve::Group::derive_generators(
"base_infinity_regression", 2);
417 G1 a = generators[0];
418 G1 b = generators[1];
423 G1 honest_result =
a * x +
b * y;
424 G1 forged_result =
a * x;
425 ASSERT_NE(honest_result, forged_result) <<
"Need b*y != 0 for a meaningful attack";
431 op_queue->mul_accumulate(
a, x);
432 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, y);
433 op_queue->eq_and_reset();
435 add_hiding_op_for_test(op_queue);
444 auto& polys = prover.
key->polynomials;
445 const size_t num_rows = polys.get_polynomial_size();
446 size_t forged_row = 0;
447 for (
size_t i = 0; i < num_rows; i++) {
448 if (polys.transcript_op[i] ==
FF(4) && polys.transcript_base_infinity[i] ==
FF(1)) {
453 ASSERT_GT(forged_row,
size_t(0)) <<
"Could not find infinity mul row";
458 auto b_affine = Curve::Group::affine_element(
b);
459 polys.transcript_Px.at(forged_row) = b_affine.x;
460 polys.transcript_Py.at(forged_row) = b_affine.y;
467 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
479 bool proof_verified = ipa_verified && eccvm_result.reduction_succeeded;
481 EXPECT_FALSE(proof_verified)
482 <<
"REGRESSION: Forged ECCVM proof must NOT verify after base_infinity coordinate constraints";
507 const auto& labels = bb::ECCVMFlavor::VerificationKey::get_labels();
509 for (
auto [vk_commitment, fixed_commitment] :
zip_view(vk_computed_by_prover.get_all(), fixed_vk.get_all())) {
510 EXPECT_EQ(vk_commitment, fixed_commitment)
511 <<
"Mismatch between vk_commitment and fixed_commitment at label: " << labels[
index];
516 EXPECT_EQ(fixed_vk, vk_computed_by_prover);
521 if (computed_hash != hardcoded_hash) {
522 info(
"VK hash mismatch! Update ECCVMHardcodedVKAndHash::vk_hash() with:");
523 info(
"0x", computed_hash);
525 EXPECT_EQ(computed_hash, hardcoded_hash) <<
"Hardcoded VK hash does not match computed hash";
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
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 std::vector< Commitment > get_all()
std::pair< Proof, OpeningClaim > construct_proof()
std::shared_ptr< ProvingKey > key
Unified ECCVM verifier class for both native and recursive verification.
ReductionResult reduce_to_ipa_opening()
Reduce the ECCVM proof to an IPA opening 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.
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, const std::vector< FF > &padding_indicator_array)
The Sumcheck verification method. First it extracts round univariate, checks sum (the sumcheck univar...
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()
void init_file_crs_factory(const std::filesystem::path &path)
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
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