40 const size_t& log_num_gates = 9,
41 const size_t& log_num_gates_with_public_inputs = 9)
69 for (
size_t i = 0; i < 32; ++i) {
75 FrNative bigfield_data = FrNative::random_element(&
engine);
76 FrNative bigfield_data_a{ bigfield_data.data[0], bigfield_data.data[1], 0, 0 };
77 FrNative bigfield_data_b{ bigfield_data.data[2], bigfield_data.data[3], 0, 0 };
79 Fq big_a(Fr::from_witness(&
builder, bigfield_data_a.to_montgomery_form()), Fr::from_witness(&
builder, 0));
80 Fq big_b(Fr::from_witness(&
builder, bigfield_data_b.to_montgomery_form()), Fr::from_witness(&
builder, 0));
82 [[maybe_unused]]
Fq result = big_a * big_b;
100 get<0>(keys)[idx] = prover_instance;
101 get<1>(keys)[idx] = verifier_instances;
114 get<0>(keys)[idx] = get<0>(accumulators);
115 get<1>(keys)[idx] = get<1>(accumulators);
123 bool circuits_of_different_size =
false)
127 for (
size_t idx : chunk.range(num_keys)) {
128 size_t log_num_gates = circuits_of_different_size ? 9 + (idx & 1) : 9;
138 for (
size_t idx = 0; idx < num_keys; idx++) {
149 return FoldingData(get<0>(keys)[idx], get<1>(keys)[idx]);
157 bool hash_accumulator =
false,
161 prover_transcript->enable_manifest();
162 if (hash_accumulator) {
166 BB_ASSERT_EQ(get<0>(verification_keys)->is_complete,
true);
167 auto accumulator_hash = get<0>(verification_keys)->hash_through_transcript(
"-", *prover_transcript);
168 prover_transcript->add_to_hash_buffer(
"accumulator_hash", accumulator_hash);
170 FoldingProver folding_prover(prover_instances, verification_keys, prover_transcript, trace_usage_tracker);
172 return folding_prover.prove();
180 bool hash_accumulator =
false)
183 verifier_transcript->enable_manifest();
184 if (hash_accumulator) {
188 auto accumulator_hash = get<0>(verification_keys)->hash_through_transcript(
"-", *verifier_transcript);
189 verifier_transcript->add_to_hash_buffer(
"accumulator_hash", accumulator_hash);
191 FoldingVerifier folding_verifier(verification_keys, verifier_transcript);
194 return { verifier_accumulator, verifier_transcript };
203 bool hash_accumulator =
false)
205 auto [prover_accumulator, folding_proof] =
206 fold(prover_instances, verification_keys, hash_accumulator, trace_usage_tracker);
208 auto [verifier_accumulator, _] =
verify_folding_proof(verification_keys, folding_proof, hash_accumulator);
210 return FoldingData{ prover_accumulator, verifier_accumulator };
216 static bool run_decider(
const std::shared_ptr<ProverInstance>& prover_accumulator,
217 const std::shared_ptr<VerifierInstance>& verifier_accumulator)
223 auto decider_output = decider_verifier.
verify_proof(decider_proof);
224 bool result = decider_output.
check();
232 const std::shared_ptr<VerifierInstance>& rhs)
237 auto compare_iterators = [&equal, &msg]<
typename T>(
const T& lhs,
const T& rhs,
const std::string& label) {
238 if (lhs.size() != rhs.size()) {
240 msg +=
"\nMistmatch in the sizes of the ";
243 for (
size_t idx = 0; idx < lhs.size(); idx++) {
244 if (lhs[idx] != rhs[idx]) {
246 msg +=
"\nMismatch in the ";
257 compare_iterators(lhs->alphas, rhs->alphas,
"alphas");
259 lhs->relation_parameters.get_to_fold(), rhs->relation_parameters.get_to_fold(),
"relation paramaters");
260 compare_iterators(lhs->gate_challenges, rhs->gate_challenges,
"gate challenges");
262 lhs->witness_commitments.get_all(), rhs->witness_commitments.get_all(),
"witness commitments");
263 compare_iterators(lhs->vk->get_all(), rhs->vk->get_all(),
"vk commitments");
264 if (lhs->target_sum != rhs->target_sum) {
266 msg +=
"\nMismatch in target sum";
269 return { equal, msg };
277 const std::shared_ptr<VerifierInstance>& rhs)
284 lhs_verifier_instance->is_complete = lhs->is_complete;
287 for (
auto [poly, comm] :
288 zip_view(lhs->polynomials.get_witness(), lhs_verifier_instance->witness_commitments.get_all())) {
289 comm = lhs->commitment_key.commit(poly);
291 lhs_verifier_instance->alphas = lhs->alphas;
292 for (
auto [verifier, prover] :
zip_view(lhs_verifier_instance->relation_parameters.get_to_fold(),
293 lhs->relation_parameters.get_to_fold())) {
296 lhs_verifier_instance->gate_challenges = lhs->gate_challenges;
297 lhs_verifier_instance->target_sum = lhs->target_sum;
309template <
typename Flavor>
310static Flavor::FF compute_accumulator_target_sum_manual(
const std::shared_ptr<ProverInstance_<Flavor>>& accumulator)
313 accumulator->is_complete,
true,
"Computing the target sum of an incomplete accumulator, indefinite behaviour.");
315 using PGInternal = ProtogalaxyProverInternal<ProverInstance_<Flavor>>;
317 const size_t accumulator_size = accumulator->dyadic_size();
318 PGInternal pg_internal;
319 const auto expected_honk_evals = pg_internal.compute_row_evaluations(
320 accumulator->polynomials, accumulator->alphas, accumulator->relation_parameters);
322 GateSeparatorPolynomial expected_gate_separators(accumulator->gate_challenges, accumulator->gate_challenges.size());
326 for (
size_t idx = 0; idx < accumulator_size; idx++) {
327 expected_target_sum += expected_honk_evals[idx] * expected_gate_separators[idx];
329 return expected_target_sum;
336template <
typename Flavor>
337static bool check_accumulator_target_sum_manual(
const std::shared_ptr<ProverInstance_<Flavor>>& accumulator)
339 return accumulator->target_sum == compute_accumulator_target_sum_manual(accumulator);
#define BB_ASSERT_EQ(actual, expected,...)
CommitmentKey object over a pairing group 𝔾₁.
Output verify_proof(const DeciderProof &)
Verify a decider proof relative to a decider verification key (ϕ, \vec{β*}, e*).
typename Curve::ScalarField FF
static void add_some_ecc_op_gates(MegaBuilder &builder)
Generate a simple test circuit with some ECC op gates and conventional arithmetic gates.
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
MegaCircuitBuilder CircuitBuilder
static void add_RAM_gates(Builder &builder)
Add some simple RAM (memory) gates for testing memory read/write functionality.
static void add_arithmetic_gates_with_public_inputs(Builder &builder, const size_t num_gates=4)
Add a specified number of arithmetic gates (with public inputs) to the provided circuit.
static void add_lookup_gates(Builder &builder, size_t num_iterations=1)
Add lookup gates using the uint32 XOR lookup table (table size 4096)
static void add_arithmetic_gates(Builder &builder, const size_t num_gates=4)
Add a specified number of arithmetic gates to the provided circuit.
std::array< std::shared_ptr< VerifierInstance >, NUM_INSTANCES > VerifierInstances
typename Flavor::VerificationKey VerificationKey
static void create_function_circuit(Builder &builder, const size_t &log_num_gates=9, const size_t &log_num_gates_with_public_inputs=9)
Create a circuit with the specified number of arithmetic gates and arithmetic gates with public input...
static FoldingVerificationResult verify_folding_proof(const VerifierInstances &verification_keys, const HonkProof &folding_proof, bool hash_accumulator=false)
Verify a folding proof. Return the folded accumulator and the verifier transcript.
std::tuple< std::shared_ptr< ProverInstance >, std::shared_ptr< VerifierInstance > > FoldingData
static FoldingResult< Flavor > fold(const ProverInstances &prover_instances, const VerifierInstances &verification_keys, bool hash_accumulator=false, ExecutionTraceUsageTracker trace_usage_tracker=ExecutionTraceUsageTracker{})
Fold two prover instances. Return folded accumulator and folding proof.
static FoldingData fold_and_verify(const ProverInstances &prover_instances, const VerifierInstances &verification_keys, ExecutionTraceUsageTracker trace_usage_tracker=ExecutionTraceUsageTracker{}, bool hash_accumulator=false)
Fold two prover instances and generate folded verifier by running the PG verifier.
ProtogalaxyProver_< Flavor > FoldingProver
std::array< std::shared_ptr< ProverInstance >, NUM_INSTANCES > ProverInstances
std::tuple< ProverInstances, VerifierInstances > TupleOfKeys
std::tuple< std::shared_ptr< VerifierInstance >, std::shared_ptr< typename FoldingVerifier::Transcript > > FoldingVerificationResult
static bool run_decider(const std::shared_ptr< ProverInstance > &prover_accumulator, const std::shared_ptr< VerifierInstance > &verifier_accumulator)
Run the decider on the given accumulator.
static void construct_instances_and_add_to_tuple(TupleOfKeys &keys, Builder &builder, size_t idx=0, TraceSettings trace_settings=TraceSettings{})
Construct Prover and Verifier instances for a provided circuit and add to tuple.
static FoldingData get_folding_data(const TupleOfKeys &keys, size_t idx)
Get folding data at index idx in the tuple of keys.
static std::pair< bool, std::string > compare_accumulators(const std::shared_ptr< VerifierInstance > &lhs, const std::shared_ptr< VerifierInstance > &rhs)
Compare two accumulators. Return the result of the comparison and error message.
static TupleOfKeys construct_instances(size_t num_keys, TraceSettings trace_settings=TraceSettings{}, bool circuits_of_different_size=false)
Construct a given number of Prover and Verifier instances.
static std::pair< bool, std::string > compare_accumulators(const std::shared_ptr< ProverInstance > &lhs, const std::shared_ptr< VerifierInstance > &rhs)
Compare a Prover accumulator and a Verifier accumulator. Return the result of the comparison and erro...
static void construct_accumulator_and_add_to_tuple(TupleOfKeys &keys, size_t idx=0, TraceSettings trace_settings=TraceSettings{})
Construct Prover and Verifier accumulators and add to tuple.
std::shared_ptr< VerifierInstance > verify_folding_proof(const std::vector< FF > &)
Run the folding protocol on the verifier side to establish whether the public data ϕ of the new accum...
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The VerifierInstance encapsulates all the necessary information for a Mega Honk Verifier to verify a ...
static void add_default(Builder &builder)
Add default public inputs when they are not present.
Entry point for Barretenberg command-line interface.
std::vector< fr > HonkProof
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
Tracks the cumulative usage of the execution trace across a series of circuits.
The result of one iteraton of Protogalaxy proving, containing a new accumulator as well as the proof ...
field_t< CircuitBuilder > ScalarField
curve::BN254::ScalarField ScalarFieldNative