Skip to content

Commit a441be9

Browse files
committed
addressing PR review comments from Cody
1 parent 1ae3efc commit a441be9

File tree

8 files changed

+71
-23
lines changed

8 files changed

+71
-23
lines changed

cpp/src/barretenberg/honk/pcs/gemini/gemini.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ template <typename Params> class MultilinearReductionScheme {
279279
std::vector<Fr> evaluations;
280280
evaluations.reserve(num_variables);
281281
for (size_t i = 0; i < num_variables; ++i) {
282-
auto eval = transcript.template receive_from_prover<Fr>("Gemini:a_" + std::to_string(i + 1));
282+
auto eval = transcript.template receive_from_prover<Fr>("Gemini:a_" + std::to_string(i));
283283
evaluations.emplace_back(eval);
284284
}
285285

cpp/src/barretenberg/honk/proof_system/prover.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ template <typename settings> void Prover<settings>::execute_univariatization_rou
305305

306306
// Compute d+1 Fold polynomials and their evaluations
307307
gemini_output = Gemini::reduce_prove(commitment_key,
308-
sumcheck_output.multivariate_query,
308+
sumcheck_output.challenge_point,
309309
std::move(batched_poly_unshifted),
310310
std::move(batched_poly_to_be_shifted),
311311
transcript);

cpp/src/barretenberg/honk/proof_system/verifier.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "barretenberg/common/throw_or_abort.hpp"
33
#include <cstddef>
44
#include <memory>
5+
#include "barretenberg/honk/transcript/transcript.hpp"
56
#include "barretenberg/plonk/proof_system/constants.hpp"
67
#include "./verifier.hpp"
78
#include "barretenberg/plonk/proof_system/public_inputs/public_inputs.hpp"
@@ -88,7 +89,7 @@ template <typename program_settings> bool Verifier<program_settings>::verify_pro
8889

8990
constexpr auto program_width = program_settings::program_width;
9091

91-
VerifierTranscript<FF> transcript{ proof.proof_data };
92+
transcript = VerifierTranscript<FF>{ proof.proof_data };
9293

9394
// TODO(Adrian): Change the initialization of the transcript to take the VK hash?
9495
const auto circuit_size = transcript.template receive_from_prover<uint32_t>("circuit_size");
@@ -103,7 +104,7 @@ template <typename program_settings> bool Verifier<program_settings>::verify_pro
103104

104105
std::vector<FF> public_inputs;
105106
for (size_t i = 0; i < public_input_size; ++i) {
106-
auto public_input_i = transcript.template receive_from_prover<FF>("public_inputs_" + std::to_string(i));
107+
auto public_input_i = transcript.template receive_from_prover<FF>("public_input_" + std::to_string(i));
107108
public_inputs.emplace_back(public_input_i);
108109
}
109110

cpp/src/barretenberg/honk/proof_system/verifier.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ template <typename program_settings> class Verifier {
2828
std::map<std::string, barretenberg::g1::affine_element> kate_g1_elements;
2929
std::map<std::string, barretenberg::fr> kate_fr_elements;
3030
std::shared_ptr<pcs::kzg::VerificationKey> kate_verification_key;
31+
VerifierTranscript<typename program_settings::fr> transcript;
3132
};
3233

3334
extern template class Verifier<honk::standard_verifier_settings>;

cpp/src/barretenberg/honk/sumcheck/sumcheck.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ template <typename FF, class Transcript, template <class> class... Relations> cl
125125
for (size_t i = 0; i < NUM_POLYNOMIALS; ++i) {
126126
multivariate_evaluations[i] = folded_polynomials[i][0];
127127
}
128-
transcript.send_to_verifier("multivariate_evaluations", multivariate_evaluations);
128+
transcript.send_to_verifier("Sumcheck:evaluations", multivariate_evaluations);
129129

130130
return { multivariate_query, multivariate_evaluations };
131131
};

