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_random_valid_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 prover_instance = std::make_shared<InnerProverInstance>(inner_circuit);
106 auto verification_key =
107 std::make_shared<typename InnerFlavor::VerificationKey>(prover_instance->get_precomputed());
108 InnerProver inner_prover(prover_instance, verification_key);
109 auto inner_proof = inner_prover.construct_proof();
110
111 // Create a recursive verification circuit for the proof of the inner circuit
112 OuterBuilder outer_circuit;
113 auto stdlib_vk_and_hash =
114 std::make_shared<typename RecursiveFlavor::VKAndHash>(outer_circuit, verification_key);
115 RecursiveVerifier verifier{ &outer_circuit, stdlib_vk_and_hash };
116 verifier.verifier_instance->vk_and_hash->vk->num_public_inputs.fix_witness();
117 verifier.verifier_instance->vk_and_hash->vk->pub_inputs_offset.fix_witness();
118 // It's currently un-used
119 verifier.verifier_instance->vk_and_hash->vk->log_circuit_size.fix_witness();
120
121 StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
122 VerifierOutput output = verifier.template verify_proof<DefaultIO<OuterBuilder>>(stdlib_inner_proof);
123 PairingObject pairing_points = output.points_accumulator;
124 pairing_points.P0.x.fix_witness();
125 pairing_points.P0.y.fix_witness();
126 pairing_points.P1.x.fix_witness();
127 pairing_points.P1.y.fix_witness();
128 if constexpr (HasIPAAccumulator<OuterFlavor>) {
129 output.ipa_claim.set_public();
130 outer_circuit.ipa_proof = output.ipa_proof.get_value();
131 }
132 info("Recursive Verifier: num gates = ", outer_circuit.get_estimated_num_finalized_gates());
133
134 // Check for a failure flag in the recursive verifier circuit
135 EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
136
137 outer_circuit.finalize_circuit(false);
138 auto graph = cdg::StaticAnalyzer(outer_circuit);
139 auto connected_components = graph.find_connected_components();
140 EXPECT_EQ(connected_components.size(), 1);
141 info("Connected components: ", connected_components.size());
142 auto variables_in_one_gate = graph.get_variables_in_one_gate();
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
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:93
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
std::shared_ptr< RecursiveVerifierInstance > verifier_instance
void info(Args... args)
Definition log.hpp:74
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
UltraStaticAnalyzer StaticAnalyzer
Definition graph.hpp:184
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