Motivation
Currently there's a way to define constant field element using field_new!(), however, there's no way of defining a constant group element over a curve.
An symptom of this problem in the library is demonstrated here -- being forced to declare generator point by its (x, y) coordinates separately as opposed to directly as a point.
Problem
Currently GroupAffine/GroupProjective::new() is not a pub const fn, and those structs contains a private/inaccessible field _params: PhantomData to be constructed directly, thus there's no way of constructing one.
Failed Attempt
The natural solution is to update new() to pub const fn new(), however, the compiler would give the following complain:
--> ec/src/models/twisted_edwards_extended.rs:55:6
|
55 | impl<P: Parameters> GroupAffine<P> {
| ^
|
= note: see issue #57563 <https://github.com/rust-lang/rust/issues/57563> for more information
= help: add `#![feature(const_fn)]` to the crate attributes to enable
The strange thing is why can we have the following in impl_Fp!(), but not ☝️ above:
impl<P> $Fp<P> {
#[inline]
pub const fn new(element: $BigIntegerType) -> Self {
Self(element, PhantomData)
}
The reason is mostly due to the wacky status quo of limited subset of const fn support in stable Rust. From a friend of mine who knew better about these progress:
having a totally generic type with no restrictions on it is allowed in const fn on stable currently
...
MIRI (Mid-level InteRmediate Interpereter) is too unstable currently to let them stabilize a lot of the remaining const bits
...
MIRI was designed to detect undefined behavior in unsafe code, but kinda got shoved into the role of being used to implement const
so its not yet 100% semantically compatible with the actual rust compiler, partially because its not done cooking, and partially because rust hasn't actually offically adopted stacked borrows yet (https://plv.mpi-sws.org/rustbelt/stacked-borrows/)
Proposed Action
- wait until respective
const fn support in Rust Stable and come back to this issue.
(cc @weikengchen feel free to add more of your GroupAffine<F, P> idea if you find fit)
Motivation
Currently there's a way to define constant field element using
field_new!(), however, there's no way of defining a constant group element over a curve.An symptom of this problem in the library is demonstrated here -- being forced to declare generator point by its (x, y) coordinates separately as opposed to directly as a point.
Problem
Currently
GroupAffine/GroupProjective::new()is not apub const fn, and those structs contains a private/inaccessible field_params: PhantomDatato be constructed directly, thus there's no way of constructing one.Failed Attempt
The natural solution is to update
new()topub const fn new(), however, the compiler would give the following complain:The strange thing is why can we have the following in
impl_Fp!(), but not ☝️ above:The reason is mostly due to the wacky status quo of limited subset of
const fnsupport in stable Rust. From a friend of mine who knew better about these progress:Proposed Action
const fnsupport in Rust Stable and come back to this issue.(cc @weikengchen feel free to add more of your
GroupAffine<F, P>idea if you find fit)