26static constexpr size_t NUM_FRS_COMM = NativeTranscript::Codec::template calc_num_fields<NativeG1>();
34 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 degree_check_poly.
at(0) +=
FF(1);
249 const FF kappa =
transcript->template get_challenge<FF>(
"KAPPA");
250 const FF kappa_inv = kappa.
invert();
253 std::vector<FF> evals;
256 for (
size_t flat_idx = 0; flat_idx < num_flattened_col_evals; ++flat_idx) {
258 if (flat_idx < num_actual_flattened_cols) {
259 eval = flattened_cols[flat_idx].evaluate(kappa);
263 evals.push_back(eval);
267 for (
size_t col = 0; col <
NUM_WIRES; ++col) {
268 evals.push_back(merged_table[col].evaluate(kappa));
272 evals.push_back(degree_check_poly.
evaluate(kappa_inv));
273 transcript->send_to_verifier(
"DEGREE_CHECK_EVAL", evals.back());
278 opening_claims.reserve(num_opening_claims);
280 for (
size_t idx = 0; idx < num_flattened_col_evals; ++idx) {
281 if (idx < num_actual_flattened_cols) {
282 opening_claims.push_back({
std::move(flattened_cols[idx]), { kappa, evals[idx] } });
284 opening_claims.push_back({
Polynomial(1), { kappa,
FF(0) } });
288 for (
size_t idx = 0; idx <
NUM_WIRES; ++idx) {
289 opening_claims.push_back(
293 opening_claims.push_back({
std::move(degree_check_poly), { kappa_inv, evals.back() } });
314 using Curve =
typename Param::CurveType;
348 auto hash = FF::from_witness(&
builder, native_hash);
349 hash.unset_free_witness_tag();
369 bool wrong_hash =
false,
370 bool check_manifest =
false)
373 std::vector<bb::fr> native_proof;
376 if (check_manifest) {
380 native_proof = prover.construct_proof();
381 if (check_manifest) {
382 prover_manifest = prover.transcript->get_manifest();
386 if (check_manifest) {
390 native_proof = prover.construct_proof();
391 if (check_manifest) {
392 prover_manifest = prover.transcript->get_manifest();
406 if (check_manifest) {
411 if (check_manifest) {
413 auto verifier_manifest = verifier.
transcript->get_manifest();
414 EXPECT_EQ(prover_manifest.
size(), verifier_manifest.size());
415 for (
size_t i = 0; i < prover_manifest.
size(); ++i) {
416 EXPECT_EQ(prover_manifest[i], verifier_manifest[i]);
428using TestParams = ::testing::Types<TestParam<curve::BN254, 9>,
439 auto res = TestFixture::prove_and_verify(op_queue,
FaultMode::NONE,
false,
true);
440 EXPECT_TRUE(res.reduction_ok);
441 EXPECT_TRUE(res.pairing_ok);
442 EXPECT_TRUE(res.circuit_ok);
448 auto res = TestFixture::prove_and_verify(op_queue);
449 EXPECT_TRUE(res.reduction_ok);
450 EXPECT_TRUE(res.pairing_ok);
451 EXPECT_TRUE(res.circuit_ok);
461 EXPECT_FALSE(res.reduction_ok);
462 EXPECT_TRUE(res.pairing_ok);
463 if constexpr (TestFixture::IsRecursive) {
464 EXPECT_FALSE(res.circuit_ok);
470 if constexpr (!TestFixture::Curve::is_stdlib_type) {
471 GTEST_SKIP() <<
"This test in native setting fails due to a deserialization failure. The verifier path in the "
472 "same for native and recursive code, so it's enough to test the recursive code.";
476 auto res = TestFixture::prove_and_verify(op_queue);
477 EXPECT_FALSE(res.reduction_ok);
478 EXPECT_FALSE(res.pairing_ok);
479 if constexpr (TestFixture::IsRecursive) {
480 EXPECT_FALSE(res.circuit_ok);
489 EXPECT_FALSE(res.reduction_ok);
490 EXPECT_TRUE(res.pairing_ok);
491 if constexpr (TestFixture::IsRecursive) {
492 EXPECT_FALSE(res.circuit_ok);
499 auto res = TestFixture::prove_and_verify(op_queue,
FaultMode::NONE,
true);
500 EXPECT_FALSE(res.reduction_ok);
501 EXPECT_TRUE(res.pairing_ok);
502 if constexpr (TestFixture::IsRecursive) {
503 EXPECT_FALSE(res.circuit_ok);
511 EXPECT_FALSE(res.reduction_ok);
512 EXPECT_TRUE(res.pairing_ok);
513 if constexpr (TestFixture::IsRecursive) {
514 EXPECT_FALSE(res.circuit_ok);
522 EXPECT_FALSE(res.reduction_ok);
523 EXPECT_TRUE(res.pairing_ok);
524 if constexpr (TestFixture::IsRecursive) {
525 EXPECT_FALSE(res.circuit_ok);
533 EXPECT_FALSE(res.reduction_ok);
534 EXPECT_TRUE(res.pairing_ok);
535 if constexpr (TestFixture::IsRecursive) {
536 EXPECT_FALSE(res.circuit_ok);
544 EXPECT_FALSE(res.reduction_ok);
545 EXPECT_TRUE(res.pairing_ok);
546 if constexpr (TestFixture::IsRecursive) {
547 EXPECT_FALSE(res.circuit_ok);
556 if constexpr (!TestFixture::IsRecursive) {
557 GTEST_SKIP() <<
"Graph description analysis only applies to stdlib (recursive) verifier circuits.";
559 using BuilderType =
typename TestFixture::BuilderType;
560 using FF =
typename TestFixture::FF;
561 using Proof =
typename TestFixture::Proof;
562 using Verifier =
typename TestFixture::Verifier;
570 Proof proof = TestFixture::create_proof(
builder, native_proof);
571 FF hash = TestFixture::create_hash(
builder, native_hash);
578 auto result = verifier.reduce_to_pairing_check(proof, hash);
583 result.pairing_points.fix_witness();
589 auto graph = Analyzer(
builder);
590 auto [cc, variables_in_one_gate] = graph.analyze_circuit(
true);
592 EXPECT_EQ(cc.size(), 1);
593 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) 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.
static constexpr size_t NUM_WIRES
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)
Returns a batched opening claim equivalent to a set of opening claims consisting of polynomials,...
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