Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add distinct keyword to make public return values be assigned to distinct witnesses #1183

Closed
1 task done
kevaundray opened this issue Apr 19, 2023 · 1 comment
Closed
1 task done
Assignees
Labels
backend Proving backends compiler frontend `noirc_frontend` crate enhancement New feature or request

Comments

@kevaundray
Copy link
Contributor

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:

fn main(x : Field) -> [Field;2] {
[x,x]
}

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:

fn main(x : Field) -> pub distinct [Field;2] {
[x,x]
}

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 the N return witnesses which may have duplicates. This has been implemented in a hacked together branch here

A 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:

/// Distinctness refers to whether the public return type
/// from the entry-point functions have distinct witness values.
///
/// The compiler will ensure witness values are distinct, if
/// variant is `Distinctness::Distinct`.
///
/// if the variant is `Distinctness::Duplicated` it could be the
/// case that the witness values are distinct due to the users
/// program.  
pub enum Distinctness {
    Distinct,
    Duplicated,
}

If the distinct keyword is present then we have Distinctness::Distinct and the other caseif not.

Submission Checklist

  • Once I hit submit, I will assign this issue to the Project Board with the appropriate tags.
@kevaundray kevaundray added this to Noir Apr 19, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Apr 19, 2023
@kevaundray kevaundray added backend Proving backends compiler frontend `noirc_frontend` crate labels Apr 19, 2023
@kevaundray
Copy link
Contributor Author

CLosing due to #1219 being merged

@github-project-automation github-project-automation bot moved this from 📋 Backlog to ✅ Done in Noir Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend Proving backends compiler frontend `noirc_frontend` crate enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

2 participants