-
Notifications
You must be signed in to change notification settings - Fork 118
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
Move Provable (formerly Circuit) to JS #889
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some comments to help reviewing!
let main = mainFromCircuitData(this._main, privateInput); | ||
let publicInputSize = this._main.publicInputType.sizeInFields(); | ||
let publicInputFields = this._main.publicInputType.toFields(publicInput); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some of the ocaml logic for the Circuit
circuit-writing API is moved to JS
* @deprecated use {@link Provable.witness} | ||
*/ | ||
static witness = SnarkyCircuit.witness; | ||
static witness = Provable.witness; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all the methods on Circuit
that are general-purpose and not specific to the Circuit
-writing API are moved to Provable
, and deprecated here
* @deprecated use {@link Provable.Array} | ||
*/ | ||
static array = SnarkyCircuit.array; | ||
static array = Provable.Array; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renamed Circuit.array
to Provable.Array
-- upper case because it's analogous to JS builtin Array
it('Provable.if out of snark', () => { | ||
let x = Provable.if(Bool(false), Int64, Int64.from(-1), Int64.from(-2)); | ||
expect(x.toString()).toBe('-2'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unit tests for Provable.if
and other rewritten provable methods
@@ -276,97 +259,12 @@ function prop(this: any, target: any, key: string) { | |||
} | |||
} | |||
|
|||
function circuitArray<A extends FlexibleProvable<any>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is moved to provable.ts
with no changes
|
||
function equal<T>(type: FlexibleProvable<T>, x: T, y: T): Bool; | ||
function equal<T extends ToFieldable>(x: T, y: T): Bool; | ||
function equal(typeOrX: any, xOrY: any, yOrUndefined?: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equal
- new implementation!
|
||
function if_<T>(condition: Bool, type: FlexibleProvable<T>, x: T, y: T): T; | ||
function if_<T extends ToFieldable>(condition: Bool, x: T, y: T): T; | ||
function if_(condition: Bool, typeOrX: any, xOrY: any, yOrUndefined?: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if
- new implementation!
return ifExplicit(condition, type as any as Provable<T>, x, y); | ||
} | ||
|
||
function switch_<T, A extends FlexibleProvable<T>>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch
is moved here from circuit_value.ts
without changes
|
||
// runners for provable code | ||
|
||
function log(...args: any) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log
is moved here from circuit_value.ts
without changes
}); | ||
} | ||
|
||
function asProver(f: () => void) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything below in this file is moved here without changes, except the new checkLength
and clone
helpers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Left some questions for my understanding
/** | ||
* {@link Provable} is | ||
* - a namespace with tools for writing provable code | ||
* - the main interface for types that can be used in provable code | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
really appreciate these comments!
bindings: o1-labs/o1js-bindings#9
closes #675
related docs update o1-labs/docs2#393
Circuit
on top of a new, simpler and less JavaScript-y OCaml interface calledSnarky
Circuit.if
andCircuit.witness
to a new namespaceProvable
, which lives inprovable.ts
provable.ts
is existing code that was moved around.Provable.{if, assertEqual, equal}
are re-implemented in JS on top of lower-level circuit gadgets, and equipped with more precise typing and better-defined error behaviorCircuit
circuit-writing API has some logic (defining input types, & the snarky circuit function) moved to JS, to get rid ofProvable<T>
handling in OCaml altogethersee comments below for details. I recommend to focus review on the re-written primitives in
provable.ts
note: tests are failing because this doesn't have updated bindings yet