Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
repeated_commitments_data.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Completed, auditors: [Sergei], commit: }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
9#include <array>
10#include <cstddef>
11#include <span>
12
13namespace bb {
14
15// Non-constexpr no-return helper used to fail constant evaluation with a readable diagnostic
16// when `repeated_commitments_from_pairs` is invoked on a layout it can't represent. Calling a
17// non-constexpr function from a constexpr context is ill-formed, so the compiler emits an error
18// pointing at this name (and the body's `throw_or_abort` runs at runtime in the unlikely event
19// the function is reached non-constexpr).
20[[noreturn]] inline void repeated_commitments_too_many_runs()
21{
22 throw_or_abort("repeated_commitments_from_pairs: layout produces more than 2 non-contiguous runs");
23}
24
37 size_t original_start = 0; // start index of the original (unshifted) polynomials in AllEntities
38 size_t duplicate_start = 0; // start index of the duplicate (shifted) entries in AllEntities
39 size_t count = 0; // number of polynomials in this range
40};
41
45
47
48 constexpr RepeatedCommitmentsData(size_t first_original_start, size_t first_duplicate_start, size_t first_count)
49 : first{ first_original_start, first_duplicate_start, first_count }
50 {}
51
52 constexpr RepeatedCommitmentsData(size_t first_original_start,
53 size_t first_duplicate_start,
54 size_t first_count,
55 size_t second_original_start,
56 size_t second_duplicate_start,
57 size_t second_count)
58 : first{ first_original_start, first_duplicate_start, first_count }
59 , second{ second_original_start, second_duplicate_start, second_count }
60 {}
61};
62
73 size_t original = 0;
74 size_t duplicate = 0;
75};
76
87{
88 if (pairs.empty()) {
89 return {};
90 }
92 size_t range_count = 0;
93 DuplicateRange current{ pairs[0].original, pairs[0].duplicate, 1 };
94 const auto close_range = [&](DuplicateRange r) constexpr {
95 if (range_count == 2) {
96 // More than two non-contiguous runs — RepeatedCommitmentsData can't represent this.
97 // Calling a non-constexpr function from a constexpr context fails compilation; if
98 // this fires, either reorder the layout to merge runs or extend
99 // RepeatedCommitmentsData to hold more ranges.
101 }
102 ranges[range_count++] = r;
103 };
104 for (size_t i = 1; i < pairs.size(); ++i) {
105 const auto& p = pairs[i];
106 if (p.original == current.original_start + current.count &&
107 p.duplicate == current.duplicate_start + current.count) {
108 ++current.count;
109 } else {
110 close_range(current);
111 current = { p.original, p.duplicate, 1 };
112 }
113 }
114 close_range(current);
115 if (range_count == 1) {
116 return RepeatedCommitmentsData{ ranges[0].original_start, ranges[0].duplicate_start, ranges[0].count };
117 }
118 return RepeatedCommitmentsData{ ranges[0].original_start, ranges[0].duplicate_start, ranges[0].count,
119 ranges[1].original_start, ranges[1].duplicate_start, ranges[1].count };
120}
121
122} // namespace bb
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
void repeated_commitments_too_many_runs()
constexpr RepeatedCommitmentsData repeated_commitments_from_pairs(std::span< const DuplicatePair > pairs)
Collapse a span of (original, duplicate) pairs into a RepeatedCommitmentsData of up to two contiguous...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
One commitment shared by an unshifted polynomial and its shifted copy.
Identifies contiguous ranges of duplicate commitments in the AllEntities ordering so that Shplemini c...
constexpr RepeatedCommitmentsData(size_t first_original_start, size_t first_duplicate_start, size_t first_count)
constexpr RepeatedCommitmentsData(size_t first_original_start, size_t first_duplicate_start, size_t first_count, size_t second_original_start, size_t second_duplicate_start, size_t second_count)
void throw_or_abort(std::string const &err)