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;
30 using InnerBuilder = typename InnerFlavor::CircuitBuilder;
33 using InnerCommitment = InnerFlavor::Commitment;
34 using InnerFF = InnerFlavor::FF;
35
36 // Defines types for the outer circuit, i.e. the circuit of the recursive verifier
37 using OuterBuilder = typename RecursiveFlavor::CircuitBuilder;
46
49
53
62 static InnerBuilder create_inner_circuit(size_t log_num_gates = 10)
63 {
64 using fr = typename InnerCurve::ScalarFieldNative;
65
67
68 // Create 2^log_n many add gates based on input log num gates
69 const size_t num_gates = (1 << log_num_gates);
70 for (size_t i = 0; i < num_gates; ++i) {
72 uint32_t a_idx = builder.add_variable(a);
73
76 fr d = a + b + c;
77 uint32_t b_idx = builder.add_variable(b);
78 uint32_t c_idx = builder.add_variable(c);
79 uint32_t d_idx = builder.add_variable(d);
80
81 builder.create_big_add_gate({ a_idx, b_idx, c_idx, d_idx, fr(1), fr(1), fr(1), fr(-1), fr(0) });
82 }
85 } else {
87 }
88 return builder;
89 };
90
91 public:
93
99 {
100 // Create an arbitrary inner circuit
101 auto inner_circuit = create_inner_circuit();
102
103 // Generate a proof over the inner circuit
104 auto prover_instance = std::make_shared<InnerProverInstance>(inner_circuit);
105 auto verification_key =
106 std::make_shared<typename InnerFlavor::VerificationKey>(prover_instance->get_precomputed());
107 InnerProver inner_prover(prover_instance, verification_key);
108 auto inner_proof = inner_prover.construct_proof();
109
110 // Create a recursive verification circuit for the proof of the inner circuit
111 OuterBuilder outer_circuit;
112 auto stdlib_vk_and_hash =
113 std::make_shared<typename RecursiveFlavor::VKAndHash>(outer_circuit, verification_key);
114 RecursiveVerifier verifier{ stdlib_vk_and_hash };
115 verifier.get_verifier_instance()->vk_and_hash->vk->num_public_inputs.fix_witness();
116 verifier.get_verifier_instance()->vk_and_hash->vk->pub_inputs_offset.fix_witness();
117 // It's currently un-used
118 verifier.get_verifier_instance()->vk_and_hash->vk->log_circuit_size.fix_witness();
119
120 StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
121 VerifierOutput output = verifier.verify_proof(stdlib_inner_proof);
122 PairingObject pairing_points = output.points_accumulator;
123
124 // The pairing points are public outputs from the recursive verifier that will be verified externally via a
125 // pairing check. While they are computed within the circuit (via batch_mul for P0 and negation for P1), their
126 // output coordinates may not appear in multiple constraint gates. Calling fix_witness() adds explicit
127 // constraints on these values. Without these constraints, the StaticAnalyzer detects unconstrained variables
128 // (coordinate limbs) that appear in only one gate. This ensures the pairing point coordinates are properly
129 // constrained within the circuit itself, rather than relying solely on them being public outputs.
130 pairing_points.P0.fix_witness();
131 pairing_points.P1.fix_witness();
132 if constexpr (HasIPAAccumulator<OuterFlavor>) {
133 output.ipa_claim.set_public();
134 outer_circuit.ipa_proof = output.ipa_proof.get_value();
135 }
136 info("Recursive Verifier: num gates = ", outer_circuit.get_num_finalized_gates_inefficient());
137
138 // Check for a failure flag in the recursive verifier circuit
139 EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
140
141 outer_circuit.finalize_circuit(false);
142 auto graph = cdg::StaticAnalyzer(outer_circuit);
143 auto [cc, variables_in_one_gate] = graph.analyze_circuit(/*filter_cc=*/true);
144 EXPECT_EQ(cc.size(), 1);
145 EXPECT_EQ(variables_in_one_gate.size(), 2);
146 }
147};
148
149// Run the recursive verifier tests with conventional Ultra builder and Goblin builder
150using Flavors = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>>;
151
153
155{
156 TestFixture::test_recursive_verification();
157};
158
159} // namespace bb::stdlib::recursion::honk
Manages the data that is propagated on the public inputs of an application/function circuit.
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The data that is propagated on the public inputs of a rollup circuit.
UltraRollupFlavor extends UltraFlavor with IPA proof support.
const std::shared_ptr< Instance > & get_verifier_instance() const
Get the verifier instance (for accessing VK and witness commitments in Chonk/Goblin)
typename Flavor::VerificationKey VerificationKey
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.
std::conditional_t< HasIPAAccumulator< OuterFlavor >, bb::RollupIO, bb::DefaultIO > OuterIO
std::conditional_t< HasIPAAccumulator< InnerFlavor >, bb::RollupIO, bb::DefaultIO > InnerIO
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.
void info(Args... args)
Definition log.hpp:89
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.
Output type for recursive ultra verification.
#define HEAVY_TYPED_TEST(x, y)
Definition test.hpp:11