cpp/src/barretenberg/honk/sumcheck/sumcheck_output.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
namespace honk::sumcheck {
66

77
/**
8-
* @brief Contains the multi-linear `evaluations` of the polynomials at the `evaluation_point`.
8+
* @brief Contains the multi-linear evaluations of the polynomials at the challenge point 'u'.
99
* These are computed by the prover and need to be checked using a multi-linear PCS like Gemini.
1010
*/
1111
template <typename FF> struct SumcheckOutput {
1212
// u = (u_0, ..., u_{d-1})
13-
std::vector<FF> multivariate_query;
13+
std::vector<FF> challenge_point;
1414
// Evaluations in `u` of the polynomials used in Sumcheck
1515
std::array<FF, bonk::StandardArithmetization::NUM_POLYNOMIALS> evaluations;
1616

cpp/src/barretenberg/honk/transcript/transcript.hpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <utility>
1414
#include <vector>
1515
#include <map>
16+
#include <algorithm>
1617

1718
namespace honk {
1819

@@ -49,6 +50,10 @@ class TranscriptManifest {
4950
manifest[round].entries.emplace_back(element_label, element_size);
5051
}
5152

53+
[[nodiscard]] size_t size() const { return manifest.size(); }
54+
55+
RoundData operator[](const size_t& round) { return manifest[round]; };
56+
5257
bool operator==(const TranscriptManifest& other) const = default;
5358
};
5459

@@ -64,7 +69,7 @@ template <typename FF> class BaseTranscript {
6469
static constexpr size_t MIN_BYTES_PER_CHALLENGE = 128 / 8; // 128 bit challenges
6570

6671
size_t round_number = 0;
67-
std::array<uint8_t, HASH_OUTPUT_SIZE> previous_challenge_buffer{};
72+
std::array<uint8_t, HASH_OUTPUT_SIZE> previous_challenge_buffer{}; // default-initialized to zeros
6873
std::vector<uint8_t> current_round_data;
6974

7075
// "Manifest" object that records a summary of the transcript interactions
@@ -193,8 +198,9 @@ template <typename FF> class ProverTranscript : public BaseTranscript<FF> {
193198
template <class T> void send_to_verifier(const std::string& label, const T& element)
194199
{
195200
using serialize::write;
196-
// DANGER: When serializing an affine_element, we write the x and y coordinates
197-
// but this is annowing to deal with right now.
201+
// TODO(Adrian): Ensure that serialization of affine elements (including point at infinity) is consistent.
202+
// TODO(Adrian): Consider restricting serialization (via concepts) to types T for which sizeof(T) reliably
203+
// returns the size of T in bytes. (E.g. this is true for std::array but not for std::vector).
198204
auto element_bytes = to_buffer(element);
199205
proof_data.insert(proof_data.end(), element_bytes.begin(), element_bytes.end());
200206

@@ -219,10 +225,12 @@ template <typename FF> class ProverTranscript : public BaseTranscript<FF> {
219225
template <class FF> class VerifierTranscript : public BaseTranscript<FF> {
220226

221227
/// Contains the raw data sent by the prover.
222-
const std::vector<uint8_t> proof_data_;
228+
std::vector<uint8_t> proof_data_;
223229
size_t num_bytes_read_ = 0;
224230

225231
public:
232+
VerifierTranscript() = default;
233+
226234
explicit VerifierTranscript(const std::vector<uint8_t>& proof_data)
227235
: proof_data_(proof_data.begin(), proof_data.end())
228236
{}
@@ -244,8 +252,6 @@ template <class FF> class VerifierTranscript : public BaseTranscript<FF> {
244252
/**
245253
* @brief Reads the next element of type `T` from the transcript, with a predefined label.
246254
*
247-
* @details
248-
*
249255
* @param label Human readable name for the challenge.
250256
* @return deserialized element of type T
251257
*/

cpp/src/barretenberg/honk/transcript/transcript.test.cpp

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ template <typename FF> class TranscriptTest : public testing::Test {
1717
/**
1818
* @brief Construct a manifest for a standard Honk proof
1919
*
20+
* @details This is where we define the "Manifest" for a Standard Honk proof. The tests in this suite are intented
21+
* to warn the developer if the Prover/Verifier has deviated from this manifest, however, the Transcript class is
22+
* not otherwise contrained to follow the manifest.
23+
*
2024
* @return TranscriptManifest
2125
*/
2226
TranscriptManifest construct_standard_honk_manifest(size_t circuit_size)
@@ -53,7 +57,7 @@ template <typename FF> class TranscriptTest : public testing::Test {
5357
}
5458

5559
round++;
56-
manifest_expected.add_entry(round, "multivariate_evaluations", size_evals);
60+
manifest_expected.add_entry(round, "Sumcheck:evaluations", size_evals);
5761
manifest_expected.add_challenge(round, "rho");
5862

5963
round++;
@@ -86,12 +90,13 @@ using FieldTypes = testing::Types<barretenberg::fr>;
8690
TYPED_TEST_SUITE(TranscriptTest, FieldTypes);
8791

8892
/**
89-
* @brief Ensure consistency between the manifests generated by the standard honk prover and verfier for a simple
90-
* circuit of size n = 8
93+
* @brief Ensure consistency between the manifest hard coded in this testing suite and the one generated by the
94+
* standard honk prover over the course of proof construction.
9195
*
9296
*/
93-
TYPED_TEST(TranscriptTest, StandardHonkManifest)
97+
TYPED_TEST(TranscriptTest, ProverManifestConsistency)
9498
{
99+
// Construct a simple circuit of size n = 8 (i.e. the minimum circuit size)
95100
auto composer = StandardHonkComposer();
96101
fr a = 1;
97102
composer.circuit_constructor.add_variable(a);
@@ -101,14 +106,49 @@ TYPED_TEST(TranscriptTest, StandardHonkManifest)
101106
auto prover = composer.create_prover();
102107
plonk::proof proof = prover.construct_proof();
103108

104-
// Check that the prover generated manifest agrees with the expectation
109+
// Check that the prover generated manifest agrees with the manifest hard coded in this suite
105110
auto manifest_expected = TestFixture::construct_standard_honk_manifest(prover.key->circuit_size);
106-
ASSERT_EQ(prover.transcript.get_manifest(), manifest_expected);
111+
auto prover_manifest = prover.transcript.get_manifest();
107112

108-
// If the proof verifies, the verifier manifest must have matched that of the prover
113+
// Note: a manifest can be printed using manifest.print()
114+
for (size_t round = 0; round < manifest_expected.size(); ++round) {
115+
ASSERT_EQ(prover_manifest[round], manifest_expected[round]) << "Prover manifest discrepency in round " << round;
116+
;
117+
}
118+
}
119+
120+
/**
121+
* @brief Ensure consistency between the manifest generated by the standard honk prover over the course of proof
122+
* construction and the one generated by the verifier over the course of proof verification.
123+
*
124+
*/
125+
TYPED_TEST(TranscriptTest, VerifierManifestConsistency)
126+
{
127+
// Construct a simple circuit of size n = 8 (i.e. the minimum circuit size)
128+
auto composer = StandardHonkComposer();
129+
fr a = 1;
130+
composer.circuit_constructor.add_variable(a);
131+
composer.circuit_constructor.add_public_variable(a);
132+
133+
// Automatically generate a transcript manifest in the prover by constructing a proof
134+
auto prover = composer.create_prover();
135+
plonk::proof proof = prover.construct_proof();
136+
137+
// Automatically generate a transcript manifest in the verifier by verifying a proof
109138
auto verifier = composer.create_verifier();
110-
bool verified = verifier.verify_proof(proof);
111-
ASSERT_TRUE(verified);
139+
verifier.verify_proof(proof);
140+
prover.transcript.print();
141+
verifier.transcript.print();
142+
143+
// Check consistency between the manifests generated by the prover and verifier
144+
auto prover_manifest = prover.transcript.get_manifest();
145+
auto verifier_manifest = verifier.transcript.get_manifest();
146+
147+
// Note: a manifest can be printed using manifest.print()
148+
for (size_t round = 0; round < prover_manifest.size(); ++round) {
149+
ASSERT_EQ(prover_manifest[round], verifier_manifest[round])
150+
<< "Prover/Verifier manifest discrepency in round " << round;
151+
}
112152
}
113153

114154
/**
@@ -207,7 +247,7 @@ TYPED_TEST(TranscriptTest, VerifierMistake)
207247
// but then generate a challenge anyway
208248
auto verifier_alpha = verifier_transcript.get_challenge("alpha");
209249

210-
// Challenges will not agree and neither will the manifests
250+
// Challenges will not agree but neither will the manifests
211251
EXPECT_NE(prover_alpha, verifier_alpha);
212252
EXPECT_NE(prover_transcript.get_manifest(), verifier_transcript.get_manifest());
213253
}

0 commit comments

Comments
 (0)