Skip to content

Comptime and ACIR cast negative values into u128 differently #8523

@rkarabut

Description

@rkarabut

Aim

The program

fn main() -> pub u128 {
    comptime {
        let a = -1;
        a as u128
    }     
}

returns 340282366920938463463374607431768211455, while the program

fn main() -> pub u128 {
    let a = -1;
    a as u128
}

returns 53438638232309528389504892708671455232.

(edit: running in comptime also seemingly causes panics in compiler/noirc_frontend/src/hir/comptime/interpreter/cast.rs:77:17 for some setups)

Expected Behavior

It's not entirely clear to me if such casts should actually fail, but they probably should agree on the result if not.

Bug

With comptime:

nargo execute --force
[test1] Circuit witness successfully solved
[test1] Witness saved to target/test1.gz
[test1] Circuit output: Field(340282366920938463463374607431768211455)

Without comptime:

nargo execute --force
[test1] Circuit witness successfully solved
[test1] Witness saved to target/test1.gz
[test1] Circuit output: Field(53438638232309528389504892708671455232)

(found with comptime_vs_brillig AST fuzzer target)

To Reproduce

Workaround

None

Workaround Description

No response

Additional Context

No response

Project Impact

None

Blocker Context

No response

Nargo Version

No response

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

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions