46 using Proof = std::vector<DataType>;
100 std::vector<DataType> full_buffer;
124 DataType new_challenge = HashFunction::hash(full_buffer);
127 return new_challenge;
167 auto element_frs = Codec::serialize_to_fields(element);
181 constexpr size_t element_fr_size = Codec::template calc_num_fields<T>();
183 throw_or_abort(
"Transcript: deserialize_from_buffer out of bounds");
186 auto element_frs = std::span{
proof_data }.subspan(
offset, element_fr_size);
187 offset += element_fr_size;
189 auto element = Codec::template deserialize_from_fields<T>(element_frs);
234 template <
typename ChallengeType>
239 for (
const auto&
label : labels) {
271 template <
typename ChallengeType>
275 const size_t num_challenges = challenges.size();
277 for (
size_t i = 0; i < num_challenges / 2; ++i) {
279 challenges[2 * i] = Codec::template convert_short_challenge<ChallengeType>(challenge_buffer[0]);
280 challenges[(2 * i) + 1] = Codec::template convert_short_challenge<ChallengeType>(challenge_buffer[1]);
282 if ((num_challenges & 1) == 1) {
284 challenges[num_challenges - 1] =
285 Codec::template convert_short_challenge<ChallengeType>(challenge_buffer[0]);
301 for (
auto& challenge : challenges) {
310 template <
typename ChallengeType,
size_t N>
314 auto vec = get_short_challenges<ChallengeType>(labels_span);
326 template <
typename ChallengeType,
size_t N>
330 auto vec = get_challenges<ChallengeType>(labels_span);
344 template <
typename ChallengeType>
347 BB_ASSERT(num_challenges > 0,
"get_dyadic_powers_of_challenge called with num_challenges=0");
348 ChallengeType challenge = get_challenge<ChallengeType>(
label);
351 for (
size_t i = 1; i < num_challenges; i++) {
352 pows[i] = pows[i - 1].sqr();
376 auto elements = Codec::serialize_to_fields(element);
404 auto element_frs = Codec::template serialize_to_fields<T>(element);
420 const size_t element_size = Codec::template calc_num_fields<T>();
422 throw_or_abort(
"Transcript: receive_from_prover out of bounds (proof too short)");
439 auto element = Codec::template deserialize_from_fields<T>(element_frs);
455 auto result = get_challenges<ChallengeType>(label_span);
467 auto result = get_short_challenges<ChallengeType>(label_span);
483 BB_ASSERT_EQ(prover_transcript->num_frs_written, 0UL,
"Expected to be empty");
485 verifier_transcript->num_frs_read =
static_cast<size_t>(verifier_transcript->proof_start);
486 verifier_transcript->proof_start = 0;
487 return verifier_transcript;
491 template <
typename T>
static std::vector<DataType>
serialize(
const T& element)
493 return Codec::serialize_to_fields(element);
498 return Codec::template deserialize_from_fields<T>(frs);
506 info(
"Warning: manifest is not enabled!");
522 constexpr uint32_t
init{ 42 };
523 transcript->send_to_verifier(
"Init",
init);
537 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<DataType>(
"Init");
538 return verifier_transcript;
547 this->proof_start = start;
548 this->num_frs_written = written;
568template <
typename Builder>
579template <
typename Curve,
bool = Curve::is_stdlib_type>
struct TranscriptFor {
#define BB_ASSERT(expression,...)
#define BB_ASSERT_EQ(actual, expected,...)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
typename Codec::DataType DataType
static constexpr bool in_circuit
DataType previous_challenge
ChallengeType get_short_challenge(const std::string &label)
Generate a single short (127-bit) challenge for label. See get_short_challenges.
BaseTranscript(const Proof &proof)
static std::shared_ptr< BaseTranscript > test_prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
const Proof & test_get_proof_data() const
T receive_from_prover(const std::string &label)
Reads the next element of type T from the transcript, with a predefined label, only used by verifier.
std::vector< ChallengeType > generate_challenges(std::span< const std::string > labels, auto &&fill)
Shared core of get_challenges / get_short_challenges: the bookkeeping common to every challenge round...
bool challenge_generation_phase
ChallengeType get_challenge(const std::string &label)
Generate a single full-width (~254-bit) challenge for label (the default). See get_challenges.
void test_set_proof_parsing_state(std::ptrdiff_t start, size_t written)
Test utility: Set proof parsing state for export after deserialization.
std::vector< DataType > current_round_data
void add_element_frs_to_hash_buffer(const std::string &label, std::span< const DataType > element_frs)
Adds challenge elements to the current_round_buffer and updates the manifest.
Proof & test_get_proof_data()
Test utility: Get mutable reference to proof_data.
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
static std::shared_ptr< BaseTranscript > test_verifier_init_empty(const std::shared_ptr< BaseTranscript > &transcript)
For testing: initializes transcript based on proof data then receives junk data produced by BaseTrans...
std::vector< ChallengeType > get_dyadic_powers_of_challenge(const std::string &label, size_t num_challenges)
Get a challenge and compute its dyadic powers [δ, δ², δ⁴, ..., δ^(2^(num_challenges-1))].
std::vector< DataType > export_proof()
Return the proof data starting at proof_start.
DataType get_next_challenge_hash()
Compute the next challenge c_next = H( Compress(c_prev || round_buffer) ).
static T deserialize(std::span< const DataType > frs)
void add_to_hash_buffer(const std::string &label, const T &element)
Adds an element to the transcript.
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.
const TranscriptManifest & get_manifest() const
void load_proof(const std::vector< DataType > &proof)
Verifier-specific method. The verifier needs to load a proof or its segment before the verification.
HashFunction_ HashFunction
std::ptrdiff_t proof_start
std::array< DataType, CHALLENGE_BUFFER_SIZE > get_next_duplex_challenge_buffer()
Compute the next challenge and split it into the two 127-bit limbs of the short-challenge buffer.
std::array< ChallengeType, N > get_challenges(const std::array< std::string, N > &labels)
Wrapper around get_challenges to handle array of challenges.
TranscriptManifest manifest
static std::vector< DataType > serialize(const T &element)
std::ptrdiff_t test_get_proof_start() const
Test utility: Get proof_start for validation.
std::vector< DataType > Proof
T deserialize_from_buffer(const Proof &proof_data, size_t &offset) const
Deserializes the frs starting at offset into the typed element and returns that element.
std::vector< ChallengeType > get_short_challenges(std::span< const std::string > labels)
Generate short (127-bit) challenges for the given labels.
std::vector< ChallengeType > get_challenges(std::span< const std::string > labels)
Generate full-width (~254-bit) challenges for the given labels (the default).
static constexpr size_t CHALLENGE_BUFFER_SIZE
static std::shared_ptr< BaseTranscript > convert_prover_transcript_to_verifier_transcript(const std::shared_ptr< BaseTranscript > &prover_transcript)
Convert a prover transcript to a verifier transcript.
std::array< ChallengeType, N > get_short_challenges(const std::array< std::string, N > &labels)
Wrapper around get_short_challenges to handle array of challenges.
void add_entry(size_t round, const std::string &element_label, size_t element_size)
void add_challenge(size_t round, const std::string &label)
Add a single challenge label to the manifest for the given round.
stdlib class that evaluates in-circuit poseidon2 hashes, consistent with behavior in crypto::poseidon...
Entry point for Barretenberg command-line interface.
std::atomic< size_t > unique_transcript_index
OriginTag extract_transcript_tag(const TranscriptType &transcript)
Extract origin tag context from a transcript.
BaseTranscript< FrCodec, bb::crypto::Poseidon2< bb::crypto::Poseidon2Bn254ScalarFieldParams > > NativeTranscript
typename TranscriptFor< Curve >::type TranscriptFor_t
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
bb::VectorAffineElementPushSpan< BaseParams > out
StdlibCodec for in-circuit (recursive) verification transcript handling.
Helper to get the appropriate Transcript type for a given Curve.
void throw_or_abort(std::string const &err)