Skip to content

Commit 2bba8e5

Browse files
Add AllocatedNum::from_parts for zero-cost variable reuse (#487)
* Initial plan * Add AllocatedNum::from_parts for zero-cost variable reuse Agent-Logs-Url: https://github.com/microsoft/Nova/sessions/320df23a-c5ac-4356-a593-cc6405d5053e Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com> * Bump crate version to 0.70.0 Agent-Logs-Url: https://github.com/microsoft/Nova/sessions/ae64668a-600c-47d5-bfca-1ad9c1198884 Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com> * fix build --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: srinathsetty <14947526+srinathsetty@users.noreply.github.com> Co-authored-by: Srinath Setty <srinath@microsoft.com>
1 parent e47799a commit 2bba8e5

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nova-snark"
3-
version = "0.69.0"
3+
version = "0.70.0"
44
authors = ["Srinath Setty <srinath@microsoft.com>"]
55
edition = "2021"
66
description = "High-speed recursive arguments from folding schemes"

src/frontend/gadgets/num.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,20 @@ impl<Scalar: PrimeField> Clone for AllocatedNum<Scalar> {
2424
}
2525

2626
impl<Scalar: PrimeField> AllocatedNum<Scalar> {
27+
/// Construct an [`AllocatedNum`] from a variable and value without adding constraints.
28+
///
29+
/// # Safety (Logical)
30+
/// The caller MUST ensure that:
31+
/// 1. The variable already exists in the constraint system
32+
/// 2. The value correctly reflects the variable's assignment
33+
///
34+
/// This is useful when a variable is known to hold a valid field element
35+
/// due to constraints added separately, enabling zero-cost reinterpretation
36+
/// (e.g., wrapping an [`AllocatedBit`](super::boolean::AllocatedBit)'s variable as a number).
37+
pub fn from_parts(variable: Variable, value: Option<Scalar>) -> Self {
38+
AllocatedNum { value, variable }
39+
}
40+
2741
/// Returns an `AllocatedNum` wrapping the built-in `CS::one()` variable.
2842
/// Costs zero constraints since it uses the input-0 wire directly.
2943
pub fn one<CS: ConstraintSystem<Scalar>>() -> Self {

0 commit comments

Comments
 (0)