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 panics if you specify an expression-width < 3 during compile #5560

Closed
0xThemis opened this issue Jul 19, 2024 · 0 comments · Fixed by #6287
Closed

Nargo panics if you specify an expression-width < 3 during compile #5560

0xThemis opened this issue Jul 19, 2024 · 0 comments · Fixed by #6287
Assignees
Labels
bug Something isn't working

Comments

@0xThemis
Copy link

Aim

When compiling a noir program and specifying the expression-width (amount of witnesses in an expression), the compiler expects a width > 2. This is most likely the correct behaviour, but nargo panics with the following message:

The application panicked (crashed).
Message:  assertion failed: width > 2
Location: acvm-repo/acvm/src/compiler/transformers/csat.rs:27

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

Expected Behavior

The program should terminate and tell me that nargo expects an expression-width > 2, instead of a panic and indicating that there is a bug.

Bug

The problem is here:

 acvm-repo/acvm/src/compiler/transformers/csat.rs:27

Here the CSat Solver asserts that the expression-width is > 2. It should return an Result instead telling the user to provide an expression-width > 2

To Reproduce

  1. nargo new wrong_expr_width && cd wrong_expr_width
  2. nargo compile --expression-width 1

Project Impact

None

Impact Context

No response

Workaround

None

Workaround Description

No response

Additional Context

No response

Installation Method

Binary (noirup default)

Nargo Version

noirc version = 0.30.0+af57471035e4fa7eaffa71693219df6d029dbcde

NoirJS Version

No response

Would you like to submit a PR for this Issue?

Maybe

Support Needs

No response

@0xThemis 0xThemis added the bug Something isn't working label Jul 19, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Jul 19, 2024
github-merge-queue bot pushed a commit that referenced this issue Oct 17, 2024
# Description

## Problem\*

Resolves #5560

## Summary\*

Rejects an invalid `--expression-value` in the CLI, which would later
cause a panic in `acvm::compiler::transformers::csat`.

An example error message looks like:

```text
error: invalid value '1' for '--expression-width <EXPRESSION_WIDTH>': minimum value is 3
```

## Additional Context

The issue suggests that
[CSatTransformer::new](https://github.com/noir-lang/noir/blob/ae87d287ab1fae0f999dfd0d1166fbddb927ba97/acvm-repo/acvm/src/compiler/transformers/csat.rs#L24-L27)
should return a `Result` explaining the problem it has with `width`,
rather than doing an `assert!` (without any message) and crashing the
program. I agree, however looking at the chain of calls, none of the
half-dozen functions we go through to reach this use `Result`, and the
`CSatTransformer` is the only option we have. This suggests to me that
this limitation is perhaps supposed to be well-known to the user, ie.
it's not the case that one transformer has X limit and another has Y
limit.

For this reason I added a `pub const MIN_EXPRESSION_WIDTH: usize = 3;`
to the `acvm::compiler` module and using that as a common value for the
assertion as well as the validation in the CLI. Should the assumption of
a single global value change, removing that will force us to update the
validation logic as well.

That said if you prefer going the `Result` route I'm not against it, it
just seemed like an overkill for this single use case.
 
## Documentation\*

Check one:
- [x] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [x] I have tested the changes locally.
- [ ] 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 Oct 17, 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
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants