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()) {
280 key.from_field_elements(elements);
292 auto deserialize = [&idx, &elements]<
typename T>(T& target) {
293 size_t size = Codec::template calc_num_fields<T>();
294 target = Codec::template deserialize_from_fields<T>(elements.subspan(idx, size));
299 deserialize(this->log_circuit_size);
300 deserialize(this->num_public_inputs);
301 deserialize(this->pub_inputs_offset);
305 for (
Commitment& commitment : this->get_all()) {
306 deserialize(commitment);
334 std::vector<DataType> vk_elements;
337 auto tag_and_append = [&]<
typename T>(
const T& component) {
338 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
339 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
343 tag_and_append(this->log_circuit_size);
344 tag_and_append(this->num_public_inputs);
345 tag_and_append(this->pub_inputs_offset);
348 for (
const Commitment& commitment : this->get_all()) {
349 tag_and_append(commitment);
353 bb::unset_free_witness_tags<in_circuit, DataType>(vk_elements);
356 return HashFunction::hash(vk_elements);
381template <
typename Builder_,
typename PrecomputedCommitments,
typename NativeVerificationKey>
385 using Commitment =
typename PrecomputedCommitments::DataType;
397 for (
auto [native_comm, comm] :
zip_view(native_key->get_all(), this->get_all())) {
398 comm = Commitment::from_witness(
builder, native_comm);
402 for (
Commitment& commitment : this->get_all()) {
403 commitment.fix_witness();
421template <
typename Builder_,
422 typename PrecomputedCommitments,
429 using Commitment =
typename PrecomputedCommitments::DataType;
444 template <
typename T = NativeVerificationKey_>
452 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_key->get_all())) {
453 commitment = Commitment::from_witness(
builder, native_commitment);
464 size_t num_frs_read = 0;
466 this->log_circuit_size = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
467 this->num_public_inputs = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
468 this->pub_inputs_offset = Codec::template deserialize_from_frs<FF>(elements, num_frs_read);
470 for (
Commitment& commitment : this->get_all()) {
471 commitment = Codec::template deserialize_from_frs<Commitment>(elements, num_frs_read);
479 const std::span<const uint32_t>& witness_indices)
481 std::vector<FF> vk_fields;
482 vk_fields.reserve(witness_indices.size());
483 for (
const auto& idx : witness_indices) {
497 for (
Commitment& commitment : this->get_all()) {
498 commitment.fix_witness();
507 template <
typename T = NativeVerificationKey_>
512 native_vk.log_circuit_size =
static_cast<uint64_t
>(this->log_circuit_size.
get_value());
513 native_vk.num_public_inputs =
static_cast<uint64_t
>(this->num_public_inputs.
get_value());
514 native_vk.pub_inputs_offset =
static_cast<uint64_t
>(this->pub_inputs_offset.
get_value());
515 for (
auto [commitment, native_commitment] :
zip_view(this->get_all(), native_vk.get_all())) {
516 native_commitment = commitment.get_value();
535 static constexpr bool in_circuit =
true;
536 std::vector<FF> vk_elements;
539 auto append_tagged = [&]<
typename T>(
const T& component) {
540 auto frs = bb::tag_and_serialize<in_circuit, Codec>(component,
tag);
541 vk_elements.insert(vk_elements.end(), frs.begin(), frs.end());
545 append_tagged(this->log_circuit_size);
546 append_tagged(this->num_public_inputs);
547 append_tagged(this->pub_inputs_offset);
550 for (
const Commitment& commitment : this->get_all()) {
551 append_tagged(commitment);
555 bb::unset_free_witness_tags<in_circuit, FF>(vk_elements);
593template <
typename FF,
typename VerificationKey>
class VKAndHash_ {
595 template <
typename T = VerificationKey>
598 template <
typename T = VerificationKey>
624 typename B =
typename VK::Builder,
625 typename NVK =
typename VK::NativeVerificationKey>
630 std::shared_ptr<VerificationKey>
vk;
643 return std::max({ std::tuple_element_t<Is, Tuple>::RELATION_LENGTH... });
654 return (0 + ... + std::tuple_element_t<I, Tuple>::SUBRELATION_PARTIAL_LENGTHS.size());
669 typename std::tuple_element_t<I, RelationsTuple>::SumcheckTupleOfUnivariatesOverSubrelations{}...);
692 typename std::tuple_element_t<I, RelationsTuple>::SumcheckArrayOfValuesOverSubrelations{}...);
702class UltraRollupFlavor;
704class UltraKeccakFlavor;
705#ifdef STARKNET_GARAGA_FLAVORS
706class UltraStarknetFlavor;
707class UltraStarknetZKFlavor;
709class UltraKeccakZKFlavor;
713class TranslatorFlavor;
714class ECCVMRecursiveFlavor;
715class TranslatorRecursiveFlavor;
716class AvmRecursiveFlavor;
717class MultilinearBatchingRecursiveFlavor;
719template <
typename BuilderType>
class UltraRecursiveFlavor_;
720template <
typename BuilderType>
class UltraZKRecursiveFlavor_;
721template <
typename BuilderType>
class UltraRollupRecursiveFlavor_;
722template <
typename BuilderType>
class MegaRecursiveFlavor_;
723template <
typename BuilderType>
class MegaZKRecursiveFlavor_;
724template <
typename BuilderType>
class MegaAvmRecursiveFlavor_;
729template <
typename PrecomputedCommitments,
731 typename HashFunction,
732 typename CommitmentKey,
742 size_t num_frs = VK::calc_num_data_types();
746 for (
auto& element : field_elements) {
750 vk.from_field_elements(field_elements);
753template <
typename PrecomputedCommitments,
755 typename HashFunction,
756 typename CommitmentKey,
759 std::vector<uint8_t>&
buf,
765 size_t before =
buf.size();
768 for (
const auto& element : field_elements) {
771 size_t after =
buf.size();
772 size_t num_frs = VK::calc_num_data_types();
777class 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)
The precomputed data needed to compute a Honk VK.
RefArray< Polynomial, NUM_PRECOMPUTED_ENTITIES > polynomials