Skip to content

Strange shifting errors and results: Attempted to shift by 0 bits on a type of bit size 8 #9696

@aakoshh

Description

@aakoshh

Aim

Reproduce a nightly error from https://github.com/noir-lang/noir/actions/runs/17338660641/job/49229352879

The following program behaves differently in ACIR, Brillig and comptime.

fn main() -> pub u64 {
    (0_u64 << (584130945418788864_u64))
}

alternatively:

fn main() -> pub u64 {
    (10_u64 << (584130945418788864_u64))
}

Expected Behavior

They should agree.

Bug

ACIR is good:

❯ cargo run -q -p nargo_cli -- execute --silence-warnings --force
error: Assertion failed: attempt to bit-shift with overflow
  ┌─ src/main.nr:2:6
  │
2 │     (0_u64 << (584130945418788864_u64))
  │      ---------------------------------
  │
  = Call stack:
    1. src/main.nr:2:6

Failed assertion

Brillig is strange:

❯ cargo run -q -p nargo_cli -- execute --silence-warnings --force-brillig
error: Assertion failed: 'Attempted to shift by 0 bits on a type of bit size 8'
  ┌─ src/main.nr:2:6
  │
2 │     (0_u64 << (584130945418788864_u64))
  │      ---------------------------------
  │
  = Call stack:
    1. src/main.nr:2:6

Failed assertion

Why does it say "type of bit size 8" and "shift by 0 bits"? Does the same if we shift 10_u64 <<.

And comptime doesn't fail (possible duplicate of #9542):

fn main() -> pub u64 {
    comptime {
        (10_u64 << (584130945418788864_u64))
    }
}
❯ cargo run -q -p nargo_cli -- execute --silence-warnings --force
[fuzz_testing] Circuit witness successfully solved
[fuzz_testing] Witness saved to target/fuzz_testing.gz
[fuzz_testing] Circuit output: 10

To Reproduce

NOIR_AST_FUZZER_SEED=0xfb5b8eed00100000 cargo test -q -p noir_ast_fuzzer_fuzz comptime_vs_brillig_direct

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

nargo version = 1.0.0-beta.11 noirc version = 1.0.0-beta.11+3b6b3592bd3058c4325637f4b13556b2ed704124 (git version hash: 3b6b359, is dirty: true)

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

✅ Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions