noir-lang / noir

Noir is a domain specific language for zero knowledge proofs
https://noir-lang.org
Apache License 2.0
894 stars 199 forks source link

Compiler should not panic when an oracle is called from constrained method #4565

Closed LogvinovLeon closed 8 months ago

LogvinovLeon commented 8 months ago

Aim

Get compilation error instead of compiler panic

Expected Behavior

compilation error

Bug

The application panicked (crashed). Message: internal error: entered unreachable code: All oracle methods should be wrapped in an unconstrained fn Location: compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs:615

To Reproduce

  1. Call an oracle function directly from constrained code

Project Impact

None

Impact Context

No response

Workaround

Yes

Workaround Description

Just don't do it ;)

Additional Context

No response

Installation Method

None

Nargo Version

noirc version = 0.25.0+3ad88696ab63d8b1838b4ca7e9a3a97f823ca976

NoirJS Version

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

TomAFrench commented 8 months ago

Thanks for highlighting this!

This can be done with similar logic used to prevent passing slices to unconstrained functions from constrained ones.

https://github.com/noir-lang/noir/blob/a8b7cdb8a3698bc8923b6fa8714deebb8bf3923f/compiler/noirc_frontend/src/hir/type_check/expr.rs#L186-L195

jfecher commented 8 months ago

@TomAFrench we should probably generalize that check to error for all types that are invalid to pass from unconstrained to constrained. Such as references.