From 34b537995d78de1aa1b0ee7c904fa163399dad1f Mon Sep 17 00:00:00 2001 From: wwared Date: Tue, 12 Mar 2024 17:42:42 -0300 Subject: [PATCH] Fix handling of None in Num::add (#88) * 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 --- .github/workflows/rust.yml | 8 ++++++++ crates/bellpepper-core/src/gadgets/num.rs | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bde61aa..2adfd2e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -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 @@ -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 diff --git a/crates/bellpepper-core/src/gadgets/num.rs b/crates/bellpepper-core/src/gadgets/num.rs index dfe0e6b..faaf740 100644 --- a/crates/bellpepper-core/src/gadgets/num.rs +++ b/crates/bellpepper-core/src/gadgets/num.rs @@ -520,8 +520,7 @@ impl Num { tmp.add_assign(&v2); Some(tmp) } - (Some(v), None) | (None, Some(v)) => Some(v), - (None, None) => None, + _ => None, }; Num { value, lc } @@ -571,6 +570,23 @@ mod test { assert!(cs.get("num") == Fr::ONE); } + #[test] + fn test_num_partial_addition() { + let a = Num::::zero(); + let b = Num:: { + 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::::new();