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.
36
37 static constexpr std::array<size_t, 3> SUBRELATION_PARTIAL_LENGTHS{
38 22, // grand product construction sub-relation
39 3, // left-shiftable polynomial sub-relation
40 3 // z_perm initialization sub-relation
41 };
42 static_assert(NUM_SUBRELATIONS == SUBRELATION_PARTIAL_LENGTHS.size());
43 // prover optimization to allow for skipping the computation of sub-relations at certain points in sumcheck.
44 template <typename AllEntities> inline static bool skip(const AllEntities& in)
45 {
46 // For the first accumulator in the set relation, the added-on term is 0 if the following vanishes:
47 //
48 // `(z_perm + lagrange_first) * numerator_evaluation - (z_perm_shift + lagrange_last) * denominator_evaluation`,
49 //
50 // i.e., if z_perm is well-formed.
51 //
52 // For the second accumulator in the set relation, the added-on term is 0 if the following vanishes:
53 //
54 // `lagrange_last_short * z_perm_shift_short`
55 //
56 // To know when we can skip this computation (i.e., when it is "automatically" 0), most cases are handled by the
57 // condtion `z_perm == z_perf_shift`. In most circumstances, this implies that with overwhelming probability,
58 // none of the wire values for the present input are involved in non-trivial copy constraints.
59 //
60 // There are two other edge-cases we need to check for to know we can skip the computation. First,
61 // `transcript_mul` can be 1 even though the multiplication is "degenerate" (and not handled by the MSM table):
62 // this holds if either the scalar is 0 or the point is the neutral element. Therefore we force this. Second, we
63 // must force lagrange_last == 0.
64 return (in.z_perm - in.z_perm_shift).is_zero() && in.transcript_mul.is_zero() && in.lagrange_last.is_zero();
65 }
66
67 template <typename Accumulator> static Accumulator convert_to_wnaf(const auto& s0, const auto& s1)
68 {
69 auto t = s0 + s0;
70 t += t;
71 t += s1;
72
73 auto naf = t + t - 15;
74 return naf;
75 }
76
77 inline static auto& get_grand_product_polynomial(auto& input) { return input.z_perm; }
78 inline static auto& get_shifted_grand_product_polynomial(auto& input) { return input.z_perm_shift; }
79
80 template <typename Accumulator, typename AllEntities, typename Parameters>
81 static Accumulator compute_grand_product_numerator(const AllEntities& in, const Parameters& params);
82
83 template <typename Accumulator, typename AllEntities, typename Parameters>
84 static Accumulator compute_grand_product_denominator(const AllEntities& in, const Parameters& params);
85
86 template <typename ContainerOverSubrelations, typename AllEntities, typename Parameters>
87 static void accumulate(ContainerOverSubrelations& accumulator,
88 const AllEntities& in,
89 const Parameters& params,
90 const FF& scaling_factor);
91};
92
94
95} // namespace bb
static Accumulator convert_to_wnaf(const auto &s0, const auto &s1)
static auto & get_shifted_grand_product_polynomial(auto &input)
static constexpr std::array< size_t, 3 > SUBRELATION_PARTIAL_LENGTHS
static constexpr uint64_t THIRD_TERM_TAG
static auto & get_grand_product_polynomial(auto &input)
static bool skip(const AllEntities &in)
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