noir icon indicating copy to clipboard operation
noir copied to clipboard

Compilation flag to add runtime checks for opcode assumptions

Open michaeljklein opened this issue 4 months ago • 1 comments

Problem

Some ACIR opcodes have built-in assumptions about their inputs/outputs, e.g.

  • Whether a point is on the curve and/or at infinity
  • An input/output being within a range (if integral) or of a specific size (if array-like)
  • Public key(s) are valid(?)

These assumptions are expected to be checked at some point throughout compilation, but

  1. They're exclusively runtime checks
  2. They're checked at different locations and/or passes
  3. They could be checked earlier in compilation and then invalidated later, e.g. by an SSA pass

Happy Case

Add a compilation flag to generate runtime code to check such assumptions, perhaps --pedantic or --pedantic-gen

  • This flag would only be used for testing, since it would be expected to have a negative impact on performance (and should be redundant)
  • This would be especially useful for fuzzing, where otherwise assumptions can be broken silently

Workaround

Yes

Workaround Description

A partial workaround is to manually trace the dependencies of a piece of user code to their ACVM opcodes and add such runtime checks, however:

  • This only works for individual and specific pieces of user code
  • It would be challenging to keep up to date, especially without feature flags

Additional Context

No response

Project Impact

Nice-to-have

Blocker Context

No response

Would you like to submit a PR for this Issue?

None

Support Needs

No response

michaeljklein avatar Oct 10 '24 17:10 michaeljklein