Skip to content

Commit 1af2e33

Browse files
committed
feat(avm): skippable check-circuit
1 parent 880075b commit 1af2e33

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

barretenberg/cpp/src/barretenberg/vm2/avm_api.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,15 @@ bool AvmAPI::check_circuit(const AvmAPI::ProvingInputs& inputs)
4545
info("Generating trace...");
4646
AvmTraceGenHelper tracegen_helper;
4747
tracegen::TraceContainer trace;
48-
tracegen_helper.fill_trace_columns(trace, std::move(events), inputs.publicInputs);
48+
AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_columns(trace, std::move(events), inputs.publicInputs));
4949

5050
// Go into interactive debug mode if requested.
5151
if (getenv("AVM_DEBUG") != nullptr) {
5252
InteractiveDebugger debugger(trace);
5353
debugger.run();
5454
}
5555

56-
tracegen_helper.fill_trace_interactions(trace);
56+
AVM_TRACK_TIME("tracegen/all", tracegen_helper.fill_trace_interactions(trace));
5757

5858
// Check circuit.
5959
info("Checking circuit...");

barretenberg/cpp/src/barretenberg/vm2/constraining/check_circuit.cpp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
#include "barretenberg/common/thread.hpp"
1111
#include "barretenberg/honk/proof_system/logderivative_library.hpp"
1212
#include "barretenberg/relations/relation_parameters.hpp"
13+
#include "barretenberg/vm2/constraining/testing/check_relation.hpp"
1314
#include "barretenberg/vm2/generated/columns.hpp"
1415

1516
namespace bb::avm2::constraining {
1617

17-
void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows)
18+
void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows, bool skippable_enabled)
1819
{
1920
bb::RelationParameters<AvmFlavor::FF> params = {
2021
.eta = 0,
@@ -37,9 +38,18 @@ void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows)
3738
typename Relation::SumcheckArrayOfValuesOverSubrelations result{};
3839

3940
for (size_t r = 0; r < num_rows; ++r) {
40-
Relation::accumulate(result, polys.get_row(r), {}, 1);
41+
auto row = polys.get_row(r);
42+
if constexpr (isSkippable<Relation, decltype(row)>) {
43+
if (skippable_enabled && Relation::skip(row)) {
44+
continue;
45+
}
46+
}
47+
48+
Relation::accumulate(result, row, {}, 1);
49+
50+
// Check the linearly independent part of the relation.
4151
for (size_t j = 0; j < result.size(); ++j) {
42-
if (!result[j].is_zero()) {
52+
if (detail::subrelation_is_linearly_independent<Relation>(j) && !result[j].is_zero()) {
4353
throw std::runtime_error(format("Relation ",
4454
Relation::NAME,
4555
", subrelation ",
@@ -49,6 +59,13 @@ void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows)
4959
}
5060
}
5161
}
62+
// Do final check for the linearly dependent part of the relation.
63+
for (size_t j = 0; j < result.size(); ++j) {
64+
if (!result[j].is_zero()) {
65+
throw std::runtime_error(format(
66+
"Relation ", Relation::NAME, ", subrelation ", Relation::get_subrelation_label(j), " failed."));
67+
}
68+
}
5269
});
5370
});
5471

@@ -62,8 +79,29 @@ void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows)
6279
// Check the logderivative relation
6380
typename Relation::SumcheckArrayOfValuesOverSubrelations lookup_result{};
6481
for (size_t r = 0; r < num_rows; ++r) {
65-
Relation::accumulate(lookup_result, polys.get_row(r), params, 1);
82+
auto row = polys.get_row(r);
83+
if constexpr (isSkippable<Relation, decltype(row)>) {
84+
if (skippable_enabled && Relation::skip(row)) {
85+
continue;
86+
}
87+
}
88+
89+
Relation::accumulate(lookup_result, row, params, 1);
90+
91+
for (size_t subrelation_idx = 0; subrelation_idx < lookup_result.size(); ++subrelation_idx) {
92+
// We need to check the linearly independent part of the relation.
93+
if (detail::subrelation_is_linearly_independent<Relation>(subrelation_idx) &&
94+
!lookup_result[subrelation_idx].is_zero()) {
95+
throw std::runtime_error(format("Lookup ",
96+
Relation::NAME,
97+
", subrelation ",
98+
Relation::get_subrelation_label(subrelation_idx),
99+
" failed at row ",
100+
r));
101+
}
102+
}
66103
}
104+
// Do final check for the linearly dependent part of the relation.
67105
for (auto r : lookup_result) {
68106
if (!r.is_zero()) {
69107
throw std::runtime_error(format("Lookup ", Relation::NAME, " failed."));

barretenberg/cpp/src/barretenberg/vm2/constraining/check_circuit.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ namespace bb::avm2::constraining {
88

99
// This is a version of check circuit that runs on the prover polynomials.
1010
// It is the closest to "real proving" that we can get without actually running the prover.
11-
void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows);
11+
void run_check_circuit(AvmFlavor::ProverPolynomials& polys, size_t num_rows, bool skippable_enabled = true);
1212

1313
} // namespace bb::avm2::constraining

barretenberg/cpp/src/barretenberg/vm2/proving_helper.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,18 @@ bool AvmProvingHelper::check_circuit(tracegen::TraceContainer&& trace)
8989
// PLUS one extra row to catch any possible errors in the empty remainder
9090
// of the circuit.
9191
const size_t num_rows = trace.get_num_rows_without_clk() + 1;
92-
info("Running check circuit over ", num_rows, " rows.");
92+
const bool skippable_enabled = true;
93+
info("Running check ",
94+
skippable_enabled ? "(with skippable)" : "(without skippable)",
95+
" circuit over ",
96+
num_rows,
97+
" rows.");
9398

9499
// Warning: this destroys the trace.
95100
auto polynomials = AVM_TRACK_TIME_V("proving/prove:compute_polynomials", constraining::compute_polynomials(trace));
96101
try {
97-
AVM_TRACK_TIME("proving/check_circuit", constraining::run_check_circuit(polynomials, num_rows));
102+
AVM_TRACK_TIME("proving/check_circuit",
103+
constraining::run_check_circuit(polynomials, num_rows, skippable_enabled));
98104
} catch (std::runtime_error& e) {
99105
// FIXME: This exception is never caught because it's thrown in a different thread.
100106
// Execution never gets here!

0 commit comments

Comments
 (0)