-
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
Open
ssjeon-p
wants to merge
6
commits into
Rate-Limiting-Nullifier:main
Choose a base branch
from
ssjeon-p:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
bfbced3
feat: run for higher epoch_limit
ssjeon-p 2ac3a0d
minor fix
ssjeon-p 2acb7ea
Merge remote-tracking branch 'upstream/main'
ssjeon-p 98cdac2
style: check fmt&clippy
ssjeon-p 2c2b857
style: change array to tuple
ssjeon-p 3d5f400
style: remove useless clone
ssjeon-p File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,76 @@ 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: &[(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 mut matrix: Vec<Vec<Fr>> = vec![vec![Fr::from(1); size]]; | ||
matrix.push(vec_x); | ||
|
||
for i in 2..size { | ||
let next_row = matrix[i - 1] | ||
.iter() | ||
.zip(&matrix[1]) | ||
.map(|(&a, &b)| a * b) | ||
.collect(); | ||
matrix.push(next_row); | ||
} | ||
|
||
let numerator = y2 * x1 - y1 * x2; | ||
let denominator = x1 - x2; | ||
let denominator = determinant(matrix.clone()); | ||
matrix[0] = vec_y; | ||
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, col) in matrix.iter().enumerate().skip(i) { | ||
if col[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 +234,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()); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.