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 for the linearly dependent part of the relation.
62 for (size_t j = 0; j < result.size(); ++j) {
63 if (!result[j].is_zero()) {
64 throw std::runtime_error(format(
65 "Relation ", Relation::NAME, ", subrelation ", Relation::get_subrelation_label(j), " failed."));
66 }
67 }
68 });
69 });
70
71 // Add calculation of logderivatives and lookup/permutation checks.
72 bb::constexpr_for<0, std::tuple_size_v<typename AvmFlavor::LookupRelations>, 1>([&]<size_t i>() {
74 checks.push_back([&, num_rows]() {
75 // Compute logderivs.
76 bb::compute_logderivative_inverse<typename AvmFlavor::FF, Relation>(polys, params, num_rows);
77
78 // Check the logderivative relation
80 for (size_t r = 0; r < num_rows; ++r) {
81 auto row = polys.get_row(r);
82 if constexpr (isSkippable<Relation, decltype(row)>) {
83 if (skippable_enabled && Relation::skip(row)) {
84 continue;
85 }
86 }
87
88 Relation::accumulate(lookup_result, row, params, 1);
89
90 for (size_t subrelation_idx = 0; subrelation_idx < lookup_result.size(); ++subrelation_idx) {
91 // We need to check the linearly independent part of the relation.
92 if (detail::subrelation_is_linearly_independent<Relation>(subrelation_idx) &&
93 !lookup_result[subrelation_idx].is_zero()) {
94 throw std::runtime_error(format("Lookup ",
95 Relation::NAME,
96 ", subrelation ",
97 Relation::get_subrelation_label(subrelation_idx),
98 " failed at row ",
99 r));
100 }
101 }
102 }
103 // Do final check for the linearly dependent part of the relation.
104 for (auto r : lookup_result) {
105 if (!r.is_zero()) {
106 throw std::runtime_error(format("Lookup ", Relation::NAME, " failed."));
107 }
108 }
109 });
110 });
111
112 // Do it!
113 bb::parallel_for(checks.size(), [&](size_t i) { checks[i](); });
114}
115
116} // 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:296
PolynomialEntitiesAtFixedRow< ProverPolynomials > get_row(size_t row_idx) const
Definition flavor.hpp:310
std::string format(Args... args)
Definition log.hpp:20
The templates defined herein facilitate sharing the relation arithmetic between the prover and the ve...
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:72
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.