Skip to content

Commit

Permalink
style: check fmt&clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
ssjeon-p committed Sep 19, 2023
1 parent 2acb7ea commit 98cdac2
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions versionA/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ static KEYS: Lazy<(Powers<Bls12_381>, VerifierKey<Bls12_381>)> = Lazy::new(|| {

struct RLN {
limit: u8,
shares: HashMap<G1Projective, (Commitment<Bls12_381>, Vec<(Fr, Fr)>)>,
shares: HashMap<G1Projective, (Commitment<Bls12_381>, Vec<[Fr; 2]>)>,
}

impl RLN {
Expand Down Expand Up @@ -92,27 +92,31 @@ impl RLN {
assert!(KZG::check(&KEYS.1, comm, message_hash, evaluation, &proof)
.expect("Wrong opening proof"));

messages.push((message_hash, evaluation));
messages.push([message_hash, evaluation]);

if messages.len() > self.limit as usize {
let key = Self::recover_key(messages);
let key = Self::recover_key(messages.to_vec());
let pubkey = KEYS.1.g.mul(key);
assert!(self.shares.get(&pubkey).is_some());

self.shares.remove(&pubkey).unwrap();
}
}

fn recover_key(shares: &Vec<(Fr, Fr)>) -> Fr {
fn recover_key(shares: Vec<[Fr; 2]>) -> 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 vec_x: Vec<Fr> = shares.iter().map(|a| a[0]).collect();
let vec_y: Vec<Fr> = shares.iter().map(|a| a[1]).collect();

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();
let next_row = matrix[i - 1]
.iter()
.zip(&vec_x)
.map(|(&a, &b)| a * b)
.collect();
matrix.push(next_row);
}

Expand All @@ -130,8 +134,8 @@ fn determinant(mut matrix: Vec<Vec<Fr>>) -> Fr {

for i in 0..n {
let mut pivot_row = i;
for j in (i + 1)..n {
if matrix[j][i] != Fr::from(0) {
for (j, col) in matrix.iter().enumerate().skip(i) {
if col[i] != Fr::from(0) {
pivot_row = j;
break;
}
Expand Down Expand Up @@ -230,7 +234,7 @@ fn main() {
user.register(&mut rln);
assert!(rln.shares.get(&user.pubkey()).is_some());

for _ in 0..EPOCH_LIMIT+1 {
for _ in 0..EPOCH_LIMIT + 1 {
user.send(Fr::rand(rng), &mut rln);
}

Expand Down

0 comments on commit 98cdac2

Please sign in to comment.