Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
eccvm_trace_checker.cpp
Go to the documentation of this file.
4
5using namespace bb;
6
9using FF = typename ECCVMFlavor::FF;
11
13 numeric::RNG* engine_ptr
14#ifdef FUZZING
15 ,
16 bool disable_fixed_dyadic_trace_size
17#endif
18)
19{
20 const FF gamma = FF::random_element(engine_ptr);
21 const FF beta = FF::random_element(engine_ptr);
22 const FF beta_sqr = beta.sqr();
23 const FF beta_cube = beta_sqr * beta;
24 const FF beta_quartic = beta_sqr * beta_sqr;
25 auto first_term_tag = beta_quartic; // FIRST_TERM_TAG (= 1) * beta_quartic
26 auto eccvm_set_permutation_delta = (gamma + first_term_tag) * (gamma + beta_sqr + first_term_tag) *
27 (gamma + beta_sqr + beta_sqr + first_term_tag) *
28 (gamma + beta_sqr + beta_sqr + beta_sqr + first_term_tag);
29 eccvm_set_permutation_delta = eccvm_set_permutation_delta.invert();
31 .eta = 0,
32 .beta = beta,
33 .gamma = gamma,
34 .public_input_delta = 0,
35 .beta_sqr = beta_sqr,
36 .beta_cube = beta_cube,
37 .beta_quartic = beta_quartic,
38 .eccvm_set_permutation_delta = eccvm_set_permutation_delta,
39 };
40
41#ifdef FUZZING
42 ProverPolynomials polynomials(builder, disable_fixed_dyadic_trace_size);
43#else
44 ProverPolynomials polynomials(builder);
45#endif
46 const size_t num_rows = polynomials.get_polynomial_size();
47 // Skip the disabled head region to preserve masking values
48 compute_logderivative_inverse<FF, ECCVMLookupRelation<FF>>(polynomials, params, Flavor::TRACE_OFFSET);
49 compute_grand_product<Flavor, ECCVMSetRelation<FF>>(polynomials, params);
50
51 polynomials.z_perm_shift = Polynomial(polynomials.z_perm.shifted());
52
53 const auto evaluate_relation = [&]<typename Relation>(const std::string& relation_name) {
55 for (auto& r : result) {
56 r = 0;
57 }
58 constexpr size_t NUM_SUBRELATIONS = result.size();
59
60 // Skip the disabled head rows (masking region) — relations are zeroed there by row-disabling polynomial
61 for (size_t i = Flavor::TRACE_OFFSET; i < num_rows; ++i) {
62 auto row = polynomials.get_row(i);
63#ifdef FUZZING
64 // Check if the relation is skippable and should be skipped (only in fuzzing builds)
65 if constexpr (isSkippable<Relation, decltype(row)>) {
66 // Only accumulate if the relation should not be skipped
67 if (!Relation::skip(row)) {
68 Relation::accumulate(result, row, params, 1);
69 }
70 } else {
71 // If not skippable, always accumulate
72 Relation::accumulate(result, row, params, 1);
73 }
74#else
75 // In non-fuzzing builds, always accumulate for maximum security
76 Relation::accumulate(result, row, params, 1);
77#endif
78
79 bool x = true;
80 for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) {
81 if (result[j] != 0) {
82 info("Relation ", relation_name, ", subrelation index ", j, " failed at row ", i);
83 x = false;
84 }
85 }
86 if (!x) {
87 return false;
88 }
89 }
90 return true;
91 };
92
93 bool result = true;
94 result = result && evaluate_relation.template operator()<ECCVMTranscriptRelation<FF>>("ECCVMTranscriptRelation");
95 result = result && evaluate_relation.template operator()<ECCVMPointTableRelation<FF>>("ECCVMPointTableRelation");
96 result = result && evaluate_relation.template operator()<ECCVMWnafRelation<FF>>("ECCVMWnafRelation");
97 result = result && evaluate_relation.template operator()<ECCVMMSMRelation<FF>>("ECCVMMSMRelation");
98 result = result && evaluate_relation.template operator()<ECCVMSetRelation<FF>>("ECCVMSetRelation");
99 result = result && evaluate_relation.template operator()<ECCVMBoolsRelation<FF>>("ECCVMBoolsRelation");
100
101 using LookupRelation = ECCVMLookupRelation<FF>;
103 for (auto& r : lookup_result) {
104 r = 0;
105 }
106 // Skip the disabled head rows (masking region) — row-disabling polynomial zeroes them in sumcheck
107 for (size_t i = Flavor::TRACE_OFFSET; i < num_rows; ++i) {
108 LookupRelation::accumulate(lookup_result, polynomials.get_row(i), params, 1);
109 }
110 for (auto r : lookup_result) {
111 if (r != 0) {
112 info("Relation ECCVMLookupRelation failed.");
113 return false;
114 }
115 }
116 return result;
117}
A container for the prover polynomials.
typename Curve::ScalarField FF
ECCVMCircuitBuilder CircuitBuilder
static constexpr size_t TRACE_OFFSET
static bool check(ECCVMCircuitBuilder &, numeric::RNG *engine_ptr=nullptr)
Structured polynomial class that represents the coefficients 'a' of a_0 + a_1 x .....
A wrapper for Relations to expose methods used by the Sumcheck prover or verifier to add the contribu...
ArrayOfValues< FF, RelationImpl::SUBRELATION_PARTIAL_LENGTHS > SumcheckArrayOfValuesOverSubrelations
#define info(...)
Definition log.hpp:93
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
AluTraceBuilder builder
Definition alu.test.cpp:124
typename ECCVMFlavor::ProverPolynomials ProverPolynomials
Entry point for Barretenberg command-line interface.
Definition api.hpp:5
Container for parameters used by the grand product (permutation, lookup) Honk relations.
constexpr field invert() const noexcept
static field random_element(numeric::RNG *engine=nullptr) noexcept
BB_INLINE constexpr field sqr() const noexcept