Skip to main content

Provable

o1js / Modules / Provable

Interface: Provable\<T>

Provable<T> is the general circuit type interface in o1js. Provable<T> interface describes how a type T is made up of Field elements and "auxiliary" (non-provable) data.

Provable<T> is the required input type in a few places in o1js. One convenient way to create a Provable<T> is using Struct.

The properties and methods on the provable type exist in all base o1js types as well (aka. Field, Bool, etc.). In most cases, a zkApp developer does not need these functions to create zkApps.

Type parameters

Name
T

Hierarchy

Table of contents

Properties

Methods

Properties

check

check: (value: T) => void

Type declaration

▸ (value): void

Add assertions to the proof to check if value is a valid member of type T. This function does not return anything, instead it creates any number of assertions to prove that value is a valid member of the type T.

For instance, calling check function on the type Bool asserts that the value of the element is either 1 or 0.

Parameters
NameTypeDescription
valueTthe element of type T to put assertions on.
Returns

void

Defined in

snarky.d.ts:98


fromFields

fromFields: (fields: Field[], aux: any[]) => T

Type declaration

▸ (fields, aux): T

A function that returns an element of type T from the given provable and "auxiliary" data.

Important: For any element of type T, this function is the reverse operation of calling toFields and toAuxilary methods on an element of type T.

Parameters
NameTypeDescription
fieldsField[]an array of Field elements describing the provable data of the new T element.
auxany[]an array of any type describing the "auxiliary" data of the new T element, optional.
Returns

T

An element of type T generated from the given provable and "auxiliary" data.

Defined in

snarky.d.ts:79


toAuxiliary

toAuxiliary: (value?: T) => any[]

Type declaration

▸ (value?): any[]

A function that takes value (optional), an element of type T, as argument and returns an array of any type that make up the "auxiliary" (non-provable) data of value.

Parameters
NameTypeDescription
value?Tthe element of type T to generate the auxiliary data array from, optional. If not provided, a default value for auxiliary data is returned.
Returns

any[]

An array of any type describing how this T element is made up of "auxiliary" (non-provable) data.

Defined in

snarky.d.ts:67


toFields

toFields: (value: T) => Field[]

Type declaration

▸ (value): Field[]

A function that takes value, an element of type T, as argument and returns an array of Field elements that make up the provable data of value.

Parameters
NameTypeDescription
valueTthe element of type T to generate the Field array from.
Returns

Field[]

A Field array describing how this T element is made up of Field elements.

Defined in

snarky.d.ts:58

Methods

sizeInFields

sizeInFields(): number

Return the size of the T type in terms of Field type, as Field is the primitive type.

Warning: This function returns a number, so you cannot use it to prove something on chain. You can use it during debugging or to understand the memory complexity of some type.

Returns

number

A number representing the size of the T type in terms of Field type.

Defined in

snarky.d.ts:88