Use closures in enforce_constraints and new_lc#176
Merged
Conversation
weikengchen
approved these changes
Jun 11, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors linear combination construction to defer computation via closures and updates related APIs accordingly.
- Replaced eager
cs.new_lc(...)calls with closure-based invocations (|| …) throughout the code. - Refactored
add_many,linear_combination, and inner-product methods to buildLinearCombinationlazily. - Adjusted dependency sourcing in
Cargo.tomlto use a git reference forark-relations.
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/fields/fp/mod.rs | Swapped cs.new_lc to use closures; updated signatures for batching and linear-comb methods. |
| src/eq.rs | Converted enforce_r1cs_constraint calls to closure form. |
| src/boolean/select.rs | Updated constraint invocations to use closures and lc_diff!. |
| src/boolean/mod.rs | Enhanced lc for Constant(true) and added a variable() helper. |
| src/boolean/eq.rs | Refactored conditional equality methods to closures and lc_diff!. |
| src/boolean/allocated.rs | Switched R1CS constraints to closure syntax and lc_diff!. |
| Cargo.toml | Pointed ark-relations to a git repo and commented out patch entries. |
Comments suppressed due to low confidence (2)
src/fields/fp/mod.rs:159
- [nitpick] The signature change from a generic
IntoIteratorto a slice&[B]is a breaking API change. To maintain flexibility, consider re-introducing an overload or supportingIntoIteratordirectly.
pub fn add_many<B: Borrow<Self>>(iter: &[B]) -> Option<Self> {
src/fields/fp/mod.rs:207
- The generic bound
I1: IntoIterator<Item = B1, IntoIter: Clone>is invalid Rust syntax. Split it into separate bounds:I1: IntoIterator<Item = B1>, I1::IntoIter: Cloneto compile successfully.
pub fn linear_combination<B1, B2, I1>(this: I1, other: &[B2]) -> Option<Self>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
Corresponds to arkworks-rs/snark#405
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
Pendingsection inCHANGELOG.mdFiles changedin the Github PR explorer