6#include "gtest/gtest.h"
20 using Builder = RecursiveFlavor::CircuitBuilder;
59 for (
size_t idx = 0;
auto [challenge_lhs, challenge_rhs] :
zip_view(lhs.
challenge, rhs.challenge)) {
60 if (challenge_lhs != challenge_rhs) {
61 info(
"Mismatch in the challenges at index ", idx);
66 info(
"Mismatch in the unshifted commitments");
70 info(
"Mismatch in the shifted commitments");
74 info(
"Mismatch in the unshifted evaluations");
78 info(
"Mismatch in the shifted evaluations");
91 using FF = RecursiveFlavor::FF;
92 using Commitment = RecursiveFlavor::Commitment;
94 using VKAndHash = RecursiveFlavor::VKAndHash;
99 FF::from_witness(
builder, native_instance->get_vk()->hash()));
105 recursive_instance->alpha = FF::from_witness(
builder, native_instance->alpha);
108 auto native_comms = native_instance->witness_commitments.get_all();
109 for (
auto [native_comm, recursive_comm] :
110 zip_view(native_comms, recursive_instance->witness_commitments.get_all())) {
111 recursive_comm = Commitment::from_witness(
builder, native_comm);
115 recursive_instance->gate_challenges = std::vector<FF>(native_instance->gate_challenges.size());
116 for (
auto [native_challenge, recursive_challenge] :
117 zip_view(native_instance->gate_challenges, recursive_instance->gate_challenges)) {
118 recursive_challenge = FF::from_witness(
builder, native_challenge);
122 recursive_instance->relation_parameters.eta =
123 FF::from_witness(
builder, native_instance->relation_parameters.eta);
124 recursive_instance->relation_parameters.eta_two =
125 FF::from_witness(
builder, native_instance->relation_parameters.eta_two);
126 recursive_instance->relation_parameters.eta_three =
127 FF::from_witness(
builder, native_instance->relation_parameters.eta_three);
128 recursive_instance->relation_parameters.beta =
129 FF::from_witness(
builder, native_instance->relation_parameters.beta);
130 recursive_instance->relation_parameters.gamma =
131 FF::from_witness(
builder, native_instance->relation_parameters.gamma);
132 recursive_instance->relation_parameters.public_input_delta =
133 FF::from_witness(
builder, native_instance->relation_parameters.public_input_delta);
136 if constexpr (NativeFlavor::HasZK) {
137 recursive_instance->gemini_masking_commitment =
138 Commitment::from_witness(
builder, native_instance->gemini_masking_commitment);
141 return recursive_instance;
151 instance->polynomials.w_l.at(1) = NativeFF::random_element();
169 constexpr size_t frs_per_G = FrCodec::calc_num_fields<curve::BN254::AffineElement>();
170 constexpr size_t NUM_SUMCHECK_UNIVARIATES = NativeFlavor::VIRTUAL_LOG_N;
177 for (
size_t i = 0; i < 4; ++i) {
180 for (
const auto& wire : {
"W_L",
"W_R",
"W_O" }) {
181 manifest.
add_entry(round, wire, frs_per_G);
183 for (
const auto& wire : {
"ECC_OP_WIRE_1",
"ECC_OP_WIRE_2",
"ECC_OP_WIRE_3",
"ECC_OP_WIRE_4" }) {
184 manifest.
add_entry(round, wire, frs_per_G);
186 for (
const auto& bus : {
"CALLDATA",
"SECONDARY_CALLDATA",
"RETURN_DATA" }) {
187 manifest.
add_entry(round, bus, frs_per_G);
188 manifest.
add_entry(round, std::string(bus) +
"_READ_COUNTS", frs_per_G);
189 manifest.
add_entry(round, std::string(bus) +
"_READ_TAGS", frs_per_G);
194 manifest.
add_challenge(round, std::array{
"beta",
"gamma" });
195 manifest.
add_entry(round,
"LOOKUP_READ_COUNTS", frs_per_G);
196 manifest.
add_entry(round,
"LOOKUP_READ_TAGS", frs_per_G);
197 manifest.
add_entry(round,
"W_4", frs_per_G);
202 manifest.
add_challenge(round,
"HypernovaFoldingProver:gate_challenge");
203 manifest.
add_entry(round,
"LOOKUP_INVERSES", frs_per_G);
204 manifest.
add_entry(round,
"CALLDATA_INVERSES", frs_per_G);
205 manifest.
add_entry(round,
"SECONDARY_CALLDATA_INVERSES", frs_per_G);
206 manifest.
add_entry(round,
"RETURN_DATA_INVERSES", frs_per_G);
207 manifest.
add_entry(round,
"Z_PERM", frs_per_G);
211 for (
size_t i = 0; i < NUM_SUMCHECK_UNIVARIATES; ++i) {
224 manifest.
add_entry(round,
"Sumcheck:evaluations", 60);
229 manifest.
add_entry(round,
"non_shifted_accumulator_commitment", frs_per_G);
230 manifest.
add_entry(round,
"shifted_accumulator_commitment", frs_per_G);
231 for (
size_t i = 0; i < NUM_SUMCHECK_UNIVARIATES; ++i) {
234 manifest.
add_entry(round,
"accumulator_evaluation_0", 1);
235 manifest.
add_entry(round,
"accumulator_evaluation_1", 1);
239 for (
size_t i = 0; i < NUM_SUMCHECK_UNIVARIATES; ++i) {
247 manifest.
add_entry(round,
"Sumcheck:evaluations", 6);
265 auto incoming_verifier_instance =
270 auto [folding_proof, folded_accumulator] = folding_prover.
fold(
std::move(accumulator), incoming_instance);
274 native_verifier_transcript->enable_manifest();
276 auto [first_sumcheck_native, second_sumcheck_native, folded_verifier_accumulator_native] =
286 auto [first_sumcheck_recursive, second_sumcheck_recursive, folded_verifier_accumulator] =
293 EXPECT_EQ(first_sumcheck_recursive, first_sumcheck_native);
294 EXPECT_TRUE(second_sumcheck_recursive);
295 EXPECT_EQ(second_sumcheck_recursive, second_sumcheck_native);
302 auto verifier_manifest = native_verifier_transcript->get_manifest();
303 EXPECT_EQ(verifier_manifest, expected_manifest);
310 test_folding(TamperingMode::None);
316 test_folding(TamperingMode::Instance);
#define BB_DISABLE_ASSERTS()
std::shared_ptr< Napi::ThreadSafeFunction > instance
static void SetUpTestSuite()
NativeFlavor::VerificationKey NativeVerificationKey
static void tampering(std::shared_ptr< ProverInstance > &instance, const TamperingMode &mode)
NativeFlavor::FF NativeFF
static std::shared_ptr< ProverInstance > generate_new_instance(size_t log_num_gates=4)
static std::shared_ptr< RecursiveVerifierInstance > create_recursive_verifier_instance(Builder *builder, const std::shared_ptr< NativeVerifierInstance > &native_instance)
Test helper to create a recursive verifier instance from a native one.
RecursiveHypernovaVerifier::Flavor RecursiveFlavor
static TranscriptManifest build_expected_folding_manifest()
Build the expected transcript manifest for HyperNova folding.
static void test_folding(const TamperingMode &mode)
NativeHypernovaVerifier::Flavor NativeFlavor
RecursiveFlavor::CircuitBuilder Builder
static bool compare_prover_verifier_accumulators(const NativeProverAccumulator &lhs, const NativeVerifierAccumulator &rhs)
RecursiveHypernovaVerifier::Proof RecursiveProof
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
HyperNova folding prover. Folds circuit instances into accumulators, deferring PCS verification.
MultilinearBatchingProverClaim Accumulator
ProverInstance_< Flavor > ProverInstance
Accumulator instance_to_accumulator(const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Turn an instance into an accumulator by running Sumcheck.
std::pair< HonkProof, Accumulator > fold(Accumulator &&accumulator, const std::shared_ptr< ProverInstance > &instance, const std::shared_ptr< VerificationKey > &honk_vk=nullptr)
Fold an instance into an accumulator.
HyperNova folding verifier (native + recursive). Verifies folding proofs and maintains accumulators.
std::tuple< bool, bool, Accumulator > verify_folding_proof(const std::shared_ptr< typename HypernovaFoldingVerifier::VerifierInstance > &instance, const Proof &proof)
Verify folding proof. Return the new accumulator and the results of the two sumchecks.
std::conditional_t< IsRecursiveFlavor< Flavor >, stdlib::Proof< MegaCircuitBuilder >, HonkProof > Proof
VerifierInstance_< Flavor > VerifierInstance
Flavor::Transcript Transcript
MultilinearBatchingVerifierClaim< Curve > Accumulator
static constexpr size_t NUM_SHIFTED_ENTITIES
static constexpr size_t NUM_UNSHIFTED_ENTITIES
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.
Base Native verification key class.
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
void add_entry(size_t round, const std::string &element_label, size_t element_size)
void add_challenge(size_t round, const std::string &label)
Add a single challenge label to the manifest for the given round.
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
The VerifierInstance encapsulates all the necessary information for a Honk Verifier to verify a proof...
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
Prover's claim for multilinear batching - contains polynomials and their evaluation claims.
Commitment non_shifted_commitment
std::vector< FF > challenge
FF non_shifted_evaluation
Commitment shifted_commitment
Verifier's claim for multilinear batching - contains commitments and evaluation claims.