Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
bb::BaseTranscript< Codec_, HashFunction_ > Class Template Reference

Common transcript class for both parties. Stores the data for the current round, as well as the manifest. More...

#include <transcript.hpp>

Inheritance diagram for bb::BaseTranscript< Codec_, HashFunction_ >:
bb::ECCVMFlavor::IPATranscript bb::avm2::AvmFlavor::Transcript

Public Types

using Codec = Codec_
 
using HashFunction = HashFunction_
 
using DataType = typename Codec::DataType
 
using Proof = std::vector< DataType >
 

Public Member Functions

 BaseTranscript ()
 
 BaseTranscript (const Proof &proof)
 
std::vector< DataTypeexport_proof ()
 Return the proof data starting at proof_start.
 
void load_proof (const std::vector< DataType > &proof)
 Verifier-specific method. The verifier needs to load a proof or its segment before the verification.
 
size_t get_proof_size ()
 
void enable_manifest ()
 
template<typename ChallengeType >
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 create the number of requested challenges.
 
template<typename ChallengeType , size_t N>
std::array< ChallengeType, N > get_challenges (const std::array< std::string, N > &labels)
 Wrapper around get_challenges to handle array of challenges.
 
template<typename ChallengeType >
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))].
 
template<class T >
void add_to_hash_buffer (const std::string &label, const T &element)
 Adds an element to the transcript.
 
template<class T >
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.
 
template<class 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.
 
template<typename ChallengeType >
ChallengeType get_challenge (const std::string &label)
 
TranscriptManifest get_manifest () const
 
void print ()
 
void test_set_proof_parsing_state (std::ptrdiff_t start, size_t written)
 Test utility: Set proof parsing state for export after deserialization.
 
std::ptrdiff_t test_get_proof_start () const
 Test utility: Get proof_start for validation.
 

Static Public Member Functions

static std::shared_ptr< BaseTranscriptconvert_prover_transcript_to_verifier_transcript (const std::shared_ptr< BaseTranscript > &prover_transcript)
 Convert a prover transcript to a verifier transcript.
 
template<typename T >
static std::vector< DataTypeserialize (const T &element)
 
template<typename T >
static T deserialize (std::span< const DataType > frs)
 
static std::shared_ptr< BaseTranscriptprover_init_empty ()
 For testing: initializes transcript with some arbitrary data so that a challenge can be generated after initialization. Only intended to be used by Prover.
 
static std::shared_ptr< BaseTranscriptverifier_init_empty (const std::shared_ptr< BaseTranscript > &transcript)
 For testing: initializes transcript based on proof data then receives junk data produced by BaseTranscript::prover_init_empty(). Only intended to be used by Verifier.
 

Static Public Attributes

static constexpr bool in_circuit = InCircuit<DataType>
 
static constexpr size_t CHALLENGE_BUFFER_SIZE = 2
 

Protected Member Functions

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.
 
template<typename T >
void serialize_to_buffer (const T &element, Proof &proof_data)
 Serializes object and appends it to proof_data.
 
template<typename 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.
 

Protected Attributes

Proof proof_data
 

Private Member Functions

std::array< DataType, CHALLENGE_BUFFER_SIZEget_next_duplex_challenge_buffer ()
 Compute next challenge c_next = H( Compress(c_prev || round_buffer) )
 

Private Attributes

size_t transcript_index = 0
 
size_t round_index = 0
 
bool reception_phase = true
 
bool is_first_challenge = true
 
DataType previous_challenge {}
 
std::vector< DataTypecurrent_round_data
 
std::ptrdiff_t proof_start = 0
 
size_t num_frs_written = 0
 
size_t num_frs_read = 0
 
size_t round_number = 0
 
bool use_manifest = false
 
TranscriptManifest manifest
 

Friends

template<typename T >
OriginTag bb::extract_transcript_tag (const T &transcript)
 

Detailed Description

template<typename Codec_, typename HashFunction_>
class bb::BaseTranscript< Codec_, HashFunction_ >

