Skip to main content

Class: Circuit

The Circuit API is a low level interface to interact and build circuits with

Table of contents

Constructors

Methods

Constructors

constructor

new Circuit()

Methods

_witness

Static _witness<S>(ctor, f): Field[]

Type parameters

NameType
Sextends Provable<any, S>

Parameters

NameType
ctorS
f() => Field[]

Returns

Field[]

Defined in

snarky.d.ts:647


addConstraint

Static addConstraint(this, kind, x, y, z): void

Adds a constraint to the circuit.

Parameters

NameType
thisCircuit
kind"multiply"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:612

Static addConstraint(this, kind, x, y, z): void

Parameters

NameType
thisCircuit
kind"add"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:619

Static addConstraint(this, kind, x, y, z): void

Parameters

NameType
thisCircuit
kind"equal"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:626

Static addConstraint(this, kind, x, y, z): void

Parameters

NameType
thisCircuit
kind"boolean"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:633


array

Static array<T>(elementType, length): Provable<T[]>

Creates a generic Provable array^.

Type parameters

Name
T

Parameters

NameType
elementTypeProvable<T>
lengthnumber

Returns

Provable<T[]>

Defined in

snarky.d.ts:675


asProver

Static asProver(f): void

Runs code as a prover.

Parameters

NameType
f() => void

Returns

void

Defined in

snarky.d.ts:656


assertEqual

Static assertEqual<T>(ctor, x, y): void

Asserts that two values are equal.

Type parameters

Name
T

Parameters

NameType
ctorObject
ctor.toFields(x: T) => Field[]
xT
yT

Returns

void

Defined in

snarky.d.ts:680

Static assertEqual<T>(x, y): void

Asserts that two values are equal.

Type parameters

Name
T

Parameters

NameType
xT
yT

Returns

void

Defined in

snarky.d.ts:685


constraintSystem

Static constraintSystem<T>(f): Object

Returns information about the constraint system in the callback function.

Type parameters

Name
T

Parameters

NameType
f() => T

Returns

Object

NameType
digeststring
resultT
rowsnumber

Defined in

snarky.d.ts:666


equal

Static equal<T>(ctor, x, y): Bool

Checks if two elements are equal.

Type parameters

Name
T

Parameters

NameType
ctorObject
ctor.toFields(x: T) => Field[]
xT
yT

Returns

Bool

Defined in

snarky.d.ts:690

Static equal<T>(x, y): Bool

Checks if two elements are equal.

Type parameters

Name
T

Parameters

NameType
xT
yT

Returns

Bool

Defined in

snarky.d.ts:695


generateKeypair

Static generateKeypair(): Keypair

Generates a proving key and a verification key for this circuit.

Returns

Keypair

Defined in

snarky.d.ts:725


if

Static if<T>(b, ctor, x, y): T

Circuit-compatible if-statement.

Type parameters

Name
T

Parameters

NameType
bboolean | Bool
ctorProvablePure<T>
xT
yT

Returns

T

Defined in

snarky.d.ts:700

Static if<T>(b, x, y): T

Circuit-compatible if-statement.

Type parameters

Name
T

Parameters

NameType
bboolean | Bool
xT
yT

Returns

T

Defined in

snarky.d.ts:704


inCheckedComputation

Static inCheckedComputation(): boolean

Checks if the circuit is in checked computation mode.

Returns

boolean

Defined in

snarky.d.ts:750


inProver

Static inProver(): boolean

Checks if the circuit is in prover mode.

Returns

boolean

Defined in

snarky.d.ts:745


log

Static log(...args): void

Interface to log elements within a circuit. Similar to Console.log().

Parameters

NameType
...argsany

Returns

void

Defined in

snarky.d.ts:755


newVariable

Static newVariable(f): Field

Creates a new variable inside the circuit.

Parameters

NameType
f() => string | number | boolean | Field

Returns

Field

Defined in

snarky.d.ts:644


prove

Static prove(privateInput, publicInput, kp): Proof

Proves a statement using the private input, public input and the Keypair of the circuit.

Parameters

NameType
privateInputany[]
publicInputany[]
kpKeypair

Returns

Proof

Defined in

snarky.d.ts:730


runAndCheck

Static runAndCheck<T>(f): T

Runs code and checks its correctness.

Type parameters

Name
T

Parameters

NameType
f() => T

Returns

T

Defined in

snarky.d.ts:661


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 Bools 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

NameType
TT
Aextends Provable<T, A>

Parameters

NameType
maskBool[]
typeA
valuesT[]

Returns

T

Defined in

snarky.d.ts:716


toFields

Static toFields<A>(a): Field[]

Serializes an element into Field elements.

Type parameters

Name
A

Parameters

NameType
aA

Returns

Field[]

Defined in

snarky.d.ts:740


verify

Static verify(publicInput, vk, pi): boolean

Verifies a proof using the public input, the proof and the initial Keypair of the circuit.

Parameters

NameType
publicInputany[]
vkVerificationKey
piProof

Returns

boolean

Defined in

snarky.d.ts:735


witness

Static witness<T, S>(ctor, f): T

Type parameters

NameType
TT
Sextends Provable<T, S> = Provable<T>

Parameters

NameType
ctorS
f() => T

Returns

T

Defined in

snarky.d.ts:648