43class UltraKeccakFlavor;
44#ifdef STARKNET_GARAGA_FLAVORS
45class UltraStarknetFlavor;
46class UltraStarknetZKFlavor;
48class UltraKeccakZKFlavor;
52class TranslatorFlavor;
53class TranslatorShortMonomialFlavor;
54class ECCVMShortMonomialFlavor;
55class ECCVMRecursiveFlavor;
56class TranslatorRecursiveFlavor;
57class MultilinearBatchingRecursiveFlavor;
59template <
typename BuilderType>
class UltraRecursiveFlavor_;
60template <
typename BuilderType>
class UltraZKRecursiveFlavor_;
61template <
typename BuilderType>
class MegaRecursiveFlavor_;
62template <
typename BuilderType>
class MegaZKRecursiveFlavor_;
63template <
typename BuilderType>
class MegaAvmRecursiveFlavor_;
65class AvmRecursiveFlavor;
86template <
typename Polynomial,
size_t NUM_PRECOMPUTED_ENTITIES>
struct PrecomputedData_ {
102template <
typename PrecomputedCommitments,
typename HashType,
typename HardcodedVKAndHash>
105 using Commitment =
typename PrecomputedCommitments::DataType;
111 :
hash(HardcodedVKAndHash::vk_hash())
113 for (
auto [vk_commitment, fixed_commitment] :
zip_view(this->get_all(), HardcodedVKAndHash::get_all())) {
114 vk_commitment = fixed_commitment;
136template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey =
void>
139 using Commitment =
typename PrecomputedCommitments::DataType;
147 template <
size_t NUM_PRECOMPUTED_ENTITIES,
typename StringType>
151 bool is_equal =
true;
168 for (
auto [this_comm, other_comm, label] :
zip_view(this->get_all(), other.get_all(), commitment_labels)) {
169 if (this_comm != other_comm) {
170 info(
"Commitment mismatch: ", label);
185 template <
typename PrecomputedData>
192 CommitmentKey commitment_key{ precomputed.metadata.dyadic_size };
193 for (
auto [polynomial, commitment] :
zip_view(precomputed.polynomials, this->get_all())) {
194 commitment = commitment_key.
commit(polynomial);
204 size_t commitments_size = PrecomputedCommitments::size() * Codec::template calc_num_fields<Commitment>();
206 return metadata_size + commitments_size;
217 auto serialize = [](
const auto& input, std::vector<DataType>&
buffer) {
218 std::vector<DataType> input_fields = Codec::serialize_to_fields(input);
219 buffer.insert(
buffer.end(), input_fields.begin(), input_fields.end());
222 std::vector<DataType> elements;
224 serialize(this->log_circuit_size, elements);
225 serialize(this->num_public_inputs, elements);
226 serialize(this->pub_inputs_offset, elements);
228 for (
const Commitment& commitment : this->get_all()) {
243 auto deserialize = [&idx, &elements]<
typename T>(T& target) {
244 size_t size = Codec::template calc_num_fields<T>();
245 target = Codec::template deserialize_from_fields<T>(elements.subspan(idx, size));
249 deserialize(this->log_circuit_size);
250 deserialize(this->num_public_inputs);
251 deserialize(this->pub_inputs_offset);
253 for (
Commitment& commitment : this->get_all()) {
254 deserialize(commitment);
281 std::vector<DataType> vk_elements;
284 auto tag_and_append = [&]<
typename T>(
const T& component) {
285 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
286 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
290 tag_and_append(this->log_circuit_size);
291 tag_and_append(this->num_public_inputs);
292 tag_and_append(this->pub_inputs_offset);
296 for (
const Commitment& commitment : this->get_all()) {
297 tag_and_append(commitment);
301 bb::unset_free_witness_tags<in_circuit, DataType>(vk_elements);
304 return HashFunction::hash(vk_elements);
331template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey>
335 using Commitment =
typename PrecomputedCommitments::DataType;
347 for (
auto [native_comm, comm] :
zip_view(native_key->get_all(), this->get_all())) {
348 comm = Commitment::from_witness(
builder, native_comm);
352 for (
Commitment& commitment : this->get_all()) {
353 commitment.fix_witness();
372template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey_ =
void>
377 using Commitment =
typename PrecomputedCommitments::DataType;
392 template <
typename T = NativeVerificationKey_>
400 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_key->get_all())) {
401 commitment = Commitment::from_witness(
builder, native_commitment);
412 size_t num_frs_read = 0;
414 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
415 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
416 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
418 for (
Commitment& commitment : this->get_all()) {
419 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
427 const std::span<const uint32_t>& witness_indices)
429 std::vector<FF> vk_fields;
430 vk_fields.reserve(witness_indices.size());
431 for (
const auto& idx : witness_indices) {
445 for (
Commitment& commitment : this->get_all()) {
446 commitment.fix_witness();
455 template <
typename T = NativeVerificationKey_>
460 native_vk.log_circuit_size =
static_cast<uint64_t
>(this->log_circuit_size.
get_value());
461 native_vk.num_public_inputs =
static_cast<uint64_t
>(this->num_public_inputs.
get_value());
462 native_vk.pub_inputs_offset =
static_cast<uint64_t
>(this->pub_inputs_offset.
get_value());
463 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_vk.get_all())) {
464 native_commitment = commitment.get_value();
482 static constexpr bool in_circuit =
true;
483 std::vector<FF> vk_elements;
486 auto append_tagged = [&]<
typename T>(
const T& component) {
487 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
488 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
492 append_tagged(this->log_circuit_size);
493 append_tagged(this->num_public_inputs);
494 append_tagged(this->pub_inputs_offset);
498 for (
const Commitment& commitment : this->get_all()) {
499 append_tagged(commitment);
503 bb::unset_free_witness_tags<in_circuit, FF>(vk_elements);
543template <
typename FF,
typename VerificationKey>
class VKAndHash_ {
545 template <
typename T = VerificationKey>
548 template <
typename T = VerificationKey>
574 typename B =
typename VK::Builder,
575 typename NVK =
typename VK::NativeVerificationKey>
580 std::shared_ptr<VerificationKey>
vk;
586template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey>
587inline void read(uint8_t
const*& it,
594 size_t num_frs = VK::calc_num_data_types();
598 for (
auto& element : field_elements) {
602 vk.from_field_elements(field_elements);
605template <
typename PrecomputedCommitments,
typename Codec,
typename HashFunction,
typename CommitmentKey>
606inline void write(std::vector<uint8_t>& buf,
612 size_t before = buf.size();
615 for (
const auto& element : field_elements) {
618 size_t after = buf.size();
619 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, bool has_duplicates_hint=false) 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
NativeVerificationKey_()=default
bool operator==(const NativeVerificationKey_ &) const =default
bool compare(const NativeVerificationKey_ &other, RefArray< StringType, NUM_PRECOMPUTED_ENTITIES > commitment_labels) const
static constexpr size_t calc_num_data_types()
Calculate the number of field elements needed for serialization.
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 SERIALIZATIO...
void write(auto &buf, const msgpack_concepts::HasMsgPack auto &obj)
Automatically derived write for any object that defines .msgpack() (implicitly defined by SERIALIZATI...
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