Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/docs/explainers/explainer-writing-noir.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ Use ` if is_unconstrained() { /`, to conditionally execute code if being called

Unless you're well into the depth of gate optimization, this advanced section can be ignored.

### `#[no_predicates]` over for "pure" functions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about advertising no_predicates yet as for unexperienced developers it is a bit more dangerous and less obvious about what is happening. @jfecher what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we have a few errors such as #5672 that still exist so I would rather not advertise publicly yet @jzaki

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put this in the advanced section with plenty of caveats.
Whilst the start is more general to help devs new to Noir start to appreciate what optimisations do/don't look like, the Advanced section is caveated ( the line above). I'll make this a warning.

The contents below came up as a question in slack (by a more advanced ecosystem dev), they happened to refer to the form of predicates in passing.


When conditional logic is compiled into gates, it is predicated with boolean expressions like X, where `X * V1() + (1-X) * V2()` is calculated. This returns `V1()` when `X` is true or `V2()` if `X` is false.

If a function is guaranteed to never fail an assertion no matter the inputs, or roughly considered "pure", it can use the macro `#[no_predicates]`, telling the compiler to not add such predicates. This can beneficially be used in say hashing functions to reduce the gate count when they intuitively must be written/used inside an `if`.

:::note
If a function may call other predicated functions, do not mark it with `#[no_predicates]`.
:::

Having a `#[no_predicates]` function call a regular function severely breaks the intended representation, proof generation, and verification of the program.

### Combine arithmetic operations

A Noir program can be honed further by combining arithmetic operators in a way that makes the most of each constraint of the backend proving system. This is in scenarios where the backend might not be doing this perfectly.
Expand Down
Loading