Common transcript class for both parties. Stores the data for the current round, as well as the manifest.

Definition at line 41 of file transcript.hpp.

Member Typedef Documentation

◆ Codec

template<typename Codec_ , typename HashFunction_ >
using bb::BaseTranscript< Codec_, HashFunction_ >::Codec = Codec_

Definition at line 43 of file transcript.hpp.

◆ DataType

template<typename Codec_ , typename HashFunction_ >
using bb::BaseTranscript< Codec_, HashFunction_ >::DataType = typename Codec::DataType

Definition at line 45 of file transcript.hpp.

◆ HashFunction

template<typename Codec_ , typename HashFunction_ >
using bb::BaseTranscript< Codec_, HashFunction_ >::HashFunction = HashFunction_

Definition at line 44 of file transcript.hpp.

◆ Proof

template<typename Codec_ , typename HashFunction_ >
using bb::BaseTranscript< Codec_, HashFunction_ >::Proof = std::vector<DataType>

Definition at line 46 of file transcript.hpp.

Constructor & Destructor Documentation

◆ BaseTranscript() [1/2]

template<typename Codec_ , typename HashFunction_ >
bb::BaseTranscript< Codec_, HashFunction_ >::BaseTranscript ( )
inline

Definition at line 53 of file transcript.hpp.

◆ BaseTranscript() [2/2]

template<typename Codec_ , typename HashFunction_ >
bb::BaseTranscript< Codec_, HashFunction_ >::BaseTranscript ( const Proof proof)
inlineexplicit

Definition at line 62 of file transcript.hpp.

Member Function Documentation

◆ add_element_frs_to_hash_buffer()

template<typename Codec_ , typename HashFunction_ >
void bb::BaseTranscript< Codec_, HashFunction_ >::add_element_frs_to_hash_buffer ( const std::string &  label,
std::span< const DataType element_frs 
)
inlineprotected

Adds challenge elements to the current_round_buffer and updates the manifest.

Parameters
labelof the element sent
element_frsserialized

Definition at line 140 of file transcript.hpp.

◆ add_to_hash_buffer()

template<typename Codec_ , typename HashFunction_ >
template<class T >
void bb::BaseTranscript< Codec_, HashFunction_ >::add_to_hash_buffer ( const std::string &  label,
const T &  element 
)
inline

Adds an element to the transcript.

Serializes the element to frs and adds it to the current_round_data buffer. Does NOT add the element to the proof.

Parameters
labelHuman-readable name for the challenge.
elementElement to be added.

Definition at line 320 of file transcript.hpp.

◆ convert_prover_transcript_to_verifier_transcript()

template<typename Codec_ , typename HashFunction_ >
static std::shared_ptr< BaseTranscript > bb::BaseTranscript< Codec_, HashFunction_ >::convert_prover_transcript_to_verifier_transcript ( const std::shared_ptr< BaseTranscript< Codec_, HashFunction_ > > &  prover_transcript)
inlinestatic

Convert a prover transcript to a verifier transcript.

Parameters
prover_transcriptThe prover transcript to convert
Returns
std::shared_ptr<BaseTranscript> The verifier transcript

Definition at line 411 of file transcript.hpp.

◆ deserialize()

template<typename Codec_ , typename HashFunction_ >
template<typename T >
static T bb::BaseTranscript< Codec_, HashFunction_ >::deserialize ( std::span< const DataType frs)
inlinestatic

Definition at line 428 of file transcript.hpp.

◆ deserialize_from_buffer()

template<typename Codec_ , typename HashFunction_ >
template<typename T >
T bb::BaseTranscript< Codec_, HashFunction_ >::deserialize_from_buffer ( const Proof proof_data,
size_t &  offset 
) const
inlineprotected

Deserializes the frs starting at offset into the typed element and returns that element.

Using the template parameter and the offset argument, this function deserializes the frs with from_buffer and then increments the offset appropriately based on the number of frs that were deserialized.

