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

feat: run for higher epoch_limit #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

ssjeon-p
Copy link

@ssjeon-p ssjeon-p commented Sep 6, 2023

This runs in the case EPOCH_LIMIT > 1.
To recover key f(0), this uses the Cramer's rule for Vandermonde matrix(https://en.wikipedia.org/wiki/Vandermonde_matrix#Applications).

I could not find a proper mod for determinant, so copy and modify "https://github.com/EdgarBarrantes/field-matrix"

Copy link
Contributor

@curryrasul curryrasul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you.
Though I noticed there are few places where clippy & fmt may be unhappy.

I pushed a Rust CI to check this. You'll probably also need to pull last changes to pass the checks (as I added Cargo.toml in root, to make it workspace).

Thanks, will wait for your fixes and then I'll merge it.

@curryrasul
Copy link
Contributor

@ssjeon-p As you see cargo fmt check didn't pass.
Please install fmt and clippy and check if it's formatted well and there're no clippy warnings before pushing changes.

Thank you!

@ssjeon-p
Copy link
Author

@curryrasul,
I struggled with using github properly, the previous commit yesterday was my mistake.
I checked fmt&clippy now.
Thank you for reviewing!

Copy link
Contributor

@curryrasul curryrasul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Thanks for fixing fmt and clippy. Change back share to a tuple or give me a reason why you decided to change it to array.

Thanks!

versionA/src/main.rs Outdated Show resolved Hide resolved
@ssjeon-p ssjeon-p closed this Sep 19, 2023
@ssjeon-p ssjeon-p reopened this Sep 19, 2023
Copy link
Contributor

@curryrasul curryrasul left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for bothering you with requests, but let's make the PR cool and final result clean and good!)

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shares should be &[(Fr, Fr)] - slice - as it's immutable. It's a good practice.

@@ -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.to_vec());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not good to do to_vec() without good reason, as it clones whole vector. If recover_key function takes just slice (as I commented further) it would be possible to just pass messages.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand. I removed this and some other useless cloning.


numerator / denominator
}
}

fn determinant(mut matrix: Vec<Vec<Fr>>) -> Fr {
Copy link
Contributor

Choose a reason for hiding this comment

The 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 numerator = y2 * x1 - y1 * x2;
let denominator = x1 - x2;
let denominator = determinant(matrix.clone());
Copy link
Contributor

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 matrix

Copy link
Author

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.

let numerator = y2 * x1 - y1 * x2;
let denominator = x1 - x2;
let denominator = determinant(matrix.clone());
_ = std::mem::replace(&mut matrix[0], vec_y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just

matrix[0] = vec_y;

?
I didn't test it, but am I missing something ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That simple code didn't work previously for some reason.
But, as I tested it now, it works properly.

@ssjeon-p
Copy link
Author

Thank you for the detailed review!
I'm learning a lot from this.
I'll reply to the requests, and commit it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants