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

Division by zero error when shifting right by the bit size of the result in Brillig #4285

Closed
ggiraldez opened this issue Feb 6, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@ggiraldez
Copy link
Contributor

ggiraldez commented Feb 6, 2024

Aim

Execute this program:

unconstrained fn main() {
    let a: u1 = 1 >> 1;
    assert(a == 0);
}

Expected Behavior

The execution completes successfully.

Bug

We get a runtime error:

error: Failed to solve brillig function, reason: Division by zero
  ┌─ /home/ggiraldez/Scratchpad/noir/bit_shifts_comptime/src/main.nr:2:22
  │
2 │     let a: u1 = 1 >> 1;
  │                      -
  │
  = Call stack:
    1. /home/ggiraldez/Scratchpad/noir/bit_shifts_comptime/src/main.nr:2:22

Failed to solve brillig function, reason: Division by zero

To Reproduce

Attempt to execute the given program.

Installation Method

Binary

Nargo Version

nargo version = 0.22.0 noirc version = 0.22.0+3fae4a03fded4e3f5065e7461c563f7e39745604 (git version hash: 3fae4a0, is dirty: false)

Additional Context

Removing the unconstrained keyword makes the program execute correctly, even when the input is not a constant to avoid optimizing away the operations.

The same error reproduces when changing the bit size of the variable along with the shifting amount, ie.: let a: u8 = 1 >> 8;

This was found while testing the debugger (which outputs Brillig by default) with the execution success case bit_shifts_comptime.

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@ggiraldez ggiraldez added the bug Something isn't working label Feb 6, 2024
@TomAFrench
Copy link
Member

Fixed in #4301

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
Archived in project
Development

No branches or pull requests

2 participants