barretenberg
Loading...
Searching...
No Matches
transcript.hpp
1#pragma once
2
3#include "barretenberg/ecc/curves/bn254/fq.hpp"
4#include "barretenberg/ecc/curves/bn254/fr.hpp"
5#include "barretenberg/ecc/curves/bn254/g1.hpp"
6#include "barretenberg/polynomials/univariate.hpp"
7
8#include "barretenberg/transcript/transcript.hpp"
9
10#include "barretenberg/stdlib/primitives/bigfield/bigfield.hpp"
11#include "barretenberg/stdlib/primitives/biggroup/biggroup.hpp"
12#include "barretenberg/stdlib/primitives/field/field.hpp"
13#include "barretenberg/stdlib/utility/utility.hpp"
14
15// Note: this namespace will be sensible once stdlib is moved out of the plonk namespace
16namespace proof_system::plonk::stdlib::recursion::honk {
17template <typename Builder> class Transcript {
18 public:
20 using FF = barretenberg::fr;
23
24 static constexpr size_t HASH_OUTPUT_SIZE = BaseTranscript::HASH_OUTPUT_SIZE;
25
26 BaseTranscript native_transcript;
27 Builder* builder;
28
29 Transcript() = default;
30
31 Transcript(Builder* builder, auto proof_data)
32 : native_transcript(proof_data)
33 , builder(builder){};
34
39 auto get_manifest() const { return native_transcript.get_manifest(); };
40
48 template <typename... Strings> std::array<field_ct, sizeof...(Strings)> get_challenges(const Strings&... labels)
49 {
50 // Compute the indicated challenges from the native transcript
51 constexpr size_t num_challenges = sizeof...(Strings);
52 std::array<uint256_t, num_challenges> native_challenges{};
53 native_challenges = native_transcript.get_challenges(labels...);
54
55 /*
56 * TODO(#1351): Do stdlib hashing here. E.g., for the current pedersen/blake setup, we could write data into a
57 * byte_array as it is received from prover, then compress via pedersen and apply blake3s. Not doing this now
58 * since it's a pain and we'll be revamping our hashing anyway. For now, simply convert the native hashes to
59 * stdlib types without adding any hashing constraints.
60 */
61 std::array<field_ct, num_challenges> challenges;
62 for (size_t i = 0; i < num_challenges; ++i) {
63 challenges[i] = field_ct::from_witness(builder, static_cast<FF>(native_challenges[i]));
64 }
65
66 return challenges;
67 }
68
75 field_ct get_challenge(const std::string& label)
76 {
77 // Compute the indicated challenge from the native transcript
78 auto native_challenge = native_transcript.get_challenge(label);
79
80 // TODO(1351): Stdlib hashing here...
81
82 return field_ct::from_witness(builder, native_challenge);
83 }
84
92 template <class T> auto receive_from_prover(const std::string& label)
93 {
94 // Get native type corresponding to input type
95 using NativeType = typename StdlibTypes::template NativeType<T>::type;
96
97 // Extract the native element from the native transcript
98 NativeType element = native_transcript.template receive_from_prover<NativeType>(label);
99
100 // Return the corresponding stdlib type
101 return StdlibTypes::from_witness(builder, element);
102 }
103};
104} // namespace proof_system::plonk::stdlib::recursion::honk
Definition: ultra_circuit_builder.hpp:31
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
Definition: transcript.hpp:62
std::array< uint256_t, 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...
Definition: transcript.hpp:226
Definition: biggroup.hpp:22
Definition: field.hpp:10
std::array< field_ct, sizeof...(Strings)> get_challenges(const Strings &... labels)
Compute the challenges (more than 1) indicated by labels.
Definition: transcript.hpp:48
field_ct get_challenge(const std::string &label)
Compute the single challenge indicated by the input label.
Definition: transcript.hpp:75
auto receive_from_prover(const std::string &label)
Extract a native element from the transcript and return a corresponding stdlib type.
Definition: transcript.hpp:92
auto get_manifest() const
Get the underlying native transcript manifest (primarily for debugging)
Definition: transcript.hpp:39
Utility class for converting native types to corresponding stdlib types.
Definition: utility.hpp:26
static field_ct from_witness(Builder *builder, uint32_t native_element)
Construct stdlib field from uint32_t.
Definition: utility.hpp:42