Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
recursive_circuit.hpp
Go to the documentation of this file.
1#pragma once
10
11namespace bb {
13 public:
23
26
31
35
43 {
45
46 field_ct a(public_witness_ct(&builder, inputs[0]));
47 field_ct b(public_witness_ct(&builder, inputs[1]));
48 field_ct c(public_witness_ct(&builder, inputs[2]));
49
50 c.assert_equal(a + b);
51
53
54 return builder;
55 }
56
66 {
67 // Create the initial inner circuit - it is just a simple multiplication gate!
68 auto inner_circuit = create_inner_circuit(inputs);
69
70 // Create the outer recursive verifier circuit
71 OuterBuilder outer_circuit;
72
73 auto inner_proving_key = std::make_shared<InnerDeciderProvingKey>(inner_circuit);
74 auto inner_verification_key =
75 std::make_shared<typename InnerFlavor::VerificationKey>(inner_proving_key->get_precomputed());
76 InnerProver inner_prover(inner_proving_key, inner_verification_key);
77 auto inner_proof = inner_prover.construct_proof();
78
79 auto stdlib_vk_and_hash =
80 std::make_shared<typename RecursiveFlavor::VKAndHash>(outer_circuit, inner_verification_key);
81
82 // Instantiate the recursive verifier using the native verification key
83 RecursiveVerifier verifier{ &outer_circuit, stdlib_vk_and_hash };
84 verifier.transcript->enable_manifest();
85
86 InnerVerifier native_verifier(inner_verification_key);
87 native_verifier.transcript->enable_manifest();
88 auto native_result = native_verifier.template verify_proof<NativeIO>(inner_proof);
89 if (!native_result) {
90 throw std::runtime_error("Inner proof verification failed");
91 }
92
93 StdlibProof stdlib_inner_proof(outer_circuit, inner_proof);
94 VerifierOutput output = verifier.template verify_proof<OuterIO>(stdlib_inner_proof);
96
97 return outer_circuit;
98 }
99};
100} // namespace bb
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
Manages the data that is propagated on the public inputs of an application/function circuit.
typename InnerFlavor::CircuitBuilder InnerBuilder
static OuterBuilder generate(uint256_t inputs[])
Generate a recursive circuit.
typename RecursiveVerifier::VerificationKey VerificationKey
bb::stdlib::public_witness_t< OuterBuilder > public_witness_ct
InnerFlavor::Commitment InnerCommitment
typename RecursiveFlavor::CircuitBuilder OuterBuilder
static InnerBuilder create_inner_circuit(uint256_t inputs[])
Create a inner circuit object. In this case an extremely simple circuit that just adds two numbers.
Curve::ScalarField FF
Curve::AffineElement Commitment
UltraCircuitBuilder CircuitBuilder
The recursive counterpart to the "native" Ultra flavor.
std::shared_ptr< Transcript > transcript
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
void assert_equal(const field_t &rhs, std::string const &msg="field_t::assert_equal") const
Copy constraint: constrain that *this field is equal to rhs element.
Definition field.cpp:929
Manages the data that is propagated on the public inputs of an application/function circuit.
static void add_default(Builder &builder)
Add default public inputs when they are not present.
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...
Entry point for Barretenberg command-line interface.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
uint32_t set_public()
Set the witness indices for the limbs of the pairing points to public.