noir icon indicating copy to clipboard operation
noir copied to clipboard

Operator `>>` does arithmetic or logical shift, depending on rhs

Open Syndamia opened this issue 1 year ago • 0 comments

Aim

Attempted to create a simple program which right-shifts a number.

The following main.nr:

fn main(a: i16) {
    println(a >> 3);
}

with Prover.toml:

a = "-769"

Results with an arithmetic >>, outputing -96.

However, the following main.nr:

fn main(a: i16, b: u8) {
    println(a >> b);
}

with Prover.toml:

a = "-769"
b = 3

Results with a logical >>, outputting 8095.

Expected Behavior

>> to act consistently on the same value

Bug

>> with a constant right hand-side behaves as an arithmetic shift, while with an input value rhs it behaves as a logical shift

To Reproduce

  1. Create two Noir projects, for each pair of program and Prover.toml
  2. Run them with nargo execute
  3. Observe the different output

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Nargo Version

nargo version = 0.34.0 noirc version = 0.34.0+94ed0b8fb13a923a59f6f3ccd8d7c75e191deeca (git version hash: 94ed0b8fb13a923a59f6f3ccd8d7c75e191deeca, 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

Syndamia avatar Oct 02 '24 13:10 Syndamia