11#include <gtest/gtest.h>
48 constexpr size_t frs_per_G = FrCodec::calc_num_fields<Flavor::Commitment>();
49 constexpr size_t NUM_SUMCHECK_ROUNDS = 17;
53 manifest.
add_entry(0,
"Gemini:masking_poly_comm", frs_per_G);
57 std::vector<std::string> wire_labels = {
58 "P_X_LOW_LIMBS",
"P_X_HIGH_LIMBS",
"P_Y_LOW_LIMBS",
"P_Y_HIGH_LIMBS",
59 "Z_LOw_LIMBS",
"Z_HIGH_LIMBS",
60 "ACCUMULATORS_BINARY_LIMBS_0",
"ACCUMULATORS_BINARY_LIMBS_1",
61 "ACCUMULATORS_BINARY_LIMBS_2",
"ACCUMULATORS_BINARY_LIMBS_3",
62 "QUOTIENT_LOW_BINARY_LIMBS",
"QUOTIENT_HIGH_BINARY_LIMBS",
63 "RELATION_WIDE_LIMBS",
64 "P_X_LOW_LIMBS_RANGE_CONSTRAINT_0",
"P_X_LOW_LIMBS_RANGE_CONSTRAINT_1",
65 "P_X_LOW_LIMBS_RANGE_CONSTRAINT_2",
"P_X_LOW_LIMBS_RANGE_CONSTRAINT_3",
66 "P_X_LOW_LIMBS_RANGE_CONSTRAINT_4",
"P_X_LOW_LIMBS_RANGE_CONSTRAINT_TAIL",
67 "P_X_HIGH_LIMBS_RANGE_CONSTRAINT_0",
"P_X_HIGH_LIMBS_RANGE_CONSTRAINT_1",
68 "P_X_HIGH_LIMBS_RANGE_CONSTRAINT_2",
"P_X_HIGH_LIMBS_RANGE_CONSTRAINT_3",
69 "P_X_HIGH_LIMBS_RANGE_CONSTRAINT_4",
"P_X_HIGH_LIMBS_RANGE_CONSTRAINT_TAIL",
70 "P_Y_LOW_LIMBS_RANGE_CONSTRAINT_0",
"P_Y_LOW_LIMBS_RANGE_CONSTRAINT_1",
71 "P_Y_LOW_LIMBS_RANGE_CONSTRAINT_2",
"P_Y_LOW_LIMBS_RANGE_CONSTRAINT_3",
72 "P_Y_LOW_LIMBS_RANGE_CONSTRAINT_4",
"P_Y_LOW_LIMBS_RANGE_CONSTRAINT_TAIL",
73 "P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_0",
"P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_1",
74 "P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_2",
"P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_3",
75 "P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_4",
"P_Y_HIGH_LIMBS_RANGE_CONSTRAINT_TAIL",
76 "Z_LOW_LIMBS_RANGE_CONSTRAINT_0",
"Z_LOW_LIMBS_RANGE_CONSTRAINT_1",
77 "Z_LOW_LIMBS_RANGE_CONSTRAINT_2",
"Z_LOW_LIMBS_RANGE_CONSTRAINT_3",
78 "Z_LOW_LIMBS_RANGE_CONSTRAINT_4",
"Z_LOW_LIMBS_RANGE_CONSTRAINT_TAIL",
79 "Z_HIGH_LIMBS_RANGE_CONSTRAINT_0",
"Z_HIGH_LIMBS_RANGE_CONSTRAINT_1",
80 "Z_HIGH_LIMBS_RANGE_CONSTRAINT_2",
"Z_HIGH_LIMBS_RANGE_CONSTRAINT_3",
81 "Z_HIGH_LIMBS_RANGE_CONSTRAINT_4",
"Z_HIGH_LIMBS_RANGE_CONSTRAINT_TAIL",
82 "ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_0",
"ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_1",
83 "ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_2",
"ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_3",
84 "ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_4",
"ACCUMULATOR_LOW_LIMBS_RANGE_CONSTRAINT_TAIL",
85 "ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_0",
"ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_1",
86 "ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_2",
"ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_3",
87 "ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_4",
"ACCUMULATOR_HIGH_LIMBS_RANGE_CONSTRAINT_TAIL",
88 "QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_0",
"QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_1",
89 "QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_2",
"QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_3",
90 "QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_4",
"QUOTIENT_LOW_LIMBS_RANGE_CONSTRAINT_TAIL",
91 "QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_0",
"QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_1",
92 "QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_2",
"QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_3",
93 "QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_4",
"QUOTIENT_HIGH_LIMBS_RANGE_CONSTRAINT_TAIL",
94 "RELATION_WIDE_LIMBS_RANGE_CONSTRAINT_0",
"RELATION_WIDE_LIMBS_RANGE_CONSTRAINT_1",
95 "RELATION_WIDE_LIMBS_RANGE_CONSTRAINT_2",
"RELATION_WIDE_LIMBS_RANGE_CONSTRAINT_3",
96 "ORDERED_RANGE_CONSTRAINTS_0",
"ORDERED_RANGE_CONSTRAINTS_1",
97 "ORDERED_RANGE_CONSTRAINTS_2",
"ORDERED_RANGE_CONSTRAINTS_3",
98 "ORDERED_RANGE_CONSTRAINTS_4",
101 for (
const auto& label : wire_labels) {
110 manifest.
add_entry(2,
"Z_PERM", frs_per_G);
114 for (
size_t i = 0; i < NUM_SUMCHECK_ROUNDS; ++i) {
119 manifest.
add_entry(20,
"Libra:concatenation_commitment", frs_per_G);
124 for (
size_t i = 0; i < NUM_SUMCHECK_ROUNDS; ++i) {
130 manifest.
add_entry(38,
"Sumcheck:evaluations", 188);
131 manifest.
add_entry(38,
"Libra:claimed_evaluation", 1);
132 manifest.
add_entry(38,
"Libra:grand_sum_commitment", frs_per_G);
133 manifest.
add_entry(38,
"Libra:quotient_commitment", frs_per_G);
137 for (
size_t i = 1; i <= 16; ++i) {
143 for (
size_t i = 1; i <= 17; ++i) {
146 manifest.
add_entry(40,
"Gemini:P_pos", 1);
147 manifest.
add_entry(40,
"Gemini:P_neg", 1);
148 manifest.
add_entry(40,
"Libra:concatenation_eval", 1);
149 manifest.
add_entry(40,
"Libra:shifted_grand_sum_eval", 1);
150 manifest.
add_entry(40,
"Libra:grand_sum_eval", 1);
151 manifest.
add_entry(40,
"Libra:quotient_eval", 1);
155 manifest.
add_entry(41,
"Shplonk:Q", frs_per_G);
159 manifest.
add_entry(42,
"KZG:W", frs_per_G);
166 static void add_random_ops(std::shared_ptr<bb::ECCOpQueue>& op_queue,
size_t count = 1)
168 for (
size_t i = 0; i < count; i++) {
169 op_queue->random_op_ultra_only();
173 static void add_mixed_ops(std::shared_ptr<bb::ECCOpQueue>& op_queue,
size_t count = 100)
178 for (
size_t i = 0; i < count; i++) {
179 op_queue->add_accumulate(P1);
180 op_queue->mul_accumulate(P2, z);
182 op_queue->eq_and_reset();
187 const Fq& evaluation_challenge_x,
188 const size_t circuit_size_parameter = 500)
193 op_queue->no_op_ultra_only();
201 return CircuitBuilder{ batching_challenge_v, evaluation_challenge_x, op_queue };
205 const Fq& evaluation_challenge_x,
206 const Fq& batching_challenge_v)
211 auto initial_transcript = prover_transcript->export_proof();
215 verifier_transcript->template receive_from_prover<Fq>(
"init");
226 op_queue_commitments[0] =
227 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.op);
228 op_queue_commitments[1] =
229 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_lo_y_hi);
230 op_queue_commitments[2] =
231 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_hi_z_1);
232 op_queue_commitments[3] =
233 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.y_lo_z_2);
236 uint256_t accumulated_result = prover.get_accumulated_result();
241 evaluation_challenge_x,
242 batching_challenge_v,
244 op_queue_commitments);
248 return result.
pairing_points.check() && result.reduction_succeeded;
267 CircuitBuilder circuit_builder = generate_test_circuit(batching_challenge_v, evaluation_challenge_x);
272 prover_transcript->export_proof();
294 CircuitBuilder circuit_builder = generate_test_circuit(batching_challenge_v, evaluation_challenge_x);
297 bool verified = prove_and_verify(circuit_builder, evaluation_challenge_x, batching_challenge_v);
298 EXPECT_TRUE(verified);
315 op_queue->no_op_ultra_only();
317 add_mixed_ops(op_queue, 100);
319 auto circuit_builder =
CircuitBuilder{ batching_challenge_v, evaluation_challenge_x, op_queue,
true };
322 bool verified = prove_and_verify(circuit_builder, evaluation_challenge_x, batching_challenge_v);
323 EXPECT_TRUE(verified);
340 prover_transcript->export_proof();
348 auto compare_computed_vk_against_fixed = [&](
size_t circuit_size_parameter) {
350 generate_test_circuit(batching_challenge_v, evaluation_challenge_x, circuit_size_parameter);
354 auto labels = TranslatorFlavor::VerificationKey::get_labels();
356 for (
auto [vk_commitment, fixed_commitment] :
zip_view(computed_vk.get_all(), fixed_vk.get_all())) {
357 EXPECT_EQ(vk_commitment, fixed_commitment)
358 <<
"Mismatch between computed vk_commitment and fixed_commitment at label: " << labels[
index];
362 EXPECT_EQ(computed_vk, fixed_vk);
366 const size_t circuit_size_parameter_1 = 1 << 2;
367 const size_t circuit_size_parameter_2 = 1 << 3;
369 compare_computed_vk_against_fixed(circuit_size_parameter_1);
370 compare_computed_vk_against_fixed(circuit_size_parameter_2);
385 CircuitBuilder circuit_builder = generate_test_circuit(batching_challenge_v, evaluation_challenge_x);
397 verifier_transcript->enable_manifest();
400 uint256_t accumulated_result = prover.get_accumulated_result();
404 op_queue_commitments[0] = proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.op);
405 op_queue_commitments[1] =
406 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_lo_y_hi);
407 op_queue_commitments[2] =
408 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.x_hi_z_1);
409 op_queue_commitments[3] =
410 proving_key->proving_key->commitment_key.commit(proving_key->proving_key->polynomials.y_lo_z_2);
415 evaluation_challenge_x,
416 batching_challenge_v,
418 op_queue_commitments);
424 auto expected_manifest = build_expected_translator_manifest();
425 auto verifier_manifest = verifier_transcript->get_manifest();
427 EXPECT_EQ(verifier_manifest, expected_manifest);
static bool prove_and_verify(const CircuitBuilder &circuit_builder, const Fq &evaluation_challenge_x, const Fq &batching_challenge_v)
static void add_random_ops(std::shared_ptr< bb::ECCOpQueue > &op_queue, size_t count=1)
Flavor::Commitment Commitment
static CircuitBuilder generate_test_circuit(const Fq &batching_challenge_v, const Fq &evaluation_challenge_x, const size_t circuit_size_parameter=500)
static void SetUpTestSuite()
static void add_mixed_ops(std::shared_ptr< bb::ECCOpQueue > &op_queue, size_t count=100)
static TranscriptManifest build_expected_translator_manifest()
Build the expected transcript manifest for Translator verification.
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Manages ECC operations for the Goblin proving system.
static const size_t OP_QUEUE_SIZE
void add_entry(size_t round, const std::string &element_label, size_t element_size)
void add_challenge(size_t round, const std::string &label)
Add a single challenge label to the manifest for the given round.
TranslatorCircuitBuilder creates a circuit that evaluates the correctness of the evaluation of EccOpQ...
static constexpr size_t NUM_RANDOM_OPS_END
static constexpr size_t NUM_RANDOM_OPS_START
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
The verification key is responsible for storing the commitments to the precomputed (non-witnessk) pol...
BaseTranscript< Codec, HashFunction > Transcript
TranslatorCircuitBuilder CircuitBuilder
Curve::AffineElement Commitment
static constexpr size_t PROOF_LENGTH_WITHOUT_PUB_INPUTS
HonkProof construct_proof()
Translator verifier class that verifies the proof of the Translator circuit.
ReductionResult reduce_to_pairing_check()
Reduce the translator proof to a pairing check.
static affine_element random_element(numeric::RNG *engine=nullptr) noexcept
Samples a random point on the curve.
group_elements::affine_element< Fq, Fr, Params > affine_element
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
field< Bn254FqParams > fq
TEST_F(IPATest, ChallengesAreZero)
field< Bn254FrParams > fr
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::string to_string(bb::avm2::ValueTag tag)
PairingPoints pairing_points
static field random_element(numeric::RNG *engine=nullptr) noexcept