Class: Circuit
The Circuit API is a low level interface to interact and build circuits with
Table of contents
Constructors
Methods
- _witness
- addConstraint
- array
- asProver
- assertEqual
- constraintSystem
- equal
- generateKeypair
- if
- inCheckedComputation
- inProver
- log
- newVariable
- prove
- runAndCheck
- switch
- toFields
- verify
- witness
Constructors
constructor
• new Circuit()
Methods
_witness
▸ Static
_witness<S
>(ctor
, f
): Field
[]
Type parameters
Name | Type |
---|---|
S | extends Provable <any , S > |
Parameters
Name | Type |
---|---|
ctor | S |
f | () => Field [] |
Returns
Field
[]
Defined in
addConstraint
▸ Static
addConstraint(this
, kind
, x
, y
, z
): void
Adds a constraint to the circuit.
Parameters
Name | Type |
---|---|
this | Circuit |
kind | "multiply" |
x | Field |
y | Field |
z | Field |
Returns
void
Defined in
▸ Static
addConstraint(this
, kind
, x
, y
, z
): void
Parameters
Name | Type |
---|---|
this | Circuit |
kind | "add" |
x | Field |
y | Field |
z | Field |
Returns
void
Defined in
▸ Static
addConstraint(this
, kind
, x
, y
, z
): void
Parameters
Name | Type |
---|---|
this | Circuit |
kind | "equal" |
x | Field |
y | Field |
z | Field |
Returns
void
Defined in
▸ Static
addConstraint(this
, kind
, x
, y
, z
): void
Parameters
Name | Type |
---|---|
this | Circuit |
kind | "boolean" |
x | Field |
y | Field |
z | Field |
Returns
void
Defined in
array
▸ Static
array<T
>(elementType
, length
): Provable
<T
[]>
Creates a generic Provable array^.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
elementType | Provable <T > |
length | number |
Returns
Provable
<T
[]>
Defined in
asProver
▸ Static
asProver(f
): void
Runs code as a prover.
Parameters
Name | Type |
---|---|
f | () => void |
Returns
void
Defined in
assertEqual
▸ Static
assertEqual<T
>(ctor
, x
, y
): void
Asserts that two values are equal.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
ctor | Object |
ctor.toFields | (x : T ) => Field [] |
x | T |
y | T |
Returns
void
Defined in
▸ Static
assertEqual<T
>(x
, y
): void
Asserts that two values are equal.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
x | T |
y | T |
Returns
void
Defined in
constraintSystem
▸ Static
constraintSystem<T
>(f
): Object
Returns information about the constraint system in the callback function.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
f | () => T |
Returns
Object
Name | Type |
---|---|
digest | string |
result | T |
rows | number |
Defined in
equal
▸ Static
equal<T
>(ctor
, x
, y
): Bool
Checks if two elements are equal.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
ctor | Object |
ctor.toFields | (x : T ) => Field [] |
x | T |
y | T |
Returns
Defined in
▸ Static
equal<T
>(x
, y
): Bool
Checks if two elements are equal.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
x | T |
y | T |
Returns
Defined in
generateKeypair
▸ Static
generateKeypair(): Keypair
Generates a proving key and a verification key for this circuit.
Returns
Defined in
if
▸ Static
if<T
>(b
, ctor
, x
, y
): T
Circuit-compatible if-statement.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
b | boolean | Bool |
ctor | ProvablePure <T > |
x | T |
y | T |
Returns
T
Defined in
▸ Static
if<T
>(b
, x
, y
): T
Circuit-compatible if-statement.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
b | boolean | Bool |
x | T |
y | T |
Returns
T
Defined in
inCheckedComputation
▸ Static
inCheckedComputation(): boolean
Checks if the circuit is in checked computation mode.
Returns
boolean
Defined in
inProver
▸ Static
inProver(): boolean
Checks if the circuit is in prover mode.
Returns
boolean
Defined in
log
▸ Static
log(...args
): void
Interface to log elements within a circuit. Similar to Console.log()
.
Parameters
Name | Type |
---|---|
...args | any |
Returns
void
Defined in
newVariable
▸ Static
newVariable(f
): Field
Creates a new variable inside the circuit.
Parameters
Name | Type |
---|---|
f | () => string | number | boolean | Field |
Returns
Defined in
prove
▸ Static
prove(privateInput
, publicInput
, kp
): Proof
Proves a statement using the private input, public input and the Keypair of the circuit.
Parameters
Name | Type |
---|---|
privateInput | any [] |
publicInput | any [] |
kp | Keypair |
Returns
Proof
Defined in
runAndCheck
▸ Static
runAndCheck<T
>(f
): T
Runs code and checks its correctness.
Type parameters
Name |
---|
T |
Parameters
Name | Type |
---|---|
f | () => T |
Returns
T
Defined in
switch
▸ Static
switch<T
, A
>(mask
, type
, values
): T
Generalization of Circuit.if
for choosing between more than two different cases.
It takes a "mask", which is an array of Bool
s that contains only one true
element, as well as a type/constructor and an array of values of that type.
The result is that value which corresponds to the true element of the mask. Example:
let x = Circuit.switch([Bool(false), Bool(true)], Field, [Field(1), Field(2)]);
x.assertEquals(2);
Type parameters
Name | Type |
---|---|
T | T |
A | extends Provable <T , A > |
Parameters
Name | Type |
---|---|
mask | Bool [] |
type | A |
values | T [] |
Returns
T
Defined in
toFields
▸ Static
toFields<A
>(a
): Field
[]
Serializes an element into Field elements.
Type parameters
Name |
---|
A |
Parameters
Name | Type |
---|---|
a | A |
Returns
Field
[]
Defined in
verify
▸ Static
verify(publicInput
, vk
, pi
): boolean
Verifies a proof using the public input, the proof and the initial Keypair of the circuit.
Parameters
Name | Type |
---|---|
publicInput | any [] |
vk | VerificationKey |
pi | Proof |
Returns
boolean
Defined in
witness
▸ Static
witness<T
, S
>(ctor
, f
): T
Type parameters
Name | Type |
---|---|
T | T |
S | extends Provable <T , S > = Provable <T > |
Parameters
Name | Type |
---|---|
ctor | S |
f | () => T |
Returns
T