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 FromRaw impl for some curve points #50

Merged
merged 8 commits into from
Jan 16, 2025
Merged

Add FromRaw impl for some curve points #50

merged 8 commits into from
Jan 16, 2025

Conversation

maurges
Copy link
Contributor

@maurges maurges commented Dec 18, 2024

This is a small change, but I never contributed to generic-ec-core, so I'm taking suggestions on the whole design

@maurges maurges requested a review from survived December 18, 2024 13:39
@maurges
Copy link
Contributor Author

maurges commented Dec 18, 2024

The checks are failing because one dependency now requires "fontconfig", what

WTF happened here, I can't find yeslogic-fontconfig-sys in transitive dependencies

Comment on lines 254 to 259
/// # Safety
/// Safe to implement when the checks in `generic_ec::TryFromRaw` would always
/// return 1 for any point. Those checks are:
/// - `point.is_on_curve()`
/// - `point.is_torsion_free()`
pub unsafe trait NoInvalidPoints {}
Copy link
Contributor

Choose a reason for hiding this comment

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

It is strange to refer to the generic_ec::TryFromRaw trait which is located in upstream library. Maybe NoInvalidPoints should be in generic_ec?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If it's in generic-ec, then I can't refer to it to impl it in generic-ec-curves, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can, as it is a trait first defined in generic_ec

Copy link
Contributor

Choose a reason for hiding this comment

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

If you define a trait in your crate, you can implement it on whatever structs you want. Other crates, however, will only be able to implement your trait only on the types defined in those crates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean I would impl it in generic-ec as well? I thought for an unsafe trait it's better to keep it closer to the curves definitions, and also to have less of #[cfg(feature)] pollution

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, curves crate can't possibly implement trait from generic-ec as it's upstream, it would cause circular dependency.

I thought for an unsafe trait it's better to keep it closer to the curves definitions

I think, generally it's a good practice, but I also think it's acceptable to do otherwise in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

and also to have less of #[cfg(feature)] pollution

That's just one #[cfg(feature)] per each impl

Copy link
Contributor

@survived survived Dec 18, 2024

Choose a reason for hiding this comment

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

I mean, you can keep it in the core if you prefer, I just suggest to rewrite/update the comment to not refer to a trait in upstream crate

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you, it is a bit silly to ask the implementers to look at the downstream crate. I'll think about it a bit

generic-ec-core/src/lib.rs Outdated Show resolved Hide resolved
@survived
Copy link
Contributor

You need to set up sign-off for lockness repos, see https://github.com/LFDT-Lockness/generic-ec/pull/50/checks?check_run_id=34596977449

@survived
Copy link
Contributor

What is that?

check-all:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
with:
cache-on-failure: "true"
- name: Check everything
run: cargo check --all-targets

It should be cargo check --all-features...

@maurges
Copy link
Contributor Author

maurges commented Dec 18, 2024

You need to set up sign-off for lockness repos

Done with a force push

@survived
Copy link
Contributor

Ah okay, --all-targets means like all tests and examples... I was thinking about all targets like linux and ios

@survived
Copy link
Contributor

I'm also curious why in the CI we see that deps are being updated. Did you forget to commit Cargo.lock?

Run cargo test --all-features --workspace
    Updating crates.io index
     Locking 205 packages to latest compatible versions
      Adding generic-array v0.14.7 (available: v1.1.1)
      Adding phantom-type v0.4.2 (available: v0.5.2)
      Adding serde_with v2.3.3 (available: v3.11.0)
      Adding tabled v0.15.0 (available: v0.17.0)
   Compiling generic-array v0.14.7
   Compiling phantom-type v0.4.2
   Compiling yeslogic-fontconfig-sys v6.0.0
   Compiling serde_with v2.3.3

@maurges
Copy link
Contributor Author

maurges commented Dec 19, 2024

I'm also curious why in the CI we see that deps are being updated. Did you forget to commit Cargo.lock?

Well I found out yesterday that we never actually had a lockfile in this repo at all. So now we can't even know what broke, our dependencies or ubuntu-latest in the runner

@survived
Copy link
Contributor

ah well, can you commit your cargo lock? Maybe it will help

@survived
Copy link
Contributor

Or you did a fresh build?

@maurges
Copy link
Contributor Author

maurges commented Dec 19, 2024

I did a fresh build. You can add your own cargo-lock to this PR

Signed-off-by: Denis Varlakov <[email protected]>
@survived
Copy link
Contributor

Let's see if that helps

@maurges
Copy link
Contributor Author

maurges commented Dec 20, 2024

Nope, still misses fontconfig. I guess I'll try downgrading ubuntu image next

@survived
Copy link
Contributor

You can also install a package

@maurges
Copy link
Contributor Author

maurges commented Dec 20, 2024

Or I could do that. I didn't because all the ways to do it are stupid and waste compute, or overcomplicated

Signed-off-by: maurges <[email protected]>
@maurges
Copy link
Contributor Author

maurges commented Dec 27, 2024

So I see two easy choices: either install the missing package, or explicilty use ubuntu-22.04 instead of ubuntu-latest - according to docs, until recently 22.04 was the "latest", and I can confirm that CI passes with it selected

@survived
Copy link
Contributor

survived commented Jan 7, 2025

I'm fine with whatever option!

Copy link
Contributor

@survived survived left a comment

Choose a reason for hiding this comment

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

Probably it's also a good idea to re-export NoInvalidPoints trait in generic_ec::traits?

pub mod traits {
#[doc(inline)]
pub use crate::core::{One, Reduce, Samplable, Zero};
/// Trait that allows you to check whether value is zero
pub trait IsZero {
/// Checks whether `self` is zero
fn is_zero(&self) -> bool;
}
}

generic-ec-core/src/lib.rs Outdated Show resolved Hide resolved
@maurges
Copy link
Contributor Author

maurges commented Jan 15, 2025

Probably it's also a good idea to re-export NoInvalidPoints trait in generic_ec::traits?

I don't think we should, this is a low-level trait for implementing, while for usage there exists the corresponding high-level trait FromRaw

Signed-off-by: maurges <[email protected]>
@survived
Copy link
Contributor

wouldn't it be helpful to be able to write E: Curve + NoInvalidPoints in generic bounds?

@maurges maurges merged commit 963f404 into m Jan 16, 2025
24 checks passed
@maurges maurges deleted the point-from-raw branch January 16, 2025 15:05
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