Template Parameters
T
Parameters
proof_data
offset
Returns
T

Definition at line 172 of file transcript.hpp.

◆ enable_manifest()

template<typename Codec_ , typename HashFunction_ >
void bb::BaseTranscript< Codec_, HashFunction_ >::enable_manifest ( )
inline

Definition at line 216 of file transcript.hpp.

◆ export_proof()

template<typename Codec_ , typename HashFunction_ >
std::vector< DataType > bb::BaseTranscript< Codec_, HashFunction_ >::export_proof ( )
inline

Return the proof data starting at proof_start.

This function returns the elements of the transcript in the interval [proof_start : proof_start + num_frs_written] and then updates proof_start. It is useful for when two provers share a transcript, as calling export_proof at the end of each provers' code returns the slices T_1, T_2 of the transcript that must be loaded by the verifiers via load_proof.

Definition at line 193 of file transcript.hpp.

◆ get_challenge()

template<typename Codec_ , typename HashFunction_ >
template<typename ChallengeType >
ChallengeType bb::BaseTranscript< Codec_, HashFunction_ >::get_challenge ( const std::string &  label)
inline

Definition at line 396 of file transcript.hpp.

◆ get_challenges() [1/2]

template<typename Codec_ , typename HashFunction_ >
template<typename ChallengeType , size_t N>
std::array< ChallengeType, N > bb::BaseTranscript< Codec_, HashFunction_ >::get_challenges ( const std::array< std::string, N > &  labels)
inline

Wrapper around get_challenges to handle array of challenges.

Parameters
arrayof labels human-readable names for the challenges for the manifest
Returns
std::array<ChallengeType, N> challenges for this round.

Definition at line 283 of file transcript.hpp.

◆ get_challenges() [2/2]

template<typename Codec_ , typename HashFunction_ >
template<typename ChallengeType >
std::vector< ChallengeType > bb::BaseTranscript< Codec_, HashFunction_ >::get_challenges ( std::span< const std::string >  labels)
inline

After all the prover messages have been sent, finalize the round by hashing all the data and then create the number of requested challenges.

Challenges are generated by iteratively hashing over the previous challenge, using get_next_challenge_buffer(). Note that the pairs of challenges will be 127 bits each, as in they will be [127, 127, 127, 127, ...].

Parameters
labelshuman-readable names for the challenges for the manifest
Returns
std::vector<ChallengeType> challenges for this round.

Definition at line 228 of file transcript.hpp.

◆ get_dyadic_powers_of_challenge()

template<typename Codec_ , typename HashFunction_ >
template<typename ChallengeType >
std::vector< ChallengeType > bb::BaseTranscript< Codec_, HashFunction_ >::get_dyadic_powers_of_challenge ( const std::string &  label,
size_t  num_challenges 
)
inline

Get a challenge and compute its dyadic powers [δ, δ², δ⁴, ..., δ^(2^(num_challenges-1))].

Generates num_challenges elements where each element is the square of the previous one. This is Step 2 of the protocol as written in the Protogalaxy paper.

Parameters
labelHuman-readable name for the challenge
num_challengesNumber of power-of-2 powers to generate
Returns
Vector of num_challenges elements: [δ, δ², δ⁴, δ⁸, ...]

Definition at line 301 of file transcript.hpp.

◆ get_manifest()

template<typename Codec_ , typename HashFunction_ >
TranscriptManifest bb::BaseTranscript< Codec_, HashFunction_ >::get_manifest ( ) const
inline

Definition at line 459 of file transcript.hpp.

◆ get_next_duplex_challenge_buffer()

template<typename Codec_ , typename HashFunction_ >
std::array< DataType, CHALLENGE_BUFFER_SIZE > bb::BaseTranscript< Codec_, HashFunction_ >::get_next_duplex_challenge_buffer ( )
inlineprivate

Compute next challenge c_next = H( Compress(c_prev || round_buffer) )

