-
Notifications
You must be signed in to change notification settings - Fork 598
fix: default pp handling #20516
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
Merged
Merged
fix: default pp handling #20516
Changes from all commits
Commits
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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ template <typename Curve> struct PairingPoints { | |
| const Group& P1() const { return _points[1]; } | ||
|
|
||
| bool is_populated() const { return has_data_; } | ||
| bool is_default() const { return is_default_; } | ||
|
|
||
| PairingPoints() = default; | ||
|
|
||
|
|
@@ -187,6 +188,7 @@ template <typename Curve> struct PairingPoints { | |
| transcript.add_to_hash_buffer("Aggregated_P1", other.P1()); | ||
| auto recursion_separator = | ||
| transcript.template get_challenge<typename Curve::ScalarField>("recursion_separator"); | ||
| is_default_ = false; // After aggregation, points are no longer default | ||
| // If Mega Builder is in use, the EC operations are deferred via Goblin. | ||
| // batch_mul with constant scalar 1 is optimal here (Goblin uses add instead of mul). | ||
| if constexpr (std::is_same_v<Builder, MegaCircuitBuilder>) { | ||
|
|
@@ -215,11 +217,21 @@ template <typename Curve> struct PairingPoints { | |
|
|
||
| /** | ||
| * @brief Set the witness indices for the pairing points to public | ||
| * @details For default (infinity) pairing points, uses set_default_to_public which directly adds zero limbs | ||
| * as public inputs, bypassing bigfield::set_public() which cannot handle constant-coordinate infinity points. | ||
| * @param ctx Optional builder context; required for default pairing points which have no circuit context. | ||
| * @return uint32_t The index into the public inputs array at which the representation is stored | ||
| */ | ||
| uint32_t set_public() | ||
| uint32_t set_public(Builder* ctx = nullptr) | ||
| { | ||
| BB_ASSERT(this->has_data_, "Calling set_public on empty pairing points."); | ||
| if (is_default_) { | ||
| Builder* builder = validate_context<Builder>(ctx, P0().get_context(), P1().get_context()); | ||
| BB_ASSERT(builder != nullptr, "set_public on default pairing points requires a builder context."); | ||
| return set_default_to_public(builder); | ||
| } | ||
| Builder* builder = validate_context<Builder>(ctx, P0().get_context(), P1().get_context()); | ||
| builder->pairing_points_tagging.set_public_pairing_points(); | ||
|
Contributor
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. much better here! |
||
| uint32_t start_idx = P0().set_public(); | ||
| P1().set_public(); | ||
| return start_idx; | ||
|
|
@@ -255,15 +267,13 @@ template <typename Curve> struct PairingPoints { | |
| */ | ||
| static uint32_t set_default_to_public(Builder* builder) | ||
| { | ||
| builder->pairing_points_tagging.set_public_pairing_points(); | ||
| // Infinity is represented as (0,0) in biggroup. Directly add zero limbs as public inputs, bypassing bigfield's | ||
| // self_reduce. | ||
| uint32_t start_idx = 0; | ||
| uint32_t start_idx = static_cast<uint32_t>(builder->num_public_inputs()); | ||
| for (size_t i = 0; i < PUBLIC_INPUTS_SIZE; i++) { | ||
| uint32_t idx = builder->add_public_variable(bb::fr(0)); | ||
| builder->fix_witness(idx, bb::fr(0)); | ||
| if (i == 0) { | ||
| start_idx = idx; | ||
| } | ||
| } | ||
| return start_idx; | ||
| } | ||
|
|
@@ -276,12 +286,15 @@ template <typename Curve> struct PairingPoints { | |
| { | ||
| Group P0(Fq(0), Fq(0), /*assert_on_curve=*/false); | ||
| Group P1(Fq(0), Fq(0), /*assert_on_curve=*/false); | ||
| return PairingPoints(P0, P1); | ||
| PairingPoints pp(P0, P1); | ||
| pp.is_default_ = true; | ||
| return pp; | ||
| } | ||
|
|
||
| private: | ||
| std::array<Group, 2> _points; | ||
| bool has_data_ = false; | ||
| bool is_default_ = false; // True for default (infinity) pairing points from construct_default() | ||
| }; | ||
|
|
||
| template <typename NCT> std::ostream& operator<<(std::ostream& os, PairingPoints<NCT> const& as) | ||
|
|
||
This file contains hidden or 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 hidden or 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.
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.
Prefer BB_UNUSED on declaration or [[maybe_unused]]