Skip to content

Commit

Permalink
Fix value handling in Num::add
Browse files Browse the repository at this point in the history
  • Loading branch information
wwared committed Mar 12, 2024
1 parent 9e8dcac commit 56a9354
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/bellpepper-core/src/gadgets/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,7 @@ impl<Scalar: PrimeField> Num<Scalar> {
tmp.add_assign(&v2);
Some(tmp)
}
(Some(v), None) | (None, Some(v)) => Some(v),
(None, None) => None,
_ => None,
};

Num { value, lc }
Expand Down Expand Up @@ -571,6 +570,21 @@ mod test {
assert!(cs.get("num") == Fr::ONE);
}

#[test]
fn test_num_partial_addition() {
let a = Num::<Fr>::zero();
let b = Num::<Fr> {
value: None,
lc: Default::default(),
};
let c = a.clone().add(&b);
assert!(c.value.is_none());
let c = b.clone().add(&a);
assert!(c.value.is_none());
let c = b.clone().add(&b);
assert!(c.value.is_none());
}

#[test]
fn test_num_addition() {
let mut cs = TestConstraintSystem::<Fr>::new();
Expand Down

0 comments on commit 56a9354

Please sign in to comment.