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=*/civc_data.mega_vk->num_public_inputs - PUBLIC_INPUTS_SIZE);
69
70 auto constraint = RecursionConstraint{ .key = key_indices,
71 .proof = proof_indices,
72 .public_inputs = public_inputs_indices,
73 .key_hash = key_hash_index,
74 .proof_type = PROOF_TYPE::CIVC };
75
76 // Construct a constraint system
77 program.constraints.varnum = static_cast<uint32_t>(program.witness.size());
78 program.constraints.num_acir_opcodes = static_cast<uint32_t>(1);
79 program.constraints.civc_recursion_constraints = { constraint };
82
83 return program;
84 }
85
87 {
88 // Build constraints
89 Builder builder = create_circuit(program, { .honk_recursion = 2 });
90
91 info("Estimate finalized number of gates: ", builder.get_estimated_num_finalized_gates());
92
93 // Construct vk
95
96 return proving_key;
97 }
98
99 protected:
101};
102
103TEST_F(CivcRecursionConstraintTest, GenerateRecursiveCivcVerifierVKFromConstraints)
104{
106 using ClientIVCData = CivcRecursionConstraintTest::ClientIVCData;
107
109
110 std::shared_ptr<VerificationKey> vk_from_valid_witness;
111 {
112 AcirProgram program = create_acir_program(civc_data);
113 auto proving_key = get_civc_recursive_verifier_pk(program);
114 vk_from_valid_witness = std::make_shared<VerificationKey>(proving_key->get_precomputed());
115
116 // Prove and verify
117 UltraProver_<UltraRollupFlavor> prover(proving_key, vk_from_valid_witness);
118 HonkProof proof = prover.prove();
119
120 VerifierCommitmentKey<curve::Grumpkin> ipa_verification_key(1 << CONST_ECCVM_LOG_N);
121 UltraVerifier_<UltraRollupFlavor> verifier(vk_from_valid_witness, ipa_verification_key);
122
123 // Split the proof
124 auto ultra_proof =
125 HonkProof(proof.begin(), proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH));
126 auto ipa_proof =
127 HonkProof(proof.begin() + static_cast<std::ptrdiff_t>(proof.size() - IPA_PROOF_LENGTH), proof.end());
128
129 EXPECT_TRUE(verifier.verify_proof<bb::RollupIO>(proof, ipa_proof));
130 }
131
132 std::shared_ptr<VerificationKey> vk_from_constraints;
133 {
134 AcirProgram program = create_acir_program(civc_data);
135 program.witness.clear();
136 auto proving_key = get_civc_recursive_verifier_pk(program);
137 vk_from_constraints = std::make_shared<VerificationKey>(proving_key->get_precomputed());
138 }
139
140 EXPECT_EQ(*vk_from_valid_witness, *vk_from_constraints);
141}
acir_format::AcirFormatOriginalOpcodeIndices create_empty_original_opcode_indices()
void mock_opcode_indices(acir_format::AcirFormat &constraint_system)
static std::shared_ptr< DeciderProvingKey > get_civc_recursive_verifier_pk(AcirProgram &program)
MegaZKFlavor::VerificationKey MegaZKVerificationKey
static AcirProgram create_acir_program(const ClientIVCData &civc_data)
static ClientIVCData get_civc_data(TraceSettings trace_settings)
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
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
static constexpr size_t PUBLIC_INPUTS_SIZE
The verification key is responsible for storing the commitments to the precomputed (non-witness) poly...
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:70
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.