135template <
typename PrecomputedCommitments,
typename HashType,
typename HardcodedVKAndHash>
138 using Commitment =
typename PrecomputedCommitments::DataType;
144 :
hash(HardcodedVKAndHash::vk_hash())
146 for (
auto [vk_commitment, fixed_commitment] :
zip_view(this->get_all(), HardcodedVKAndHash::get_all())) {
147 vk_commitment = fixed_commitment;
167template <
typename PrecomputedCommitments,
169 typename HashFunction,
170 typename CommitmentKey = void,
174 using Commitment =
typename PrecomputedCommitments::DataType;
182 template <
size_t NUM_PRECOMPUTED_ENTITIES,
typename StringType>
186 bool is_equal =
true;
203 for (
auto [this_comm, other_comm, label] :
zip_view(this->get_all(), other.get_all(), commitment_labels)) {
204 if (this_comm != other_comm) {
205 info(
"Commitment mismatch: ", label);
223 template <
typename PrecomputedData>
230 CommitmentKey commitment_key{ precomputed.metadata.dyadic_size };
231 for (
auto [polynomial, commitment] :
zip_view(precomputed.polynomials, this->get_all())) {
232 commitment = commitment_key.
commit(polynomial);
243 size_t commitments_size = PrecomputedCommitments::size() * Codec::template calc_num_fields<Commitment>();
244 size_t metadata_size = 0;
247 metadata_size = 3 * Codec::template calc_num_fields<uint64_t>();
250 return metadata_size + commitments_size;
261 auto serialize = [](
const auto& input, std::vector<DataType>&
buffer) {
262 std::vector<DataType> input_fields = Codec::serialize_to_fields(input);
263 buffer.insert(
buffer.end(), input_fields.begin(), input_fields.end());
266 std::vector<DataType> elements;
269 serialize(this->log_circuit_size, elements);
270 serialize(this->num_public_inputs, elements);
271 serialize(this->pub_inputs_offset, elements);
275 for (
const Commitment& commitment : this->get_all()) {
290 auto deserialize = [&idx, &elements]<
typename T>(T& target) {
291 size_t size = Codec::template calc_num_fields<T>();
292 target = Codec::template deserialize_from_fields<T>(elements.subspan(idx, size));
297 deserialize(this->log_circuit_size);
298 deserialize(this->num_public_inputs);
299 deserialize(this->pub_inputs_offset);
303 for (
Commitment& commitment : this->get_all()) {
304 deserialize(commitment);
332 std::vector<DataType> vk_elements;
335 auto tag_and_append = [&]<
typename T>(
const T& component) {
336 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
337 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
341 tag_and_append(this->log_circuit_size);
342 tag_and_append(this->num_public_inputs);
343 tag_and_append(this->pub_inputs_offset);
346 for (
const Commitment& commitment : this->get_all()) {
347 tag_and_append(commitment);
351 bb::unset_free_witness_tags<in_circuit, DataType>(vk_elements);
354 return HashFunction::hash(vk_elements);
379template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey>
383 using Commitment =
typename PrecomputedCommitments::DataType;
395 for (
auto [native_comm, comm] :
zip_view(native_key->get_all(), this->get_all())) {
396 comm = Commitment::from_witness(
builder, native_comm);
400 for (
Commitment& commitment : this->get_all()) {
401 commitment.fix_witness();
419template <
typename Builder_,
420 typename PrecomputedCommitments,
427 using Commitment =
typename PrecomputedCommitments::DataType;
442 template <
typename T = NativeVerificationKey_>
450 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_key->get_all())) {
451 commitment = Commitment::from_witness(
builder, native_commitment);
462 size_t num_frs_read = 0;
464 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
465 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
466 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
468 for (
Commitment& commitment : this->get_all()) {
469 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
477 const std::span<const uint32_t>& witness_indices)
479 std::vector<FF> vk_fields;
480 vk_fields.reserve(witness_indices.size());
481 for (
const auto& idx : witness_indices) {
495 for (
Commitment& commitment : this->get_all()) {
496 commitment.fix_witness();
505 template <
typename T = NativeVerificationKey_>
510 native_vk.log_circuit_size =
static_cast<uint64_t
>(this->log_circuit_size.
get_value());
511 native_vk.num_public_inputs =
static_cast<uint64_t
>(this->num_public_inputs.
get_value());
512 native_vk.pub_inputs_offset =
static_cast<uint64_t
>(this->pub_inputs_offset.
get_value());
513 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_vk.get_all())) {
514 native_commitment = commitment.get_value();
533 static constexpr bool in_circuit =
true;
534 std::vector<FF> vk_elements;
537 auto append_tagged = [&]<
typename T>(
const T& component) {
538 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
539 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
543 append_tagged(this->log_circuit_size);
544 append_tagged(this->num_public_inputs);
545 append_tagged(this->pub_inputs_offset);
548 for (
const Commitment& commitment : this->get_all()) {
549 append_tagged(commitment);
553 bb::unset_free_witness_tags<in_circuit, FF>(vk_elements);
591template <
typename FF,
typename VerificationKey>
class VKAndHash_ {
593 template <
typename T = VerificationKey>
596 template <
typename T = VerificationKey>
622 typename B =
typename VK::Builder,
623 typename NVK =
typename VK::NativeVerificationKey>
628 std::shared_ptr<VerificationKey>
vk;
641 return std::max({ std::tuple_element_t<Is, Tuple>::RELATION_LENGTH... });
652 return (0 + ... + std::tuple_element_t<I, Tuple>::SUBRELATION_PARTIAL_LENGTHS.size());
667 typename std::tuple_element_t<I, RelationsTuple>::SumcheckTupleOfUnivariatesOverSubrelations{}...);
690 typename std::tuple_element_t<I, RelationsTuple>::SumcheckArrayOfValuesOverSubrelations{}...);
701class UltraKeccakFlavor;
702#ifdef STARKNET_GARAGA_FLAVORS
703class UltraStarknetFlavor;
704class UltraStarknetZKFlavor;
706class UltraKeccakZKFlavor;
710class TranslatorFlavor;
711class ECCVMRecursiveFlavor;
712class TranslatorRecursiveFlavor;
713class AvmRecursiveFlavor;
714class MultilinearBatchingRecursiveFlavor;
716template <
typename BuilderType>
class UltraRecursiveFlavor_;
717template <
typename BuilderType>
class UltraZKRecursiveFlavor_;
718template <
typename BuilderType>
class MegaRecursiveFlavor_;
719template <
typename BuilderType>
class MegaZKRecursiveFlavor_;
720template <
typename BuilderType>
class MegaAvmRecursiveFlavor_;
725template <
typename PrecomputedCommitments,
727 typename HashFunction,
728 typename CommitmentKey,
738 size_t num_frs = VK::calc_num_data_types();
742 for (
auto& element : field_elements) {
746 vk.from_field_elements(field_elements);
749template <
typename PrecomputedCommitments,
751 typename HashFunction,
752 typename CommitmentKey,
755 std::vector<uint8_t>&
buf,
761 size_t before =
buf.size();
764 for (
const auto& element : field_elements) {
767 size_t after =
buf.size();
768 size_t num_frs = VK::calc_num_data_types();
773class 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 𝔾₁.
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).
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).
bool operator==(const FixedVKAndHash_ &) const =default
HashType get_hash() const
typename PrecomputedCommitments::DataType Commitment
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)
StdlibCodec for in-circuit (recursive) verification transcript handling.
The precomputed data needed to compute a Honk VK.
RefArray< Polynomial, NUM_PRECOMPUTED_ENTITIES > polynomials