Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
graph_description_merge_recursive_verifier.test.cpp
Go to the documentation of this file.
7
8using namespace cdg;
9
11
19template <class RecursiveBuilder> class BoomerangRecursiveMergeVerifierTest : public testing::Test {
20
21 // Types for recursive verifier circuit
25
26 // Define types relevant for inner circuit
30
31 // Define additional types for testing purposes
38
39 public:
41
42 static void analyze_circuit(RecursiveBuilder& outer_circuit)
43 {
44 auto tool = StaticAnalyzer_<bb::fr, RecursiveBuilder>(outer_circuit);
45 auto result = tool.analyze_circuit();
46 EXPECT_EQ(result.first.size(), 1);
47 EXPECT_EQ(result.second.size(), 0);
48 }
49
50 static std::shared_ptr<ECCOpQueue> construct_final_merge_op_queue(const size_t num_subtables_up_to_tail)
51 {
52 auto op_queue = std::make_shared<ECCOpQueue>();
53
54 for (size_t idx = 0; idx < num_subtables_up_to_tail; ++idx) {
55 InnerBuilder circuit{ op_queue };
57 op_queue->merge();
58 }
59
60 op_queue->construct_zk_columns();
61
62 InnerBuilder hiding_circuit{ op_queue };
64 return op_queue;
65 }
66
67 static void prove_and_verify_merge(const std::shared_ptr<ECCOpQueue>& op_queue, const bool run_analyzer = false)
68
69 {
70 RecursiveBuilder outer_circuit;
71
72 auto prover_transcript = std::make_shared<NativeTranscript>();
73 MergeProver merge_prover{ op_queue, prover_transcript };
74 auto merge_proof = merge_prover.construct_proof();
75
76 // Subtable values and commitments - needed for (Recursive)MergeVerifier
77 MergeCommitments merge_commitments;
78 RecursiveMergeCommitments recursive_merge_commitments;
79 auto t_current = op_queue->construct_current_ultra_ops_subtable_columns();
80 auto T_prev = op_queue->construct_table_columns_up_to_tail();
81 for (size_t idx = 0; idx < InnerFlavor::NUM_WIRES; idx++) {
82 merge_commitments.t_commitments[idx] = merge_prover.pcs_commitment_key.commit(t_current[idx]);
83 merge_commitments.T_prev_commitments[idx] = merge_prover.pcs_commitment_key.commit(T_prev[idx]);
84 recursive_merge_commitments.t_commitments[idx] =
85 RecursiveMergeVerifier::Commitment::from_witness(&outer_circuit, merge_commitments.t_commitments[idx]);
86 recursive_merge_commitments.T_prev_commitments[idx] = RecursiveMergeVerifier::Commitment::from_witness(
87 &outer_circuit, merge_commitments.T_prev_commitments[idx]);
88 // Removing the free witness tag, since the merge commitments in the full scheme are supposed to
89 // be fiat-shamirred earlier
90 recursive_merge_commitments.t_commitments[idx].unset_free_witness_tag();
91 recursive_merge_commitments.T_prev_commitments[idx].unset_free_witness_tag();
92 }
93
94 // Create a recursive merge verification circuit for the merge proof
96 RecursiveMergeVerifier verifier{ merge_transcript };
97 const stdlib::Proof<RecursiveBuilder> stdlib_merge_proof(outer_circuit, merge_proof);
98 auto [pairing_points, merged_commitments, reduction_succeeded] =
99 verifier.reduce_to_pairing_check(stdlib_merge_proof, recursive_merge_commitments);
100
101 // The pairing points are public outputs from the recursive verifier that will be verified externally via a
102 // pairing check. Their output coordinate limbs (from goblin batch_mul's queue_ecc_eq) may only appear in a
103 // single ECC op gate. Calling fix_witness() adds explicit constraints on these values so the StaticAnalyzer
104 // does not flag them as under-constrained.
105 pairing_points.fix_witness();
106
107 // Check for a failure flag in the recursive verifier circuit
108 EXPECT_FALSE(outer_circuit.failed());
109 if (run_analyzer) {
110 analyze_circuit(outer_circuit);
111 }
112 }
113
115 {
116 auto op_queue = construct_final_merge_op_queue(/*num_subtables_up_to_tail=*/3);
117 prove_and_verify_merge(op_queue, /*run_analyzer=*/true);
118 }
119};
120
121using Builder = testing::Types<MegaCircuitBuilder>;
122
124
126{
127 TestFixture::test_recursive_merge_verification();
128};
129
130} // namespace bb::stdlib::recursion::goblin
static void construct_simple_circuit(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
Curve::ScalarField FF
static constexpr size_t NUM_WIRES
MegaCircuitBuilder CircuitBuilder
Curve::AffineElement Commitment
Prover for the single-step Goblin ECC op queue merge protocol.
std::vector< FF > MergeProof
BB_PROFILE MergeProof construct_proof()
Prove proper construction of the aggregate Goblin ECC op queue polynomials T_j.
Verifier for the single-step Goblin ECC op queue merge protocol.
std::array< Commitment, NUM_WIRES > TableCommitments
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
static std::shared_ptr< ECCOpQueue > construct_final_merge_op_queue(const size_t num_subtables_up_to_tail)
static void prove_and_verify_merge(const std::shared_ptr< ECCOpQueue > &op_queue, const bool run_analyzer=false)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TYPED_TEST_SUITE(BoomerangRecursiveMergeVerifierTest, Builder)
TYPED_TEST(BoomerangRecursiveMergeVerifierTest, RecursiveMergeVerification)
Definition graph.cpp:21
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13