You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new method to AllocVar that creates a witness variable or constant in the constraint system depending on the type of cs.
Problem Definition
When feeding non-deterministic advice for some computation $f$ to a circuit, it is often desirable to call new_variable with a mode based on the context. That is, when the inputs to $f$ are all constant, we can choose AllocationMode::Constant for the advice to save some constraints for enforcing its validity. Otherwise, we need to choose AllocationMode::Witness.
However, doing so manually introduces redundancy. We can find many duplicated code fragments for this purpose in this repo, e.g.,
Furthermore, taking care for every advice allocation increases the mental burden of a circuit developer, while failing to do so may result in a larger circuit.
Proposal
This proposal aims to address the above problem by introducing a new method (tentatively dubbed new_hint) to AllocVar, which creates a constant if cs is None and a witness variable otherwise. The logic of new_hint should be similar as below:
Sure, new_variable_with_inferred_mode also sounds better to me! I agree that naming it by functionality is better than by usage, as users may use it in some other cases.
winderica
added a commit
to winderica/r1cs-std
that referenced
this issue
Apr 1, 2024
Summary
Add a new method to
AllocVar
that creates a witness variable or constant in the constraint system depending on the type ofcs
.Problem Definition
When feeding non-deterministic advice for some computation$f$ to a circuit, it is often desirable to call $f$ are all constant, we can choose
new_variable
with amode
based on the context. That is, when the inputs toAllocationMode::Constant
for the advice to save some constraints for enforcing its validity. Otherwise, we need to chooseAllocationMode::Witness
.However, doing so manually introduces redundancy. We can find many duplicated code fragments for this purpose in this repo, e.g.,
r1cs-std/src/groups/curves/twisted_edwards/mod.rs
Lines 120 to 138 in 4020fbc
r1cs-std/src/fields/quadratic_extension.rs
Lines 279 to 291 in 4020fbc
Furthermore, taking care for every advice allocation increases the mental burden of a circuit developer, while failing to do so may result in a larger circuit.
Proposal
This proposal aims to address the above problem by introducing a new method (tentatively dubbed
new_hint
) toAllocVar
, which creates a constant ifcs
isNone
and a witness variable otherwise. The logic ofnew_hint
should be similar as below:Please let me know what you think, and I can create a PR if this proposal looks good to you :)
For Admin Use
The text was updated successfully, but these errors were encountered: