Preprocessing Arguments for Noir Circuits

Circuits must be fixed in size. However, one is often faced with dynamically sized objects which then require either recursion or dedicated circuits for every single size.

At ETHGlobal London last weekend we were working on circuits for proving audio processing. One of the challenges was that audio files varying in size and processing history require different circuits for the same operation. This led us to create a small templating framework for Noir to dynamically fill in parts of the circuit just before compilation once the required specifications for the circuit were known. That way we only needed one circuit template for each operation from which we could generate any circuits needed. We were able to reduce any changes or adjustments in the circuit to a set of global variables that controlled the final circuit.

For our use case, having something like “CLI arguments” that are passed to noir_wasm and can be used inside the circuit would have already been sufficient. What do you think about adding something like this to the Noir language compiler?

26 Likes

For now an external script is a good way to implement this when the input is unknown in advance, and is to be used on the fly.
Something that we can consider is to compile a set of different circuit sizes in advance, then choose the appropriate one for proving/verifying based on the input. Not sure where it fits in the Noir roadmap yet.

15 Likes

Thanks for the response! I’m not sure having multiple precompiled circuits of different sizes would have helped in our case since the audio file can have any size n\in\mathbb{N}_{>0}. I think in the long term, this is something best handled on the library level since this would have implications for development tools, especially linting, but if there are no immediate plans, I would also be willing to turn our implementation into a small wrapper library for noir_wasm for others to use. Generally, is procedural circuit generation something you have on your roadmap at the moment?

22 Likes

I think it was about having circuits of multiple bit sizes (8, 16, 32, …). Other Noir programs use larger circuits, and pad smaller lengths of data with 0’s.
So in this case it could be to use the smallest size that can contain the input length.

I’d encourage you to create the wrapper :nerd_face:
Please post it back here and also in the Noir discord. Feel free to @ me too.

23 Likes