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 }
82
84 auto [stdlib_opening_claim, ipa_proof] =
85 IPA<grumpkin<InnerBuilder>>::create_fake_ipa_claim_and_proof(builder);
86 stdlib_opening_claim.set_public();
87 builder.ipa_proof = ipa_proof;
88 }
89 return builder;
90 };
91
92 public:
94
100 {
101 // Create an arbitrary inner circuit
102 auto inner_circuit = create_inner_circuit();
103
104 // Generate a proof over the inner circuit
105 auto proving_key = std::make_shared<InnerDeciderProvingKey>(inner_circuit);
106 auto verification_key = std::make_shared<typename InnerFlavor::VerificationKey>(proving_key->get_precomputed());
107 InnerProver inner_prover(proving_key, 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{ &outer_circuit, stdlib_vk_and_hash };
115 verifier.key->vk_and_hash->vk->num_public_inputs.fix_witness();
116 verifier.key->vk_and_hash->vk->pub_inputs_offset.fix_witness();
117 // It's currently un-used
118 verifier.key->vk_and_hash->vk->log_circuit_size.fix_witness();
119
120 StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
121 VerifierOutput output = verifier.template verify_proof<DefaultIO<OuterBuilder>>(stdlib_inner_proof);
122 PairingObject pairing_points = output.points_accumulator;
123 pairing_points.P0.x.fix_witness();
124 pairing_points.P0.y.fix_witness();
125 pairing_points.P1.x.fix_witness();
126 pairing_points.P1.y.fix_witness();
127 if constexpr (HasIPAAccumulator<OuterFlavor>) {
128 output.ipa_claim.set_public();
129 outer_circuit.ipa_proof = output.ipa_proof.get_value();
130 }
131 info("Recursive Verifier: num gates = ", outer_circuit.get_estimated_num_finalized_gates());
132
133 // Check for a failure flag in the recursive verifier circuit
134 EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
135
136 outer_circuit.finalize_circuit(false);
137 auto graph = cdg::StaticAnalyzer(outer_circuit);
138 auto connected_components = graph.find_connected_components();
139 EXPECT_EQ(connected_components.size(), 2);
140 info("Connected components: ", connected_components.size());
141 auto variables_in_one_gate = graph.show_variables_in_one_gate(outer_circuit);
142 EXPECT_EQ(variables_in_one_gate.size(), 2);
143 }
144};
145
146// Run the recursive verifier tests with conventional Ultra builder and Goblin builder
147using Flavors = testing::Types<UltraRecursiveFlavor_<UltraCircuitBuilder>>;
148
150
152{
153 TestFixture::test_recursive_verification();
154};
155
156} // namespace bb::stdlib::recursion::honk
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:95
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
void info(Args... args)
Definition log.hpp:70
AluTraceBuilder builder
Definition alu.test.cpp:123
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
StaticAnalyzer_< bb::fr > StaticAnalyzer
Definition graph.hpp:201
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.
static void add_default_to_public_inputs(Builder &builder)
Adds default public inputs to the builder.
#define HEAVY_TYPED_TEST(x, y)
Definition test.hpp:11