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 const FF beta_quartic = beta_sqr * beta_sqr;
138 relation_parameters.
gamma = gamma;
139 relation_parameters.
beta = beta;
140 relation_parameters.
beta_sqr = beta_sqr;
141 relation_parameters.
beta_cube = beta_sqr * beta;
143 auto first_term_tag = beta_quartic;
145 (gamma + beta_sqr + beta_sqr + first_term_tag) *
146 (gamma + beta_sqr + beta_sqr + beta_sqr + first_term_tag);
149 const size_t unmasked_witness_size = pk->circuit_size - NUM_DISABLED_ROWS_IN_SUMCHECK;
151 compute_logderivative_inverse<FF, ECCVMFlavor::LookupRelation, ECCVMFlavor::ProverPolynomials, true>(
152 pk->polynomials, relation_parameters, unmasked_witness_size);
153 compute_grand_products<ECCVMFlavor>(pk->polynomials, relation_parameters, unmasked_witness_size);
156 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
170 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
181 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
189 EXPECT_THROW(op_queue->get_eccvm_ops(), std::runtime_error);
196 add_hiding_op_for_test(op_queue);
204 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
215 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
227 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
237 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
249 op_queue->eq_and_reset();
251 add_hiding_op_for_test(op_queue);
259 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
269 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
297 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
307 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
314 builder.op_queue->add_erroneous_equality_op_for_testing();
323 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
333 ASSERT_FALSE(ipa_verified && eccvm_result.reduction_succeeded);
345 std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
370 ZKData zk_sumcheck_data = ZKData(CONST_ECCVM_LOG_N, prover_transcript);
372 auto prover_output = sumcheck_prover.
prove(zk_sumcheck_data);
378 std::vector<FF> padding_indicator_array(CONST_ECCVM_LOG_N,
FF(1));
380 sumcheck_verifier.
verify(relation_parameters, gate_challenges, padding_indicator_array);
384 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
385 FF true_eval_at_the_challenge = prover_output.round_univariates[idx].evaluate(prover_output.challenge[idx]);
387 EXPECT_TRUE(true_eval_at_the_challenge == verifier_eval_at_the_challenge);
391 FF prover_target_sum = zk_sumcheck_data.libra_challenge * zk_sumcheck_data.libra_total_sum;
396 EXPECT_TRUE(verifier_output.
verified);
420 auto generators = Curve::Group::derive_generators(
"base_infinity_regression", 2);
421 G1 a = generators[0];
422 G1 b = generators[1];
427 G1 honest_result =
a * x +
b * y;
428 G1 forged_result =
a * x;
429 ASSERT_NE(honest_result, forged_result) <<
"Need b*y != 0 for a meaningful attack";
435 op_queue->mul_accumulate(
a, x);
436 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, y);
437 op_queue->eq_and_reset();
439 add_hiding_op_for_test(op_queue);
448 auto& polys = prover.
key->polynomials;
449 const size_t num_rows = polys.get_polynomial_size();
450 size_t forged_row = 0;
451 for (
size_t i = 0; i < num_rows; i++) {
452 if (polys.transcript_op[i] ==
FF(4) && polys.transcript_base_infinity[i] ==
FF(1)) {
457 ASSERT_GT(forged_row,
size_t(0)) <<
"Could not find infinity mul row";
462 auto b_affine = Curve::Group::affine_element(
b);
463 polys.transcript_Px.at(forged_row) = b_affine.x;
464 polys.transcript_Py.at(forged_row) = b_affine.y;
471 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
483 bool proof_verified = ipa_verified && eccvm_result.reduction_succeeded;
485 EXPECT_FALSE(proof_verified)
486 <<
"REGRESSION: Forged ECCVM proof must NOT verify after base_infinity coordinate constraints";
511 const auto& labels = bb::ECCVMFlavor::VerificationKey::get_labels();
513 for (
auto [vk_commitment, fixed_commitment] :
zip_view(vk_computed_by_prover.get_all(), fixed_vk.get_all())) {
514 EXPECT_EQ(vk_commitment, fixed_commitment)
515 <<
"Mismatch between vk_commitment and fixed_commitment at label: " << labels[
index];
520 EXPECT_EQ(fixed_vk, vk_computed_by_prover);
525 if (computed_hash != hardcoded_hash) {
526 info(
"VK hash mismatch! Update ECCVMHardcodedVKAndHash::vk_hash() with:");
527 info(
"0x", computed_hash);
529 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