Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
shplemini.test.cpp
Go to the documentation of this file.
16#include <gtest/gtest.h>
17
18using namespace bb;
19
20template <class PCS> class ShpleminiRecursionTest : public CommitmentTest<typename PCS::Curve::NativeCurve> {};
21
23
29TEST(ShpleminiRecursionTest, ProveAndVerifySingle)
30{
31 // Define some useful type aliases
33 using Curve = typename stdlib::bn254<Builder>;
34 using NativeCurve = typename Curve::NativeCurve;
35 using Commitment = typename Curve::AffineElement;
36 using NativeCurve = typename Curve::NativeCurve;
38 using CommitmentKey = typename NativePCS::CK;
39 using ShpleminiProver = ShpleminiProver_<NativeCurve>;
40 using ShpleminiVerifier = ShpleminiVerifier_<Curve>;
41 using Fr = typename Curve::ScalarField;
42 using NativeFr = typename Curve::NativeCurve::ScalarField;
44 using ClaimBatcher = ClaimBatcher_<Curve>;
45 using ClaimBatch = ClaimBatcher::Batch;
46 using MockClaimGen = MockClaimGenerator<NativeCurve>;
47 using StdlibProof = bb::stdlib::Proof<Builder>;
48
50 auto run_shplemini = [](size_t log_circuit_size) {
51 size_t N = 1 << log_circuit_size;
52 const std::vector<Fr> padding_indicator_array(CONST_PROOF_SIZE_LOG_N, 1);
53 constexpr size_t NUM_POLYS = 5;
54 constexpr size_t NUM_SHIFTED = 2;
55 constexpr size_t NUM_RIGHT_SHIFTED_BY_K = 0;
56
57 CommitmentKey commitment_key(16384);
58
59 std::vector<NativeFr> u_challenge;
60 u_challenge.reserve(CONST_PROOF_SIZE_LOG_N);
61 for (size_t idx = 0; idx < CONST_PROOF_SIZE_LOG_N; idx++) {
62 u_challenge.emplace_back(NativeFr::random_element(&shplemini_engine));
63 };
64
65 // Construct mock multivariate polynomial opening claims
66 MockClaimGen mock_claims(N, NUM_POLYS, NUM_SHIFTED, NUM_RIGHT_SHIFTED_BY_K, u_challenge, commitment_key);
67
68 // Initialize an empty NativeTranscript
69 auto prover_transcript = NativeTranscript::prover_init_empty();
70 auto prover_opening_claims =
71 ShpleminiProver::prove(N, mock_claims.polynomial_batcher, u_challenge, commitment_key, prover_transcript);
72 KZG<NativeCurve>::compute_opening_proof(commitment_key, prover_opening_claims, prover_transcript);
74 StdlibProof stdlib_proof(builder, prover_transcript->export_proof());
75 auto stdlib_verifier_transcript = std::make_shared<Transcript>();
76 stdlib_verifier_transcript->load_proof(stdlib_proof);
77 [[maybe_unused]] auto _ = stdlib_verifier_transcript->template receive_from_prover<Fr>("Init");
78
79 // Execute Verifier protocol without the need for vk prior the final check
80 const auto commitments_to_witnesses = [&builder](const auto& commitments) {
81 std::vector<Commitment> commitments_in_biggroup(commitments.size());
82 std::transform(commitments.begin(),
83 commitments.end(),
84 commitments_in_biggroup.begin(),
85 [&builder](const auto& native_commitment) {
86 return Commitment::from_witness(&builder, native_commitment);
87 });
88 return commitments_in_biggroup;
89 };
90 const auto elements_to_witness = [&](const auto& elements) {
91 std::vector<Fr> elements_in_circuit(elements.size());
92 std::transform(
93 elements.begin(), elements.end(), elements_in_circuit.begin(), [&builder](const auto& native_element) {
94 return Fr::from_witness(&builder, native_element);
95 });
96 return elements_in_circuit;
97 };
98 auto stdlib_unshifted_commitments =
99 commitments_to_witnesses(mock_claims.claim_batcher.get_unshifted().commitments);
100 auto stdlib_to_be_shifted_commitments =
101 commitments_to_witnesses(mock_claims.claim_batcher.get_shifted().commitments);
102 auto stdlib_to_be_right_shifted_commitments =
103 commitments_to_witnesses(mock_claims.claim_batcher.get_right_shifted_by_k().commitments);
104 auto stdlib_unshifted_evaluations = elements_to_witness(mock_claims.claim_batcher.get_unshifted().evaluations);
105 auto stdlib_shifted_evaluations = elements_to_witness(mock_claims.claim_batcher.get_shifted().evaluations);
106 auto stdlib_right_shifted_evaluations =
107 elements_to_witness(mock_claims.claim_batcher.get_right_shifted_by_k().evaluations);
108
109 std::vector<Fr> u_challenge_in_circuit;
110 u_challenge_in_circuit.reserve(CONST_PROOF_SIZE_LOG_N);
111
112 for (auto u : u_challenge) {
113 u_challenge_in_circuit.emplace_back(Fr::from_witness(&builder, u));
114 }
115
116 ClaimBatcher claim_batcher{
117 .unshifted = ClaimBatch{ RefVector(stdlib_unshifted_commitments), RefVector(stdlib_unshifted_evaluations) },
118 .shifted = ClaimBatch{ RefVector(stdlib_to_be_shifted_commitments), RefVector(stdlib_shifted_evaluations) },
119 .right_shifted_by_k = ClaimBatch{ RefVector(stdlib_to_be_right_shifted_commitments),
120 RefVector(stdlib_right_shifted_evaluations) },
121 .k_shift_magnitude = MockClaimGen::k_magnitude
122 };
123
124 const auto opening_claim = ShpleminiVerifier::compute_batch_opening_claim(padding_indicator_array,
125 claim_batcher,
126 u_challenge_in_circuit,
127 Commitment::one(&builder),
128 stdlib_verifier_transcript);
129 auto pairing_points = KZG<Curve>::reduce_verify_batch_opening_claim(opening_claim, stdlib_verifier_transcript);
130 EXPECT_TRUE(CircuitChecker::check(builder));
131
133 EXPECT_EQ(vk.pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()), true);
134
135 // Return finalized number of gates;
136 return builder.num_gates;
137 };
138
139 size_t num_gates_6 = run_shplemini(6);
140 size_t num_gates_13 = run_shplemini(13);
141 EXPECT_EQ(num_gates_6, num_gates_13);
142}
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
CommitmentKey object over a pairing group 𝔾₁.
IPA (inner product argument) commitment scheme class.
Definition ipa.hpp:95
static VerifierAccumulator reduce_verify_batch_opening_claim(BatchOpeningClaim< Curve > batch_opening_claim, const std::shared_ptr< Transcript > &transcript)
Computes the input points for the pairing check needed to verify a KZG opening claim obtained from a ...
Definition kzg.hpp:122
static void compute_opening_proof(const CK &ck, const ProverOpeningClaim< Curve > &opening_claim, const std::shared_ptr< Transcript > &prover_trancript)
Computes the KZG commitment to an opening proof polynomial at a single evaluation point.
Definition kzg.hpp:40
A template class for a reference vector. Behaves as if std::vector<T&> was possible.
An efficient verifier for the evaluation proofs of multilinear polynomials and their shifts.
static bool check(const Builder &circuit)
Check the witness satisifies the circuit.
Representation of the Grumpkin Verifier Commitment Key inside a bn254 circuit.
typename Group::affine_element AffineElement
Definition grumpkin.hpp:56
A simple wrapper around a vector of stdlib field elements representing a proof.
Definition proof.hpp:19
AluTraceBuilder builder
Definition alu.test.cpp:123
RNG & get_debug_randomness(bool reset, std::uint_fast64_t seed)
Definition engine.cpp:190
std::filesystem::path bb_crs_path()
void init_file_crs_factory(const std::filesystem::path &path)
Entry point for Barretenberg command-line interface.
TEST(MegaCircuitBuilder, CopyConstructor)
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
VerifierCommitmentKey< Curve > vk
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
For a small integer N = virtual_log_n and a given witness x = log_n, compute in-circuit an indicator_...
numeric::RNG & shplemini_engine
Logic to support batching opening claims for unshifted and shifted polynomials in Shplemini.
Constructs random polynomials, computes commitments and corresponding evaluations.