Prechádzať zdrojové kódy

make combinecomm more functional-style

Ian Goldberg 3 mesiacov pred
rodič
commit
c640a12c27
1 zmenil súbory, kde vykonal 14 pridanie a 13 odobranie
  1. 14 13
      src/shine.rs

+ 14 - 13
src/shine.rs

@@ -218,20 +218,21 @@ pub fn combinecomm_polys(
     assert!(mu >= 2 * (t as usize) - 1);
     assert!(mu == lag_polys.len());
     assert!(mu == lag_polys[0].coeffs.len());
-    for i in (t as usize)..mu {
-        let mut bi = RistrettoPoint::identity();
-        for j in 0..mu {
-            bi += lag_polys[j].coeffs[i] * commitments[j];
-        }
-        if bi != RistrettoPoint::identity() {
-            return None;
-        }
-    }
-    let mut res = RistrettoPoint::identity();
-    for j in 0..mu {
-        res += lag_polys[j].coeffs[0] * commitments[j];
+    if ((t as usize)..mu)
+        .map(|i| {
+            (0..mu)
+                .map(|j| lag_polys[j].coeffs[i] * commitments[j])
+                .sum()
+        })
+        .any(|bi: RistrettoPoint| bi != RistrettoPoint::identity())
+    {
+        return None;
     }
-    Some(res)
+    Some(
+        (0..mu)
+            .map(|j| lag_polys[j].coeffs[0] * commitments[j])
+            .sum(),
+    )
 }
 
 // Combine commitments. Return None if the commitments are not