Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
translator_recursive_verifier.test.cpp
Go to the documentation of this file.
8#include <gtest/gtest.h>
9namespace bb {
10
18// TODO(https://github.com/AztecProtocol/barretenberg/issues/980): Add failing tests after we have a proper shared
19// transcript interface between ECCVM and Translator and we are able to deserialise and serialise the transcript
20// correctly.
21class TranslatorRecursiveTests : public ::testing::Test {
22 public:
32
34
40
42
44
46
47 static std::shared_ptr<bb::ECCOpQueue> create_op_queue(const size_t num_ops)
48 {
49 auto P1 = InnerG1::random_element();
50 auto P2 = InnerG1::random_element();
51 auto z = InnerFF::random_element();
52
53 // Add the same operations to the ECC op queue; the native computation is performed under the hood.
54 auto op_queue = std::make_shared<bb::ECCOpQueue>();
55 op_queue->no_op_ultra_only();
56
57 for (size_t i = 0; i < num_ops; i++) {
58 op_queue->add_accumulate(P1);
59 op_queue->mul_accumulate(P2, z);
60 }
61 op_queue->merge();
62 return op_queue;
63 }
64
66 {
67 using NativeVerifierCommitmentKey = InnerFlavor::VerifierCommitmentKey;
68 // Add the same operations to the ECC op queue; the native computation is performed under the hood.
69 auto op_queue = create_op_queue(500);
70
71 auto prover_transcript = std::make_shared<Transcript>();
72 prover_transcript->send_to_verifier("init", InnerBF::random_element());
73 // normally this would be the eccvm proof
74 auto fake_inital_proof = prover_transcript->export_proof();
75
76 InnerBF batching_challenge_v = InnerBF::random_element();
77 InnerBF evaluation_challenge_x = InnerBF::random_element();
78
79 auto circuit_builder = InnerBuilder(batching_challenge_v, evaluation_challenge_x, op_queue);
80 EXPECT_TRUE(TranslatorCircuitChecker::check(circuit_builder));
81 auto proving_key = std::make_shared<TranslatorProvingKey>(circuit_builder);
82 InnerProver prover{ proving_key, prover_transcript };
83 auto proof = prover.construct_proof();
84
85 OuterBuilder outer_circuit;
86
87 // Mock a previous verifier that would in reality be the ECCVM recursive verifier
88 stdlib::Proof<OuterBuilder> stdlib_proof(outer_circuit, fake_inital_proof);
90 transcript->load_proof(stdlib_proof);
91 [[maybe_unused]] auto _ = transcript->template receive_from_prover<RecursiveFlavor::BF>("init");
92
93 auto verification_key = std::make_shared<typename InnerFlavor::VerificationKey>(prover.key->proving_key);
94 RecursiveVerifier verifier{ &outer_circuit, verification_key, transcript };
95 typename RecursiveVerifier::PairingPoints pairing_points =
96 verifier.verify_proof(proof, evaluation_challenge_x, batching_challenge_v);
97 pairing_points.set_public();
98 info("Recursive Verifier: num gates = ", outer_circuit.num_gates);
99
100 // Check for a failure flag in the recursive verifier circuit
101 EXPECT_EQ(outer_circuit.failed(), false) << outer_circuit.err();
102
103 auto native_verifier_transcript = std::make_shared<Transcript>();
104 native_verifier_transcript->load_proof(fake_inital_proof);
105 native_verifier_transcript->template receive_from_prover<InnerBF>("init");
106 InnerVerifier native_verifier(verification_key, native_verifier_transcript);
107 bool native_result = native_verifier.verify_proof(proof, evaluation_challenge_x, batching_challenge_v);
108 NativeVerifierCommitmentKey pcs_vkey{};
109 auto recursive_result = pcs_vkey.pairing_check(pairing_points.P0.get_value(), pairing_points.P1.get_value());
110 EXPECT_EQ(recursive_result, native_result);
111
112 auto recursive_manifest = verifier.transcript->get_manifest();
113 auto native_manifest = native_verifier.transcript->get_manifest();
114 for (size_t i = 0; i < recursive_manifest.size(); ++i) {
115 EXPECT_EQ(recursive_manifest[i], native_manifest[i])
116 << "Recursive Verifier/Verifier manifest discrepency in round " << i;
117 }
118
119 EXPECT_EQ(static_cast<uint64_t>(verifier.key->log_circuit_size.get_value()),
120 verification_key->log_circuit_size);
121 EXPECT_EQ(static_cast<uint64_t>(verifier.key->num_public_inputs.get_value()),
122 verification_key->num_public_inputs);
123 for (auto [vk_poly, native_vk_poly] : zip_view(verifier.key->get_all(), verification_key->get_all())) {
124 EXPECT_EQ(vk_poly.get_value(), native_vk_poly);
125 }
126
127 {
128 auto proving_key = std::make_shared<OuterDeciderProvingKey>(outer_circuit);
129 auto verification_key = std::make_shared<OuterFlavor::VerificationKey>(proving_key->get_precomputed());
130 OuterProver prover(proving_key, verification_key);
131 OuterVerifier verifier(verification_key);
132 auto proof = prover.construct_proof();
133 bool verified = verifier.template verify_proof<DefaultIO>(proof).result;
134
135 ASSERT_TRUE(verified);
136 }
137 }
138
140 {
141
142 // Retrieves the trace blocks (each consisting of a specific gate) from the recursive verifier circuit
143 auto get_blocks = [](size_t num_ops)
145 auto op_queue = create_op_queue(num_ops);
146
147 auto prover_transcript = std::make_shared<Transcript>();
148 prover_transcript->send_to_verifier("init", InnerBF::random_element());
149
150 // normally this would be the eccvm proof
151 auto fake_inital_proof = prover_transcript->export_proof();
152 InnerBF batching_challenge_v = InnerBF::random_element();
153 InnerBF evaluation_challenge_x = InnerBF::random_element();
154
155 auto inner_circuit = InnerBuilder(batching_challenge_v, evaluation_challenge_x, op_queue);
156
157 // Generate a proof over the inner circuit
158 auto inner_proving_key = std::make_shared<TranslatorProvingKey>(inner_circuit);
159 InnerProver inner_prover(inner_proving_key, prover_transcript);
160 info("test circuit size: ", inner_proving_key->proving_key->circuit_size);
161 auto verification_key =
163 auto inner_proof = inner_prover.construct_proof();
164
165 // Create a recursive verification circuit for the proof of the inner circuit
166 OuterBuilder outer_circuit;
167
168 // Mock a previous verifier that would in reality be the ECCVM recursive verifier
169 stdlib::Proof<OuterBuilder> stdlib_proof(outer_circuit, fake_inital_proof);
171 transcript->load_proof(stdlib_proof);
172 [[maybe_unused]] auto _ = transcript->template receive_from_prover<typename RecursiveFlavor::BF>("init");
173
174 RecursiveVerifier verifier{ &outer_circuit, verification_key, transcript };
175 typename RecursiveVerifier::PairingPoints pairing_points =
176 verifier.verify_proof(inner_proof,
177 TranslatorBF::from_witness(&outer_circuit, evaluation_challenge_x),
178 TranslatorBF::from_witness(&outer_circuit, batching_challenge_v));
179 pairing_points.set_public();
180
181 auto outer_proving_key = std::make_shared<OuterDeciderProvingKey>(outer_circuit);
182 auto outer_verification_key =
183 std::make_shared<typename OuterFlavor::VerificationKey>(outer_proving_key->get_precomputed());
184
185 return { outer_circuit.blocks, outer_verification_key };
186 };
187
188 auto [blocks_256, verification_key_256] = get_blocks(256);
189 auto [blocks_512, verification_key_512] = get_blocks(512);
190
191 compare_ultra_blocks_and_verification_keys<OuterFlavor>({ blocks_256, blocks_512 },
192 { verification_key_256, verification_key_512 });
193 };
194};
195
200
205} // namespace bb
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
const std::string & err() const
A DeciderProvingKey is normally constructed from a finalized circuit and it contains all the informat...
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
TranslatorCircuitBuilder CircuitBuilder
Curve::ScalarField FF
Curve::AffineElement Commitment
bb::VerifierCommitmentKey< Curve > VerifierCommitmentKey
NativeTranscript Transcript
std::shared_ptr< TranslatorProvingKey > key
The recursive counterpart of the native Translator flavor.
Test suite for standalone recursive verification of translation proofs.
std::conditional_t< IsMegaBuilder< OuterBuilder >, MegaFlavor, UltraFlavor > OuterFlavor
static std::shared_ptr< bb::ECCOpQueue > create_op_queue(const size_t num_ops)
bool verify_proof(const HonkProof &proof, const uint256_t &evaluation_input_x, const BF &batching_challenge_v)
This function verifies a TranslatorFlavor Honk proof for given program settings.
std::shared_ptr< Transcript > transcript
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
void info(Args... args)
Definition log.hpp:70
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
Definition ipa.test.cpp:123
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept
uint32_t set_public()
Set the witness indices for the limbs of the pairing points to public.