Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
padding_indicator_array.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
8#include "../circuit_builders/circuit_builders_fwd.hpp"
9#include "../witness/witness.hpp"
12
13namespace bb::stdlib {
14
39template <typename Curve, size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N>
40static std::vector<typename Curve::ScalarField> compute_padding_indicator_array(
41 const typename Curve::ScalarField& log_n)
42{
43 using Fr = typename Curve::ScalarField;
44 // Create a domain of size `virtual_log_n` and compute Lagrange denominators
45 using Data = BarycentricDataRunTime<Fr, virtual_log_n, /*num_evals=*/1>;
46
47 std::vector<Fr> result(virtual_log_n);
48 // 1) Build prefix products:
49 // prefix[i] = ∏_{m=0..(i-1)} (x - 1 - big_domain[m]), with prefix[0] = 1.
50 std::vector<Fr> prefix(virtual_log_n, Fr{ 1 });
51 for (size_t i = 1; i < virtual_log_n; ++i) {
52 prefix[i] = prefix[i - 1] * (log_n - Fr{ 1 } - Data::big_domain[i - 1]);
53 }
54
55 // 2) Build suffix products:
56 // suffix[i] = ∏_{m=i..(N-1)} (x - 1 - big_domain[m]),
57 // but we'll store it in reverse:
58 // suffix[virtual_log_n] = 1.
59 std::vector<Fr> suffix(virtual_log_n + 1, Fr(1));
60 for (size_t i = virtual_log_n; i > 0; i--) {
61 suffix[i - 1] = suffix[i] * (log_n - Fr{ 1 } - Data::big_domain[i - 1]);
62 }
63
64 // To ensure 0 < log_n < N, note that suffix[1] = \prod_{i=1}^{N-1} (x - 1 - i), therefore we just need to ensure
65 // that this product is 0.
66 if constexpr (Curve::is_stdlib_type) {
67 suffix[0].assert_equal(Fr{ 0 });
68 }
69
70 // 3) Combine prefixes & suffixes to get L_i(x-1):
71 // L_i(x-1) = (1 / lagrange_denominators[i]) * prefix[i] * suffix[i+1].
72 // (We skip factor (x - big_domain[i]) by splitting into prefix & suffix.)
73 for (size_t i = 0; i < virtual_log_n; ++i) {
74 result[i] = Data::precomputed_denominator_inverses[i] * prefix[i] * suffix[i + 1];
75 }
76 // Convert result into the array of step function evaluations sums b_i.
77 for (size_t idx = virtual_log_n - 1; idx > 0; idx--) {
78 // Use idx - 1 in the body if you prefer
79 result[idx - 1] += result[idx];
80 }
81
82 // OriginTag false positive: the padding indicator array elements are derived from a `log_circuit_size` and are used
83 // to perform conditional padding logic in Sumcheck (Currently, only in UltraZKRecursiveFlavor), where they are
84 // mixing with sumcheck univariates.
85 if constexpr (Curve::is_stdlib_type) {
86 for (auto& indicator : result) {
87 indicator.clear_round_provenance();
88 }
89 }
90
91 return result;
92}
93} // namespace bb::stdlib
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:69
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
This file contains part of the logic for the Origin Tag mechanism that tracks the use of in-circuit p...
Curve::ScalarField Fr