From 712753e42353fe207567444621de2a4bc1593b60 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Mon, 24 Feb 2025 15:57:01 +0000 Subject: [PATCH 1/3] adds new function to the transfer that allows for hashing without the element being added to the proof data --- .../barretenberg/transcript/transcript.hpp | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp index 032bc8472945..dbb4e9f69fce 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp @@ -350,6 +350,31 @@ template class BaseTranscript { return call_get_challenges(); } + /** + * @brief Adds an element to the transcript. + * @details Serializes the element to frs and adds it to the current_round_data buffer. + * + * @param label Human-readable name for the challenge. + * @param element Element to be added. + */ + template void consume_element(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) { + info("consumed: ", label, ": ", element); + } +#endif + BaseTranscript::consume_prover_element_frs(label, element_frs); + } + /** * @brief Adds a prover message to the transcript, only intended to be used by the prover. * From ec4e6b89939651df56f35bbf5f5c9ab3a5eda1ec Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 25 Feb 2025 19:15:50 +0000 Subject: [PATCH 2/3] add test to test consume_element functionality --- .../barretenberg/transcript/transcript.test.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp index 69e5c91df3c5..d21983fc0dbb 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp @@ -144,4 +144,18 @@ TEST(NativeTranscript, TwoProversTwoFields) EXPECT_TRUE(received_k.is_point_at_infinity()); EXPECT_EQ(received_k, elt_k); } -} \ No newline at end of file +} + +/** + * @brief Test the consume_element functionality + * + */ +TEST(NativeTranscript, ConsumeElement) +{ + Transcript prover_transcript, verifier_transcript; + prover_transcript.consume_element("a", Fr(1)); + verifier_transcript.consume_element("a", Fr(1)); + auto prover_chal = prover_transcript.get_challenge("alpha"); + auto verifier_chal = verifier_transcript.get_challenge("alpha"); + EXPECT_EQ(prover_chal, verifier_chal); +} From b93aee9fdddfe3f4dca3e4f94147a205913d3c28 Mon Sep 17 00:00:00 2001 From: lucasxia01 Date: Tue, 25 Feb 2025 21:21:25 +0000 Subject: [PATCH 3/3] cleanup and change names --- .../src/barretenberg/transcript/transcript.hpp | 15 ++++++++------- .../barretenberg/transcript/transcript.test.cpp | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp index dbb4e9f69fce..a3bf578fb22d 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.hpp @@ -211,7 +211,7 @@ template class BaseTranscript { * @param label of the element sent * @param element_frs serialized */ - void consume_prover_element_frs(const std::string& label, std::span element_frs) + void add_element_frs_to_hash_buffer(const std::string& label, std::span element_frs) { if (use_manifest) { // Add an entry to the current round of the manifest @@ -352,12 +352,13 @@ template class BaseTranscript { /** * @brief Adds an element to the transcript. - * @details Serializes the element to frs and adds it to the current_round_data buffer. + * @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 void consume_element(const std::string& label, const T& element) + template void add_to_hash_buffer(const std::string& label, const T& element) { DEBUG_LOG(label, element); @@ -372,14 +373,14 @@ template class BaseTranscript { info("consumed: ", label, ": ", element); } #endif - BaseTranscript::consume_prover_element_frs(label, element_frs); + 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 @@ -404,7 +405,7 @@ template 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); } /** @@ -422,7 +423,7 @@ template 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(element_frs); DEBUG_LOG(label, element); diff --git a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp index d21983fc0dbb..092d52320132 100644 --- a/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp +++ b/barretenberg/cpp/src/barretenberg/transcript/transcript.test.cpp @@ -147,14 +147,14 @@ TEST(NativeTranscript, TwoProversTwoFields) } /** - * @brief Test the consume_element functionality + * @brief Test the add_to_hash_buffer functionality * */ TEST(NativeTranscript, ConsumeElement) { Transcript prover_transcript, verifier_transcript; - prover_transcript.consume_element("a", Fr(1)); - verifier_transcript.consume_element("a", Fr(1)); + 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("alpha"); auto verifier_chal = verifier_transcript.get_challenge("alpha"); EXPECT_EQ(prover_chal, verifier_chal);