-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
457 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This is a hack needed to be able to use files that use stats (e.g., constraining/polynomials.cpp) in testing in vm2 | ||
// It can be removed once VM1 is removed and stats are moved to VM2. | ||
#include "barretenberg/vm/stats.cpp" |
93 changes: 93 additions & 0 deletions
93
barretenberg/cpp/src/barretenberg/vm2/constraining/polynomials.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#include "barretenberg/vm2/constraining/polynomials.hpp" | ||
|
||
#include <cstdint> | ||
|
||
#include "barretenberg/common/thread.hpp" | ||
#include "barretenberg/vm/stats.hpp" | ||
#include "barretenberg/vm2/common/constants.hpp" | ||
#include "barretenberg/vm2/generated/columns.hpp" | ||
|
||
namespace bb::avm2::constraining { | ||
|
||
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer& trace) | ||
{ | ||
AvmProver::ProverPolynomials polys; | ||
|
||
// Polynomials that will be shifted need special care. | ||
AVM_TRACK_TIME("proving/init_polys_to_be_shifted", ({ | ||
auto to_be_shifted = polys.get_to_be_shifted(); | ||
|
||
// TODO: cannot parallelize because Polynomial construction uses parallelism. | ||
for (size_t i = 0; i < to_be_shifted.size(); i++) { | ||
auto& poly = to_be_shifted[i]; | ||
// WARNING! Column-Polynomials order matters! | ||
Column col = static_cast<Column>(TO_BE_SHIFTED_COLUMNS_ARRAY.at(i)); | ||
// We need at least 2 rows for the shifted columns. | ||
uint32_t num_rows = std::max<uint32_t>(trace.get_column_rows(col), 2); | ||
|
||
poly = AvmProver::Polynomial( | ||
/*memory size*/ | ||
num_rows - 1, | ||
/*largest possible index*/ CIRCUIT_SUBGROUP_SIZE, | ||
/*make shiftable with offset*/ 1); | ||
} | ||
})); | ||
|
||
// Catch-all with fully formed polynomials | ||
// Note: derived polynomials (i.e., inverses) are not in the trace at this point, because they can only | ||
// be computed after committing to the other witnesses. Therefore, they will be initialized as empty | ||
// and they will be not set below. The derived polynomials will be reinitialized and set in the prover | ||
// itself mid-proving. (TO BE DONE!). | ||
// | ||
// NOTE FOR SELF: however, the counts will be known here and the inv have the same size? | ||
// think about it and check the formula. | ||
AVM_TRACK_TIME("proving/init_polys_unshifted", ({ | ||
auto unshifted = polys.get_unshifted(); | ||
|
||
// Derived polynomials will be empty. | ||
bb::parallel_for(unshifted.size(), [&](size_t i) { | ||
auto& poly = unshifted[i]; | ||
// FIXME: this is a bad way to check if the polynomial is already initialized. | ||
// It could be that it has been initialized, but it's all zeroes. | ||
if (!poly.is_empty()) { | ||
// Already initialized above. | ||
return; | ||
} | ||
|
||
// WARNING! Column-Polynomials order matters! | ||
Column col = static_cast<Column>(i); | ||
const auto num_rows = trace.get_column_rows(col); | ||
poly = AvmProver::Polynomial::create_non_parallel_zero_init(num_rows, CIRCUIT_SUBGROUP_SIZE); | ||
}); | ||
})); | ||
|
||
AVM_TRACK_TIME("proving/set_polys_unshifted", ({ | ||
auto unshifted = polys.get_unshifted(); | ||
|
||
// TODO: We are now visiting per-column. Profile if per-row is better. | ||
// This would need changes to the trace container. | ||
bb::parallel_for(unshifted.size(), [&](size_t i) { | ||
// WARNING! Column-Polynomials order matters! | ||
auto& poly = unshifted[i]; | ||
Column col = static_cast<Column>(i); | ||
|
||
trace.visit_column(col, [&](size_t row, const AvmProver::FF& value) { | ||
// We use `at` because we are sure the row exists and the value is non-zero. | ||
poly.at(row) = value; | ||
}); | ||
// We free columns as we go. | ||
// TODO: If we merge the init with the setting, this would be even more memory efficient. | ||
trace.clear_column(col); | ||
}); | ||
})); | ||
|
||
AVM_TRACK_TIME("proving/set_polys_shifted", ({ | ||
for (auto [shifted, to_be_shifted] : zip_view(polys.get_shifted(), polys.get_to_be_shifted())) { | ||
shifted = to_be_shifted.shifted(); | ||
} | ||
})); | ||
|
||
return polys; | ||
} | ||
|
||
} // namespace bb::avm2::constraining |
10 changes: 10 additions & 0 deletions
10
barretenberg/cpp/src/barretenberg/vm2/constraining/polynomials.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#pragma once | ||
|
||
#include "barretenberg/vm2/generated/prover.hpp" | ||
#include "barretenberg/vm2/tracegen/trace_container.hpp" | ||
|
||
namespace bb::avm2::constraining { | ||
|
||
AvmProver::ProverPolynomials compute_polynomials(tracegen::TraceContainer& trace); | ||
|
||
} // namespace bb::avm2::constraining |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
barretenberg/cpp/src/barretenberg/vm2/constraining/testing/check_relation.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include "barretenberg/vm2/constraining/testing/check_relation.hpp" | ||
|
||
namespace bb::avm2::constraining::detail { | ||
|
||
const RelationParameters<FF>& get_test_params() | ||
{ | ||
static RelationParameters<FF> params = { | ||
.eta = 0, | ||
.beta = FF::random_element(), | ||
.gamma = FF::random_element(), | ||
.public_input_delta = 0, | ||
.lookup_grand_product_delta = 0, | ||
.beta_sqr = 0, | ||
.beta_cube = 0, | ||
.eccvm_set_permutation_delta = 0, | ||
}; | ||
return params; | ||
} | ||
|
||
} // namespace bb::avm2::constraining::detail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.