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

Panic when attempting to get location for RuntimeError::UnsupportedIntegerSize error #2193

Closed
Jurarpereurs opened this issue Aug 7, 2023 · 1 comment · Fixed by #2202
Closed
Assignees
Labels
bug Something isn't working ssa

Comments

@Jurarpereurs
Copy link

Aim

I'm trying to convert a field variable to an integer so that I can compare two field variables. However, when I try to do this, Noir crashes:

fn main(x : Field, y : pub Field) {
    assert((x as u253) < (y as u253));
}

Expected Behavior

Noir should not crash when converting Field to u253.

Bug

Noir panicked when doing x as u253, where x is a Field variable.

To Reproduce

Save the following code into src/main.nr:

fn main(x : Field, y : pub Field) {
    assert((x as u253) < (y as u253));
}

Save the following as input into Prover.toml:

x = "1"
y = "2"

Run the following command:

nargo prove

You would see the following error message:

The application panicked (crashed).
Message:  called `Option::unwrap()` on a `None` value
Location: crates/noirc_evaluator/src/errors.rs:74

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml

Installation Method

Binary

Nargo Version

nargo 0.9.0 (git version hash: effb02a, is dirty: false)

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@Jurarpereurs Jurarpereurs added the bug Something isn't working label Aug 7, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 7, 2023
@TomAFrench
Copy link
Member

Hey @Jurarpereurs, thanks for reporting this. Looks like the issue is that no location is being attached to the < instruction so when this errors then it's unable to show the location of the error which causes the panic.

Once thing I should flag up is that you won't be able to use u253 like this even once this issue is fixed as integer operations could cause the field to overflow. We'll instead just show an error message rather than panic:

// Conservative max bit size that is small enough such that two operands can be
// multiplied and still fit within the field modulus. This is necessary for the
// truncation technique: result % 2^bit_size to be valid.
let max_integer_bit_size = FieldElement::max_num_bits() / 2;
if *bit_size > max_integer_bit_size {
return Err(RuntimeError::UnsupportedIntegerSize {
num_bits: *bit_size,
max_num_bits: max_integer_bit_size,
location: self.acir_context.get_location(),
});
}

@TomAFrench TomAFrench changed the title Noir crashes when converting field variables to integers Panic when attempting to get location for RuntimeError::UnsupportedIntegerSize error Aug 7, 2023
@jfecher jfecher self-assigned this Aug 7, 2023
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working ssa
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants