Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Define a "Brillig stdlib" for common functions for easier display #471

Closed
TomAFrench opened this issue Aug 2, 2023 · 1 comment
Closed
Labels
enhancement New feature or request

Comments

@TomAFrench
Copy link
Member

Problem

Noir is currently replacing the usage of a number of directives with Brillig functions.

The example Noir program

fn main(x : Field, y : pub Field) {
    assert(x != y);
}

currently gets displayed as

Compiled ACIR for main (unoptimized):
current witness index : 5
public parameters indices : [2]
return value indices : []
EXPR [ (1, _1) (-1, _2) (-1, _3) 0 ]
BRILLIG: inputs: [Single(Expression { mul_terms: [], linear_combinations: [(1, Witness(3))], q_c: 0 })]
outputs: [Simple(Witness(4))]
[JumpIfNot { condition: RegisterIndex(0), location: 3 }, Const { destination: RegisterIndex(1), value: Value { inner: 1 } }, BinaryFieldOp { destination: RegisterIndex(0), op: Div, lhs: RegisterIndex(1), rhs: RegisterIndex(0) }, Stop]

EXPR [ (1, _3, _4) (1, _5) -1 ]
EXPR [ (1, _3, _5) 0 ]
EXPR [ (-1, _5) 0 ]

What was once DIR::INVERT (_3, out: _4) is now

BRILLIG: inputs: [Single(Expression { mul_terms: [], linear_combinations: [(1, Witness(3))], q_c: 0 })] outputs: [Simple(Witness(4))] [JumpIfNot { condition: RegisterIndex(0), location: 3 }, Const { destination: RegisterIndex(1), value: Value { inner: 1 } }, BinaryFieldOp { destination: RegisterIndex(0), op: Div, lhs: RegisterIndex(1), rhs: RegisterIndex(0) }, Stop]

This makes it much harder to read ACIR code while debugging as the user needs to verify that this brillig bytecode is correct.

Happy Case

We should define a set of standard brillig functions such as inversion, quotient, etc. here in ACVM. When displaying brillig opcodes we can then hash the bytecode to compare against this known list of brillig functions. We can then display a human readable format similarly to what we do for the Directive opcodes.

Alternatives Considered

No response

Additional Context

No response

Would you like to submit a PR for this Issue?

Yes

Support Needs

No response

@TomAFrench TomAFrench added the enhancement New feature or request label Aug 2, 2023
@github-project-automation github-project-automation bot moved this to 📋 Backlog in Noir Aug 2, 2023
@TomAFrench
Copy link
Member Author

Will be handled as part of noir-lang/noir#3907

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Archived in project
Development

No branches or pull requests

1 participant