Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
grand_product_delta.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
10#include <span>
11namespace bb {
12
25template <typename Flavor>
27 const typename Flavor::FF& beta,
28 const typename Flavor::FF& gamma,
29 const typename Flavor::FF& offset = 0)
30{
31 using Field = typename Flavor::FF;
32 Field numerator = Field(1);
33 Field denominator = Field(1);
34
35 // Let m be the number of public inputs x₀,…, xₘ₋₁.
36 // Recall that we broke the permutation σ⁰ by changing the mapping
37 // (i) -> (n+i) to (i) -> (-(i+1)) i.e. σ⁰ᵢ = −(i+1)
38 //
39 // Therefore, the term in the numerator with ID¹ᵢ = n+i does not cancel out with any term in the denominator.
40 // Similarly, the denominator contains an extra σ⁰ᵢ = −(i+1) term that does not appear in the numerator.
41 // We expect the values of W⁰ᵢ and W¹ᵢ to be equal to xᵢ.
42 // The expected accumulated product would therefore be equal to
43
44 // ∏ᵢ (γ + W¹ᵢ + β⋅ID¹ᵢ) ∏ᵢ (γ + xᵢ + β⋅(n+i) )
45 // ----------------------- = ------------------------
46 // ∏ᵢ (γ + W⁰ᵢ + β⋅σ⁰ᵢ ) ∏ᵢ (γ + xᵢ - β⋅(i+1) )
47
48 // At the start of the loop for each xᵢ where i = 0, 1, …, m-1,
49 // we have
50 // numerator_acc = γ + β⋅(n+i) = γ + β⋅n + β⋅i
51 // denominator_acc = γ - β⋅(1+i) = γ - β - β⋅i
52 // at the end of the loop, add and subtract β to each term respectively to
53 // set the expected value for the start of iteration i+1.
54 // Note: The public inputs may be offset from the 0th index of the wires, for example due to the inclusion of an
55 // initial zero row or Goblin-stlye ECC op gates. Accordingly, the indices i in the above formulas are given by i =
56 // [0, m-1] + offset, i.e. i = offset, 1 + offset, …, m - 1 + offset.
57
58 // Using n = SEPARATOR ensures that the evaluations of `id_i` (`sigma_i`) and `id_j`(`sigma_j`) polynomials on the
59 // boolean hypercube do not intersect for i != j.
60 const Field SEPARATOR(PERMUTATION_ARGUMENT_VALUE_SEPARATOR);
61 Field numerator_acc = gamma + (beta * (SEPARATOR + offset));
62 Field denominator_acc = gamma - beta * (offset + 1);
63
64 for (size_t i = 0; i < public_inputs.size(); i++) {
65 numerator *= (numerator_acc + public_inputs[i]); // γ + xᵢ + β(n+i)
66 denominator *= (denominator_acc + public_inputs[i]); // γ + xᵢ - β(1+i)
67
68 // To avoid introducing extra variables in the circuit, we skip numerator_acc and denominator_acc in the final
69 // loop iteration, since their values won't be used
70 if (i < public_inputs.size() - 1) {
71 numerator_acc += beta;
72 denominator_acc -= beta;
73 }
74 }
75 return numerator / denominator;
76}
77
78} // namespace bb
Curve::ScalarField FF
ssize_t offset
Definition engine.cpp:36
Entry point for Barretenberg command-line interface.
Flavor::FF compute_public_input_delta(std::span< const typename Flavor::FF > public_inputs, const typename Flavor::FF &beta, const typename Flavor::FF &gamma, const typename Flavor::FF &offset=0)
Compute the correction term for the permutation argument.
constexpr uint32_t PERMUTATION_ARGUMENT_VALUE_SEPARATOR
Definition constants.hpp:9
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13