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 const size_t unmasked_witness_size = num_rows - NUM_DISABLED_ROWS_IN_SUMCHECK;
48 compute_logderivative_inverse<FF, ECCVMLookupRelation<FF>>(polynomials, params, unmasked_witness_size);
49 compute_grand_product<Flavor, ECCVMSetRelation<FF>>(polynomials, params, unmasked_witness_size);
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 for (size_t i = 0; i < num_rows; ++i) {
61 auto row = polynomials.get_row(i);
62#ifdef FUZZING
63 // Check if the relation is skippable and should be skipped (only in fuzzing builds)
64 if constexpr (isSkippable<Relation, decltype(row)>) {
65 // Only accumulate if the relation should not be skipped
66 if (!Relation::skip(row)) {
67 Relation::accumulate(result, row, params, 1);
68 }
69 } else {
70 // If not skippable, always accumulate
71 Relation::accumulate(result, row, params, 1);
72 }
73#else
74 // In non-fuzzing builds, always accumulate for maximum security
75 Relation::accumulate(result, row, params, 1);
76#endif
77
78 bool x = true;
79 for (size_t j = 0; j < NUM_SUBRELATIONS; ++j) {
80 if (result[j] != 0) {
81 info("Relation ", relation_name, ", subrelation index ", j, " failed at row ", i);
82 x = false;
83 }
84 }
85 if (!x) {
86 return false;
87 }
88 }
89 return true;
90 };
91
92 bool result = true;
93 result = result && evaluate_relation.template operator()<ECCVMTranscriptRelation<FF>>("ECCVMTranscriptRelation");
94 result = result && evaluate_relation.template operator()<ECCVMPointTableRelation<FF>>("ECCVMPointTableRelation");
95 result = result && evaluate_relation.template operator()<ECCVMWnafRelation<FF>>("ECCVMWnafRelation");
96 result = result && evaluate_relation.template operator()<ECCVMMSMRelation<FF>>("ECCVMMSMRelation");
97 result = result && evaluate_relation.template operator()<ECCVMSetRelation<FF>>("ECCVMSetRelation");
98 result = result && evaluate_relation.template operator()<ECCVMBoolsRelation<FF>>("ECCVMBoolsRelation");
99
100 using LookupRelation = ECCVMLookupRelation<FF>;
102 for (auto& r : lookup_result) {
103 r = 0;
104 }
105 for (size_t i = 0; i < num_rows; ++i) {
106 LookupRelation::accumulate(lookup_result, polynomials.get_row(i), params, 1);
107 }
108 for (auto r : lookup_result) {
109 if (r != 0) {
110 info("Relation ECCVMLookupRelation failed.");
111 return false;
112 }
113 }
114 return result;
115}
A container for the prover polynomials.
typename Curve::ScalarField FF
ECCVMCircuitBuilder CircuitBuilder
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