noir-idioms
Installation
SKILL.md
Writing Idiomatic Noir
These guidelines help you write Noir programs that are readable, idiomatic, and produce efficient circuits.
Core Principle: Hint and Verify
Computing a value is often more expensive in a circuit than verifying a claimed value is correct. Use unconstrained functions to compute results off-circuit, then verify them with cheap constraints.
// Expensive: sorting an array in-circuit requires many comparisons and swaps
let sorted = sort_in_circuit(arr);
// Cheaper: hint the sorted array, verify it's a valid permutation and is ordered
let sorted = unsafe { sort_hint(arr) };
// verify sorted order and that sorted is a permutation of arr
Note that the compiler already injects unconstrained helpers for some operations automatically (e.g., integer division). Don't hint what the compiler already optimizes — focus on higher-level computations like sorting, searching, and array construction where the compiler cannot automatically apply this pattern.