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
20 // Types for Chonk
23
24 // Public inputs added by bb to a Chonk proof
26
27 struct ChonkData {
28 std::shared_ptr<MegaZKVerificationKey> mega_vk;
30 };
31
33 {
34 static constexpr size_t NUM_APP_CIRCUITS = 1;
35
36 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
37 const size_t num_circuits = circuit_producer.total_num_circuits;
38 Chonk ivc{ num_circuits };
39
40 for (size_t j = 0; j < num_circuits; ++j) {
41 circuit_producer.construct_and_accumulate_next_circuit(ivc);
42 }
43
44 ChonkProof proof = ivc.prove();
45 return { ivc.get_hiding_kernel_vk_and_hash()->vk, proof };
46 }
47
48 static AcirProgram create_acir_program(const ChonkData& chonk_data)
49 {
50 AcirProgram program;
51
53 program.witness,
54 chonk_data.proof.to_field_elements(),
55 chonk_data.mega_vk->to_field_elements(),
56 chonk_data.mega_vk->hash(),
58 /*num_public_inputs_to_extract=*/static_cast<size_t>(chonk_data.mega_vk->num_public_inputs) -
60 PROOF_TYPE::CHONK);
61
62 // Remove the predicate as it is not used in Chonk recursion constraints
63 program.witness.pop_back();
65
66 // Construct a constraint system
67 program.constraints.max_witness_index = static_cast<uint32_t>(program.witness.size() - 1);
68 program.constraints.num_acir_opcodes = static_cast<uint32_t>(1);
69 program.constraints.chonk_recursion_constraints = { constraint };
72
73 return program;
74 }
75
77 {
78 // Build constraints
79 auto builder = create_circuit<Builder>(program, { .has_ipa_claim = true });
80
81 // Construct vk
82 auto prover_instance = std::make_shared<ProverInstance>(builder);
83
84 return prover_instance;
85 }
86
87 protected:
89};
90
91TEST_F(ChonkRecursionConstraintTest, GenerateRecursiveChonkVerifierVKFromConstraints)
92{
95
96 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
97
98 std::shared_ptr<VerificationKey> vk_from_valid_witness;
99 {
100 AcirProgram program = create_acir_program(chonk_data);
101 auto prover_instance = get_chonk_recursive_verifier_pk(program);
102 vk_from_valid_witness = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
103
104 // Prove and verify
105 UltraProver_<UltraFlavor> prover(prover_instance, vk_from_valid_witness);
106 HonkProof proof = prover.construct_proof();
107
108 auto vk_and_hash = std::make_shared<UltraFlavor::VKAndHash>(vk_from_valid_witness);
109 UltraRollupVerifier verifier(vk_and_hash);
110
111 EXPECT_TRUE(verifier.verify_proof(proof).result);
112 }
113
114 std::shared_ptr<VerificationKey> vk_from_constraints;
115 {
116 AcirProgram program = create_acir_program(chonk_data);
117 program.witness.clear();
118 auto prover_instance = get_chonk_recursive_verifier_pk(program);
119 vk_from_constraints = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
120 }
121
122 EXPECT_EQ(*vk_from_valid_witness, *vk_from_constraints);
123}
124
125TEST_F(ChonkRecursionConstraintTest, GateCountChonkRecursion)
126{
128
129 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
130
131 AcirProgram program = create_acir_program(chonk_data);
132
133 ProgramMetadata metadata{ .has_ipa_claim = true, .collect_gates_per_opcode = true };
134 auto builder = create_circuit<Builder>(program, metadata);
135
136 // Verify the gate count was recorded
137 EXPECT_EQ(program.constraints.gates_per_opcode.size(), 1);
138
140}
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:135
Contains all the information required by a Honk prover to create a proof, constructed from a finalize...
NativeVerificationKey_< PrecomputedEntities< Commitment >, Codec, HashFunction, CommitmentKey > VerificationKey
The verification key stores commitments to the precomputed (non-witness) polynomials used by the veri...
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()