-
Notifications
You must be signed in to change notification settings - Fork 234
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
feat: removed redundant scalar muls from the verifiers using shplemini #9392
Merged
Merged
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4702ddd
added a method to remove shifted commitments
iakovenkos ebb5c06
eccvm supports shifted removal
iakovenkos 738565e
Merge branch 'master' into si/zk-sumcheck-plus-shplemini
iakovenkos fc161ec
removed shifted comms from mega and eccvm verifiers
iakovenkos b417485
translator draft adjustments
iakovenkos 33fc216
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos ed20963
translator 820k
iakovenkos 630e10c
removed shifted commitments in all shplemini verifiers
iakovenkos 7a2028a
restored zeromorph's master state
iakovenkos 4f5edc4
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos 4ac6cc7
tests + docs + clean-up
iakovenkos 9086b3e
Merge branch 'si/shplemini-shifts-removal' of github.com:AztecProtoco…
iakovenkos acbd1a5
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos 3392bec
noisy empty lines removed
iakovenkos a1d1796
resolving comments
iakovenkos 4681a19
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos 96cc1b0
added offset for zk
iakovenkos 8eff6aa
small fixes
iakovenkos 774f117
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos df0fd90
reverted changes in ultra and mega/removed assert
iakovenkos 5898638
slightly changed docs [skip ci]
iakovenkos 4c7360b
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos 0ca39f9
fixed comment
iakovenkos 90482ca
Merge branch 'master' into si/shplemini-shifts-removal
iakovenkos 5af5391
added a todo
iakovenkos 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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
#include "barretenberg/commitment_schemes/gemini/gemini_impl.hpp" | ||
#include "barretenberg/commitment_schemes/shplonk/shplonk.hpp" | ||
#include "barretenberg/commitment_schemes/verification_key.hpp" | ||
#include "barretenberg/flavor/repeated_commitments_data.hpp" | ||
#include "barretenberg/transcript/transcript.hpp" | ||
|
||
namespace bb { | ||
|
@@ -132,6 +133,7 @@ template <typename Curve> class ShpleminiVerifier_ { | |
const std::vector<Fr>& multivariate_challenge, | ||
const Commitment& g1_identity, | ||
const std::shared_ptr<Transcript>& transcript, | ||
const RepeatedCommitmentsData& repeated_commitments = {}, | ||
RefSpan<Commitment> libra_univariate_commitments = {}, | ||
const std::vector<Fr>& libra_univariate_evaluations = {}, | ||
const std::vector<RefVector<Commitment>>& concatenation_group_commitments = {}, | ||
|
@@ -288,6 +290,8 @@ template <typename Curve> class ShpleminiVerifier_ { | |
commitments.emplace_back(g1_identity); | ||
scalars.emplace_back(constant_term_accumulator); | ||
|
||
remove_repeated_commitments(commitments, scalars, repeated_commitments, has_zk); | ||
|
||
// For ZK flavors, the sumcheck output contains the evaluations of Libra univariates that submitted to the | ||
// ShpleminiVerifier, otherwise this argument is set to be empty | ||
if (has_zk) { | ||
|
@@ -493,13 +497,92 @@ template <typename Curve> class ShpleminiVerifier_ { | |
} | ||
} | ||
|
||
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. the main feature introduced in this PR |
||
/** | ||
* @brief Combines scalars of repeating commitments to reduce the number of scalar multiplications performed by the | ||
* verifier. | ||
* | ||
* @details The Shplemini verifier gets the access to multiple groups of commitments, some of which are duplicated | ||
* because they correspond to polynomials whose shifts also evaluated or used in concatenation groups in | ||
* Translator. This method combines the scalars associated with these repeating commitments, reducing the total | ||
* number of scalar multiplications required during the verification. | ||
* | ||
* More specifically, the Shplemini verifier receives two or three groups of commitments: get_unshifted() and | ||
* get_to_be_shifted() in the case of Ultra, Mega, and ECCVM Flavors; and get_unshifted_without_concatenated(), | ||
* get_to_be_shifted(), and get_groups_to_be_concatenated() in the case of the TranslatorFlavor. The commitments are | ||
* then placed in this specific order in a BatchOpeningClaim object containing a vector of commitments and a vector | ||
* of scalars. The ranges with repeated commitments belong to the Flavors. This method iterates over these ranges | ||
* and sums the scalar multipliers corresponding to the same group element. After combining the scalars, we erase | ||
* corresponding entries in both vectors. | ||
* | ||
*/ | ||
static void remove_repeated_commitments(std::vector<Commitment>& commitments, | ||
std::vector<Fr>& scalars, | ||
const RepeatedCommitmentsData& repeated_commitments, | ||
bool has_zk) | ||
{ | ||
// We started populating commitments and scalars by adding Shplonk:Q commitmment and the corresponding scalar | ||
// factor 1. In the case of ZK, we also added Gemini:masking_poly_comm before populating the vector with | ||
// commitments to prover polynomials | ||
const size_t offset = has_zk ? 2 : 1; | ||
|
||
// Extract the indices from the container, which is normally created in a given Flavor | ||
const size_t& first_range_to_be_shifted_start = repeated_commitments.first_range_to_be_shifted_start + offset; | ||
const size_t& first_range_shifted_start = repeated_commitments.first_range_shifted_start + offset; | ||
const size_t& first_range_size = repeated_commitments.first_range_size; | ||
|
||
const size_t& second_range_to_be_shifted_start = repeated_commitments.second_range_to_be_shifted_start + offset; | ||
const size_t& second_range_shifted_start = repeated_commitments.second_range_shifted_start + offset; | ||
const size_t& second_range_size = repeated_commitments.second_range_size; | ||
|
||
// Iterate over the first range of to-be-shifted scalars and their shifted counterparts | ||
for (size_t i = 0; i < first_range_size; i++) { | ||
size_t idx_to_be_shifted = i + first_range_to_be_shifted_start; | ||
size_t idx_shifted = i + first_range_shifted_start; | ||
scalars[idx_to_be_shifted] = scalars[idx_to_be_shifted] + scalars[idx_shifted]; | ||
} | ||
|
||
// Iterate over the second range of to-be-shifted precomputed scalars and their shifted counterparts (if | ||
// provided) | ||
for (size_t i = 0; i < second_range_size; i++) { | ||
size_t idx_to_be_shifted = i + second_range_to_be_shifted_start; | ||
size_t idx_shifted = i + second_range_shifted_start; | ||
scalars[idx_to_be_shifted] = scalars[idx_to_be_shifted] + scalars[idx_shifted]; | ||
} | ||
|
||
if (second_range_shifted_start > first_range_shifted_start) { | ||
// Erase the shifted scalars and commitments from the second range (if provided) | ||
for (size_t i = 0; i < second_range_size; ++i) { | ||
scalars.erase(scalars.begin() + static_cast<std::ptrdiff_t>(second_range_shifted_start)); | ||
commitments.erase(commitments.begin() + static_cast<std::ptrdiff_t>(second_range_shifted_start)); | ||
} | ||
|
||
// Erase the shifted scalars and commitments from the first range | ||
for (size_t i = 0; i < first_range_size; ++i) { | ||
scalars.erase(scalars.begin() + static_cast<std::ptrdiff_t>(first_range_shifted_start)); | ||
commitments.erase(commitments.begin() + static_cast<std::ptrdiff_t>(first_range_shifted_start)); | ||
} | ||
} else { | ||
// Erase the shifted scalars and commitments from the first range | ||
for (size_t i = 0; i < first_range_size; ++i) { | ||
scalars.erase(scalars.begin() + static_cast<std::ptrdiff_t>(first_range_shifted_start)); | ||
commitments.erase(commitments.begin() + static_cast<std::ptrdiff_t>(first_range_shifted_start)); | ||
} | ||
// Erase the shifted scalars and commitments from the second range (if provided) | ||
for (size_t i = 0; i < second_range_size; ++i) { | ||
scalars.erase(scalars.begin() + static_cast<std::ptrdiff_t>(second_range_shifted_start)); | ||
commitments.erase(commitments.begin() + static_cast<std::ptrdiff_t>(second_range_shifted_start)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @brief Add the opening data corresponding to Libra masking univariates to the batched opening claim | ||
* | ||
* @details After verifying ZK Sumcheck, the verifier has to validate the claims about the evaluations of Libra | ||
* univariates used to mask Sumcheck round univariates. To minimize the overhead of such openings, we continue the | ||
* Shplonk batching started in Gemini, i.e. we add new claims multiplied by a suitable power of the Shplonk batching | ||
* challenge and re-use the evaluation challenge sampled to prove the evaluations of Gemini polynomials. | ||
* univariates used to mask Sumcheck round univariates. To minimize the overhead of such openings, we continue | ||
* the Shplonk batching started in Gemini, i.e. we add new claims multiplied by a suitable power of the Shplonk | ||
* batching challenge and re-use the evaluation challenge sampled to prove the evaluations of Gemini | ||
* polynomials. | ||
* | ||
* @param commitments | ||
* @param scalars | ||
|
@@ -541,8 +624,8 @@ template <typename Curve> class ShpleminiVerifier_ { | |
if constexpr (!Curve::is_stdlib_type) { | ||
Fr::batch_invert(denominators); | ||
} | ||
// add Libra commitments to the vector of commitments; compute corresponding scalars and the correction to the | ||
// constant term | ||
// add Libra commitments to the vector of commitments; compute corresponding scalars and the correction to | ||
// the constant term | ||
for (const auto [libra_univariate_commitment, denominator, libra_univariate_evaluation] : | ||
zip_view(libra_univariate_commitments, denominators, libra_univariate_evaluations)) { | ||
commitments.push_back(std::move(libra_univariate_commitment)); | ||
|
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.
We really need to clean up these pcs test files by having single methods that generate input rather than duplicating code over and over again (similar to what we do for circuits). I previously added an issue on this. Just saying, not suggesting that it's something that should be done in this PR