Add distinct keyword to make public return values be assigned to distinct witnesses #1183
Closed
1 task done
Labels
backend
Proving backends
compiler frontend
`noirc_frontend` crate
enhancement
New feature or request
Problem
Suppose that the Noir proof being created needed to conform to some Virtual Machine.
This virtual machine will take in a Noir proof and a fixed number of public inputs.
Lets produce a Noir program which will cause this VM model problems:
Our example, VM will expect a proof and 2 distinct public inputs. The noir compiler will notice that
x
is being used twice and return the same public input twice. So it returns one distinct public input.Proposed solution
We propose to add a
distinct
keyword for return types on main, which will ensure that the witnesses being returned as public inputs are all unique.The noir program will now look like:
How this transformation will happen
The naive way to apply this transformation is to create
N
public witnesses and create a constraint to make them equal to theN
return witnesses which may have duplicates. This has been implemented in a hacked together branch hereA clever way to do this would be to keep track of the witnesses which we have already seen and do not create new witnesses for them.
Alternatives considered
No response
Additional context
In the parser, we can add this new enum for the distinct keyword:
If the distinct keyword is present then we have
Distinctness::Distinct
and the other caseif not.Submission Checklist
The text was updated successfully, but these errors were encountered: