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#pragma once
3#include <algorithm>
4#include <cstdint>
5#include <vector>
6
7namespace bb {
8
16 private:
17 std::vector<uint32_t> pairing_points_tags_;
19 bool has_pairing_points_ = false;
21
22 public:
25 PairingPointsTagging(PairingPointsTagging&& other) noexcept = default;
29
30 bool operator==(const PairingPointsTagging& other) const = default;
31
37 {
39 uint32_t new_tag = next_pairing_point_tag_++;
40 pairing_points_tags_.emplace_back(
41 new_tag); // Each PairingPoints starts with tag equal to the number of PairingPoints created before it
42 return new_tag;
43 }
44
52 void merge_pairing_point_tags(uint32_t tag1_index, uint32_t tag2_index)
53 {
55 "Cannot merge pairing point tags after pairing points have been set to public.");
56
57 // If different tags, override tag2 with tag1
58 uint32_t tag1 = pairing_points_tags_[tag1_index];
59 uint32_t tag2 = pairing_points_tags_[tag2_index];
60
61 if (tag1 != tag2) {
62 for (auto& tag : pairing_points_tags_) {
63 tag = tag == tag2 ? tag1 : tag;
64 }
65 }
66 }
67
73 {
75 return true; // No pairing points created
76 }
77 // Check that there is only one tag
78 uint32_t unique_tag = pairing_points_tags_[0];
79 return std::ranges::all_of(pairing_points_tags_, [unique_tag](auto const& tag) { return tag == unique_tag; });
80 }
81
87 {
88 std::vector<uint32_t> unique_tags;
89 unique_tags.resize(pairing_points_tags_.size());
90 for (auto const& tag : pairing_points_tags_) {
91 unique_tags[tag] = 1;
92 }
93 uint32_t sum = 0;
94 for (auto v : unique_tags) {
95 sum += v;
96 }
97 return sum;
98 }
99
105
111
115 uint32_t get_tag(uint32_t tag_index) const { return pairing_points_tags_.at(tag_index); }
116
121 {
123 "Trying to set pairing points to public for a circuit that already has public pairing points.");
125 }
126};
127
128} // namespace bb
#define BB_ASSERT(expression,...)
Definition assert.hpp:80
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