zkcrypto / ff

Traits and utilities for working with finite fields.
Apache License 2.0
236 stars 101 forks source link

Consider promoting `Field::{zero, one}` to associated constants #87

Closed tarcieri closed 1 year ago

tarcieri commented 2 years ago

Right now Field::zero() and Field::one() are static methods of the Field trait.

If they were instead associated constants, e.g. Field::ZERO/Field::ONE, they can be used in const contexts such as defining other constants:

pub struct ProjectivePoint<Fe: Field> { x: Fe, y: Fe, z: Fe }

impl<Fe: Field> ProjectivePoint<Fe> {
    pub const IDENTITY: Self = Self {
        x: Fe::ZERO,
        y: Fe::ONE,
        z: Fe::ZERO,
    };
}
str4d commented 1 year ago

I vaguely recall that at the time the traits were first written, there were limitations on how the associated constants could be either constructed or used? I don't recall the specifics, but the course of action depends on several things:

str4d commented 1 year ago

I've opened #94 so we can test the first bullet point.