46 using Proof = std::vector<DataType>;
102 std::vector<DataType> full_buffer;
126 DataType new_challenge = HashFunction::hash(full_buffer);
130 return new_challenges;
160 auto element_frs = Codec::serialize_to_fields(element);
174 constexpr size_t element_fr_size = Codec::template calc_num_fields<T>();
177 auto element_frs = std::span{
proof_data }.subspan(
offset, element_fr_size);
178 offset += element_fr_size;
180 auto element = Codec::template deserialize_from_fields<T>(element_frs);
230 const size_t num_challenges = labels.size();
234 for (
const auto& label : labels) {
248 challenges.resize(num_challenges);
251 for (
size_t i = 0; i < num_challenges / 2; i += 1) {
253 challenges[2 * i] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
254 challenges[(2 * i) + 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[1]);
256 if ((num_challenges & 1) == 1) {
258 challenges[num_challenges - 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
282 template <
typename ChallengeType,
size_t N>
286 auto vec = get_challenges<ChallengeType>(labels_span);
288 std::move(vec.begin(), vec.end(), out.begin());
300 template <
typename ChallengeType>
303 ChallengeType challenge = get_challenge<ChallengeType>(label);
306 for (
size_t i = 1; i < num_challenges; i++) {
307 pows[i] = pows[i - 1].sqr();
332 auto elements = Codec::serialize_to_fields(element);
353 auto element_frs = Codec::template serialize_to_fields<T>(element);
369 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);
441 constexpr uint32_t
init{ 42 };
442 transcript->send_to_verifier(
"Init",
init);
456 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<DataType>(
"Init");
457 return verifier_transcript;
464 info(
"Warning: manifest is not enabled!");
477 this->proof_start = start;
478 this->num_frs_written = written;
491template <
typename Builder>
502template <
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)
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.
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.
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
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
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
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.
static std::shared_ptr< BaseTranscript > 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_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...
Helper to get the appropriate Transcript type for a given Curve.