barretenberg
Loading...
Searching...
No Matches
grand_product_delta.hpp
1#pragma once
2
3#include <span>
4namespace proof_system::honk {
5
18template <typename Flavor>
19typename Flavor::FF compute_public_input_delta(std::span<const typename Flavor::FF> public_inputs,
20 const typename Flavor::FF& beta,
21 const typename Flavor::FF& gamma,
22 const auto domain_size,
23 size_t offset = 0)
24{
25 using Field = typename Flavor::FF;
26 Field numerator = Field(1);
27 Field denominator = Field(1);
28
29 // Let m be the number of public inputs x₀,…, xₘ₋₁.
30 // Recall that we broke the permutation σ⁰ by changing the mapping
31 // (i) -> (n+i) to (i) -> (-(i+1)) i.e. σ⁰ᵢ = −(i+1)
32 //
33 // Therefore, the term in the numerator with ID¹ᵢ = n+i does not cancel out with any term in the denominator.
34 // Similarly, the denominator contains an extra σ⁰ᵢ = −(i+1) term that does not appear in the numerator.
35 // We expect the values of W⁰ᵢ and W¹ᵢ to be equal to xᵢ.
36 // The expected accumulated product would therefore be equal to
37
38 // ∏ᵢ (γ + W¹ᵢ + β⋅ID¹ᵢ) ∏ᵢ (γ + xᵢ + β⋅(n+i) )
39 // ----------------------- = ------------------------
40 // ∏ᵢ (γ + W⁰ᵢ + β⋅σ⁰ᵢ ) ∏ᵢ (γ + xᵢ - β⋅(i+1) )
41
42 // At the start of the loop for each xᵢ where i = 0, 1, …, m-1,
43 // we have
44 // numerator_acc = γ + β⋅(n+i) = γ + β⋅n + β⋅i
45 // denominator_acc = γ - β⋅(1+i) = γ - β - β⋅i
46 // at the end of the loop, add and subtract β to each term respectively to
47 // set the expected value for the start of iteration i+1.
48 // Note: The public inputs may be offset from the 0th index of the wires, for example due to the inclusion of an
49 // initial zero row or Goblin-stlye ECC op gates. Accordingly, the indices i in the above formulas are given by i =
50 // [0, m-1] + offset, i.e. i = offset, 1 + offset, …, m - 1 + offset.
51 Field numerator_acc = gamma + (beta * Field(domain_size + offset));
52 Field denominator_acc = gamma - beta * Field(1 + offset);
53
54 for (const auto& x_i : public_inputs) {
55 numerator *= (numerator_acc + x_i); // γ + xᵢ + β(n+i)
56 denominator *= (denominator_acc + x_i); // γ + xᵢ - β(1+i)
57
58 numerator_acc += beta;
59 denominator_acc -= beta;
60 }
61 return numerator / denominator;
62}
63
79template <typename Field>
80Field compute_lookup_grand_product_delta(const Field& beta, const Field& gamma, const auto domain_size)
81{
82 Field gamma_by_one_plus_beta = gamma * (Field(1) + beta); // γ(1 + β)
83 return gamma_by_one_plus_beta.pow(domain_size); // (γ(1 + β))^n
84}
85
86} // namespace proof_system::honk
Defines particular circuit builder types expected to be used for circuit construction in stdlib and c...
Definition: claim.hpp:6
Field compute_lookup_grand_product_delta(const Field &beta, const Field &gamma, const auto domain_size)
Compute lookup grand product delta.
Definition: grand_product_delta.hpp:80
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 auto domain_size, size_t offset=0)
Compute the correction term for the permutation argument.
Definition: grand_product_delta.hpp:19