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 // AUDITTODO: The 8 under-constrained variables are the _is_infinity boolean flags from the 8
45 // commitments created via goblin_element::from_witness (4 t_commitments + 4 T_prev_commitments).
46 // Each boolean is only constrained by a single bool gate (x * (x - 1) = 0) and is not
47 // connected to the point coordinates. This may be a security issue if the infinity flag is not
48 // properly bound to the coordinates via Fiat-Shamir - a malicious prover could potentially
49 // set the flag independently of the actual point value.
50 constexpr size_t EXPECTED_UNCONSTRAINED_INFINITY_FLAGS = 4;
51
52 if constexpr (IsMegaBuilder<RecursiveBuilder>) {
53 MegaStaticAnalyzer tool = MegaStaticAnalyzer(outer_circuit);
54 auto result = tool.analyze_circuit();
55 EXPECT_EQ(result.first.size(), 1);
56 EXPECT_EQ(result.second.size(), EXPECTED_UNCONSTRAINED_INFINITY_FLAGS);
57 }
59 StaticAnalyzer tool = StaticAnalyzer(outer_circuit);
60 auto result = tool.analyze_circuit();
61 EXPECT_EQ(result.first.size(), 1);
62 EXPECT_EQ(result.second.size(), EXPECTED_UNCONSTRAINED_INFINITY_FLAGS);
63 }
64 }
65
68 const bool run_analyzer = false)
69
70 {
71 RecursiveBuilder outer_circuit;
72
73 auto prover_transcript = std::make_shared<NativeTranscript>();
74 MergeProver merge_prover{ op_queue, prover_transcript, settings };
75 auto merge_proof = merge_prover.construct_proof();
76
77 // Subtable values and commitments - needed for (Recursive)MergeVerifier
78 MergeCommitments merge_commitments;
79 RecursiveMergeCommitments recursive_merge_commitments;
80 auto t_current = op_queue->construct_current_ultra_ops_subtable_columns();
81 auto T_prev = op_queue->construct_previous_ultra_ops_table_columns();
82 for (size_t idx = 0; idx < InnerFlavor::NUM_WIRES; idx++) {
83 merge_commitments.t_commitments[idx] = merge_prover.pcs_commitment_key.commit(t_current[idx]);
84 merge_commitments.T_prev_commitments[idx] = merge_prover.pcs_commitment_key.commit(T_prev[idx]);
85 recursive_merge_commitments.t_commitments[idx] =
86 RecursiveMergeVerifier::Commitment::from_witness(&outer_circuit, merge_commitments.t_commitments[idx]);
87 recursive_merge_commitments.T_prev_commitments[idx] = RecursiveMergeVerifier::Commitment::from_witness(
88 &outer_circuit, merge_commitments.T_prev_commitments[idx]);
89 // Removing the free witness tag, since the merge commitments in the full scheme are supposed to
90 // be fiat-shamirred earlier
91 recursive_merge_commitments.t_commitments[idx].unset_free_witness_tag();
92 recursive_merge_commitments.T_prev_commitments[idx].unset_free_witness_tag();
93 }
94
95 // Create a recursive merge verification circuit for the merge proof
97 RecursiveMergeVerifier verifier{ settings, merge_transcript };
98 const stdlib::Proof<RecursiveBuilder> stdlib_merge_proof(outer_circuit, merge_proof);
99 [[maybe_unused]] auto [pairing_points, merged_commitments, reduction_succeeded] =
100 verifier.reduce_to_pairing_check(stdlib_merge_proof, recursive_merge_commitments);
101
102 // Check for a failure flag in the recursive verifier circuit
103 EXPECT_FALSE(outer_circuit.failed());
104 if (run_analyzer) {
105 analyze_circuit(outer_circuit);
106 }
107 }
108
110 {
111 auto op_queue = std::make_shared<ECCOpQueue>();
112
113 InnerBuilder circuit{ op_queue };
115 prove_and_verify_merge(op_queue);
116
117 InnerBuilder circuit2{ op_queue };
119 prove_and_verify_merge(op_queue);
120
121 InnerBuilder circuit3{ op_queue };
124 }
125
127 {
128 auto op_queue = std::make_shared<ECCOpQueue>();
129
130 InnerBuilder circuit{ op_queue };
132 prove_and_verify_merge(op_queue);
133
134 InnerBuilder circuit2{ op_queue };
136 prove_and_verify_merge(op_queue);
137
138 InnerBuilder circuit3{ op_queue };
141 }
142};
143
144using Builder = testing::Types<MegaCircuitBuilder>;
145
147
149{
150 TestFixture::test_recursive_merge_verification_prepend();
151};
152
154{
155 TestFixture::test_recursive_merge_verification_append();
156};
157
158} // 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