noir-lang / noir

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

feat: `static_assert` builtin #5342

Closed michaeljklein closed 3 days ago

michaeljklein commented 4 days ago

Description

Problem*

Resolves https://github.com/noir-lang/noir/issues/5182

Summary*

  1. New builtin that behaves almost exactly like assert_constant, but also checks that the input is true
  2. Add recursion to assert_constant so that [dynamic_var] is no longer treated as constant

Additional Context

Documentation*

Check one:

PR Checklist*

github-actions[bot] commented 4 days ago

🚀 Deployed on https://667dc8473d9dce5e85cba424--noir-docs.netlify.app

TomAFrench commented 4 days ago

Something to be aware of is that this will result in any printlns happening in test functions not printing if the test fails due to one of these static asserts. We should be careful to ensure that we maintain a good UX for when one of these fails rather than just going up in smoke.

github-actions[bot] commented 3 days ago

FYI @noir-lang/developerrelations on Noir doc changes.

vezenovm commented 3 days ago

Something to be aware of is that this will result in any printlns happening in test functions not printing if the test fails due to one of these static asserts.

It shouldn't be bad to add support for compile time prints (especially with us having println supported in the interpreter now: https://github.com/noir-lang/noir/pull/5197). We can probably add this in a follow-up though. Let's make an issue to make sure test functions can still print on failure even when a static assert is hit @michaeljklein