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


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

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

Parameters

NameType
thisCircuit
kind"add"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:752

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

Parameters

NameType
thisCircuit
kind"equal"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:759

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

Parameters

NameType
thisCircuit
kind"boolean"
xField
yField
zField

Returns

void

Defined in

snarky.d.ts:766


array

Static array<A>(elementType, length): InferredProvable<A[]>

Creates a Provable for a generic array.

Type parameters

NameType
Aextends FlexibleProvable<any>

Parameters

NameType
elementTypeA
lengthnumber

Returns

InferredProvable<A[]>

Defined in

snarky.d.ts:816


asProver

Static asProver(f): void

Runs code as a prover.

Parameters

NameType
f() => void

Returns

void

Defined in

snarky.d.ts:789


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

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


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
gatesGate[]
publicInputSizenumber
resultT
rowsnumber

Defined in

snarky.d.ts:799


constraintSystemFromKeypair

Static constraintSystemFromKeypair(keypair): Gate[]

Returns a low-level JSON representation of the Circuit from its Keypair: a list of gates, each of which represents a row in a table, with certain coefficients and wires to other (row, column) pairs

Parameters

NameType
keypairKeypair

Returns

Gate[]

Defined in

snarky.d.ts:811


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

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


generateKeypair

Static generateKeypair(): Keypair

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

Returns

Keypair

Defined in

snarky.d.ts:869


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

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


inCheckedComputation

Static inCheckedComputation(): boolean

Checks if the circuit is in checked computation mode.

Returns

boolean

Defined in

snarky.d.ts:894


inProver

Static inProver(): boolean

Checks if the circuit is in prover mode.

Returns

boolean

Defined in

snarky.d.ts:889


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


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


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


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


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 FlexibleProvable<T>

Parameters

NameType
maskBool[]
typeA
valuesT[]

Returns

T

Defined in

snarky.d.ts:860


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


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


witness

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

Type parameters

NameType
TT
Sextends FlexibleProvable<T> = FlexibleProvable<T>

Parameters

NameType
ctorS
f() => T

Returns

T

Defined in

snarky.d.ts:781