136template <
typename PrecomputedCommitments,
138 typename HashFunction,
143 using Commitment =
typename PrecomputedCommitments::DataType;
151 template <
size_t NUM_PRECOMPUTED_ENTITIES,
typename StringType>
155 bool is_equal =
true;
172 for (
auto [this_comm, other_comm, label] :
zip_view(this->get_all(), other.get_all(), commitment_labels)) {
173 if (this_comm != other_comm) {
174 info(
"Commitment mismatch: ", label);
192 template <
typename PrecomputedData>
200 for (
auto [polynomial, commitment] :
zip_view(precomputed.polynomials, this->get_all())) {
201 commitment = commitment_key.commit(polynomial);
212 size_t commitments_size = PrecomputedCommitments::size() * Codec::template calc_num_fields<Commitment>();
213 size_t metadata_size = 0;
216 metadata_size = 3 * Codec::template calc_num_fields<uint64_t>();
219 return metadata_size + commitments_size;
230 auto serialize = [](
const auto& input, std::vector<DataType>&
buffer) {
231 std::vector<DataType> input_fields = Codec::serialize_to_fields(input);
232 buffer.insert(
buffer.end(), input_fields.begin(), input_fields.end());
235 std::vector<DataType> elements;
238 serialize(this->log_circuit_size, elements);
239 serialize(this->num_public_inputs, elements);
240 serialize(this->pub_inputs_offset, elements);
244 for (
const Commitment& commitment : this->get_all()) {
249 key.from_field_elements(elements);
261 auto deserialize = [&idx, &elements]<
typename T>(T& target) {
262 size_t size = Codec::template calc_num_fields<T>();
263 target = Codec::template deserialize_from_fields<T>(elements.subspan(idx, size));
268 deserialize(this->log_circuit_size);
269 deserialize(this->num_public_inputs);
270 deserialize(this->pub_inputs_offset);
274 for (
Commitment& commitment : this->get_all()) {
275 deserialize(commitment);
303 std::vector<DataType> vk_elements;
306 auto tag_and_append = [&]<
typename T>(
const T& component) {
307 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
308 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
312 tag_and_append(this->log_circuit_size);
313 tag_and_append(this->num_public_inputs);
314 tag_and_append(this->pub_inputs_offset);
317 for (
const Commitment& commitment : this->get_all()) {
318 tag_and_append(commitment);
322 bb::unset_free_witness_tags<in_circuit, DataType>(vk_elements);
325 return HashFunction::hash(vk_elements);
349template <
typename Builder_,
350 typename PrecomputedCommitments,
351 typename NativeVerificationKey_ = void,
357 using Commitment =
typename PrecomputedCommitments::DataType;
372 template <
typename T = NativeVerificationKey_>
380 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_key->get_all())) {
381 commitment = Commitment::from_witness(
builder, native_commitment);
392 size_t num_frs_read = 0;
394 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
395 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
396 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
398 for (
Commitment& commitment : this->get_all()) {
399 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
407 const std::span<const uint32_t>& witness_indices)
409 std::vector<FF> vk_fields;
410 vk_fields.reserve(witness_indices.size());
411 for (
const auto& idx : witness_indices) {
425 for (
Commitment& commitment : this->get_all()) {
426 commitment.fix_witness();
435 template <
typename T = NativeVerificationKey_>
440 native_vk.log_circuit_size =
static_cast<uint64_t
>(this->log_circuit_size.
get_value());
441 native_vk.num_public_inputs =
static_cast<uint64_t
>(this->num_public_inputs.
get_value());
442 native_vk.pub_inputs_offset =
static_cast<uint64_t
>(this->pub_inputs_offset.
get_value());
443 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_vk.get_all())) {
444 native_commitment = commitment.get_value();
463 static constexpr bool in_circuit =
true;
464 std::vector<FF> vk_elements;
467 auto append_tagged = [&]<
typename T>(
const T& component) {
468 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
469 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
473 append_tagged(this->log_circuit_size);
474 append_tagged(this->num_public_inputs);
475 append_tagged(this->pub_inputs_offset);
478 for (
const Commitment& commitment : this->get_all()) {
479 append_tagged(commitment);
483 bb::unset_free_witness_tags<in_circuit, FF>(vk_elements);
521template <
typename FF,
typename VerificationKey>
class VKAndHash_ {
523 template <
typename T = VerificationKey>
526 template <
typename T = VerificationKey>
552 typename B =
typename VK::Builder,
553 typename NVK =
typename VK::NativeVerificationKey>
558 std::shared_ptr<VerificationKey>
vk;
571 return std::max({ std::tuple_element_t<Is, Tuple>::RELATION_LENGTH... });
582 return (0 + ... + std::tuple_element_t<I, Tuple>::SUBRELATION_PARTIAL_LENGTHS.size());
597 typename std::tuple_element_t<I, RelationsTuple>::SumcheckTupleOfUnivariatesOverSubrelations{}...);
620 typename std::tuple_element_t<I, RelationsTuple>::SumcheckArrayOfValuesOverSubrelations{}...);
630class UltraRollupFlavor;
632class UltraKeccakFlavor;
633#ifdef STARKNET_GARAGA_FLAVORS
634class UltraStarknetFlavor;
635class UltraStarknetZKFlavor;
637class UltraKeccakZKFlavor;
641class TranslatorFlavor;
642class ECCVMRecursiveFlavor;
643class TranslatorRecursiveFlavor;
644class AvmRecursiveFlavor;
645class MultilinearBatchingRecursiveFlavor;
647template <
typename BuilderType>
class UltraRecursiveFlavor_;
648template <
typename BuilderType>
class UltraZKRecursiveFlavor_;
649template <
typename BuilderType>
class UltraRollupRecursiveFlavor_;
650template <
typename BuilderType>
class MegaRecursiveFlavor_;
651template <
typename BuilderType>
class MegaZKRecursiveFlavor_;
652template <
typename BuilderType>
class MegaAvmRecursiveFlavor_;
657template <
typename PrecomputedCommitments,
659 typename HashFunction,
660 typename CommitmentKey,
670 size_t num_frs = VK::calc_num_data_types();
674 for (
auto& element : field_elements) {
678 vk.from_field_elements(field_elements);
681template <
typename PrecomputedCommitments,
683 typename HashFunction,
684 typename CommitmentKey,
687 std::vector<uint8_t>&
buf,
693 size_t before =
buf.size();
696 for (
const auto& element : field_elements) {
699 size_t after =
buf.size();
700 size_t num_frs = VK::calc_num_data_types();
705class AvmRecursiveFlavor;
#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 𝔾₁.
Base Native verification key class.
DataType hash_with_origin_tagging(const Transcript &transcript) const
An overload that accepts a transcript and extracts the tag internally.
fr hash() const
Compute VK hash.
static size_t calc_num_data_types()
Calculate the number of field elements needed for serialization.
uint64_t log_circuit_size
uint64_t num_public_inputs
bool operator==(const NativeVerificationKey_ &) const =default
NativeVerificationKey_()=default
uint64_t pub_inputs_offset
size_t from_field_elements(const std::span< const DataType > &elements)
Populate verification key from field elements.
virtual ~NativeVerificationKey_()=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.
NativeVerificationKey_(const PrecomputedData &precomputed)
Construct VK from precomputed data by committing to polynomials.
virtual std::vector< DataType > to_field_elements() const
Serialize verification key to field elements.
typename PrecomputedCommitments::DataType Commitment
NativeVerificationKey_(const size_t circuit_size, const size_t num_public_inputs)
A template class for a reference array. Behaves as if std::array<T&, N> was possible.
Base Stdlib verification key class.
StdlibVerificationKey_(std::span< FF > elements)
Deserialize a verification key from a vector of field elements.
void fix_witness()
Fixes witnesses of VK to be constants.
typename PrecomputedCommitments::DataType Commitment
FF hash_with_origin_tagging(const Transcript &transcript) const
An overload that accepts a transcript and extracts the tag internally.
bool operator==(const StdlibVerificationKey_ &) const =default
T get_value() const
Get the native verification key corresponding to this stdlib verification key.
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.
StdlibVerificationKey_()=default
StdlibVerificationKey_(Builder *builder, const std::shared_ptr< T > &native_key)
Construct a new Verification Key with stdlib types from a provided native verification key.
virtual FF hash_with_origin_tagging(const OriginTag &tag) const
Tag VK components and hash.
virtual ~StdlibVerificationKey_()=default
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)
uint8_t buffer[RANDOM_BUFFER_SIZE]
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.
VKSerializationMode
Enum to control verification key metadata serialization.
constexpr size_t compute_number_of_subrelations()
Utility function to find the number of subrelations.
constexpr auto create_tuple_of_arrays_of_values()
constexpr size_t compute_max_partial_relation_length()
Utility function to find max PARTIAL_RELATION_LENGTH tuples of Relations.
constexpr auto create_sumcheck_tuple_of_tuples_of_univariates()
Utility function to construct a container for the subrelation accumulators of sumcheck proving.
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
TUPLET_INLINE constexpr auto make_tuple(Ts &&... args)
The precomputed data needed to compute a Honk VK.
RefArray< Polynomial, NUM_PRECOMPUTED_ENTITIES > polynomials