Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
pairing_points_tagging.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: not started, auditors: [], date: YYYY-MM-DD }
3// external_1: { status: not started, auditors: [], date: YYYY-MM-DD }
4// external_2: { status: not started, auditors: [], date: YYYY-MM-DD }
5// =====================
6
7#pragma once
9#include <algorithm>
10#include <cstdint>
11#include <vector>
12
13namespace bb {
14
22 private:
23 std::vector<uint32_t> pairing_points_tags_;
25 bool has_pairing_points_ = false;
27
28 public:
31 PairingPointsTagging(PairingPointsTagging&& other) noexcept = default;
35
36 bool operator==(const PairingPointsTagging& other) const = default;
37
43 {
45 uint32_t new_tag = next_pairing_point_tag_++;
46 pairing_points_tags_.emplace_back(
47 new_tag); // Each PairingPoints starts with tag equal to the number of PairingPoints created before it
48 return new_tag;
49 }
50
58 void merge_pairing_point_tags(uint32_t tag1_index, uint32_t tag2_index)
59 {
61 "Cannot merge pairing point tags after pairing points have been set to public.");
62
63 // If different tags, override tag2 with tag1
64 uint32_t tag1 = pairing_points_tags_[tag1_index];
65 uint32_t tag2 = pairing_points_tags_[tag2_index];
66
67 if (tag1 != tag2) {
68 for (auto& tag : pairing_points_tags_) {
69 tag = tag == tag2 ? tag1 : tag;
70 }
71 }
72 }
73
79 {
81 return true; // No pairing points created
82 }
83 // Check that there is only one tag
84 uint32_t unique_tag = pairing_points_tags_[0];
85 return std::ranges::all_of(pairing_points_tags_, [unique_tag](auto const& tag) { return tag == unique_tag; });
86 }
87
93 {
94 std::vector<uint32_t> unique_tags;
95 unique_tags.resize(pairing_points_tags_.size());
96 for (auto const& tag : pairing_points_tags_) {
97 unique_tags[tag] = 1;
98 }
99 uint32_t sum = 0;
100 for (auto v : unique_tags) {
101 sum += v;
102 }
103 return sum;
104 }
105
111
117
121 uint32_t get_tag(uint32_t tag_index) const { return pairing_points_tags_.at(tag_index); }
122
127 {
129 "Trying to set pairing points to public for a circuit that already has public pairing points.");
131 }
132};
133
134} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:67
Class to manage pairing point tagging.
PairingPointsTagging & operator=(const PairingPointsTagging &other)=default
bool has_pairing_points() const
Check if any pairing points have been created.
bool operator==(const PairingPointsTagging &other) const =default
uint32_t num_unique_pairing_points() const
Return the number of unique pairing point tags.
bool has_single_pairing_point_tag() const
Check if all pairing point tags belong to a single equivalence class.
bool has_public_pairing_points() const
Check if pairings points have been set to public.
PairingPointsTagging(const PairingPointsTagging &other)=default
uint32_t get_tag(uint32_t tag_index) const
Get the tag for a specific pairing point index.
PairingPointsTagging(PairingPointsTagging &&other) noexcept=default
uint32_t create_pairing_point_tag()
Create a new unique pairing point tag.
void merge_pairing_point_tags(uint32_t tag1_index, uint32_t tag2_index)
Merge two pairing point tags.
std::vector< uint32_t > pairing_points_tags_
PairingPointsTagging & operator=(PairingPointsTagging &&other) noexcept=default
void set_public_pairing_points()
Record that pairing points have been set to public.
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
Inner sum(Cont< Inner, Args... > const &in)
Definition container.hpp:70