29template <
typename T,
typename... U>
36template <
typename T,
typename =
void>
struct is_iterable : std::false_type {};
40struct is_iterable<T,
std::void_t<decltype(std::begin(std::declval<T&>())), decltype(std::end(std::declval<T&>()))>>
58 using Proof = std::vector<DataType>;
121 std::vector<DataType> full_buffer;
140 DataType new_challenge = HashFunction::hash(full_buffer);
144 return new_challenges;
176 auto element_frs = Codec::serialize_to_fields(element);
190 constexpr size_t element_fr_size = Codec::template calc_num_fields<T>();
193 auto element_frs = std::span{
proof_data }.subspan(
offset, element_fr_size);
194 offset += element_fr_size;
196 auto element = Codec::template deserialize_from_fields<T>(element_frs);
252 template <
typename T>
static std::vector<DataType>
serialize(
const T& element)
254 return Codec::serialize_to_fields(element);
259 return Codec::template deserialize_from_fields<T>(frs);
262 template <
typename T>
static size_t calc_num_data_types() {
return Codec::template calc_num_fields<T>(); }
274 template <
typename ChallengeType,
typename... Strings>
275 std::array<ChallengeType,
sizeof...(Strings)>
get_challenges(
const Strings&... labels)
277 constexpr size_t num_challenges =
sizeof...(Strings);
290 element.unset_free_witness_tag();
299 for (
size_t i = 0; i < num_challenges / 2; i += 1) {
301 challenges[2 * i] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
302 challenges[(2 * i) + 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[1]);
304 if ((num_challenges & 1) == 1) {
306 challenges[num_challenges - 1] = Codec::template convert_challenge<ChallengeType>(challenge_buffer[0]);
316 for (
size_t i = 0; i < num_challenges; i++) {
332 template <
typename ChallengeType,
typename String, std::
size_t N>
336 return std::apply([
this](
auto const&... xs) {
return this->get_challenges<ChallengeType>(xs...); }, labels);
343 template <
typename ChallengeType>
345 const ChallengeType& round_challenge)
348 pows[0] = round_challenge;
349 for (
size_t i = 1; i < num_powers; i++) {
350 pows[i] = pows[i - 1].sqr();
355 template <
typename ChallengeType,
typename String>
381 if constexpr (is_iterable_v<T>) {
382 for (
const auto& subelement : element) {
390 auto element_frs = Codec::serialize_to_fields(element);
392#ifdef LOG_INTERACTIONS
394 info(
"independent hash buffer consumed: ", label,
": ", element);
411 element.unset_free_witness_tag();
439 if constexpr (is_iterable_v<T>) {
440 for (
const auto& subelement : element) {
448 auto elements = Codec::serialize_to_fields(element);
450#ifdef LOG_INTERACTIONS
452 info(
"consumed: ", label,
": ", element);
474 auto element_frs = Codec::template serialize_to_fields<T>(element);
478#ifdef LOG_INTERACTIONS
480 info(
"sent: ", label,
": ", element);
495 const size_t element_size = Codec::template calc_num_fields<T>();
509 for (
auto& subelement : element_frs) {
510 subelement.set_origin_tag(element_origin_tag);
517 auto element = Codec::template deserialize_from_fields<T>(element_frs);
524 if constexpr (is_iterable_v<T>) {
525 for (
auto& subelement : element) {
526 ASSERT(subelement.get_origin_tag() == element_origin_tag);
530 ASSERT(element.get_origin_tag() == element_origin_tag);
533#ifdef LOG_INTERACTIONS
535 info(
"received: ", label,
": ", element);
552 BB_ASSERT_EQ(prover_transcript->num_frs_written,
static_cast<size_t>(0),
"Expected to be empty");
554 verifier_transcript->num_frs_read =
static_cast<size_t>(verifier_transcript->proof_start);
555 verifier_transcript->proof_start = 0;
556 return verifier_transcript;
567 constexpr uint32_t
init{ 42 };
568 transcript->send_to_verifier(
"Init",
init);
582 verifier_transcript->load_proof(transcript->proof_data);
583 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<DataType>(
"Init");
584 return verifier_transcript;
587 template <
typename ChallengeType> ChallengeType
get_challenge(
const std::string& label)
589 ChallengeType result = get_challenges<ChallengeType>(label)[0];
590#if defined LOG_CHALLENGES || defined LOG_INTERACTIONS
591 info(
"challenge: ", label,
": ", result);
602 info(
"Warning: manifest is not enabled!");
663 return branched_transcript;
670template <
typename Builder>
#define BB_ASSERT_EQ(actual, expected,...)
#define BB_ASSERT_LTE(left, right,...)
#define ASSERT(expression,...)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
std::vector< DataType > independent_hash_buffer
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...
TranscriptManifest manifest
std::array< DataType, 2 > get_next_duplex_challenge_buffer(size_t num_challenges)
Compute next challenge c_next = H( Compress(c_prev || round_buffer) )
typename Codec::DataType DataType
TranscriptManifest get_manifest() const
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 enable_manifest()
Enables the manifest.
ChallengeType get_challenge(const std::string &label)
std::vector< DataType > export_proof()
Return the proof data starting at proof_start.
static constexpr bool in_circuit
DataType previous_challenge
void serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
static DataType hash(const std::vector< DataType > &data)
Static hash method that forwards to Codec hash.
std::array< ChallengeType, sizeof...(Strings)> get_challenges(const Strings &... labels)
After all the prover messages have been sent, finalize the round by hashing all the data and then cre...
void add_to_independent_hash_buffer(const std::string &label, const T &element)
Adds an element to an independent hash buffer.
std::vector< DataType > current_round_data
void add_to_hash_buffer(const std::string &label, const T &element)
Adds an element to the transcript.
std::vector< ChallengeType > compute_round_challenge_pows(const size_t num_powers, const ChallengeType &round_challenge)
Given δ, compute the vector [δ, δ^2,..., δ^2^num_powers].
std::vector< DataType > Proof
std::ptrdiff_t proof_start
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.
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< ChallengeType, N > get_challenges(std::array< String, N > const &labels)
Wrapper around get_challenges to handle array of challenges.
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.
static size_t calc_num_data_types()
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.
size_t size_proof_data()
Return the size of proof_data.
void load_proof(const std::vector< DataType > &proof)
BaseTranscript branch_transcript()
Branch a transcript to perform verifier-only computations.
static std::vector< DataType > serialize(const T &element)
Serialize a size_t to a vector of field elements.
DataType hash_independent_buffer()
Hashes the independent hash buffer and clears it.
static T deserialize(std::span< const DataType > frs)
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::vector< ChallengeType > get_powers_of_challenge(const String &label, size_t num_challenges)
void add_entry(size_t round, const std::string &element_label, size_t element_size)
void add_challenge(size_t round, Strings &... labels)
stdlib class that evaluates in-circuit poseidon2 hashes, consistent with behavior in crypto::poseidon...
const std::vector< FF > data
Entry point for Barretenberg command-line interface.
std::atomic< size_t > unique_transcript_index
constexpr bool is_iterable_v
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept