46 using Proof = std::vector<DataType>;
101 std::vector<DataType> full_buffer;
125 DataType new_challenge = HashFunction::hash(full_buffer);
129 return new_challenges;
159 auto element_frs = Codec::serialize_to_fields(element);
173 constexpr size_t element_fr_size = Codec::template calc_num_fields<T>();
176 auto element_frs = std::span{
proof_data }.subspan(
offset, element_fr_size);
177 offset += element_fr_size;
179 auto element = Codec::template deserialize_from_fields<T>(element_frs);
229 const size_t num_challenges = labels.size();
233 for (
const auto& label : labels) {
247 challenges.resize(num_challenges);
250 for (
size_t i = 0; i < num_challenges / 2; i += 1) {
252 challenges[2 * i] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
253 challenges[(2 * i) + 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[1]);
255 if ((num_challenges & 1) == 1) {
257 challenges[num_challenges - 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
277 template <
typename ChallengeType,
size_t N>
281 auto vec = get_challenges<ChallengeType>(labels_span);
283 std::move(vec.begin(), vec.end(), out.begin());
295 template <
typename ChallengeType>
298 ChallengeType challenge = get_challenge<ChallengeType>(label);
301 for (
size_t i = 1; i < num_challenges; i++) {
302 pows[i] = pows[i - 1].sqr();
326 auto elements = Codec::serialize_to_fields(element);
354 auto element_frs = Codec::template serialize_to_fields<T>(element);
370 const size_t element_size = Codec::template calc_num_fields<T>();
387 auto element = Codec::template deserialize_from_fields<T>(element_frs);
396 template <
typename ChallengeType> ChallengeType
get_challenge(
const std::string& label)
399 auto result = get_challenges<ChallengeType>(label_span);
415 BB_ASSERT_EQ(prover_transcript->num_frs_written, 0UL,
"Expected to be empty");
417 verifier_transcript->num_frs_read =
static_cast<size_t>(verifier_transcript->proof_start);
418 verifier_transcript->proof_start = 0;
419 return verifier_transcript;
423 template <
typename T>
static std::vector<DataType>
serialize(
const T& element)
425 return Codec::serialize_to_fields(element);
430 return Codec::template deserialize_from_fields<T>(frs);
438 info(
"Warning: manifest is not enabled!");
454 constexpr uint32_t
init{ 42 };
455 transcript->send_to_verifier(
"Init",
init);
469 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<DataType>(
"Init");
470 return verifier_transcript;
479 this->proof_start = start;
480 this->num_frs_written = written;
500template <
typename Builder>
511template <
typename Curve,
bool = Curve::is_stdlib_type>
struct TranscriptFor {
#define BB_ASSERT(expression,...)
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LTE(left, right,...)
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
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.
bool challenge_generation_phase
ChallengeType get_challenge(const std::string &label)
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.
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.
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
TranscriptManifest get_manifest() const
std::array< DataType, CHALLENGE_BUFFER_SIZE > get_next_duplex_challenge_buffer()
Compute next challenge c_next = H( Compress(c_prev || round_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_challenges(std::span< const std::string > labels)
After all the prover messages have been sent, finalize the round by hashing all the data and then cre...
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.
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...
StdlibCodec for in-circuit (recursive) verification transcript handling.
Helper to get the appropriate Transcript type for a given Curve.