|
Barretenberg
The ZK-SNARK library at the core of Aztec
|
Common transcript class for both parties. Stores the data for the current round, as well as the manifest. More...
#include <transcript.hpp>
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< DataType > | export_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 > | generate_challenges (std::span< const std::string > labels, auto &&fill) |
Shared core of get_challenges / get_short_challenges: the bookkeeping common to every challenge round (manifest, free-witness sanitization, phase flag, origin tags). The full and short paths differ only in how the challenge vector is filled, which the caller supplies via fill. | |
| template<typename ChallengeType > | |
| std::vector< ChallengeType > | get_short_challenges (std::span< const std::string > labels) |
| Generate short (127-bit) challenges for the given labels. | |
| template<typename ChallengeType > | |
| std::vector< ChallengeType > | get_challenges (std::span< const std::string > labels) |
| Generate full-width (~254-bit) challenges for the given labels (the default). | |
| template<typename ChallengeType , size_t N> | |
| std::array< ChallengeType, N > | get_short_challenges (const std::array< std::string, N > &labels) |
| Wrapper around get_short_challenges to handle array of 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 > | |
| 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) |
Generate a single full-width (~254-bit) challenge for label (the default). See get_challenges. | |
| template<typename ChallengeType > | |
| ChallengeType | get_short_challenge (const std::string &label) |
Generate a single short (127-bit) challenge for label. See get_short_challenges. | |
| const 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. | |
| Proof & | test_get_proof_data () |
| Test utility: Get mutable reference to proof_data. | |
| const Proof & | test_get_proof_data () const |
Static Public Member Functions | |
| 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. | |
| template<typename T > | |
| static std::vector< DataType > | serialize (const T &element) |
| template<typename T > | |
| static T | deserialize (std::span< const DataType > frs) |
| static std::shared_ptr< BaseTranscript > | test_prover_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< 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 BaseTranscript::test_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 > | |
| 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 | |
| DataType | get_next_challenge_hash () |
| Compute the next challenge c_next = H( Compress(c_prev || round_buffer) ). | |
| std::array< DataType, CHALLENGE_BUFFER_SIZE > | get_next_duplex_challenge_buffer () |
| Compute the next challenge and split it into the two 127-bit limbs of the short-challenge buffer. | |
Private Attributes | |
| size_t | transcript_index = 0 |
| size_t | round_index = 0 |
| bool | challenge_generation_phase = false |
| bool | is_first_challenge = true |
| DataType | previous_challenge {} |
| std::vector< DataType > | current_round_data |
| std::ptrdiff_t | proof_start = 0 |
| size_t | num_frs_written = 0 |
| size_t | num_frs_read = 0 |
| bool | use_manifest = false |
| TranscriptManifest | manifest |
Friends | |
| template<typename T > | |
| OriginTag | bb::extract_transcript_tag (const T &transcript) |
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.
| using bb::BaseTranscript< Codec_, HashFunction_ >::Codec = Codec_ |
Definition at line 43 of file transcript.hpp.
| using bb::BaseTranscript< Codec_, HashFunction_ >::DataType = typename Codec::DataType |
Definition at line 45 of file transcript.hpp.
| using bb::BaseTranscript< Codec_, HashFunction_ >::HashFunction = HashFunction_ |
Definition at line 44 of file transcript.hpp.
| using bb::BaseTranscript< Codec_, HashFunction_ >::Proof = std::vector<DataType> |
Definition at line 46 of file transcript.hpp.
|
inline |
Definition at line 53 of file transcript.hpp.
|
inlineexplicit |
Definition at line 62 of file transcript.hpp.
|
inlineprotected |
Adds challenge elements to the current_round_buffer and updates the manifest.
| label | of the element sent |
| element_frs | serialized |
Definition at line 147 of file transcript.hpp.
|
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.
| label | Human-readable name for the challenge. |
| element | Element to be added. |
Definition at line 365 of file transcript.hpp.
|
inlinestatic |
Convert a prover transcript to a verifier transcript.
| prover_transcript | The prover transcript to convert |
Definition at line 479 of file transcript.hpp.
|
inlinestatic |
Definition at line 496 of file transcript.hpp.
|
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.
| T |
| proof_data | |
| offset |
Definition at line 179 of file transcript.hpp.
|
inline |
Definition at line 225 of file transcript.hpp.
|
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 202 of file transcript.hpp.
|
inline |
Shared core of get_challenges / get_short_challenges: the bookkeeping common to every challenge round (manifest, free-witness sanitization, phase flag, origin tags). The full and short paths differ only in how the challenge vector is filled, which the caller supplies via fill.
| fill | Callback that populates the (pre-sized) challenge vector; it owns the squeeze loop. |
Definition at line 235 of file transcript.hpp.
|
inline |
Generate a single full-width (~254-bit) challenge for label (the default). See get_challenges.
| label | Human-readable name for the challenge (recorded in the manifest). |
Definition at line 452 of file transcript.hpp.
|
inline |
Wrapper around get_challenges to handle array of challenges.
| array | of labels human-readable names for the challenges for the manifest |
Definition at line 327 of file transcript.hpp.
|
inline |
Generate full-width (~254-bit) challenges for the given labels (the default).
One transcript hash yields one full field challenge.
| labels | human-readable names for the challenges for the manifest |
Definition at line 297 of file transcript.hpp.
|
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.
| label | Human-readable name for the challenge |
| num_challenges | Number of power-of-2 powers to generate |
Definition at line 345 of file transcript.hpp.
|
inline |
Definition at line 501 of file transcript.hpp.
|
inlineprivate |
Compute the next challenge c_next = H( Compress(c_prev || round_buffer) ).
Computes a new challenge for the current round using the previous challenge and the current round data, if they exist. Clears current_round_data after hashing to minimize how much we compress, and sets previous_challenge to the new challenge to set up the next call.
Definition at line 97 of file transcript.hpp.
|
inlineprivate |
Compute the next challenge and split it into the two 127-bit limbs of the short-challenge buffer.
Thin wrapper around get_next_challenge_hash.
Definition at line 135 of file transcript.hpp.
|
inline |
Definition at line 222 of file transcript.hpp.
|
inline |
Generate a single short (127-bit) challenge for label. See get_short_challenges.
Definition at line 464 of file transcript.hpp.
|
inline |
Wrapper around get_short_challenges to handle array of challenges.
Definition at line 311 of file transcript.hpp.
|
inline |
Generate short (127-bit) challenges for the given labels.
Each transcript hash is split into two 127-bit limbs, so two challenges are produced per hash. get_challenges (full width) is the default.
| labels | human-readable names for the challenges for the manifest |
Definition at line 272 of file transcript.hpp.
|
inline |
Verifier-specific method. The verifier needs to load a proof or its segment before the verification.
| proof |
Definition at line 216 of file transcript.hpp.
|
inline |
Definition at line 503 of file transcript.hpp.
|
inline |
Reads the next element of type T from the transcript, with a predefined label, only used by verifier.
| label | Human readable name for the challenge. |
Definition at line 418 of file transcript.hpp.
|
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.
| label | Description/name of the object being added. |
| element | Serializable object that will be added to the transcript |
Definition at line 394 of file transcript.hpp.
|
inlinestatic |
Definition at line 491 of file transcript.hpp.
|
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.
| T |
| element | |
| proof_data |
Definition at line 165 of file transcript.hpp.
|
inline |
Test utility: Get mutable reference to proof_data.
Used by test utilities that need to deserialize/serialize proof structure
Definition at line 561 of file transcript.hpp.
|
inline |
Definition at line 562 of file transcript.hpp.
|
inline |
Test utility: Get proof_start for validation.
Used by test fixtures to verify transcript conversion
Definition at line 555 of file transcript.hpp.
|
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.
Definition at line 519 of file transcript.hpp.
|
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 545 of file transcript.hpp.
|
inlinestatic |
For testing: initializes transcript based on proof data then receives junk data produced by BaseTranscript::test_prover_init_empty(). Only intended to be used by Verifier.
| transcript |
Definition at line 534 of file transcript.hpp.
|
friend |
|
staticconstexpr |
Definition at line 51 of file transcript.hpp.
|
private |
Definition at line 74 of file transcript.hpp.
|
private |
Definition at line 79 of file transcript.hpp.
|
staticconstexpr |
Definition at line 49 of file transcript.hpp.
|
private |
Definition at line 77 of file transcript.hpp.
|
private |
Definition at line 88 of file transcript.hpp.
|
private |
Definition at line 84 of file transcript.hpp.
|
private |
Definition at line 83 of file transcript.hpp.
|
private |
Definition at line 78 of file transcript.hpp.
|
protected |
Definition at line 65 of file transcript.hpp.
|
private |
Definition at line 82 of file transcript.hpp.
|
private |
Definition at line 73 of file transcript.hpp.
|
private |
Definition at line 72 of file transcript.hpp.
|
private |
Definition at line 87 of file transcript.hpp.