25static constexpr size_t NUM_FRS_COMM = NativeTranscript::Codec::template calc_num_fields<NativeG1>();
33 using type =
typename Curve::Builder;
49 for (
size_t i = 0; i < num_ops; ++i) {
50 op_queue->add_accumulate(NativeG1::random_element());
52 op_queue->eq_and_reset();
58 const size_t max_op_queue_ops = 10;
60 for (
size_t i = 0; i < n; ++i) {
62 op_queue->initialize_new_subtable();
77 std::vector<bb::fr> round_inputs;
78 bb::fr previous_challenge(0);
79 bool is_first_challenge =
true;
81 for (
size_t subtable_idx = 0; subtable_idx <
N; ++subtable_idx) {
83 if (!is_first_challenge) {
84 round_inputs.push_back(previous_challenge);
86 for (
size_t col = 0; col < NUM_WIRES; ++col) {
87 const size_t global_col_idx = (subtable_idx * NUM_WIRES) + col;
88 const size_t base = (global_col_idx * NUM_FRS_COMM);
89 for (
size_t j = 0; j < NUM_FRS_COMM; ++j) {
90 round_inputs.push_back(proof[base + j]);
96 previous_challenge = full_hash;
97 is_first_challenge =
false;
100 return previous_challenge;
130 size_t N = subtable_cols.size();
132 std::vector<size_t> shift_sizes(
N);
133 size_t max_shift_size = 0;
134 for (
size_t i = 0; i <
N; ++i) {
135 shift_sizes[i] = subtable_cols[i][0].size();
136 max_shift_size =
std::max(max_shift_size, shift_sizes[i]);
141 for (
size_t idx = 0; idx <
N; ++idx) {
142 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
153 for (
size_t idx =
N; idx < M; ++idx) {
154 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
155 const bool non_infinity_padding =
167 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
169 Polynomial larger_zk_col(zk_columns[col], zk_columns[col].size() + 1);
170 larger_zk_col.
at(larger_zk_col.
size() - 1) =
FF(1);
171 zk_columns[col] =
std::move(larger_zk_col);
175 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
179 max_shift_size =
std::max(max_shift_size, zk_columns[0].size());
184 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
185 flattened_cols.push_back(
std::move(zk_columns[col]));
187 for (
auto& subtable_col : subtable_cols) {
188 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
192 flattened_cols.push_back(
std::move(subtable_col[col]));
198 uint32_t sent_num_subtables =
static_cast<uint32_t
>(
N);
200 sent_num_subtables = 0;
202 transcript->send_to_verifier(
"NUM_SUBTABLES", sent_num_subtables);
203 for (
size_t i = 0; i < M; ++i) {
204 uint32_t sent_shift_size =
static_cast<uint32_t
>(i <
N ? shift_sizes[i] : 0);
210 sent_shift_size =
static_cast<uint32_t
>(shift_sizes[0] - 1);
221 merged_table[0].at(0) +=
FF(1);
223 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
227 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
233 const FF degree_check_challenge =
transcript->template get_challenge<FF>(
"DEGREE_CHECK_CHALLENGE");
235 std::vector<FF> degree_check_challenges = {
FF(1), degree_check_challenge };
236 for (
size_t idx = 2; idx < num_degree_check_challenges; ++idx) {
237 degree_check_challenges.push_back(degree_check_challenges.back() * degree_check_challenge);
244 size_t diff = flattened_cols.size() - num_degree_check_challenges;
245 for (
size_t idx = 0; idx < diff *
NUM_WIRES; ++idx) {
247 degree_check_challenges.push_back(degree_check_challenges.back() * degree_check_challenge);
257 degree_check_challenges.pop_back();
261 degree_check_poly.
at(0) +=
FF(1);
267 const FF kappa =
transcript->template get_challenge<FF>(
"KAPPA");
268 const FF kappa_inv = kappa.
invert();
271 std::vector<FF> evals;
274 for (
size_t flat_idx = 0; flat_idx < num_flattened_col_evals; ++flat_idx) {
276 if (flat_idx < num_actual_flattened_cols) {
277 eval = flattened_cols[flat_idx].evaluate(kappa);
281 evals.push_back(eval);
285 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
286 evals.push_back(merged_table[col].evaluate(kappa));
290 evals.push_back(degree_check_poly.
evaluate(kappa_inv));
291 transcript->send_to_verifier(
"DEGREE_CHECK_EVAL", evals.back());
296 opening_claims.reserve(num_opening_claims);
298 for (
size_t idx = 0; idx < num_flattened_col_evals; ++idx) {
299 if (idx < num_actual_flattened_cols) {
300 opening_claims.push_back({
std::move(flattened_cols[idx]), { kappa, evals[idx] } });
302 opening_claims.push_back({
Polynomial(1), { kappa,
FF(0) } });
306 for (
size_t idx = 0; idx <
NUM_WIRES; ++idx) {
307 opening_claims.push_back(
311 opening_claims.push_back({
std::move(degree_check_poly), { kappa_inv, evals.back() } });
332 using Curve =
typename Param::CurveType;
366 auto hash = FF::from_witness(&
builder, native_hash);
367 hash.unset_free_witness_tag();
387 bool wrong_hash =
false,
388 bool check_manifest =
false)
391 std::vector<bb::fr> native_proof;
394 if (check_manifest) {
398 native_proof = prover.construct_proof();
399 if (check_manifest) {
400 prover_manifest = prover.transcript->get_manifest();
404 if (check_manifest) {
408 native_proof = prover.construct_proof();
409 if (check_manifest) {
410 prover_manifest = prover.transcript->get_manifest();
424 if (check_manifest) {
429 if (check_manifest) {
431 auto verifier_manifest = verifier.
transcript->get_manifest();
432 EXPECT_EQ(prover_manifest.
size(), verifier_manifest.size());
433 for (
size_t i = 0; i < prover_manifest.
size(); ++i) {
434 EXPECT_EQ(prover_manifest[i], verifier_manifest[i]);
446using TestParams = ::testing::Types<TestParam<curve::BN254, 9>,
457 auto res = TestFixture::prove_and_verify(op_queue,
FaultMode::NONE,
false,
true);
458 EXPECT_TRUE(res.reduction_ok);
459 EXPECT_TRUE(res.pairing_ok);
460 EXPECT_TRUE(res.circuit_ok);
466 auto res = TestFixture::prove_and_verify(op_queue);
467 EXPECT_TRUE(res.reduction_ok);
468 EXPECT_TRUE(res.pairing_ok);
469 EXPECT_TRUE(res.circuit_ok);
479 EXPECT_FALSE(res.reduction_ok);
480 EXPECT_TRUE(res.pairing_ok);
481 if constexpr (TestFixture::IsRecursive) {
482 EXPECT_FALSE(res.circuit_ok);
488 if constexpr (!TestFixture::Curve::is_stdlib_type) {
489 GTEST_SKIP() <<
"This test in native setting fails due to a deserialization failure. The verifier path in the "
490 "same for native and recursive code, so it's enough to test the recursive code.";
495 EXPECT_FALSE(res.reduction_ok);
496 EXPECT_FALSE(res.pairing_ok);
497 if constexpr (TestFixture::IsRecursive) {
498 EXPECT_FALSE(res.circuit_ok);
507 EXPECT_FALSE(res.reduction_ok);
508 EXPECT_TRUE(res.pairing_ok);
509 if constexpr (TestFixture::IsRecursive) {
510 EXPECT_FALSE(res.circuit_ok);
517 auto res = TestFixture::prove_and_verify(op_queue,
FaultMode::NONE,
true);
518 EXPECT_FALSE(res.reduction_ok);
519 EXPECT_TRUE(res.pairing_ok);
520 if constexpr (TestFixture::IsRecursive) {
521 EXPECT_FALSE(res.circuit_ok);
529 EXPECT_FALSE(res.reduction_ok);
530 EXPECT_TRUE(res.pairing_ok);
531 if constexpr (TestFixture::IsRecursive) {
532 EXPECT_FALSE(res.circuit_ok);
540 EXPECT_FALSE(res.reduction_ok);
541 EXPECT_TRUE(res.pairing_ok);
542 if constexpr (TestFixture::IsRecursive) {
543 EXPECT_FALSE(res.circuit_ok);
551 EXPECT_FALSE(res.reduction_ok);
552 EXPECT_TRUE(res.pairing_ok);
553 if constexpr (TestFixture::IsRecursive) {
554 EXPECT_FALSE(res.circuit_ok);
562 EXPECT_FALSE(res.reduction_ok);
563 EXPECT_TRUE(res.pairing_ok);
564 if constexpr (TestFixture::IsRecursive) {
565 EXPECT_FALSE(res.circuit_ok);
574 if constexpr (!TestFixture::IsRecursive) {
575 GTEST_SKIP() <<
"Graph description analysis only applies to stdlib (recursive) verifier circuits.";
577 using BuilderType =
typename TestFixture::BuilderType;
578 using FF =
typename TestFixture::FF;
579 using Proof =
typename TestFixture::Proof;
580 using Verifier =
typename TestFixture::Verifier;
588 Proof proof = TestFixture::create_proof(
builder, native_proof);
589 FF hash = TestFixture::create_hash(
builder, native_hash);
595 auto result = verifier.reduce_to_pairing_check(proof, hash);
600 result.pairing_points.fix_witness();
606 auto graph = Analyzer(
builder);
607 auto [cc, variables_in_one_gate] = graph.analyze_circuit(
true);
609 EXPECT_EQ(cc.size(), 1);
610 EXPECT_EQ(variables_in_one_gate.size(), 0);
#define BB_ASSERT_GT(left, right,...)
#define BB_DISABLE_ASSERTS()
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
static constexpr size_t NUM_WIRES
CommitmentKey pcs_commitment_key
std::shared_ptr< Transcript > transcript
std::shared_ptr< ECCOpQueue > op_queue
std::vector< FF > MergeProof
MergeProof construct_proof()
Construct the batch merge proof.
static Polynomial compute_degree_check_polynomial(const std::vector< Polynomial > &flattened_columns, const std::vector< FF > °ree_check_challenges, const size_t max_size)
static constexpr size_t ZK_OFFSET
typename Verifier::Transcript Transcript
typename Param::CurveType Curve
static Proof create_proof(BuilderType &builder, const std::vector< bb::fr > &native_proof)
static constexpr bool IsRecursive
static constexpr size_t NumSubtables
typename Verifier::Proof Proof
static bool check_circuit(BuilderType &builder)
static void SetUpTestSuite()
static FF create_hash(BuilderType &builder, const bb::fr &native_hash)
typename BuilderTypeHelper< Curve >::type BuilderType
static constexpr size_t VERIFIER_NUM_GATES
static VerifyResult prove_and_verify(const std::shared_ptr< ECCOpQueue > &op_queue, FaultMode fault_mode=FaultMode::NONE, bool wrong_hash=false, bool check_manifest=false)
typename Curve::ScalarField FF
Unified batch verifier for the batch Goblin ECC op queue merge protocol.
std::shared_ptr< Transcript > transcript
ReductionResult reduce_to_pairing_check(const Proof &proof, const FF hash)
Reduce the batch merge proof to a pairing check.
TranscriptFor_t< Curve > Transcript
Commitment commit(PolynomialSpan< const Fr > polynomial, bool has_duplicates_hint=false) const
Uses the ProverSRS to create a commitment to p(X)
static void compute_opening_proof(const CK &ck, const ProverOpeningClaim< Curve > &opening_claim, const std::shared_ptr< Transcript > &prover_trancript)
Computes the KZG commitment to an opening proof polynomial at a single evaluation point.
Fr evaluate(const Fr &z) const
Fr & at(size_t index)
Our mutable accessor, unlike operator[]. We abuse precedent a bit to differentiate at() and operator[...
Polynomial p and an opening pair (r,v) such that p(r) = v.
static ProverOpeningClaim< Curve > prove(const CommitmentKey< Curve > &commitment_key, std::span< ProverOpeningClaim< Curve > > opening_claims, const std::shared_ptr< Transcript > &transcript, std::span< ProverOpeningClaim< Curve > > libra_opening_claims={}, std::span< ProverOpeningClaim< Curve > > sumcheck_round_claims={}, const size_t virtual_log_n=0)
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
TweakableBatchMergeProver(const std::shared_ptr< ECCOpQueue > &op_queue, size_t max_subtables, FaultMode mode=FaultMode::NONE)
bb::Polynomial< FF > Polynomial
MergeProof construct_proof()
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
typename Group::affine_element AffineElement
static constexpr bool is_stdlib_type
A simple wrapper around a vector of stdlib field elements representing a proof.
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
@ ZK_TABLE_DEGREE_TOO_HIGH
TYPED_TEST_SUITE(CommitmentKeyTest, Curves)
field< Bn254FrParams > fr
bb::fr compute_running_hash(const std::vector< bb::fr > &proof, size_t N)
void populate_subtable(const std::shared_ptr< ECCOpQueue > &op_queue, size_t num_ops)
TYPED_TEST(CommitmentKeyTest, CommitToZeroPoly)
NativeCurve::AffineElement NativeG1
std::shared_ptr< ECCOpQueue > make_op_queue_with_n_subtables(size_t n)
::testing::Types< TestParam< curve::BN254, 9 >, TestParam< curve::BN254, CHONK_MAX_NUM_CIRCUITS >, TestParam< stdlib::bn254< MegaCircuitBuilder >, 9 >, TestParam< stdlib::bn254< MegaCircuitBuilder >, CHONK_MAX_NUM_CIRCUITS > > TestParams
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
StaticAnalyzer_< bb::fr, bb::MegaCircuitBuilder > MegaStaticAnalyzer
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
typename Curve::Builder type
static constexpr size_t NumSubtables
constexpr field invert() const noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept