Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
chonk_recursion_constraints.test.cpp
Go to the documentation of this file.
6
7#include <gtest/gtest.h>
8
9using namespace acir_format;
10using namespace bb;
11using namespace bb::stdlib::recursion::honk;
12
13class ChonkRecursionConstraintTest : public ::testing::Test {
14 public:
16
17 // Types for Chonk recursive verifier
21 // Types for Chonk
24
25 // Public inputs added by bb to a Chonk proof
27
28 struct ChonkData {
29 std::shared_ptr<MegaZKVerificationKey> mega_vk;
31 };
32
34 {
35 static constexpr size_t NUM_APP_CIRCUITS = 1;
36
37 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
38 const size_t num_circuits = circuit_producer.total_num_circuits;
39 Chonk ivc{ num_circuits };
40
41 for (size_t j = 0; j < num_circuits; ++j) {
42 circuit_producer.construct_and_accumulate_next_circuit(ivc);
43 }
44
45 ChonkProof proof = ivc.prove();
46 return { ivc.get_hiding_kernel_vk_and_hash()->vk, proof };
47 }
48
49 static AcirProgram create_acir_program(const ChonkData& chonk_data)
50 {
51 AcirProgram program;
52
54 program.witness,
55 chonk_data.proof.to_field_elements(),
56 chonk_data.mega_vk->to_field_elements(),
57 chonk_data.mega_vk->hash(),
59 /*num_public_inputs_to_extract=*/static_cast<size_t>(chonk_data.mega_vk->num_public_inputs) -
61 PROOF_TYPE::CHONK);
62
63 // Remove the predicate as it is not used in Chonk recursion constraints
64 program.witness.pop_back();
66
67 // Construct a constraint system
68 program.constraints.max_witness_index = static_cast<uint32_t>(program.witness.size() - 1);
69 program.constraints.num_acir_opcodes = static_cast<uint32_t>(1);
70 program.constraints.chonk_recursion_constraints = { constraint };
73
74 return program;
75 }
76
78 {
79 // Build constraints
80 auto builder = create_circuit<Builder>(program, { .has_ipa_claim = true });
81
82 // Construct vk
83 auto prover_instance = std::make_shared<ProverInstance>(builder);
84
85 return prover_instance;
86 }
87
88 protected:
90};
91
92TEST_F(ChonkRecursionConstraintTest, GenerateRecursiveChonkVerifierVKFromConstraints)
93{
96
97 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
98
99 std::shared_ptr<VerificationKey> vk_from_valid_witness;
100 {
101 AcirProgram program = create_acir_program(chonk_data);
102 auto prover_instance = get_chonk_recursive_verifier_pk(program);
103 vk_from_valid_witness = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
104
105 // Prove and verify
106 UltraProver_<UltraRollupFlavor> prover(prover_instance, vk_from_valid_witness);
107 HonkProof proof = prover.prove();
108
109 auto vk_and_hash = std::make_shared<UltraRollupFlavor::VKAndHash>(vk_from_valid_witness);
111
112 EXPECT_TRUE(verifier.verify_proof(proof).result);
113 }
114
115 std::shared_ptr<VerificationKey> vk_from_constraints;
116 {
117 AcirProgram program = create_acir_program(chonk_data);
118 program.witness.clear();
119 auto prover_instance = get_chonk_recursive_verifier_pk(program);
120 vk_from_constraints = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
121 }
122
123 EXPECT_EQ(*vk_from_valid_witness, *vk_from_constraints);
124}
125
126TEST_F(ChonkRecursionConstraintTest, GateCountChonkRecursion)
127{
129
130 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
131
132 AcirProgram program = create_acir_program(chonk_data);
133
134 ProgramMetadata metadata{ .has_ipa_claim = true, .collect_gates_per_opcode = true };
135 auto builder = create_circuit<Builder>(program, metadata);
136
137 // Verify the gate count was recorded
138 EXPECT_EQ(program.constraints.gates_per_opcode.size(), 1);
139
141}
MegaZKFlavor::VerificationKey MegaZKVerificationKey
static std::shared_ptr< ProverInstance > get_chonk_recursive_verifier_pk(AcirProgram &program)
static AcirProgram create_acir_program(const ChonkData &chonk_data)
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:38
static constexpr size_t PUBLIC_INPUTS_SIZE
Base Native verification key class.
Definition flavor.hpp:141
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
UltraRollupFlavor extends UltraFlavor with IPA proof support.
Output verify_proof(const Proof &proof)
Perform ultra verification.
AluTraceBuilder builder
Definition alu.test.cpp:124
RecursionConstraint recursion_data_to_recursion_constraint(std::vector< bb::fr > &witness, const std::vector< bb::fr > &proof, const std::vector< bb::fr > &key, const bb::fr &key_hash, const bb::fr &predicate, const size_t num_public_inputs_to_extract, const uint32_t proof_type)
========== TESTING UTILITIES ========== ///
Definition utils.cpp:53
constexpr size_t CHONK_RECURSION_GATES
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
TEST_F(BoomerangGoblinRecursiveVerifierTests, graph_description_basic)
Construct and check a goblin recursive verification circuit.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
std::vector< fr > HonkProof
Definition proof.hpp:15
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
std::shared_ptr< MegaZKVerificationKey > mega_vk
AcirFormatOriginalOpcodeIndices original_opcode_indices
std::vector< size_t > gates_per_opcode
std::vector< RecursionConstraint > chonk_recursion_constraints
Indices of the original opcode that originated each constraint in AcirFormat.
Struct containing both the constraints to be added to the circuit and the witness vector.
Metadata required to create a circuit.
RecursionConstraint struct contains information required to recursively verify a proof.
WitnessOrConstant< bb::fr > predicate
static WitnessOrConstant from_constant(FF value)
std::vector< FF > to_field_elements() const
Serialize proof to field elements (native mode)
static constexpr field one()
static constexpr field zero()