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 compile-time assertions on generic arguments of stdlib functions #6962

Open
michaeljklein opened this issue Jan 6, 2025 · 0 comments · May be fixed by #6981
Open

Add compile-time assertions on generic arguments of stdlib functions #6962

michaeljklein opened this issue Jan 6, 2025 · 0 comments · May be fixed by #6981
Assignees
Labels
enhancement New feature or request

Comments

@michaeljklein
Copy link
Contributor

Problem

Several requirements on generic arguments of stdlib functions are only documented and not checked when they could be checked at compile-time.

E.g. for to_le_bits on Field:

    /// # Safety
    /// Values of `N` equal to or greater than the number of bits necessary to represent the `Field` modulus
    /// (e.g. 254 for the BN254 field) allow for multiple bit decompositions. This is due to how the `Field` will
    /// wrap around due to overflow when verifying the decomposition.
    #[builtin(to_le_bits)]
    // docs:start:to_le_bits
    pub fn to_le_bits<let N: u32>(self: Self) -> [u1; N] {}

Happy Case

  1. Find such stdlib functions
  2. Add compile-time assertions, e.g.
    #[builtin(to_le_bits_unsafe)]
    fn to_le_bits_unsafe<let N: u32>(self: Self) -> [u1; N] {}

    pub fn to_le_bits<let N: u32>(self: Self) -> [u1; N] {
        static_assert(N < Field_modulus, "Values of `N` equal to or greater than..");
        self.to_le_bits_unsafe::<N>()
    }

Workaround

Yes

Workaround Description

Explicitly check inputs as per stdlib function docs

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: 📋 Backlog
Development

Successfully merging a pull request may close this issue.

1 participant