43class UltraKeccakFlavor;
44#ifdef STARKNET_GARAGA_FLAVORS
45class UltraStarknetFlavor;
46class UltraStarknetZKFlavor;
48class UltraKeccakZKFlavor;
52class TranslatorFlavor;
53class ECCVMRecursiveFlavor;
54class TranslatorRecursiveFlavor;
55class MultilinearBatchingRecursiveFlavor;
57template <
typename BuilderType>
class UltraRecursiveFlavor_;
58template <
typename BuilderType>
class UltraZKRecursiveFlavor_;
59template <
typename BuilderType>
class MegaRecursiveFlavor_;
60template <
typename BuilderType>
class MegaZKRecursiveFlavor_;
61template <
typename BuilderType>
class MegaAvmRecursiveFlavor_;
63class AvmRecursiveFlavor;
84template <
typename Polynomial,
size_t NUM_PRECOMPUTED_ENTITIES>
struct PrecomputedData_ {
100template <
typename PrecomputedCommitments,
typename HashType,
typename HardcodedVKAndHash>
103 using Commitment =
typename PrecomputedCommitments::DataType;
109 :
hash(HardcodedVKAndHash::vk_hash())
111 for (
auto [vk_commitment, fixed_commitment] :
zip_view(this->get_all(), HardcodedVKAndHash::get_all())) {
112 vk_commitment = fixed_commitment;
134template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey =
void>
137 using Commitment =
typename PrecomputedCommitments::DataType;
145 template <
size_t NUM_PRECOMPUTED_ENTITIES,
typename StringType>
149 bool is_equal =
true;
166 for (
auto [this_comm, other_comm, label] :
zip_view(this->get_all(), other.get_all(), commitment_labels)) {
167 if (this_comm != other_comm) {
168 info(
"Commitment mismatch: ", label);
183 template <
typename PrecomputedData>
190 CommitmentKey commitment_key{ precomputed.metadata.dyadic_size };
191 for (
auto [polynomial, commitment] :
zip_view(precomputed.polynomials, this->get_all())) {
192 commitment = commitment_key.
commit(polynomial);
202 size_t commitments_size = PrecomputedCommitments::size() * Codec::template calc_num_fields<Commitment>();
204 return metadata_size + commitments_size;
215 auto serialize = [](
const auto& input, std::vector<DataType>&
buffer) {
216 std::vector<DataType> input_fields = Codec::serialize_to_fields(input);
217 buffer.insert(
buffer.end(), input_fields.begin(), input_fields.end());
220 std::vector<DataType> elements;
222 serialize(this->log_circuit_size, elements);
223 serialize(this->num_public_inputs, elements);
224 serialize(this->pub_inputs_offset, elements);
226 for (
const Commitment& commitment : this->get_all()) {
241 auto deserialize = [&idx, &elements]<
typename T>(T& target) {
242 size_t size = Codec::template calc_num_fields<T>();
243 target = Codec::template deserialize_from_fields<T>(elements.subspan(idx, size));
247 deserialize(this->log_circuit_size);
248 deserialize(this->num_public_inputs);
249 deserialize(this->pub_inputs_offset);
251 for (
Commitment& commitment : this->get_all()) {
252 deserialize(commitment);
279 std::vector<DataType> vk_elements;
282 auto tag_and_append = [&]<
typename T>(
const T& component) {
283 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
284 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
288 tag_and_append(this->log_circuit_size);
289 tag_and_append(this->num_public_inputs);
290 tag_and_append(this->pub_inputs_offset);
294 for (
const Commitment& commitment : this->get_all()) {
295 tag_and_append(commitment);
299 bb::unset_free_witness_tags<in_circuit, DataType>(vk_elements);
302 return HashFunction::hash(vk_elements);
329template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey>
333 using Commitment =
typename PrecomputedCommitments::DataType;
345 for (
auto [native_comm, comm] :
zip_view(native_key->get_all(), this->get_all())) {
346 comm = Commitment::from_witness(
builder, native_comm);
350 for (
Commitment& commitment : this->get_all()) {
351 commitment.fix_witness();
370template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey_ =
void>
375 using Commitment =
typename PrecomputedCommitments::DataType;
390 template <
typename T = NativeVerificationKey_>
398 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_key->get_all())) {
399 commitment = Commitment::from_witness(
builder, native_commitment);
410 size_t num_frs_read = 0;
412 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
413 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
414 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
416 for (
Commitment& commitment : this->get_all()) {
417 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
425 const std::span<const uint32_t>& witness_indices)
427 std::vector<FF> vk_fields;
428 vk_fields.reserve(witness_indices.size());
429 for (
const auto& idx : witness_indices) {
443 for (
Commitment& commitment : this->get_all()) {
444 commitment.fix_witness();
453 template <
typename T = NativeVerificationKey_>
458 native_vk.log_circuit_size =
static_cast<uint64_t
>(this->log_circuit_size.
get_value());
459 native_vk.num_public_inputs =
static_cast<uint64_t
>(this->num_public_inputs.
get_value());
460 native_vk.pub_inputs_offset =
static_cast<uint64_t
>(this->pub_inputs_offset.
get_value());
461 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_vk.get_all())) {
462 native_commitment = commitment.get_value();
480 static constexpr bool in_circuit =
true;
481 std::vector<FF> vk_elements;
484 auto append_tagged = [&]<
typename T>(
const T& component) {
485 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
486 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
490 append_tagged(this->log_circuit_size);
491 append_tagged(this->num_public_inputs);
492 append_tagged(this->pub_inputs_offset);
496 for (
const Commitment& commitment : this->get_all()) {
497 append_tagged(commitment);
501 bb::unset_free_witness_tags<in_circuit, FF>(vk_elements);
541template <
typename FF,
typename VerificationKey>
class VKAndHash_ {
543 template <
typename T = VerificationKey>
546 template <
typename T = VerificationKey>
572 typename B =
typename VK::Builder,
573 typename NVK =
typename VK::NativeVerificationKey>
578 std::shared_ptr<VerificationKey>
vk;
584template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey>
585inline void read(uint8_t
const*& it,
592 size_t num_frs = VK::calc_num_data_types();
596 for (
auto& element : field_elements) {
600 vk.from_field_elements(field_elements);
603template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey>
610 size_t before =
buf.size();
613 for (
const auto& element : field_elements) {
616 size_t after =
buf.size();
617 size_t num_frs = VK::calc_num_data_types();
#define BB_ASSERT_EQ(actual, expected,...)
Common transcript class for both parties. Stores the data for the current round, as well as the manif...
CommitmentKey object over a pairing group 𝔾₁.
Commitment commit(PolynomialSpan< const Fr > polynomial) const
Uses the ProverSRS to create a commitment to p(X)
Simple stdlib verification key class for fixed-size circuits (ECCVM, Translator, AVM).
FixedStdlibVKAndHash_(Builder *builder, const std::shared_ptr< NativeVerificationKey > &native_key)
Construct from native verification key and fix all witnesses (VK is constant for fixed circuits)
typename PrecomputedCommitments::DataType Commitment
FixedStdlibVKAndHash_()=default
bool operator==(const FixedStdlibVKAndHash_ &) const =default
Simple verification key class for fixed-size circuits (ECCVM, Translator, AVM).
bool operator==(const FixedVKAndHash_ &) const =default
HashType get_hash() const
typename PrecomputedCommitments::DataType Commitment
Base Native verification key class.
uint64_t pub_inputs_offset
uint64_t num_public_inputs
uint64_t log_circuit_size
static size_t calc_num_data_types()
Calculate the number of field elements needed for serialization.
NativeVerificationKey_()=default
bool operator==(const NativeVerificationKey_ &) const =default
bool compare(const NativeVerificationKey_ &other, RefArray< StringType, NUM_PRECOMPUTED_ENTITIES > commitment_labels) const
typename Codec::DataType DataType
virtual DataType hash_with_origin_tagging(const OriginTag &tag) const
Tag VK components and hash.
fr hash() const
Compute VK hash.
DataType hash_with_origin_tagging(const Transcript &transcript) const
An overload that accepts a transcript and extracts the tag internally.
size_t from_field_elements(const std::span< const DataType > &elements)
Populate verification key from field elements.
NativeVerificationKey_(const PrecomputedData &precomputed)
Construct VK from precomputed data by committing to polynomials.
virtual ~NativeVerificationKey_()=default
typename PrecomputedCommitments::DataType Commitment
virtual std::vector< DataType > to_field_elements() const
Serialize verification key to field elements.
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Base Stdlib verification key class.
bool operator==(const StdlibVerificationKey_ &) const =default
T get_value() const
Get the native verification key corresponding to this stdlib verification key.
typename PrecomputedCommitments::DataType Commitment
void fix_witness()
Fixes witnesses of VK to be constants.
StdlibVerificationKey_(Builder *builder, const std::shared_ptr< T > &native_key)
Construct a new Verification Key with stdlib types from a provided native verification key.
StdlibVerificationKey_()=default
StdlibVerificationKey_(std::span< FF > elements)
Deserialize a verification key from a vector of field elements.
FF hash_with_origin_tagging(const Transcript &transcript) const
An overload that accepts a transcript and extracts the tag internally.
virtual FF hash_with_origin_tagging(const OriginTag &tag) const
Tag VK components and hash.
virtual ~StdlibVerificationKey_()=default
static StdlibVerificationKey_ from_witness_indices(Builder &builder, const std::span< const uint32_t > &witness_indices)
Construct a VerificationKey from a set of corresponding witness indices.
Wrapper holding a verification key and its precomputed hash.
VKAndHash_(B &builder, const std::shared_ptr< NVK > &native_vk)
Construct stdlib VKAndHash from a native VK (recursive verification keys only).
typename std::enable_if_t< requires { typename T::NativeVerificationKey NativeVerificationKey
std::shared_ptr< VerificationKey > vk
typename std::enable_if_t< requires { typename T::Builder Builder
VKAndHash_(const std::shared_ptr< VerificationKey > &vk, const FF &hash)
Construct from VK and pre-provided hash.
VKAndHash_(const std::shared_ptr< VerificationKey > &vk)
Construct from VK, auto-computing the hash.
static FF hash(const std::vector< FF > &input)
Hashes a vector of field elements.
static field_t from_witness_index(Builder *ctx, uint32_t witness_index)
bb::fr get_value() const
Given a := *this, compute its value given by a.v * a.mul + a.add.
static field_t from_witness(Builder *ctx, const bb::fr &input)
std::unique_ptr< uint8_t[]> buffer
UltraKeccakFlavor::VerificationKey VerificationKey
constexpr T get_msb(const T in)
Entry point for Barretenberg command-line interface.
void read(B &it, field2< base_field, Params > &value)
void write(B &buf, field2< base_field, Params > const &value)
OriginTag extract_transcript_tag(const TranscriptType &transcript)
Extract origin tag context from a transcript.
VerifierCommitmentKey< Curve > vk
void read(auto &it, msgpack_concepts::HasMsgPack auto &obj)
Automatically derived read for any object that defines .msgpack() (implicitly defined by MSGPACK_FIEL...
void write(auto &buf, const msgpack_concepts::HasMsgPack auto &obj)
Automatically derived write for any object that defines .msgpack() (implicitly defined by MSGPACK_FIE...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
StdlibCodec for in-circuit (recursive) verification transcript handling.
The precomputed data needed to compute a Honk VK.
RefArray< Polynomial, NUM_PRECOMPUTED_ENTITIES > polynomials