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

Add generate_random_point(), bump patch version. #148

Merged
merged 5 commits into from
Oct 19, 2021

Conversation

tmpfs
Copy link
Contributor

@tmpfs tmpfs commented Oct 12, 2021

No description provided.

@survived
Copy link
Contributor

survived commented Oct 12, 2021

Can I ask you to move this function to curv::elliptic::curves::secp256k1::hash_to_curve module? (you'll need to create a new module hash_to_curve). I find this relocation suitable since the function is specific to secp256k1 curve. Also I'd like to replace it with different more generic hash-to-curve implementation in near future, so it's better to keep it deeper for now 🙂

@tmpfs
Copy link
Contributor Author

tmpfs commented Oct 13, 2021

Sure thing @survived, that is done 👍

@elichai
Copy link
Contributor

elichai commented Oct 13, 2021

Thanks for the PR!

src/elliptic/curves/secp256_k1.rs Outdated Show resolved Hide resolved
Comment on lines +531 to +535
let truncated = if bytes.len() > compressed_point_len - 1 {
&bytes[0..compressed_point_len - 1]
} else {
&bytes
};
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe force bytes to be 32 bytes?(use an array) otherwise there can be collisions, say generate_random_point(&[1u8; 32]) == generate_random_point(&[1u8; 40])

Copy link
Contributor

Choose a reason for hiding this comment

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

Good point, but we'll have to update all the places it's being called from. Actually, I checked — all the times it called in bulletproof crate, 64 bytes are passed 😄. But that can be relatively easily fixed

use crate::{arithmetic::traits::*, BigInt};
use generic_array::{typenum::Unsigned, GenericArray};

pub fn generate_random_point(bytes: &[u8]) -> Point<Secp256k1> {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what's "random" here?
If what is the use-case here? if it's to create NUMS points then lets do that instead?(e.g keep hashing the generator to generate more and more points, or even hash some random data if you need to make sure it is a unique NUMS point)

Copy link
Contributor

Choose a reason for hiding this comment

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

@elichai, the function is just copypasted from bulletproofs/centipede repos. It's purpose is to take uniformly distributed bytes and produce a point with unknown logarithm.

The reason why the function is appeared here — it's being used in two different crates (bulletproofs/centipede), but they just copypast it. So this PR basically removes code duplication in these crates.

My intention was to move that function here for now without modifications, and then replace with some proper generic hash-to-curve implementation (e.g. this one)

Copy link
Contributor

Choose a reason for hiding this comment

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

ohh I unerstand

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, we can merge it as is and change later

src/elliptic/curves/secp256_k1.rs Outdated Show resolved Hide resolved
Comment on lines +546 to +550
let bn = BigInt::from_bytes(bytes);
let two = BigInt::from(2);
let bn_times_two = BigInt::mod_mul(&bn, &two, Scalar::<Secp256k1>::group_order());
let bytes = BigInt::to_bytes(&bn_times_two);
generate_random_point(&bytes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a specific reason why multiply by 2 and reduce mod p and not hash it or something? (I'm not sure that's better but I'm curious what do you think)

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps @omershlo can answer this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, as I said above, I'd like to replace this function with something more generic and well-researched in near future, so it's supposed to be a temporary solution

@survived survived merged commit 89de0e6 into ZenGo-X:master Oct 19, 2021
@tmpfs
Copy link
Contributor Author

tmpfs commented Oct 19, 2021

@survived, I was hoping to get a patch version published at 0.8.3 then to update bulletproofs and centipede to use this version of generate_random_point() but when I pull master I notice the version has been updated to 0.9.0 and the published crate is at 0.8.2.

Whats the best way to proceed?

@survived
Copy link
Contributor

@tmpfs I'm releasing v0.8.3 with your patch right now, but I'd like to update all crates to use v0.9. No changes are required (besides switching on curv's generate_random_point()). I can update all the PRs on my own

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.

None yet

3 participants