Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
civc_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 CivcRecursionConstraintTest : public ::testing::Test {
14 public:
16
17 // Types for ClientIVC recursive verifier
22
23 // Types for ClientIVC
26
27 // Public inputs added by bb to a ClientIVC proof
29
31 std::shared_ptr<MegaZKVerificationKey> mega_vk;
33 };
34
36 {
37 static constexpr size_t NUM_APP_CIRCUITS = 2;
38
39 PrivateFunctionExecutionMockCircuitProducer circuit_producer(NUM_APP_CIRCUITS);
40
41 ClientIVC ivc(circuit_producer.total_num_circuits, trace_settings);
42
43 for (size_t idx = 0; idx < circuit_producer.total_num_circuits; idx++) {
44 circuit_producer.construct_and_accumulate_next_circuit(ivc);
45 }
46
47 ClientIVC::Proof proof = ivc.prove();
48
49 return { ivc.get_vk().mega, proof };
50 }
51
53 {
54 AcirProgram program;
55
56 // Extract the witnesses from the provided data
57 auto key_witnesses = civc_data.mega_vk->to_field_elements();
58 auto key_hash_witness = civc_data.mega_vk->hash();
59 std::vector<fr> proof_witnesses = civc_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>(civc_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::CIVC };
76
77 // Construct a constraint system
78 program.constraints.varnum = static_cast<uint32_t>(program.witness.size());
79 program.constraints.num_acir_opcodes = static_cast<uint32_t>(1);
80 program.constraints.civc_recursion_constraints = { constraint };
83
84 return program;
85 }
86
87 static std::shared_ptr<ProverInstance> get_civc_recursive_verifier_pk(AcirProgram& program)
88 {
89 // Build constraints
90 Builder builder = create_circuit(program, { .honk_recursion = 2 });
91
92 info("Estimate finalized number of gates: ", builder.get_estimated_num_finalized_gates());
93
94 // Construct vk
95 auto prover_instance = std::make_shared<ProverInstance>(builder);
96
97 return prover_instance;
98 }
99
100 protected:
102};
103
104TEST_F(CivcRecursionConstraintTest, GenerateRecursiveCivcVerifierVKFromConstraints)
105{
107 using ClientIVCData = CivcRecursionConstraintTest::ClientIVCData;
108
110
111 std::shared_ptr<VerificationKey> vk_from_valid_witness;
112 {
113 AcirProgram program = create_acir_program(civc_data);
114 auto prover_instance = get_civc_recursive_verifier_pk(program);
115 vk_from_valid_witness = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
116
117 // Prove and verify
118 UltraProver_<UltraRollupFlavor> prover(prover_instance, vk_from_valid_witness);
119 HonkProof proof = prover.prove();
120
121 VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
122 UltraVerifier_<UltraRollupFlavor> verifier(vk_from_valid_witness, ipa_verification_key);
123
124 // Split the proof
125 auto ultra_proof =
126 HonkProof(proof.begin(), proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH));
127 auto ipa_proof =
128 HonkProof(proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH), proof.end());
129
130 EXPECT_TRUE(verifier.verify_proof<bb::RollupIO>(proof, ipa_proof));
131 }
132
133 std::shared_ptr<VerificationKey> vk_from_constraints;
134 {
135 AcirProgram program = create_acir_program(civc_data);
136 program.witness.clear();
137 auto prover_instance = get_civc_recursive_verifier_pk(program);
138 vk_from_constraints = std::make_shared<VerificationKey>(prover_instance->get_precomputed());
139 }
140
141 EXPECT_EQ(*vk_from_valid_witness, *vk_from_constraints);
142}
acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indices()
void mock_opcode_indices(acir_format::AcirFormat &constraint_system)
MegaZKFlavor::VerificationKey MegaZKVerificationKey
static AcirProgram create_acir_program(const ClientIVCData &civc_data)
static ClientIVCData get_civc_data(TraceSettings trace_settings)
static std::shared_ptr< ProverInstance > get_civc_recursive_verifier_pk(AcirProgram &program)
static RecursionWitnessData populate_recursion_witness_data(bb::SlabVector< 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.
Proof prove()
Construct a proof for the IVC, which, if verified, fully establishes its correctness.
VerificationKey get_vk() const
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.
void info(Args... args)
Definition log.hpp:74
AluTraceBuilder builder
Definition alu.test.cpp:123
UltraKeccakFlavor::VerificationKey VerificationKey
UltraCircuitBuilder create_circuit(AcirProgram &program, const ProgramMetadata &metadata)
Specialization for creating an Ultra circuit from an acir program.
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.
std::vector< fr > HonkProof
Definition proof.hpp:15
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
AcirFormatOriginalOpcodeIndices original_opcode_indices
std::vector< RecursionConstraint > civc_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 circuit (wh...
std::vector< FF > to_field_elements() const
Serialize proof to field elements.