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

Using large Field's in numeric generics fails with "array length too large" #6125

Open
Tracked by #6191
michaeljklein opened this issue Sep 23, 2024 · 1 comment
Open
Tracked by #6191
Assignees
Labels
bug Something isn't working

Comments

@michaeljklein
Copy link
Contributor

Aim

Attempted to use a Field larger than u32::MAX as a numeric generic:

global A: Field = 4294967297;

fn foo<let A: Field>() { }

fn main() {
    let C = foo::<A>();
}

Expected Behavior

Expected the program to compile successfully or fail with a clear error

Bug

Compilation fails with a message that the Field is too large to be an array length, but it's not used as an array length:

~/.nargo/bin/nargo compile
warning: unused variable C
   ┌─ src/main.nr:12:9
   │
12 │     let C = foo::<A>();
   │         - unused variable 
   │

error: Integer too large to be evaluated to an array-length
  ┌─ src/main.nr:7:19
  │
7 │ global A: Field = 4294967297;
  │                   ---------- Array-lengths may be a maximum size of usize::MAX, including intermediate calculations
  │

Aborting due to 1 previous error

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 0.34.0 noirc version = 0.34.0+5598059576c6cbc72474aff4b18bc5e4bb9f08e1 (git version hash: 5598059, is dirty: false)

NoirJS Version

No response

Proving Backend Tooling & Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Sep 23, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Sep 23, 2024
@michaeljklein
Copy link
Contributor Author

As a noirc_frontend test:

#[test]
fn use_global_larger_than_u32_as_generic() {
    let src = r#"
        // 2^32 + 1
        global A: Field = 4294967297;

        fn foo<let A: Field>() { }

        fn main() {
            let C = foo::<A>();
        }
    "#;

    let errors = get_program_errors(src);

    // TODO cleanup
    dbg!(&errors);

    assert_eq!(errors.len(), 0);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: 📋 Backlog
Development

No branches or pull requests

1 participant