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.
7
8#include <gtest/gtest.h>
9
10using namespace acir_format;
11using namespace bb;
12using namespace bb::stdlib::recursion::honk;
13
14class ChonkRecursionConstraintTest : public ::testing::Test {
15 public:
17
18 // Types for Chonk recursive verifier
23
24 // Types for Chonk
27
28 // Public inputs added by bb to a Chonk proof
30
31 struct ChonkData {
32 std::shared_ptr<MegaZKVerificationKey> mega_vk;
34 };
35
37 {
38 static constexpr size_t NUM_APP_CIRCUITS = 1;
39
40 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
41 const size_t num_circuits = circuit_producer.total_num_circuits;
42 Chonk ivc{ num_circuits };
43
44 for (size_t j = 0; j < num_circuits; ++j) {
45 circuit_producer.construct_and_accumulate_next_circuit(ivc);
46 }
47
48 Chonk::Proof proof = ivc.prove();
49 return { ivc.get_vk().mega, proof };
50 }
51
52 static AcirProgram create_acir_program(const ChonkData& chonk_data)
53 {
54 AcirProgram program;
55
56 // Extract the witnesses from the provided data
57 auto key_witnesses = chonk_data.mega_vk->to_field_elements();
58 auto key_hash_witness = chonk_data.mega_vk->hash();
59 std::vector<fr> proof_witnesses = chonk_data.proof.to_field_elements();
60
61 // Construct witness indices for each component in the constraint; populate the witness array
62 auto [key_indices, key_hash_index, proof_indices, public_inputs_indices] =
64 program.witness,
65 proof_witnesses,
66 key_witnesses,
67 key_hash_witness,
68 /*num_public_inputs_to_extract=*/static_cast<size_t>(chonk_data.mega_vk->num_public_inputs) -
70
71 auto constraint = RecursionConstraint{ .key = key_indices,
72 .proof = proof_indices,
73 .public_inputs = public_inputs_indices,
74 .key_hash = key_hash_index,
75 .proof_type = PROOF_TYPE::CHONK };
76
77 // Construct a constraint system
78 program.constraints.max_witness_index = static_cast<uint32_t>(program.witness.size() - 1);
79 program.constraints.num_acir_opcodes = static_cast<uint32_t>(1);
80 program.constraints.chonk_recursion_constraints = { constraint };
83
84 return program;
85 }
86
88 {
89 // Build constraints
90 auto builder = create_circuit<Builder>(program, { .has_ipa_claim = true });
91
92 // Construct vk
93 auto prover_instance = std::make_shared<ProverInstance>(builder);
94
95 return prover_instance;
96 }
97
98 protected:
100};
101
102TEST_F(ChonkRecursionConstraintTest, GenerateRecursiveChonkVerifierVKFromConstraints)
103{
106
107 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
108
109 std::shared_ptr<VerificationKey> vk_from_valid_witness;
110 {
111 AcirProgram program = create_acir_program(chonk_data);
112 auto prover_instance = get_chonk_recursive_verifier_pk(program);
113 vk_from_valid_witness = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
114
115 // Prove and verify
116 UltraProver_<UltraRollupFlavor> prover(prover_instance, vk_from_valid_witness);
117 HonkProof proof = prover.prove();
118
119 VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
120 UltraVerifier_<UltraRollupFlavor> verifier(vk_from_valid_witness, ipa_verification_key);
121
122 // Split the proof
123 auto ultra_proof =
124 HonkProof(proof.begin(), proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH));
125 auto ipa_proof =
126 HonkProof(proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH), proof.end());
127
128 EXPECT_TRUE(verifier.verify_proof<bb::RollupIO>(proof, ipa_proof));
129 }
130
131 std::shared_ptr<VerificationKey> vk_from_constraints;
132 {
133 AcirProgram program = create_acir_program(chonk_data);
134 program.witness.clear();
135 auto prover_instance = get_chonk_recursive_verifier_pk(program);
136 vk_from_constraints = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
137 }
138
139 EXPECT_EQ(*vk_from_valid_witness, *vk_from_constraints);
140}
141
142TEST_F(ChonkRecursionConstraintTest, GateCountChonkRecursion)
143{
145
146 ChonkData chonk_data = ChonkRecursionConstraintTest::get_chonk_data();
147
148 AcirProgram program = create_acir_program(chonk_data);
149
150 ProgramMetadata metadata{ .has_ipa_claim = true, .collect_gates_per_opcode = true };
151 auto builder = create_circuit<Builder>(program, metadata);
152
153 // Verify the gate count was recorded
154 EXPECT_EQ(program.constraints.gates_per_opcode.size(), 1);
155
157}
acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indices()
void mock_opcode_indices(acir_format::AcirFormat &constraint_system)
MegaZKFlavor::VerificationKey MegaZKVerificationKey
static std::shared_ptr< ProverInstance > get_chonk_recursive_verifier_pk(AcirProgram &program)
static AcirProgram create_acir_program(const ChonkData &chonk_data)
static RecursionWitnessData populate_recursion_witness_data(std::vector< FF > &witness, std::vector< FF > &proof_witnesses, const std::vector< FF > &key_witnesses, const FF &key_hash_witness, const size_t num_public_inputs_to_extract)
Populate a witness vector with key, proof, and public inputs; track witness indices for each componen...
The IVC scheme used by the aztec client for private function execution.
Definition chonk.hpp:38
static constexpr size_t PUBLIC_INPUTS_SIZE
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
A ProverInstance is normally constructed from a finalized circuit and it contains all the information...
The data that is propagated on the public inputs of a rollup circuit.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
UltraVerifierOutput verify_proof(const Proof &proof, const Proof &ipa_proof={})
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
AluTraceBuilder builder
Definition alu.test.cpp:124
UltraKeccakFlavor::VerificationKey VerificationKey
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
RecursionConstraint struct contains information required to recursively verify a proof!
A full proof for the IVC scheme containing a Mega proof showing correctness of the Hiding kernel (whi...
Definition chonk.hpp:91
std::vector< FF > to_field_elements() const
Serialize proof to field elements.
Definition chonk.cpp:559