feat: add built-in zero wire (Aux(0)) to constraint system#491
Open
sai-deng wants to merge 3 commits intomicrosoft:mainfrom
Open
feat: add built-in zero wire (Aux(0)) to constraint system#491sai-deng wants to merge 3 commits intomicrosoft:mainfrom
sai-deng wants to merge 3 commits intomicrosoft:mainfrom
Conversation
Reserve Aux(0) as a built-in zero variable, enforced with a single 0 * 0 = Aux(0) constraint at CS construction time. This makes AllocatedNum::zero() and alloc_zero() free (zero additional constraints or variables), mirroring AllocatedNum::one(). - Add CS::zero() -> Variable to ConstraintSystem trait + all impls - All CS types (ShapeCS, WitnessCS, TestShapeCS, TestConstraintSystem) initialize with Aux(0)=0 and the enforcement constraint - WitnessCS::extend() skips aux[0] like it skips input[0] - AllocatedNum::zero() wraps CS::zero() with no constraints - alloc_zero() delegates to AllocatedNum::zero() - Net savings: ~7 constraints per augmented circuit
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a built-in “zero wire” (Aux(0)) across the bellpepper-style constraint systems in this repo, enforced once at CS construction time via a 0 * 0 = Aux(0) constraint. This makes AllocatedNum::zero() / alloc_zero() effectively free and reduces constraint counts in Nova/Neutron augmented circuits.
Changes:
- Add
ConstraintSystem::zero() -> Variable(defaulting toAux(0)) and thread it through wrapper CS types. - Initialize all CS implementations with
Aux(0)=0plus a single enforcement constraint0 * 0 = Aux(0); ensureWitnessCS::extend()skips aux[0]. - Switch
AllocatedNum::zero()andalloc_zero()to use the built-in zero wire; update expected digests/constraint-count tests accordingly.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/frontend/constraint_system.rs | Adds ConstraintSystem::zero() and forwards it through Namespace / &mut CS impls. |
| src/frontend/shape_cs.rs | Reserves Aux(0) and injects the single “zero enforcement” constraint into shapes. |
| src/frontend/util_cs/witness_cs.rs | Pre-initializes aux with 0 and updates extend() to skip aux[0]. |
| src/frontend/util_cs/test_cs.rs | Test CS now starts with Aux(0)=0 and a built-in “ZERO” constraint. |
| src/frontend/test_shape_cs.rs | Test shape CS now reserves Aux(0) and records the built-in constraint/aux name. |
| src/frontend/gadgets/num.rs | Adds AllocatedNum::zero() and updates constraint-count assertions in tests. |
| src/frontend/gadgets/multieq.rs | Forwards zero() through the MultiEq CS wrapper. |
| src/gadgets/utils.rs | Makes alloc_zero() delegate to AllocatedNum::zero() (no alloc/enforce). |
| src/nova/circuit/mod.rs | Updates expected constraint counts reflecting net savings. |
| src/nova/mod.rs | Updates expected public-parameter digest test vectors due to shape/witness layout changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
… neutron expects - Remove default impl for CS::zero(); all root CS types now provide explicit impls. Prevents soundness footgun for external impls. - Add doc comment on zero() specifying implementor invariants (reserve Aux(0), enforce 0*0=Aux(0), exclude from alloc). - Add test_allocated_num_zero unit test. - Fix extend() comments to say 'built-in reserved slot' not 'temporarily allocated'. - Update neutron circuit constraint counts and pp_digest expects (behind 'experimental' feature).
Replace all 8 alloc_zero() call sites with AllocatedNum::zero::<CS>() and remove the alloc_zero function entirely, matching how alloc_one was previously removed in favor of AllocatedNum::one().
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.
Reserve Aux(0) as a built-in zero variable, enforced with a single 0 * 0 = Aux(0) constraint at CS construction time. This makes AllocatedNum::zero() and alloc_zero() free (zero additional constraints or variables), mirroring AllocatedNum::one().