diff --git a/algebra/src/zq.rs b/algebra/src/zq.rs index 86c06ca..06c14a0 100644 --- a/algebra/src/zq.rs +++ b/algebra/src/zq.rs @@ -26,13 +26,19 @@ impl Zq { } } - pub fn value(&self) -> usize { + pub fn value(self) -> usize { self.value } - pub fn pow(&self, other: usize) -> Self { + pub fn pow(self, other: usize) -> Self { Zq::new(self.value.pow(other as u32)) } + + // bypass clippy for now as we'll implement Zq in isize/i64 (no div_ceil function supported) later + #[allow(clippy::manual_div_ceil)] + pub fn div_ceil(self, other: Zq) -> Zq { + Zq::new((self.value + other.value - 1) / other.value) + } } impl PartialOrd for Zq { @@ -156,4 +162,17 @@ mod tests { let result = a % b; assert_eq!(result.value, 1); } + + #[test] + fn test_zq_ceil_div() { + let mut a; + let mut b; + a = Zq::new(10); + b = Zq::new(3); + assert_eq!(a.div_ceil(b).value(), 4); + + a = Zq::new(9); + b = Zq::new(3); + assert_eq!(a.div_ceil(b).value(), 3); + } } diff --git a/labrador/src/prover.rs b/labrador/src/prover.rs index 90d0369..47b18ee 100644 --- a/labrador/src/prover.rs +++ b/labrador/src/prover.rs @@ -295,8 +295,8 @@ pub fn prove( println!("Prover: Do aggregation"); // 4. GOAL: Aggregation // 4.1 psi^(k) is randomly chosen from Z_q^{L} - // k = 1..λ/log2^q - let size_k = Zq::new(lambda.value() / log_q.value()); + // k = 1..ceil(λ/log2^q) + let size_k = lambda.div_ceil(log_q); let psi: Vec> = (0..size_k.value()) .map(|_| { (0..constraint_num_l.value())