Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
transcript.test.cpp
Go to the documentation of this file.
1// Unified transcript tests - works for both native and stdlib transcripts
2// Replaces: transcript.test.cpp and stdlib_transcript.test.cpp
3
5
6namespace bb::test {
7
8// Helper to extract Codec and HashFn from std::pair
9template <typename T> struct TranscriptTests;
10template <typename Codec, typename HashFn>
11struct TranscriptTests<std::pair<Codec, HashFn>> : TranscriptTest<Codec, HashFn> {};
12
14
15// ============================================================================
16// Basic Type Send/Receive Tests
17// ============================================================================
18
19TYPED_TEST(TranscriptTests, ScalarSendReceive)
20{
21 this->test_scalar_send_receive();
22}
23
24TYPED_TEST(TranscriptTests, BasefieldSendReceive)
25{
26 this->test_basefield_send_receive();
27}
28
29TYPED_TEST(TranscriptTests, BN254CommitmentSendReceive)
30{
31 this->test_bn254_commitment_send_receive();
32}
33
34TYPED_TEST(TranscriptTests, GrumpkinCommitmentSendReceive)
35{
36 this->test_grumpkin_commitment_send_receive();
37}
38
39TYPED_TEST(TranscriptTests, ArraySendReceive)
40{
41 this->template test_array_send_receive<8>();
42}
43
44TYPED_TEST(TranscriptTests, GrumpkinFieldArraySendReceive)
45{
46 this->template test_grumpkin_field_array_send_receive<7>();
47}
48
49TYPED_TEST(TranscriptTests, UnivariateSendReceive)
50{
51 this->template test_univariate_send_receive<8>();
52}
53
54TYPED_TEST(TranscriptTests, GrumpkinUnivariateSendReceive)
55{
56 this->template test_grumpkin_univariate_send_receive<3>();
57}
58
59// ============================================================================
60// Point at Infinity Tests
61// ============================================================================
62
63TYPED_TEST(TranscriptTests, BN254InfinityHandling)
64{
65 this->test_bn254_infinity_handling();
66}
67
68TYPED_TEST(TranscriptTests, GrumpkinInfinityHandling)
69{
70 this->test_grumpkin_infinity_handling();
71}
72
73// ============================================================================
74// Test multiple Provers sharing a Transcript
75// ============================================================================
76
77TYPED_TEST(TranscriptTests, BasicMultiRoundProtocol)
78{
79 this->test_multi_round_protocol();
80}
81
82TYPED_TEST(TranscriptTests, ManifestConsistency)
83{
84 this->test_manifest_consistency();
85}
86
87// ============================================================================
88// Challenge Generation Tests
89// ============================================================================
90
91TYPED_TEST(TranscriptTests, ChallengesNonZero)
92{
93 this->test_challenges_are_nonzero();
94}
95
96// ============================================================================
97// Hash Buffer Tests
98// ============================================================================
99
100TYPED_TEST(TranscriptTests, HashBufferConsistency)
101{
102 this->test_hash_buffer_consistency();
103}
104
105// ============================================================================
106// Native-Specific Tests
107// ============================================================================
108
109TYPED_TEST(TranscriptTests, ProverToVerifierConversion)
110{
111 this->test_prover_to_verifier_conversion();
112}
113
114TYPED_TEST(TranscriptTests, TamperingDetection)
115{
116 this->test_tampering_detection();
117}
118
119// ============================================================================
120// Test Batch Challenge Generation
121// ============================================================================
122
126TYPED_TEST(TranscriptTests, BatchChallengeGeneration)
127{
128 using FF = typename TestFixture::FF;
129
130 NativeTranscript prover;
132
133 std::array<std::string, 3> labels = { "alpha", "beta", "gamma" };
134 auto [p_alpha, p_beta, p_gamma] = prover.template get_challenges<bb::fr>(labels);
135
136 typename TestFixture::Transcript verifier(this->export_proof(prover));
137 verifier.template receive_from_prover<FF>("data");
138
139 auto [v_alpha, v_beta, v_gamma] = verifier.template get_challenges<FF>(labels);
140
141 EXPECT_EQ(p_alpha, this->to_native(v_alpha));
142 EXPECT_EQ(p_beta, this->to_native(v_beta));
143 EXPECT_EQ(p_gamma, this->to_native(v_gamma));
144
145 this->check_circuit();
146}
147
151TYPED_TEST(TranscriptTests, VectorChallengeGeneration)
152{
153 using FF = typename TestFixture::FF;
154
155 NativeTranscript prover;
156 // Need at least one piece of data before generating challenges
157 prover.send_to_verifier("init", bb::fr(1));
158 std::vector<std::string> labels = { "c1", "c2", "c3", "c4", "c5" };
159 auto prover_challenges = prover.template get_challenges<bb::fr>(labels);
160
161 typename TestFixture::Transcript verifier(this->export_proof(prover));
162 verifier.template receive_from_prover<FF>("init");
163 auto verifier_challenges = verifier.template get_challenges<FF>(labels);
164
165 ASSERT_EQ(prover_challenges.size(), verifier_challenges.size());
166 for (size_t i = 0; i < prover_challenges.size(); ++i) {
167 EXPECT_EQ(prover_challenges[i], this->to_native(verifier_challenges[i]));
168 }
169
170 this->check_circuit();
171}
172
173} // namespace bb::test
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
void send_to_verifier(const std::string &label, const T &element)
Adds a prover message to the transcript, only intended to be used by the prover.
TYPED_TEST_SUITE(TranscriptTests, TranscriptTypes)
TYPED_TEST(TranscriptTests, ScalarSendReceive)
::testing::Types< std::pair< NativeCodec, NativeHash >, std::pair< UltraCodec, UltraHash >, std::pair< MegaCodec, MegaHash > > TranscriptTypes
STL namespace.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
static field random_element(numeric::RNG *engine=nullptr) noexcept