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

Nargo debugger fails when zero opcodes #4231

Closed
michaeljklein opened this issue Feb 1, 2024 · 0 comments · Fixed by #4283
Closed

Nargo debugger fails when zero opcodes #4231

michaeljklein opened this issue Feb 1, 2024 · 0 comments · Fixed by #4283
Labels
bug Something isn't working debugger

Comments

@michaeljklein
Copy link
Contributor

Aim

Nargo debugger should return the expected error without panicing when running on code with zero ACIR opcodes.

It currently panics here:

let Opcode::Brillig(brillig) = &self.opcodes[self.instruction_pointer] else {

Expected Behavior

nargo debug fails without a panic

Bug

nargo debug fails with a panic when you call continue.

To Reproduce

Running on the following main.nr file:

fn main() {
    let x1 = &mut 42;
    let set_x1 = |y| { *x1 = y; };

    assert(*x1 == 42);
    set_x1(44);
    assert(*x1 == 44);
    set_x1(*x1);
    assert(*x1 == 44);
}

#[test]
fn test_main() {
    main();
}

cargo run execute succeeds, cargo run debug fails, but only after continue:

❯ cargo run execute
    Finished dev [optimized + debuginfo] target(s) in 0.31s
     Running `/Users/michaelklein/Coding/rust/noir/target/debug/nargo execute`
[missing_closure_env] Circuit witness successfully solved

❯ cargo run debug
    Finished dev [optimized + debuginfo] target(s) in 0.23s
     Running `/Users/michaelklein/Coding/rust/noir/target/debug/nargo debug`
[missing_closure_env] Starting debugger
Finished execution
> continue
(Continuing execution...)
The application panicked (crashed).
Message:  index out of bounds: the len is 0 but the index is 0
Location: /Users/michaelklein/Coding/rust/noir/acvm-repo/acvm/src/pwg/mod.rs:350

This is a bug. We may have already fixed this in newer versions of Nargo so try searching for similar issues at https://github.com/noir-lang/noir/issues/.
If there isn't an open issue for this bug, consider opening one at https://github.com/noir-lang/noir/issues/new?labels=bug&template=bug_report.yml
❯ cargo run info --json
    Finished dev [optimized + debuginfo] target(s) in 0.21s
     Running `/Users/michaelklein/Coding/rust/noir/target/debug/nargo info --json`
{"programs":[{"name":"missing_closure_env","acir_opcodes":0,"circuit_size":5}],"contracts":[]}

Installation Method

None

Nargo Version

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

No

Support Needs

No response

@michaeljklein michaeljklein added the bug Something isn't working label Feb 1, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Feb 1, 2024
github-merge-queue bot pushed a commit that referenced this issue Feb 6, 2024
# Description

## Problem\*

Resolves #4231

The REPL debugger is not handling the case when the compiled circuit has
no opcodes and since it assumes there will be some opcodes, it panics on
continue.

## Summary\*

With this PR, the REPL debugger will start in a "finished" stated in
those cases and the DAP will not start the main loop.

## Additional Context

This edge case is very unlikely to happen, especially after applying
#4185 which changes the default mode for the debugger to Brillig (seems
to generate at least a trampoline-like fragment even for empty programs)
and after the introduction of debugging instrumentation. Nevertheless it
will still be possible (eg. empty program and passing `--acir-mode`
option).

## Documentation\*

Check one:
- [X] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[Exceptional Case]** Documentation to be submitted in a separate
PR.

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working debugger
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants