Skip to content

Comptime doesn't match Brillig on mutable reference handling #9950

@rkarabut

Description

@rkarabut

Aim

The following program:

fn main() -> pub Field {
    comptime {
        unsafe {
            foo(1)
        }
    }
}
unconstrained fn foo(mut a: Field) -> Field {
    let mut b: &mut Field = (&mut 0xdeadbeef);
    for i in 0..2 {
        a = 0;
        a = *b;
        b = (&mut a);
    }
    a
}

results in the output of 0. However, removing comptime makes it return 0xdeadbeef. Not quite sure which should be considered correct here.

Expected Behavior

The behavior should match.

Bug

With comptime:

$ nargo execute --force
[test1] Circuit witness successfully solved
[test1] Witness saved to target/test1.gz
[test1] Circuit output: 0x00

Without comptime:

$ nargo execute --force
[test1] Circuit witness successfully solved
[test1] Witness saved to target/test1.gz
[test1] Circuit output: 0xdeadbeef

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

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions