Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
ecc_set_relation.hpp
Go to the documentation of this file.
1// === AUDIT STATUS ===
2// internal: { status: Complete, auditors: [Raju], commit: 2a49eb6 }
3// external_1: { status: not started, auditors: [], commit: }
4// external_2: { status: not started, auditors: [], commit: }
5// =====================
6
7#pragma once
8#include <array>
9#include <tuple>
10
14
15namespace bb {
16
17template <typename FF_> class ECCVMSetRelationImpl {
18 public:
19 using FF = FF_;
20
21 // Domain separation tags for the three tuple families in the set relation grand product.
22 // Each tuple family uses a distinct tag multiplied by beta^4 to prevent cross-family collisions.
23 // Without these tags, tuples from different families with identical packed values would produce
24 // identical fingerprints, allowing cross-family substitution in the multiset equality check.
25 static constexpr uint64_t FIRST_TERM_TAG = 1; // (pc, round, wnaf_slice)
26 static constexpr uint64_t SECOND_TERM_TAG = 2; // (pc, P.x, P.y, scalar)
27 static constexpr uint64_t THIRD_TERM_TAG = 3; // (pc, P.x, P.y, msm_size)
28
29 // Named subrelation indices — matches SUBRELATION_PARTIAL_LENGTHS ordering.
30 // NOTE: the previous Z_PERM_INIT subrelation (`lagrange_first · z_perm = 0`) was moved
31 // to ECCVMShiftableInitRelation as part of centralizing all `lagrange_first · col = 0`
32 // pins. The grand product still requires `z_perm[lagrange_first row] = 0` — that
33 // initialization is now enforced there.
39
40 static constexpr std::array<size_t, 2> SUBRELATION_PARTIAL_LENGTHS{
41 22, // grand product construction sub-relation
42 3, // left-shiftable polynomial sub-relation
43 };
44 static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
45 // prover optimization to allow for skipping the computation of sub-relations at certain points in sumcheck.
46 template <typename AllEntities> inline static bool skip(const AllEntities& in)
47 {
48 // For the first accumulator in the set relation, the added-on term is 0 if the following vanishes:
49 //
50 // `(z_perm + lagrange_first) * numerator_evaluation - (z_perm_shift + lagrange_last) * denominator_evaluation`,
51 //
52 // i.e., if z_perm is well-formed.
53 //
54 // For the second accumulator in the set relation, the added-on term is 0 if the following vanishes:
55 //
56 // `lagrange_last_short * z_perm_shift_short`
57 //
58 // To know when we can skip this computation (i.e., when it is "automatically" 0), most cases are handled by the
59 // condtion `z_perm == z_perf_shift`. In most circumstances, this implies that with overwhelming probability,
60 // none of the wire values for the present input are involved in non-trivial copy constraints.
61 //
62 // There are two other edge-cases we need to check for to know we can skip the computation. First,
63 // `transcript_mul` can be 1 even though the multiplication is "degenerate" (and not handled by the MSM table):
64 // this holds if either the scalar is 0 or the point is the neutral element. Therefore we force this. Second, we
65 // must force lagrange_last == 0.
66 return (in.z_perm - in.z_perm_shift).is_zero() && in.transcript_mul.is_zero() && in.lagrange_last.is_zero();
67 }
68
69 template <typename Accumulator> static Accumulator convert_to_wnaf(const auto& s0, const auto& s1)
70 {
71 auto t = s0 + s0;
72 t += t;
73 t += s1;
74
75 auto naf = t + t - 15;
76 return naf;
77 }
78
79 inline static auto& get_grand_product_polynomial(auto& input) { return input.z_perm; }
80 inline static auto& get_shifted_grand_product_polynomial(auto& input) { return input.z_perm_shift; }
81
82 template <typename Accumulator, typename AllEntities, typename Parameters>
83 static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params);
84
85 template <typename Accumulator, typename AllEntities, typename Parameters>
86 static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params);
87
88 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
89 static void accumulate(ContainerOverSubrelations& accumulator,
90 const AllEntities& in,
91 const Parameters& params,
92 const FF& scaling_factor);
93};
94
96
97} // namespace bb
static Accumulator convert_to_wnaf(const auto &s0, const auto &s1)
static auto & get_shifted_grand_product_polynomial(auto &input)
static constexpr uint64_t THIRD_TERM_TAG
static auto & get_grand_product_polynomial(auto &input)
static bool skip(const AllEntities &in)
static constexpr std::array< size_t, 2 > SUBRELATION_PARTIAL_LENGTHS
static constexpr uint64_t FIRST_TERM_TAG
static constexpr uint64_t SECOND_TERM_TAG
static Accumulator compute_grand_product_denominator(const AllEntities &in, const Parameters &params)
static Accumulator compute_grand_product_numerator(const AllEntities &in, const Parameters &params)
Performs multiset equality checks for the ECCVM. This faciliates "communication" between disjoint set...
static void accumulate(ContainerOverSubrelations &accumulator, const AllEntities &in, const Parameters &params, const FF &scaling_factor)
Expression for the standard arithmetic gate. @dbetails The relation is defined as C(in(X)....
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
Entry point for Barretenberg command-line interface.
Definition api.hpp:5