3#include <gtest/gtest.h>
34 for (
auto [polynomial, commitment] :
zip_view(proving_key->polynomials.get_precomputed(),
vk.get_all())) {
35 commitment = proving_key->commitment_key.commit(polynomial);
47 for (
const auto&
fr : frs) {
48 elements.push_back(
fr);
81 op_queue->add_accumulate(
a);
82 op_queue->mul_accumulate(
a, x);
83 op_queue->mul_accumulate(
b, x);
84 op_queue->mul_accumulate(
b, y);
85 op_queue->add_accumulate(
a);
86 op_queue->mul_accumulate(
b, x);
87 op_queue->eq_and_reset();
88 op_queue->add_accumulate(c);
89 op_queue->mul_accumulate(
a, x);
90 op_queue->mul_accumulate(
b, x);
91 op_queue->eq_and_reset();
92 op_queue->mul_accumulate(
a, x);
93 op_queue->mul_accumulate(
b, x);
94 op_queue->mul_accumulate(c, x);
96 add_hiding_op_for_test(op_queue);
112 for (
auto i = 0; i < 8; i++) {
114 op_queue->mul_accumulate(Curve::Group::affine_point_at_infinity, x);
117 for (
auto i = 0; i < 8; i++) {
119 op_queue->mul_accumulate(g, 0);
123 add_hiding_op_for_test(op_queue);
131 std::vector<FF>& gate_challenges)
137 const FF beta_sqr = beta * beta;
138 const FF beta_quartic = beta_sqr * beta_sqr;
139 relation_parameters.
gamma = gamma;
140 relation_parameters.
beta = beta;
141 relation_parameters.
beta_sqr = beta_sqr;
142 relation_parameters.
beta_cube = beta_sqr * beta;
144 auto first_term_tag = beta_quartic;
146 (gamma + beta_sqr + beta_sqr + first_term_tag) *
147 (gamma + beta_sqr + beta_sqr + beta_sqr + first_term_tag);
152 compute_logderivative_inverse<FF, ECCVMFlavor::LookupRelation, ECCVMFlavor::ProverPolynomials, true>(
154 compute_grand_products<ECCVMFlavor>(pk->polynomials, relation_parameters);
157 for (
size_t idx = 0; idx < CONST_ECCVM_LOG_N; idx++) {
171 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
182 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
190 EXPECT_THROW(op_queue->get_eccvm_ops(), std::runtime_error);
197 add_hiding_op_for_test(op_queue);
205 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
216 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
228 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
238 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
250 op_queue->eq_and_reset();
252 add_hiding_op_for_test(op_queue);
260 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
270 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
300 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
310 ASSERT_TRUE(ipa_verified && eccvm_result.reduction_succeeded);
317 builder.op_queue->add_erroneous_equality_op_for_testing();
326 PCS::compute_opening_proof(prover.
key->commitment_key, opening_claim, ipa_transcript);
336 ASSERT_FALSE(ipa_verified && eccvm_result.reduction_succeeded);
348 std::vector<FF> gate_challenges(CONST_ECCVM_LOG_N);
373 ZKData zk_sumcheck_data = ZKData(CONST_ECCVM_LOG_N, prover_transcript);
374 auto prover_output = sumcheck_prover.
prove(zk_sumcheck_data);
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";
543 auto check_masked = [](
const auto& poly,
const std::string& label) {
544 bool has_masking =
false;
545 for (
size_t j = 0; j < NUM_MASKED_ROWS; j++) {
546 has_masking |= !poly[NUM_ZERO_ROWS + j].is_zero();
548 EXPECT_TRUE(has_masking) << label <<
" should be masked but has all zeros in masking region";
552 for (
auto [poly, label] :
zip_view(polynomials.get_wires(), labels.get_wires())) {
553 check_masked(poly, label);
555 check_masked(polynomials.z_perm,
"z_perm");
556 check_masked(polynomials.lookup_inverses,
"lookup_inverses");
572 auto unshifted = pk->polynomials.get_unshifted();
573 auto to_be_shifted = pk->polynomials.get_to_be_shifted();
576 ASSERT_EQ(to_be_shifted.size(), repeated.first.count);
579 const auto&
ck = pk->commitment_key;
581 commitments.push_back(ECCVMFlavor::Commitment::one());
582 for (
auto& poly : unshifted) {
583 commitments.push_back(
ck.commit(poly));
585 for (
auto& poly : to_be_shifted) {
586 commitments.push_back(
ck.commit(poly));
591 for (
size_t i = 0; i < repeated.first.count; i++) {
592 EXPECT_EQ(commitments[repeated.first.original_start +
offset + i],
593 commitments[repeated.first.duplicate_start +
offset + i])
594 <<
"REPEATED_COMMITMENTS commitment mismatch at index " << i;
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
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
static constexpr bool HasZK
typename Curve::ScalarField FF
typename Curve::BaseField BF
static constexpr size_t PROOF_LENGTH
bb::CommitmentKey< Curve > CommitmentKey
static constexpr RepeatedCommitmentsData REPEATED_COMMITMENTS
BaseTranscript< Codec, HashFunction > Transcript
static constexpr size_t TRACE_OFFSET
static 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)
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)
CommitmentKey< Curve > ck
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