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.
11
12using namespace cdg;
13
15
23template <class RecursiveBuilder> class BoomerangRecursiveMergeVerifierTest : public testing::Test {
24
25 // Types for recursive verifier circuit
29
30 // Define types relevant for inner circuit
34
35 // Define additional types for testing purposes
42
43 public:
45
46 static void analyze_circuit(RecursiveBuilder& outer_circuit)
47 {
48 // AUDITTODO: The 8 under-constrained variables are the _is_infinity boolean flags from the 8
49 // commitments created via goblin_element::from_witness (4 t_commitments + 4 T_prev_commitments).
50 // Each boolean is only constrained by a single bool gate (x * (x - 1) = 0) and is not
51 // connected to the point coordinates. This may be a security issue if the infinity flag is not
52 // properly bound to the coordinates via Fiat-Shamir - a malicious prover could potentially
53 // set the flag independently of the actual point value.
54 constexpr size_t EXPECTED_UNCONSTRAINED_INFINITY_FLAGS = 8;
55
56 if constexpr (IsMegaBuilder<RecursiveBuilder>) {
57 MegaStaticAnalyzer tool = MegaStaticAnalyzer(outer_circuit);
58 auto result = tool.analyze_circuit();
59 EXPECT_EQ(result.first.size(), 1);
60 EXPECT_EQ(result.second.size(), EXPECTED_UNCONSTRAINED_INFINITY_FLAGS);
61 }
63 StaticAnalyzer tool = StaticAnalyzer(outer_circuit);
64 auto result = tool.analyze_circuit();
65 EXPECT_EQ(result.first.size(), 1);
66 EXPECT_EQ(result.second.size(), EXPECTED_UNCONSTRAINED_INFINITY_FLAGS);
67 }
68 }
69
72 const bool run_analyzer = false)
73
74 {
75 RecursiveBuilder outer_circuit;
76
77 auto prover_transcript = std::make_shared<NativeTranscript>();
78 MergeProver merge_prover{ op_queue, prover_transcript, settings };
79 auto merge_proof = merge_prover.construct_proof();
80
81 // Subtable values and commitments - needed for (Recursive)MergeVerifier
82 MergeCommitments merge_commitments;
83 RecursiveMergeCommitments recursive_merge_commitments;
84 auto t_current = op_queue->construct_current_ultra_ops_subtable_columns();
85 auto T_prev = op_queue->construct_previous_ultra_ops_table_columns();
86 for (size_t idx = 0; idx < InnerFlavor::NUM_WIRES; idx++) {
87 merge_commitments.t_commitments[idx] = merge_prover.pcs_commitment_key.commit(t_current[idx]);
88 merge_commitments.T_prev_commitments[idx] = merge_prover.pcs_commitment_key.commit(T_prev[idx]);
89 recursive_merge_commitments.t_commitments[idx] =
90 RecursiveMergeVerifier::Commitment::from_witness(&outer_circuit, merge_commitments.t_commitments[idx]);
91 recursive_merge_commitments.T_prev_commitments[idx] = RecursiveMergeVerifier::Commitment::from_witness(
92 &outer_circuit, merge_commitments.T_prev_commitments[idx]);
93 // Removing the free witness tag, since the merge commitments in the full scheme are supposed to
94 // be fiat-shamirred earlier
95 recursive_merge_commitments.t_commitments[idx].unset_free_witness_tag();
96 recursive_merge_commitments.T_prev_commitments[idx].unset_free_witness_tag();
97 }
98
99 // Create a recursive merge verification circuit for the merge proof
101 RecursiveMergeVerifier verifier{ settings, merge_transcript };
102 const stdlib::Proof<RecursiveBuilder> stdlib_merge_proof(outer_circuit, merge_proof);
103 [[maybe_unused]] auto [pairing_points, merged_commitments, reduction_succeeded] =
104 verifier.reduce_to_pairing_check(stdlib_merge_proof, recursive_merge_commitments);
105
106 // Check for a failure flag in the recursive verifier circuit
107 EXPECT_FALSE(outer_circuit.failed());
108 if (run_analyzer) {
109 analyze_circuit(outer_circuit);
110 }
111 }
112
114 {
115 auto op_queue = std::make_shared<ECCOpQueue>();
116
117 InnerBuilder circuit{ op_queue };
119 prove_and_verify_merge(op_queue);
120
121 InnerBuilder circuit2{ op_queue };
123 prove_and_verify_merge(op_queue);
124
125 InnerBuilder circuit3{ op_queue };
128 }
129
131 {
132 auto op_queue = std::make_shared<ECCOpQueue>();
133
134 InnerBuilder circuit{ op_queue };
136 prove_and_verify_merge(op_queue);
137
138 InnerBuilder circuit2{ op_queue };
140 prove_and_verify_merge(op_queue);
141
142 InnerBuilder circuit3{ op_queue };
145 }
146};
147
148using Builder = testing::Types<MegaCircuitBuilder>;
149
151
153{
154 TestFixture::test_recursive_merge_verification_prepend();
155};
156
158{
159 TestFixture::test_recursive_merge_verification_append();
160};
161
162} // 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 class for the Goblin ECC op queue transcript merge protocol.
std::vector< FF > MergeProof
BB_PROFILE MergeProof construct_proof()
Prove proper construction of the aggregate Goblin ECC op queue polynomials T_j.
Unified verifier class for the Goblin ECC op queue transcript merge protocol.
std::array< Commitment, NUM_WIRES > TableCommitments
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
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 void prove_and_verify_merge(const std::shared_ptr< ECCOpQueue > &op_queue, const MergeSettings settings=MergeSettings::PREPEND, const bool run_analyzer=false)
std::pair< std::vector< ConnectedComponent >, std::unordered_set< uint32_t > > analyze_circuit(bool filter_cc=true)
this functions was made for more convenient testing process
Definition graph.cpp:1402
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TYPED_TEST_SUITE(BoomerangRecursiveMergeVerifierTest, Builder)
TYPED_TEST(BoomerangRecursiveMergeVerifierTest, RecursiveVerificationPrepend)
MergeSettings
The MergeSettings define whether an current subtable will be added at the beginning (PREPEND) or at t...
Definition graph.cpp:21
StaticAnalyzer_< bb::fr, bb::MegaCircuitBuilder > MegaStaticAnalyzer
Definition graph.hpp:189
UltraStaticAnalyzer StaticAnalyzer
Definition graph.hpp:190
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13