Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
graph_description_ultra_recursive_verifier.test.cpp
Go to the documentation of this file.
11
13
23template <typename RecursiveFlavor> class BoomerangRecursiveVerifierTest : public testing::Test {
24
25 // Define types for the inner circuit, i.e. the circuit whose proof will be recursively verified
26 using InnerFlavor = typename RecursiveFlavor::NativeFlavor;
29 using InnerBuilder = typename InnerFlavor::CircuitBuilder;
32 using InnerCommitment = InnerFlavor::Commitment;
33 using InnerFF = InnerFlavor::FF;
34
35 // Defines types for the outer circuit, i.e. the circuit of the recursive verifier
36 using OuterBuilder = typename RecursiveFlavor::CircuitBuilder;
44
47
51
60 static InnerBuilder create_inner_circuit(size_t log_num_gates = 10)
61 {
62 using fr = typename InnerCurve::ScalarFieldNative;
63
65
66 // Create 2^log_n many add gates based on input log num gates
67 const size_t num_gates = (1 << log_num_gates);
68 for (size_t i = 0; i < num_gates; ++i) {
70 uint32_t a_idx = builder.add_variable(a);
71
74 fr d = a + b + c;
75 uint32_t b_idx = builder.add_variable(b);
76 uint32_t c_idx = builder.add_variable(c);
77 uint32_t d_idx = builder.add_variable(d);
78
79 builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) });
80 }
83 } else {
85 }
86 return builder;
87 };
88
89 public:
91
97 {
98 // Create an arbitrary inner circuit
99 auto inner_circuit = create_inner_circuit();
100
101 // Generate a proof over the inner circuit
102 auto prover_instance = std::make_shared<InnerProverInstance>(inner_circuit);
103 auto verification_key =
104 std::make_shared<typename InnerFlavor::VerificationKey>(prover_instance->get_precomputed());
105 InnerProver inner_prover(prover_instance, verification_key);
106 auto inner_proof = inner_prover.construct_proof();
107
108 // Create a recursive verification circuit for the proof of the inner circuit
109 OuterBuilder outer_circuit;
110 auto stdlib_vk_and_hash =
111 std::make_shared<typename RecursiveFlavor::VKAndHash>(outer_circuit, verification_key);
112 RecursiveVerifier verifier{ &outer_circuit, stdlib_vk_and_hash };
113 verifier.verifier_instance->vk_and_hash->vk->num_public_inputs.fix_witness();
114 verifier.verifier_instance->vk_and_hash->vk->pub_inputs_offset.fix_witness();
115 // It's currently un-used
116 verifier.verifier_instance->vk_and_hash->vk->log_circuit_size.fix_witness();
117
118 StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
119 VerifierOutput output = verifier.template verify_proof<DefaultIO<OuterBuilder>>(stdlib_inner_proof);
120 PairingObject pairing_points = output.points_accumulator;
121
122 // The pairing points are public outputs from the recursive verifier that will be verified externally via a
123 // pairing check. While they are computed within the circuit (via batch_mul for P0 and negation for P1), their
124 // output coordinates may not appear in multiple constraint gates. Calling fix_witness() adds explicit
125 // constraints on these values. Without these constraints, the StaticAnalyzer detects unconstrained variables
126 // (coordinate limbs) that appear in only one gate. This ensures the pairing point coordinates are properly
127 // constrained within the circuit itself, rather than relying solely on them being public outputs.
128 pairing_points.P0.fix_witness();
129 pairing_points.P1.fix_witness();
130 if constexpr (HasIPAAccumulator<OuterFlavor>) {
131 output.ipa_claim.set_public();
132 outer_circuit.ipa_proof = output.ipa_proof.get_value();
133 }
134 info("Recursive Verifier: num gates = ", outer_circuit.get_num_finalized_gates_inefficient());
135
136 // Check for a failure flag in the recursive verifier circuit
137 EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
138
139 outer_circuit.finalize_circuit(false);
140 auto graph = cdg::StaticAnalyzer(outer_circuit);
141 auto [cc, variables_in_one_gate] = graph.analyze_circuit(/*filter_cc=*/true);
142 EXPECT_EQ(cc.size(), 1);
143 EXPECT_EQ(variables_in_one_gate.size(), 2);
144 }
145};
146
147// Run the recursive verifier tests with conventional Ultra builder and Goblin builder
148using Flavors = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>>;
149
151
153{
154 TestFixture::test_recursive_verification();
155};
156
157} // namespace bb::stdlib::recursion::honk
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
Test suite for recursive verification of Honk proofs for both Ultra and Mega arithmetisation.
static InnerBuilder create_inner_circuit(size_t log_num_gates=10)
Create a non-trivial arbitrary inner circuit, the proof of which will be recursively verified.
static void test_recursive_verification()
Construct a recursive verification circuit for the proof of an inner circuit then check the number of...
std::conditional_t< IsMegaBuilder< OuterBuilder >, MegaFlavor, std::conditional_t< HasIPAAccumulator< RecursiveFlavor >, UltraRollupFlavor, UltraFlavor > > OuterFlavor
static void add_default(Builder &builder)
Add default public inputs when they are not present.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
std::shared_ptr< RecursiveVerifierInstance > verifier_instance
void info(Args... args)
Definition log.hpp:75
AluTraceBuilder builder
Definition alu.test.cpp:124
FF a
FF b
Base class templates for structures that contain data parameterized by the fundamental polynomials of...
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
testing::Types< UltraRecursiveFlavor_< UltraCircuitBuilder > > Flavors
TYPED_TEST_SUITE(BoomerangRecursiveVerifierTest, Flavors)
field< Bn254FrParams > fr
Definition fr.hpp:174
UltraStaticAnalyzer StaticAnalyzer
Definition graph.hpp:187
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept
curve::BN254::ScalarField ScalarFieldNative
Definition bn254.hpp:24
An object storing two EC points that represent the inputs to a pairing check.
#define HEAVY_TYPED_TEST(x, y)
Definition test.hpp:11