This function computes a new challenge for the current round using the previous challenge and the current round data, if they exist. It clears the current_round_data if nonempty after computing the challenge to minimize how much we compress. It also sets previous_challenge to the current challenge buffer to set up next function call.

Returns
std::array<DataType, CHALLENGE_BUFFER_SIZE>

Definition at line 99 of file transcript.hpp.

◆ get_proof_size()

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::get_proof_size ( )
inline

Definition at line 213 of file transcript.hpp.

◆ load_proof()

template<typename Codec_ , typename HashFunction_ >
void bb::BaseTranscript< Codec_, HashFunction_ >::load_proof ( const std::vector< DataType > &  proof)
inline

Verifier-specific method. The verifier needs to load a proof or its segment before the verification.

Parameters
proof

Definition at line 207 of file transcript.hpp.

◆ print()

template<typename Codec_ , typename HashFunction_ >
void bb::BaseTranscript< Codec_, HashFunction_ >::print ( )
inline

Definition at line 461 of file transcript.hpp.

◆ prover_init_empty()

template<typename Codec_ , typename HashFunction_ >
static std::shared_ptr< BaseTranscript > bb::BaseTranscript< Codec_, HashFunction_ >::prover_init_empty ( )
inlinestatic

For testing: initializes transcript with some arbitrary data so that a challenge can be generated after initialization. Only intended to be used by Prover.

Returns
BaseTranscript

Definition at line 438 of file transcript.hpp.

◆ receive_from_prover()

template<typename Codec_ , typename HashFunction_ >
template<class T >
T bb::BaseTranscript< Codec_, HashFunction_ >::receive_from_prover ( const std::string &  label)
inline

Reads the next element of type T from the transcript, with a predefined label, only used by verifier.

Parameters
labelHuman readable name for the challenge.
Returns
deserialized element of type T

Definition at line 367 of file transcript.hpp.

◆ send_to_verifier()

template<typename Codec_ , typename HashFunction_ >
template<class T >
void bb::BaseTranscript< Codec_, HashFunction_ >::send_to_verifier ( const std::string &  label,
const T &  element 
)
inline

Adds a prover message to the transcript, only intended to be used by the prover.

Serializes the provided object into proof_data, and updates the current round state in add_element_frs_to_hash_buffer.

Parameters
labelDescription/name of the object being added.
elementSerializable object that will be added to the transcript
Todo:
Use a concept to only allow certain types to be passed. Requirements are that the object should be serializable.

Definition at line 350 of file transcript.hpp.

◆ serialize()

template<typename Codec_ , typename HashFunction_ >
template<typename T >
static std::vector< DataType > bb::BaseTranscript< Codec_, HashFunction_ >::serialize ( const T &  element)
inlinestatic

Definition at line 423 of file transcript.hpp.

◆ serialize_to_buffer()

template<typename Codec_ , typename HashFunction_ >
template<typename T >
void bb::BaseTranscript< Codec_, HashFunction_ >::serialize_to_buffer ( const T &  element,
Proof proof_data 
)
inlineprotected

Serializes object and appends it to proof_data.

Calls to_buffer on element to serialize, and modifies proof_data object by appending the serialized frs to it.

Template Parameters
T
Parameters
element
proof_data

Definition at line 158 of file transcript.hpp.

◆ test_get_proof_start()

template<typename Codec_ , typename HashFunction_ >
std::ptrdiff_t bb::BaseTranscript< Codec_, HashFunction_ >::test_get_proof_start ( ) const
inline

Test utility: Get proof_start for validation.

Used by test fixtures to verify transcript conversion

Definition at line 485 of file transcript.hpp.

◆ test_set_proof_parsing_state()

template<typename Codec_ , typename HashFunction_ >
void bb::BaseTranscript< Codec_, HashFunction_ >::test_set_proof_parsing_state ( std::ptrdiff_t  start,
size_t  written 
)
inline

Test utility: Set proof parsing state for export after deserialization.

