Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: issue 29 use ceiling for size k #31

Merged
merged 3 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
pinhaocypher marked this conversation as resolved.
Show resolved Hide resolved
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
Loading