Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
shplemini.test.cpp
Go to the documentation of this file.
15#include <gtest/gtest.h>
16
17using namespace bb;
18
19template <class PCS> class ShpleminiRecursionTest : public CommitmentTest<typename PCS::Curve::NativeCurve> {};
20
22
28TEST(ShpleminiRecursionTest, ProveAndVerifySingle)
29{
30 // Define some useful type aliases
32 using Curve = typename stdlib::bn254<Builder>;
33 using NativeCurve = typename Curve::NativeCurve;
34 using Commitment = typename Curve::AffineElement;
35 using NativeCurve = typename Curve::NativeCurve;
37 using CommitmentKey = typename NativePCS::CK;
38 using ShpleminiProver = ShpleminiProver_<NativeCurve>;
39 using ShpleminiVerifier = ShpleminiVerifier_<Curve>;
40 using Fr = typename Curve::ScalarField;
41 using NativeFr = typename Curve::NativeCurve::ScalarField;
43 using ClaimBatcher = ClaimBatcher_<Curve>;
44 using ClaimBatch = ClaimBatcher::Batch;
45 using MockClaimGen = MockClaimGenerator<NativeCurve>;
46 using StdlibProof = bb::stdlib::Proof<Builder>;
47
49 auto run_shplemini = [](size_t log_circuit_size) {
50 size_t N = 1 << log_circuit_size;
51 const std::vector<Fr> padding_indicator_array(CONST_PROOF_SIZE_LOG_N, 1);
52 constexpr size_t NUM_POLYS = 5;
53 constexpr size_t NUM_SHIFTED = 2;
54 constexpr size_t NUM_RIGHT_SHIFTED_BY_K = 0;
55
56 CommitmentKey commitment_key(16384);
57
58 std::vector<NativeFr> u_challenge;
59 u_challenge.reserve(CONST_PROOF_SIZE_LOG_N);
60 for (size_t idx = 0; idx < CONST_PROOF_SIZE_LOG_N; idx++) {
61 u_challenge.emplace_back(NativeFr::random_element(&shplemini_engine));
62 };
63
64 // Construct mock multivariate polynomial opening claims
65 MockClaimGen mock_claims(N, NUM_POLYS, NUM_SHIFTED, NUM_RIGHT_SHIFTED_BY_K, u_challenge, commitment_key);
66
67 // Initialize an empty NativeTranscript
68 auto prover_transcript = NativeTranscript::prover_init_empty();
69 auto prover_opening_claims =
70 ShpleminiProver::prove(N, mock_claims.polynomial_batcher, u_challenge, commitment_key, prover_transcript);
71 KZG<NativeCurve>::compute_opening_proof(commitment_key, prover_opening_claims, prover_transcript);
73 StdlibProof stdlib_proof(builder, prover_transcript->export_proof());
74 auto stdlib_verifier_transcript = std::make_shared<Transcript>();
75 stdlib_verifier_transcript->load_proof(stdlib_proof);
76 [[maybe_unused]] auto _ = stdlib_verifier_transcript->template receive_from_prover<Fr>("Init");
77
78 // Execute Verifier protocol without the need for vk prior the final check
79 const auto commitments_to_witnesses = [&builder](const auto& commitments) {
80 std::vector<Commitment> commitments_in_biggroup(commitments.size());
81 std::transform(commitments.begin(),
82 commitments.end(),
83 commitments_in_biggroup.begin(),
84 [&builder](const auto& native_commitment) {
85 auto comm = Commitment::from_witness(&builder, native_commitment);
86 // Removing the free witness tag, since the commitment in the full scheme are supposed to
87 // be fiat-shamirred earlier
88 comm.unset_free_witness_tag();
89 return comm;
90 });
91 return commitments_in_biggroup;
92 };
93 const auto elements_to_witness = [&](const auto& elements) {
94 std::vector<Fr> elements_in_circuit(elements.size());
95 std::transform(
96 elements.begin(), elements.end(), elements_in_circuit.begin(), [&builder](const auto& native_element) {
97 auto element = Fr::from_witness(&builder, native_element);
98 // Removing the free witness tag, since the element in the full scheme are supposed to
99 // be fiat-shamirred earlier
100 element.unset_free_witness_tag();
101 return element;
102 });
103 return elements_in_circuit;
104 };
105 auto stdlib_unshifted_commitments =
106 commitments_to_witnesses(mock_claims.claim_batcher.get_unshifted().commitments);
107 auto stdlib_to_be_shifted_commitments =
108 commitments_to_witnesses(mock_claims.claim_batcher.get_shifted().commitments);
109 auto stdlib_to_be_right_shifted_commitments =
110 commitments_to_witnesses(mock_claims.claim_batcher.get_right_shifted_by_k().commitments);
111 auto stdlib_unshifted_evaluations = elements_to_witness(mock_claims.claim_batcher.get_unshifted().evaluations);
112 auto stdlib_shifted_evaluations = elements_to_witness(mock_claims.claim_batcher.get_shifted().evaluations);
113 auto stdlib_right_shifted_evaluations =
114 elements_to_witness(mock_claims.claim_batcher.get_right_shifted_by_k().evaluations);
115
116 std::vector<Fr> u_challenge_in_circuit;
117 u_challenge_in_circuit.reserve(CONST_PROOF_SIZE_LOG_N);
118
119 for (auto u : u_challenge) {
120 u_challenge_in_circuit.emplace_back(Fr::from_witness(&builder, u));
121 // Removing the free witness tag, since the u_challenge in the full scheme are supposed to
122 // be derived from the transcript earlier
123 u_challenge_in_circuit.back().unset_free_witness_tag();
124 }
125
126 ClaimBatcher claim_batcher{
127 .unshifted = ClaimBatch{ RefVector(stdlib_unshifted_commitments), RefVector(stdlib_unshifted_evaluations) },
128 .shifted = ClaimBatch{ RefVector(stdlib_to_be_shifted_commitments), RefVector(stdlib_shifted_evaluations) },
129 .right_shifted_by_k = ClaimBatch{ RefVector(stdlib_to_be_right_shifted_commitments),
130 RefVector(stdlib_right_shifted_evaluations) },
131 .k_shift_magnitude = MockClaimGen::k_magnitude
132 };
133
134 const auto opening_claim = ShpleminiVerifier::compute_batch_opening_claim(padding_indicator_array,
135 claim_batcher,
136 u_challenge_in_circuit,
137 Commitment::one(&builder),
138 stdlib_verifier_transcript);
139 auto pairing_points = KZG<Curve>::reduce_verify_batch_opening_claim(opening_claim, stdlib_verifier_transcript);
140 EXPECT_TRUE(CircuitChecker::check(builder));
141
143 EXPECT_EQ(vk.pairing_check(pairing_points[0].get_value(), pairing_points[1].get_value()), true);
144
145 // Return finalized number of gates;
146 return builder.num_gates;
147 };
148
149 size_t num_gates_6 = run_shplemini(6);
150 size_t num_gates_13 = run_shplemini(13);
151 EXPECT_EQ(num_gates_6, num_gates_13);
152}
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:93
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.
UltraCircuitBuilder_< UltraExecutionTraceBlocks > UltraCircuitBuilder
TEST(BoomerangMegaCircuitBuilder, BasicCircuit)
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.