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

Other possible sqrt-related operations #33

Closed
str4d opened this issue Sep 4, 2020 · 3 comments · Fixed by #93
Closed

Other possible sqrt-related operations #33

str4d opened this issue Sep 4, 2020 · 3 comments · Fixed by #93

Comments

@str4d
Copy link
Member

str4d commented Sep 4, 2020

We removed the SqrtField trait in ff 0.7.0, as all fields that we intend the Field trait to apply to support a sqrt operation (ff_derive is able to derive implementations for p = 3 (mod 4) and p = 1 (mod 16)). More precisely, SqrtField was a separate trait because Field was previously implemented on the pairing::bls12_381::{Fq6, Fq12} extension fields of BLS12-381, which didn't have square-root operations; these are not part of the bls12_381 crate's public API.

In #6, @hdevalence had separately suggested adding several sqrt-related operations to the then-existing SqrtField trait:

pub trait SqrtField: FiniteField {
    /// Computes sqrt(u/v)
    fn sqrt_ratio(u: &Self, v: &Self) -> Self;

    /// Computes 1/sqrt(self)
    fn invsqrt(&self) -> Self {
        Self::sqrt_ratio(&Self::one(), self)
    }

    /// Computes sqrt(self)
    fn sqrt(&self) -> Self {
        Self::sqrt_ratio(self, &Self::one())
    }
}

If these would be sufficiently widely-useful, they could be added to the Field trait. If not, we could consider re-introducing the SqrtField trait.

@daira
Copy link
Contributor

daira commented Jan 7, 2021

zcash/halo2#120 implements a generalization of sqrt_ratio based on https://ristretto.group/formulas/invsqrt.html for the Pasta curves. That implementation is more efficient than the existing Tonelli–Shanks-based one in ff, for fields that it supports (currently, those with a 2-adicity of 32, but that could easily be extended).

@str4d
Copy link
Member Author

str4d commented Oct 31, 2022

#33 adds the sqrt_ratio and sqrt_alt APIs that basically cover this issue.

@daira
Copy link
Contributor

daira commented Oct 31, 2022

I think you mean #93.

@ebfull ebfull closed this as completed in #93 Nov 2, 2022
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 a pull request may close this issue.

2 participants