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"
11
12namespace bb::stdlib {
13
38template <typename Curve, size_t virtual_log_n = CONST_PROOF_SIZE_LOG_N>
39static std::vector<typename Curve::ScalarField> compute_padding_indicator_array(
40 const typename Curve::ScalarField& log_n)
41{
42 using Fr = typename Curve::ScalarField;
43 // Create a domain of size `virtual_log_n` and compute Lagrange denominators
44 using Data = BarycentricDataRunTime<Fr, virtual_log_n, /*num_evals=*/1>;
45
46 std::vector<Fr> result(virtual_log_n);
47 // 1) Build prefix products:
48 // prefix[i] = ∏_{m=0..(i-1)} (x - 1 - big_domain[m]), with prefix[0] = 1.
49 std::vector<Fr> prefix(virtual_log_n, Fr{ 1 });
50 for (size_t i = 1; i < virtual_log_n; ++i) {
51 prefix[i] = prefix[i - 1] * (log_n - Fr{ 1 } - Data::big_domain[i - 1]);
52 }
53
54 // 2) Build suffix products:
55 // suffix[i] = ∏_{m=i..(N-1)} (x - 1 - big_domain[m]),
56 // but we'll store it in reverse:
57 // suffix[virtual_log_n] = 1.
58 std::vector<Fr> suffix(virtual_log_n + 1, Fr(1));
59 for (size_t i = virtual_log_n; i > 0; i--) {
60 suffix[i - 1] = suffix[i] * (log_n - Fr{ 1 } - Data::big_domain[i - 1]);
61 }
62
63 // To ensure 0 < log_n < N, note that suffix[1] = \prod_{i=1}^{N-1} (x - 1 - i), therefore we just need to ensure
64 // that this product is 0.
65 if constexpr (Curve::is_stdlib_type) {
66 suffix[0].assert_equal(Fr{ 0 });
67 }
68
69 // 3) Combine prefixes & suffixes to get L_i(x-1):
70 // L_i(x-1) = (1 / lagrange_denominators[i]) * prefix[i] * suffix[i+1].
71 // (We skip factor (x - big_domain[i]) by splitting into prefix & suffix.)
72 for (size_t i = 0; i < virtual_log_n; ++i) {
73 result[i] = Data::precomputed_denominator_inverses[i] * prefix[i] * suffix[i + 1];
74 }
75 // Convert result into the array of step function evaluations sums b_i.
76 for (size_t idx = virtual_log_n - 1; idx > 0; idx--) {
77 // Use idx - 1 in the body if you prefer
78 result[idx - 1] += result[idx];
79 }
80
81 return result;
82}
83} // namespace bb::stdlib
static constexpr bool is_stdlib_type
Definition grumpkin.hpp:62
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Curve::ScalarField Fr