Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
check_circuit.cpp
Go to the documentation of this file.
2
3#include <array>
4#include <functional>
5#include <span>
6#include <stdexcept>
7
15
17
18void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows, bool skippable_enabled)
19{
21 .eta = 0,
22 .beta = AvmFlavor::FF::random_element(),
23 .gamma = AvmFlavor::FF::random_element(),
24 .public_input_delta = 0,
25 .beta_sqr = 0,
26 .beta_cube = 0,
27 .eccvm_set_permutation_delta = 0,
28 };
29
30 // Checks that we will run.
31 std::vector<std::function<void()>> checks;
32
33 // Add relation checks.
34 bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::MainRelations>, 1>([&]<size_t i>() {
36 checks.push_back([&]() {
38
39 for (size_t r = 0; r < num_rows; ++r) {
40 auto row = polys.get_row(r);
41 if constexpr (isSkippable<Relation, decltype(row)>) {
42 if (skippable_enabled && Relation::skip(row)) {
43 continue;
44 }
45 }
46
47 Relation::accumulate(result, row, {}, 1);
48
49 // Check the linearly independent part of the relation.
50 for (size_t j = 0; j < result.size(); ++j) {
51 if (detail::subrelation_is_linearly_independent<Relation>(j) && !result[j].is_zero()) {
52 throw std::runtime_error(format("Relation ",
53 Relation::NAME,
54 ", subrelation ",
55 Relation::get_subrelation_label(j),
56 " failed at row ",
57 r));
58 }
59 }
60 }
61 // Do final check (accumulation over all rows) for all the subrelations and in
62 // particular the linearly dependent ones. (Linearly independent sub-relations are
63 // checked to be zero as each row by the above loop so their accumulation is zero.)
64 for (size_t j = 0; j < result.size(); ++j) {
65 if (!result[j].is_zero()) {
66 throw std::runtime_error(format(
67 "Relation ", Relation::NAME, ", subrelation ", Relation::get_subrelation_label(j), " failed."));
68 }
69 }
70 });
71 });
72
73 // Add calculation of logderivatives and lookup/permutation checks.
74 bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::LookupRelations>, 1>([&]<size_t i>() {
76 checks.push_back([&, num_rows]() {
77 // We need to resize the inverse polynomials for the relation, now that the selectors have been computed.
79 Relation::Settings::INVERSES,
80 Relation::Settings::SRC_SELECTOR,
81 Relation::Settings::DST_SELECTOR);
82
83 // Compute logderivs.
84 bb::compute_logderivative_inverse<typename AvmFlavor::FF, Relation>(polys, params, num_rows);
85
86 // Check the logderivative relation
88 for (size_t r = 0; r < num_rows; ++r) {
89 auto row = polys.get_row(r);
90 if constexpr (isSkippable<Relation, decltype(row)>) {
91 if (skippable_enabled && Relation::skip(row)) {
92 continue;
93 }
94 }
95
96 Relation::accumulate(lookup_result, row, params, 1);
97
98 for (size_t subrelation_idx = 0; subrelation_idx < lookup_result.size(); ++subrelation_idx) {
99 // We need to check the linearly independent part of the relation.
100 if (detail::subrelation_is_linearly_independent<Relation>(subrelation_idx) &&
101 !lookup_result[subrelation_idx].is_zero()) {
102 throw std::runtime_error(format("Lookup ",
103 Relation::NAME,
104 ", subrelation ",
105 Relation::get_subrelation_label(subrelation_idx),
106 " failed at row ",
107 r));
108 }
109 }
110 }
111 // Do final check for the linearly dependent part of the relation.
112 for (auto r : lookup_result) {
113 if (!r.is_zero()) {
114 throw std::runtime_error(format("Lookup ", Relation::NAME, " failed."));
115 }
116 }
117 });
118 });
119
120 // Do it!
121 bb::parallel_for(checks.size(), [&](size_t i) { checks[i](); });
122}
123
124} // namespace bb::avm2::constraining
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
A container for the prover polynomials handles.
Definition flavor.hpp:281
PolynomialEntitiesAtFixedRow< ProverPolynomials > get_row(size_t row_idx) const
Definition flavor.hpp:298
std::string format(Args... args)
Definition log.hpp:21
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
void resize_inverses(AvmFlavor::ProverPolynomials &prover_polynomials, Column inverses_col, Column src_selector_col, Column dst_selector_col)
void run_check_circuit(AvmFlavor::ProverPolynomials &polys, size_t num_rows, bool skippable_enabled)
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
Definition thread.cpp:111
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13
Container for parameters used by the grand product (permutation, lookup) Honk relations.