-
Notifications
You must be signed in to change notification settings - Fork 3
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
feat: run for higher epoch_limit #2
base: main
Are you sure you want to change the base?
Changes from 2 commits
bfbced3
2ac3a0d
2acb7ea
98cdac2
2c2b857
3d5f400
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ use once_cell::sync::Lazy; | |
type UniPoly_381 = DensePolynomial<<Bls12_381 as PairingEngine>::Fr>; | ||
type KZG = KZG10<Bls12_381, UniPoly_381>; | ||
|
||
const EPOCH_LIMIT: u8 = 1; | ||
const EPOCH_LIMIT: u8 = 3; | ||
const DEGREE: usize = EPOCH_LIMIT as usize; | ||
|
||
static KEYS: Lazy<(Powers<Bls12_381>, VerifierKey<Bls12_381>)> = Lazy::new(|| { | ||
|
@@ -95,25 +95,72 @@ impl RLN { | |
messages.push((message_hash, evaluation)); | ||
|
||
if messages.len() > self.limit as usize { | ||
let key = Self::recover_key([messages[0], messages[1]]); | ||
let key = Self::recover_key(messages); | ||
let pubkey = KEYS.1.g.mul(key); | ||
assert!(self.shares.get(&pubkey).is_some()); | ||
|
||
self.shares.remove(&pubkey).unwrap(); | ||
} | ||
} | ||
|
||
fn recover_key(shares: [(Fr, Fr); (EPOCH_LIMIT + 1) as usize]) -> Fr { | ||
let (x1, y1) = shares[0]; | ||
let (x2, y2) = shares[1]; | ||
fn recover_key(shares: &Vec<(Fr, Fr)>) -> Fr { | ||
let size = (EPOCH_LIMIT + 1) as usize; | ||
let vec_x: Vec<Fr> = shares.iter().map(|a| {a.0}).collect(); | ||
let vec_y: Vec<Fr> = shares.iter().map(|a| {a.1}).collect(); | ||
|
||
let numerator = y2 * x1 - y1 * x2; | ||
let denominator = x1 - x2; | ||
let mut matrix: Vec<Vec<Fr>> = vec![vec![Fr::from(1); size]]; | ||
matrix.push(vec_x.clone()); | ||
|
||
for i in 2..size { | ||
let next_row = matrix[i-1].iter().zip(&vec_x).map(|(&a, &b)| {a * b}).collect(); | ||
matrix.push(next_row); | ||
} | ||
|
||
let denominator = determinant(matrix.clone()); | ||
_ = std::mem::replace(&mut matrix[0], vec_y); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not just matrix[0] = vec_y; ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That simple code didn't work previously for some reason. |
||
let numerator = determinant(matrix); | ||
|
||
numerator / denominator | ||
} | ||
} | ||
|
||
fn determinant(mut matrix: Vec<Vec<Fr>>) -> Fr { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing here, don't need to take ownership of Vector, can just get slice |
||
let n = matrix.len(); | ||
let mut det = Fr::from(1); | ||
|
||
for i in 0..n { | ||
let mut pivot_row = i; | ||
for j in (i + 1)..n { | ||
if matrix[j][i] != Fr::from(0) { | ||
pivot_row = j; | ||
break; | ||
} | ||
} | ||
|
||
if pivot_row != i { | ||
matrix.swap(i, pivot_row); | ||
det = -det; | ||
} | ||
|
||
let pivot = matrix[i][i]; | ||
|
||
if pivot == Fr::from(0) { | ||
return Fr::from(0); | ||
} | ||
|
||
det *= pivot; | ||
|
||
for j in (i + 1)..n { | ||
let factor = matrix[j][i] / pivot; | ||
for k in (i + 1)..n { | ||
matrix[j][k] = matrix[j][k] - factor * matrix[i][k]; | ||
} | ||
} | ||
} | ||
|
||
det | ||
} | ||
|
||
struct User { | ||
polynomial: UniPoly_381, | ||
} | ||
|
@@ -183,8 +230,9 @@ fn main() { | |
user.register(&mut rln); | ||
assert!(rln.shares.get(&user.pubkey()).is_some()); | ||
|
||
user.send(Fr::rand(rng), &mut rln); | ||
user.send(Fr::rand(rng), &mut rln); | ||
for _ in 0..EPOCH_LIMIT+1 { | ||
user.send(Fr::rand(rng), &mut rln); | ||
} | ||
|
||
assert!(rln.shares.get(&user.pubkey()).is_none()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
determinant()
takes slice - you won't need to clone matrixThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The determinant function manipulates the matrix, but I need the original matrix one more time.
I think this needs cloning here.