26template <
typename T,
typename... U>
40 info(
"\tchallenge: ", label);
43 info(
"\telement (", entry.second,
"): ", entry.first);
56 info(
"Round: ", round.first);
61 template <
typename... Strings>
void add_challenge(
size_t round, Strings&... labels)
63 manifest[round].challenge_label = { labels... };
65 template <
typename String,
size_t NumChallenges>
68 auto call_add_challenge = [&] {
69 auto call_fn_with_expanded_parameters =
78 void add_entry(
size_t round,
const std::string& element_label,
size_t element_size)
80 manifest[round].entries.emplace_back(element_label, element_size);
97 return bb::field_conversion::convert_challenge<T>(challenge);
110 static constexpr size_t LO_BITS = DataType::Params::MAX_BITS_PER_ENDOMORPHISM_SCALAR;
113 auto converted =
static_cast<uint256_t>(challenge);
120 return bb::field_conversion::calc_num_bn254_frs<T>();
124 return bb::field_conversion::convert_from_bn254_frs<T>(frs);
126 template <
typename T>
static inline std::vector<DataType>
serialize(
const T& element)
136template <
typename T,
typename =
void>
struct is_iterable : std::false_type {};
140struct is_iterable<T,
std::void_t<decltype(std::begin(std::declval<T&>())), decltype(std::end(std::declval<T&>()))>>
157 using Proof =
typename TranscriptParams::Proof;
190 std::vector<DataType>
192 std::vector<DataType>
222 std::vector<DataType> full_buffer;
241 DataType new_challenge = TranscriptParams::hash(full_buffer);
245 return new_challenges;
277 auto element_frs = TranscriptParams::serialize(element);
291 constexpr size_t element_fr_size = TranscriptParams::template calc_num_data_types<T>();
294 auto element_frs = std::span{
proof_data }.subspan(
offset, element_fr_size);
295 offset += element_fr_size;
297 auto element = TranscriptParams::template deserialize<T>(element_frs);
353 template <
typename T>
static inline std::vector<DataType>
serialize(
const T& element)
355 return TranscriptParams::serialize(element);
368 template <
typename ChallengeType,
typename... Strings>
369 std::array<ChallengeType,
sizeof...(Strings)>
get_challenges(
const Strings&... labels)
371 constexpr size_t num_challenges =
sizeof...(Strings);
384 for (
size_t i = 0; i < num_challenges / 2; i += 1) {
386 challenges[2 * i] = TranscriptParams::template convert_challenge<ChallengeType>(challenge_buffer[0]);
387 challenges[2 * i + 1] = TranscriptParams::template convert_challenge<ChallengeType>(challenge_buffer[1]);
389 if ((num_challenges & 1) == 1) {
391 challenges[num_challenges - 1] =
392 TranscriptParams::template convert_challenge<ChallengeType>(challenge_buffer[0]);
402 for (
size_t i = 0; i < num_challenges; i++) {
418 template <
typename ChallengeType,
typename String, std::
size_t N>
422 return std::apply([
this](
auto const&... xs) {
return this->get_challenges<ChallengeType>(xs...); }, labels);
429 template <
typename ChallengeType>
431 const ChallengeType& round_challenge)
434 pows[0] = round_challenge;
435 for (
size_t i = 1; i < num_powers; i++) {
436 pows[i] = pows[i - 1].sqr();
441 template <
typename ChallengeType,
typename String>
467 if constexpr (is_iterable_v<T>) {
468 for (
const auto& subelement : element) {
476 auto element_frs = TranscriptParams::serialize(element);
478#ifdef LOG_INTERACTIONS
480 info(
"independent hash buffer consumed: ", label,
": ", element);
518 if constexpr (is_iterable_v<T>) {
519 for (
const auto& subelement : element) {
527 auto elements = TranscriptParams::serialize(element);
529#ifdef LOG_INTERACTIONS
531 info(
"consumed: ", label,
": ", element);
554 auto element_frs = TranscriptParams::serialize(element);
558#ifdef LOG_INTERACTIONS
560 info(
"sent: ", label,
": ", element);
573 if constexpr (is_iterable_v<T>) {
574 for (
const auto& subelement : element) {
593 const size_t element_size = TranscriptParams::template calc_num_data_types<T>();
601 auto element = TranscriptParams::template deserialize<T>(element_frs);
604#ifdef LOG_INTERACTIONS
606 info(
"received: ", label,
": ", element);
619 if constexpr (is_iterable_v<T>) {
620 for (
auto& subelement : element) {
641 BB_ASSERT_EQ(prover_transcript->num_frs_written,
static_cast<size_t>(0),
"Expected to be empty");
643 verifier_transcript->num_frs_read =
static_cast<size_t>(verifier_transcript->proof_start);
644 verifier_transcript->proof_start = 0;
645 return verifier_transcript;
656 constexpr uint32_t
init{ 42 };
657 transcript->send_to_verifier(
"Init",
init);
671 verifier_transcript->load_proof(transcript->proof_data);
672 [[maybe_unused]]
auto _ = verifier_transcript->template receive_from_prover<DataType>(
"Init");
673 return verifier_transcript;
676 template <
typename ChallengeType> ChallengeType
get_challenge(
const std::string& label)
678 ChallengeType result = get_challenges<ChallengeType>(label)[0];
679#if defined LOG_CHALLENGES || defined LOG_INTERACTIONS
680 info(
"challenge: ", label,
": ", result);
691 info(
"Warning: manifest is not enabled!");
751 return branched_transcript;
769 for (
auto& word : hash_result.
word64s) {
771 word = __builtin_bswap64(word);
774 std::array<uint8_t, 32> result;
776 for (
size_t i = 0; i < 4; ++i) {
777 for (
size_t j = 0; j < 8; ++j) {
778 uint8_t
byte =
static_cast<uint8_t
>(hash_result.
word64s[i] >> (56 - (j * 8)));
779 result[i * 8 + j] = byte;
783 return from_buffer<bb::fr>(result);
795 return bb::field_conversion::convert_challenge<T>(challenge);
800 return bb::field_conversion::calc_num_uint256_ts<T>();
804 return bb::field_conversion::convert_from_uint256_ts<T>(elements);
806 template <
typename T>
static inline std::vector<DataType>
serialize(
const T& element)
814 static constexpr size_t LO_BITS = bb::fr::Params::MAX_BITS_PER_ENDOMORPHISM_SCALAR;
817 auto converted =
static_cast<uint256_t>(challenge);
#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...
DataType hash_independent_buffer()
Hashes the independent hash buffer and clears it.
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.
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.
DataType previous_challenge
std::array< ChallengeType, N > get_challenges(std::array< String, N > const &labels)
Wrapper around get_challenges to handle array of challenges.
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 constexpr size_t HASH_OUTPUT_SIZE
std::array< DataType, 2 > get_next_duplex_challenge_buffer(size_t num_challenges)
Compute next challenge c_next = H( Compress(c_prev || round_buffer) )
void load_proof(const std::vector< DataType > &proof)
void add_to_hash_buffer(const std::string &label, const T &element)
Adds an element to the transcript.
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 serialize_to_buffer(const T &element, Proof &proof_data)
Serializes object and appends it to proof_data.
std::vector< DataType > export_proof()
Return the proof data starting at proof_start.
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.
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_powers_of_challenge(const String &label, size_t num_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.
TranscriptManifest get_manifest() const
BaseTranscript branch_transcript()
Branch a transcript to perform verifier-only computations.
void add_to_independent_hash_buffer(const std::string &label, const T &element)
Adds an element to an independent hash buffer.
std::ptrdiff_t proof_start
void enable_manifest()
Enables the manifest.
static std::vector< DataType > serialize(const T &element)
Serialize a size_t to a vector of field elements.
TranscriptParams::DataType DataType
std::vector< ChallengeType > compute_round_challenge_pows(const size_t num_powers, const ChallengeType &round_challenge)
Given δ, compute the vector [δ, δ^2,..., δ^2^num_powers].
static constexpr bool in_circuit
static std::shared_ptr< BaseTranscript > prover_init_empty()
For testing: initializes transcript with some arbitrary data so that a challenge can be generated aft...
typename TranscriptParams::Proof Proof
size_t size_proof_data()
Return the size of proof_data.
static DataType hash(const std::vector< DataType > &data)
Static hash method that forwards to TranscriptParams hash.
std::vector< DataType > independent_hash_buffer
ChallengeType get_challenge(const std::string &label)
TranscriptManifest manifest
std::vector< DataType > current_round_data
RoundData operator[](const size_t &round)
void add_entry(size_t round, const std::string &element_label, size_t element_size)
bool operator==(const TranscriptManifest &other) const =default
std::map< size_t, RoundData > manifest
void add_challenge(size_t round, Strings &... labels)
void add_challenge(size_t round, std::array< String, NumChallenges > labels)
constexpr uint256_t slice(uint64_t start, uint64_t end) const
constexpr uint64_t get_msb() const
const std::vector< FF > data
struct keccak256 ethash_keccak256(const uint8_t *data, size_t size) NOEXCEPT
uint8_t buffer[RANDOM_BUFFER_SIZE]
std::vector< bb::fr > convert_to_bn254_frs(const T &val)
Conversion from transcript values to bb::frs.
std::vector< uint256_t > convert_to_uint256(const T &val)
Conversion from transcript values to bb::frs.
Entry point for Barretenberg command-line interface.
std::atomic< size_t > unique_transcript_index
constexpr bool is_iterable_v
std::vector< fr > HonkProof
field< Bn254FrParams > fr
bb::fr keccak_hash_uint256(std::vector< uint256_t > const &data)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< uint8_t > to_buffer(T const &value)
static T convert_challenge(const DataType &challenge)
static std::vector< DataType > serialize(const T &element)
static T deserialize(std::span< const DataType > elements)
static std::array< DataType, 2 > split_challenge(const DataType &challenge)
static Fr hash(const std::vector< DataType > &data)
std::vector< uint256_t > Proof
static constexpr size_t calc_num_data_types()
static constexpr size_t calc_num_data_types()
static std::vector< DataType > serialize(const T &element)
static DataType hash(const std::vector< DataType > &data)
static std::array< DataType, 2 > split_challenge(const DataType &challenge)
Split a challenge field element into two half-width challenges.
static T deserialize(std::span< const DataType > frs)
static T convert_challenge(const DataType &challenge)
std::vector< std::string > challenge_label
bool operator==(const RoundData &other) const =default
std::vector< std::pair< std::string, size_t > > entries
static constexpr uint256_t modulus