noir-lang / noir

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

fix: skip emission of brillig calls which will never be executed #5314

Closed TomAFrench closed 3 months ago

TomAFrench commented 3 months ago

Description

Problem*

Pulls across fix made in sync PR at https://github.com/AztecProtocol/aztec-packages/pull/7134/commits/e39be3dc0ee89d9a246366a1f88eb36b26f25751

Summary*

For some reason in the noir-contracts workspace, we're emitting a lot (100+ MB worth) of brillig call opcodes which have their predicate hardcoded to zero (i.e. they will never actually be executed).

This PR adds a check before we emit a brillig call opcode to see if the predicate is zero and, if so, we skip it and zero out all the outputs at compile time.

Additional Context

Documentation*

Check one:

PR Checklist*

github-actions[bot] commented 3 months ago

Changes to circuit sizes

Generated at commit: 2e2c4b383f57755a694918e9f7d1452f20d85124, compared to commit: 49e1b0c0d45565f3e87469b77f2fef0c283f6ea1

๐Ÿงพ Summary (10% most significant diffs)

Program ACIR opcodes (+/-) % Circuit size (+/-) %
conditional_1 -5 โœ… -0.06% 0 โž– 0.00%
hashmap -15 โœ… -0.01% 0 โž– 0.00%

Full diff report ๐Ÿ‘‡
| Program | ACIR opcodes (+/-) | % | Circuit size (+/-) | % | |:-|-:|-:|-:|-:| | **conditional_1** | 8,545 (-5) | **-0.06%** | 38,809 (0) | **0.00%** | | **hashmap** | 209,896 (-15) | **-0.01%** | 397,324 (0) | **0.00%** |