Skip to content

Commit

Permalink
Merge pull request #31 from lattice-complete/29_ceiling_k
Browse files Browse the repository at this point in the history
fix: issue 29 use ceiling for size k
  • Loading branch information
pinhaocrypto authored Jan 6, 2025
2 parents 7fdfff9 + 6b0d123 commit d752488
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 21 additions & 2 deletions algebra/src/zq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions labrador/src/prover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Zq>> = (0..size_k.value())
.map(|_| {
(0..constraint_num_l.value())
Expand Down

0 comments on commit d752488

Please sign in to comment.