Skip to content

Commit

Permalink
Fix handling of None in Num::add (#88)
Browse files Browse the repository at this point in the history
* Fix value handling in Num::add

* Attempt to fix check-lurk-compiles CI workflow

* Attempt to install deps in CI

* Use correct action path

* Better attempt at fixing CI
  • Loading branch information
wwared authored and huitseeker committed Mar 19, 2024
1 parent 02cdf17 commit 34b5379
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
env:
RUSTFLAGS: -D warnings
steps:
- uses: actions/checkout@v4
with:
repository: lurk-lab/ci-workflows
- uses: ./.github/actions/ci-env
- uses: ./.github/actions/install-deps
with:
packages: 'pkg-config libssl-dev protobuf-compiler libprotobuf-dev'
- uses: actions/checkout@v4
with:
path: ${{ github.workspace }}/bellpepper
Expand All @@ -59,6 +66,7 @@ jobs:
run: |
echo "[patch.'https://github.com/lurk-lab/bellpepper']" >> Cargo.toml
echo "bellpepper = { path='../bellpepper/crates/bellpepper' }" >> Cargo.toml
echo "[patch.crates-io]" >> Cargo.toml
echo "bellpepper-core = { path='../bellpepper/crates/bellpepper-core' }" >> Cargo.toml
- name: Check Lurk-rs types don't break spectacularly
working-directory: ${{ github.workspace }}/lurk
Expand Down
20 changes: 18 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,23 @@ 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());
let c = a.clone().add(&a);
assert!(c.value == Some(Fr::ZERO));
}

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

0 comments on commit 34b5379

Please sign in to comment.