Used by test utilities that need to re-export proofs after tampering

Definition at line 475 of file transcript.hpp.

◆ verifier_init_empty()

template<typename Codec_ , typename HashFunction_ >
static std::shared_ptr< BaseTranscript > bb::BaseTranscript< Codec_, HashFunction_ >::verifier_init_empty ( const std::shared_ptr< BaseTranscript< Codec_, HashFunction_ > > &  transcript)
inlinestatic

For testing: initializes transcript based on proof data then receives junk data produced by BaseTranscript::prover_init_empty(). Only intended to be used by Verifier.

Parameters
transcript
Returns
BaseTranscript

Definition at line 453 of file transcript.hpp.

Friends And Related Symbol Documentation

◆ bb::extract_transcript_tag

template<typename Codec_ , typename HashFunction_ >
template<typename T >
OriginTag bb::extract_transcript_tag ( const T &  transcript)
friend

Member Data Documentation

◆ CHALLENGE_BUFFER_SIZE

template<typename Codec_ , typename HashFunction_ >
constexpr size_t bb::BaseTranscript< Codec_, HashFunction_ >::CHALLENGE_BUFFER_SIZE = 2
staticconstexpr

Definition at line 51 of file transcript.hpp.

◆ current_round_data

template<typename Codec_ , typename HashFunction_ >
std::vector<DataType> bb::BaseTranscript< Codec_, HashFunction_ >::current_round_data
private

Definition at line 79 of file transcript.hpp.

◆ in_circuit

template<typename Codec_ , typename HashFunction_ >
constexpr bool bb::BaseTranscript< Codec_, HashFunction_ >::in_circuit = InCircuit<DataType>
staticconstexpr

Definition at line 49 of file transcript.hpp.

◆ is_first_challenge

template<typename Codec_ , typename HashFunction_ >
bool bb::BaseTranscript< Codec_, HashFunction_ >::is_first_challenge = true
private

Definition at line 77 of file transcript.hpp.

◆ manifest

template<typename Codec_ , typename HashFunction_ >
TranscriptManifest bb::BaseTranscript< Codec_, HashFunction_ >::manifest
private

Definition at line 89 of file transcript.hpp.

◆ num_frs_read

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::num_frs_read = 0
private

Definition at line 84 of file transcript.hpp.

◆ num_frs_written

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::num_frs_written = 0
private

Definition at line 83 of file transcript.hpp.

◆ previous_challenge

template<typename Codec_ , typename HashFunction_ >
DataType bb::BaseTranscript< Codec_, HashFunction_ >::previous_challenge {}
private

Definition at line 78 of file transcript.hpp.

◆ proof_data

template<typename Codec_ , typename HashFunction_ >
Proof bb::BaseTranscript< Codec_, HashFunction_ >::proof_data
protected

Definition at line 65 of file transcript.hpp.

◆ proof_start

template<typename Codec_ , typename HashFunction_ >
std::ptrdiff_t bb::BaseTranscript< Codec_, HashFunction_ >::proof_start = 0
private

Definition at line 82 of file transcript.hpp.

◆ reception_phase

template<typename Codec_ , typename HashFunction_ >
bool bb::BaseTranscript< Codec_, HashFunction_ >::reception_phase = true
private

Definition at line 74 of file transcript.hpp.

◆ round_index

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::round_index = 0
private

Definition at line 73 of file transcript.hpp.

◆ round_number

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::round_number = 0
private

Definition at line 85 of file transcript.hpp.

◆ transcript_index

template<typename Codec_ , typename HashFunction_ >
size_t bb::BaseTranscript< Codec_, HashFunction_ >::transcript_index = 0
private

Definition at line 72 of file transcript.hpp.

◆ use_manifest

template<typename Codec_ , typename HashFunction_ >
bool bb::BaseTranscript< Codec_, HashFunction_ >::use_manifest = false
private

Definition at line 88 of file transcript.hpp.


The documentation for this class was generated from the following file: