-
Notifications
You must be signed in to change notification settings - Fork 184
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(bb): more graceful pippenger on non-powers-of-2 #8279
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
5616be3
remove redundant pippenger param
ludamad 57d4d81
speed up non powers of 2 in pippenger
ludamad bb6b7cc
fix commitmentkey: rounding up to power of 2
ludamad d6d08d0
comment
ludamad 4a871b2
comment and use new pippenger
ludamad cf62795
comment and use new pippenger
ludamad 01efa1f
working
ludamad 5c8418a
revert
ludamad cb8f5e6
revert
ludamad 536ebbe
std span
ludamad 528142a
revert
ludamad c371e37
Update scalar_multiplication.cpp
ludamad 94e6df3
Update scalar_multiplication.cpp
ludamad 7dc942b
Update scalar_multiplication.cpp
ludamad 25f64be
Update scalar_multiplication.cpp
ludamad bf21caf
Update scalar_multiplication.hpp
ludamad 1b16007
compile fix
ludamad 485d627
Merge branch 'master' into ad/pippenger-edge-case-smoothing
ludamad 39a9525
fix scalar mul edge cases. woops, tried to be too clever
ludamad 47c7736
Merge remote-tracking branch 'origin/ad/pippenger-edge-case-smoothing…
ludamad 686c4a5
Merge branch 'master' into ad/pippenger-edge-case-smoothing
ludamad c3e37c5
speculative fix
ludamad ac15f5b
Merge remote-tracking branch 'origin/ad/pippenger-edge-case-smoothing…
ludamad 7dae750
better error
ludamad a9c2617
fix edge case causing srs size too big
ludamad 2be10cd
revert
ludamad 70f03c5
format
ludamad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 | ||||
---|---|---|---|---|---|---|
|
@@ -129,6 +129,22 @@ template <typename Curve> void bench_commit_random(::benchmark::State& state) | |||||
key->commit(polynomial); | ||||||
} | ||||||
} | ||||||
// Commit to a polynomial with dense random nonzero entries but NOT our happiest case of an exact power of 2 | ||||||
// Note this used to be a 50% regression just subtracting a power of 2 by 1. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe something like this is a bit more clear. |
||||||
template <typename Curve> void bench_commit_random_non_power_of_2(::benchmark::State& state) | ||||||
{ | ||||||
using Fr = typename Curve::ScalarField; | ||||||
auto key = create_commitment_key<Curve>(MAX_NUM_POINTS); | ||||||
|
||||||
const size_t num_points = 1 << state.range(0); | ||||||
auto polynomial = Polynomial<Fr>(num_points - 1); | ||||||
for (auto& coeff : polynomial) { | ||||||
coeff = Fr::random_element(); | ||||||
} | ||||||
for (auto _ : state) { | ||||||
key->commit(polynomial); | ||||||
} | ||||||
} | ||||||
|
||||||
BENCHMARK(bench_commit_zero<curve::BN254>) | ||||||
->DenseRange(MIN_LOG_NUM_POINTS, MAX_LOG_NUM_POINTS) | ||||||
|
@@ -148,6 +164,9 @@ BENCHMARK(bench_commit_sparse_random_preprocessed<curve::BN254>) | |||||
BENCHMARK(bench_commit_random<curve::BN254>) | ||||||
->DenseRange(MIN_LOG_NUM_POINTS, MAX_LOG_NUM_POINTS) | ||||||
->Unit(benchmark::kMillisecond); | ||||||
BENCHMARK(bench_commit_random_non_power_of_2<curve::BN254>) | ||||||
->DenseRange(MIN_LOG_NUM_POINTS, MAX_LOG_NUM_POINTS) | ||||||
->Unit(benchmark::kMillisecond); | ||||||
|
||||||
} // namespace bb | ||||||
|
||||||
|
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 |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
#include "barretenberg/common/op_count.hpp" | ||
#include "barretenberg/ecc/scalar_multiplication/scalar_multiplication.hpp" | ||
#include "barretenberg/numeric/bitop/get_msb.hpp" | ||
#include "barretenberg/numeric/bitop/pow.hpp" | ||
#include "barretenberg/polynomials/polynomial_arithmetic.hpp" | ||
#include "barretenberg/srs/factories/crs_factory.hpp" | ||
|
@@ -34,6 +35,17 @@ template <class Curve> class CommitmentKey { | |
using Fr = typename Curve::ScalarField; | ||
using Commitment = typename Curve::AffineElement; | ||
using G1 = typename Curve::AffineElement; | ||
static constexpr size_t EXTRA_SRS_POINTS_FOR_ECCVM_IPA = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Iirc it’s not strictly an ECCVM thing but generally applies for IPA? |
||
|
||
static size_t get_num_needed_srs_points(size_t num_points) | ||
{ | ||
// NOTE 1: Currently we must round up internal space for points as our pippenger algorithm (specifically, | ||
// pippenger_unsafe_optimized_for_non_dyadic_polys) will use next power of 2. This is used to simplify the | ||
// recursive halving scheme. We do, however allow the polynomial to not be fully formed. Pippenger internally | ||
// will pad 0s into the runtime state. | ||
// NOTE 2: We then add one for ECCVM to provide for IPA verification | ||
return numeric::round_up_power_2(num_points) + EXTRA_SRS_POINTS_FOR_ECCVM_IPA; | ||
} | ||
|
||
public: | ||
scalar_multiplication::pippenger_runtime_state<Curve> pippenger_runtime_state; | ||
|
@@ -50,9 +62,9 @@ template <class Curve> class CommitmentKey { | |
* | ||
*/ | ||
CommitmentKey(const size_t num_points) | ||
: pippenger_runtime_state(num_points) | ||
: pippenger_runtime_state(get_num_needed_srs_points(num_points)) | ||
, crs_factory(srs::get_crs_factory<Curve>()) | ||
, srs(crs_factory->get_prover_crs(num_points)) | ||
, srs(crs_factory->get_prover_crs(get_num_needed_srs_points(num_points))) | ||
{} | ||
|
||
// Note: This constructor is to be used only by Plonk; For Honk the srs lives in the CommitmentKey | ||
|
@@ -70,16 +82,17 @@ template <class Curve> class CommitmentKey { | |
Commitment commit(std::span<const Fr> polynomial) | ||
{ | ||
BB_OP_COUNT_TIME(); | ||
const size_t degree = polynomial.size(); | ||
if (degree > srs->get_monomial_size()) { | ||
info("Attempting to commit to a polynomial of degree ", | ||
degree, | ||
" with an SRS of size ", | ||
// See constructor, we must round up the number of used srs points to a power of 2. | ||
const size_t consumed_srs = numeric::round_up_power_2(polynomial.size()); | ||
if (consumed_srs > srs->get_monomial_size()) { | ||
info("Attempting to commit to a polynomial that needs ", | ||
consumed_srs, | ||
" points with an SRS of size ", | ||
srs->get_monomial_size()); | ||
ASSERT(false); | ||
} | ||
return scalar_multiplication::pippenger_unsafe<Curve>( | ||
polynomial, srs->get_monomial_points(), degree, pippenger_runtime_state); | ||
return scalar_multiplication::pippenger_unsafe_optimized_for_non_dyadic_polys<Curve>( | ||
polynomial, { srs->get_monomial_points(), srs->get_monomial_size() }, pippenger_runtime_state); | ||
}; | ||
|
||
/** | ||
|
@@ -145,8 +158,7 @@ template <class Curve> class CommitmentKey { | |
} | ||
|
||
// Call the version of pippenger which assumes all points are distinct | ||
return scalar_multiplication::pippenger_unsafe<Curve>( | ||
scalars, points.data(), scalars.size(), pippenger_runtime_state); | ||
return scalar_multiplication::pippenger_unsafe<Curve>(scalars, points.data(), pippenger_runtime_state); | ||
} | ||
}; | ||
|
||
|
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this only running some of the tube tests now? Is this intended?