Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions barretenberg/cpp/src/barretenberg/transcript/transcript.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ template <typename TranscriptParams> class BaseTranscript {
* @param label of the element sent
* @param element_frs serialized
*/
void consume_prover_element_frs(const std::string& label, std::span<const Fr> element_frs)
void add_element_frs_to_hash_buffer(const std::string& label, std::span<const Fr> element_frs)
{
if (use_manifest) {
// Add an entry to the current round of the manifest
Expand Down Expand Up @@ -350,11 +350,37 @@ template <typename TranscriptParams> class BaseTranscript {
return call_get_challenges();
}

/**
* @brief Adds an element to the transcript.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update this description to mention that this doesn't implicitly add to the proof?

* @details Serializes the element to frs and adds it to the current_round_data buffer. Does NOT add the element to
* the proof.
*
* @param label Human-readable name for the challenge.
* @param element Element to be added.
*/
template <class T> void add_to_hash_buffer(const std::string& label, const T& element)
{
DEBUG_LOG(label, element);

// TODO(Adrian): Ensure that serialization of affine elements (including point at infinity) is consistent.
// TODO(Adrian): Consider restricting serialization (via concepts) to types T for which sizeof(T) reliably
// returns the size of T in frs. (E.g. this is true for std::array but not for std::vector).
// convert element to field elements
auto element_frs = TranscriptParams::convert_to_bn254_frs(element);

#ifdef LOG_INTERACTIONS
if constexpr (Loggable<T>) {
info("consumed: ", label, ": ", element);
}
#endif
BaseTranscript::add_element_frs_to_hash_buffer(label, element_frs);
}

/**
* @brief Adds a prover message to the transcript, only intended to be used by the prover.
*
* @details Serializes the provided object into `proof_data`, and updates the current round state in
* consume_prover_element_frs.
* add_element_frs_to_hash_buffer.
*
* @param label Description/name of the object being added.
* @param element Serializable object that will be added to the transcript
Expand All @@ -379,7 +405,7 @@ template <typename TranscriptParams> class BaseTranscript {
info("sent: ", label, ": ", element);
}
#endif
BaseTranscript::consume_prover_element_frs(label, element_frs);
BaseTranscript::add_element_frs_to_hash_buffer(label, element_frs);
}

/**
Expand All @@ -397,7 +423,7 @@ template <typename TranscriptParams> class BaseTranscript {
auto element_frs = std::span{ proof_data }.subspan(num_frs_read, element_size);
num_frs_read += element_size;

BaseTranscript::consume_prover_element_frs(label, element_frs);
BaseTranscript::add_element_frs_to_hash_buffer(label, element_frs);

auto element = TranscriptParams::template convert_from_bn254_frs<T>(element_frs);
DEBUG_LOG(label, element);
Expand Down
16 changes: 15 additions & 1 deletion barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,18 @@ TEST(NativeTranscript, TwoProversTwoFields)
EXPECT_TRUE(received_k.is_point_at_infinity());
EXPECT_EQ(received_k, elt_k);
}
}
}

/**
* @brief Test the add_to_hash_buffer functionality
*
*/
TEST(NativeTranscript, ConsumeElement)
{
Transcript prover_transcript, verifier_transcript;
prover_transcript.add_to_hash_buffer("a", Fr(1));
verifier_transcript.add_to_hash_buffer("a", Fr(1));
auto prover_chal = prover_transcript.get_challenge<Fr>("alpha");
auto verifier_chal = verifier_transcript.get_challenge<Fr>("alpha");
EXPECT_EQ(prover_chal, verifier_chal);
}
Loading