Skip to main content

Provable

type Provable<T, TValue>: {
check: (value: T) => void;
fromFields: (fields: Field[], aux: any[]) => T;
fromValue: (x: TValue | T) => T;
toAuxiliary: (value?: T) => any[];
toFields: (value: T) => Field[];
toValue: (x: T) => TValue;
sizeInFields: number;
};

Provable<T> is the general interface for provable types in o1js.

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

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

All built-in provable types in o1js (Field, Bool, etc.) are instances of Provable<T> as well.

Note: These methods are meant to be used by the library internally and are not directly when writing provable code.

Type parameters

T

TValue = any

Type declaration

check()

check: (value: T) => 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

value: T

the element of type T to put assertions on.

Returns

void

fromFields()

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

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

This function is the reverse operation of calling toFields and toAuxilary methods on an element of type T.

Parameters

fields: Field[]

an array of Field elements describing the provable data of the new T element.

aux: any[]

an array of any type describing the "auxiliary" data of the new T element, optional.

Returns

T

fromValue()

fromValue: (x: TValue | T) => T;

Convert provable type from a normal JS type.

Parameters

x: TValue | T

Returns

T

toAuxiliary()

toAuxiliary: (value?: T) => 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

value?: T

the 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[]

toFields()

toFields: (value: T) => 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

value: T

the element of type T to generate the Field array from.

Returns

Field[]

toValue()

toValue: (x: T) => TValue;

Convert provable type to a normal JS type.

Parameters

x: T

Returns

TValue

sizeInFields()

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

Returns

number

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

Source

lib/provable/types/provable-intf.ts:17