Skip to main content

Unconstrained

o1js / Modules / Unconstrained

Class: Unconstrained\<T>

Container which holds an unconstrained value. This can be used to pass values between the out-of-circuit blocks in provable code.

Invariants:

  • An Unconstrained's value can only be accessed in auxiliary contexts.
  • An Unconstrained can be empty when compiling, but never empty when running as the prover. (there is no way to create an empty Unconstrained in the prover)

Example

let x = Unconstrained.from(0n);

class MyContract extends SmartContract {
`@method` myMethod(x: Unconstrained<bigint>) {

Provable.witness(Field, () => {
// we can access and modify `x` here
let newValue = x.get() + otherField.toBigInt();
x.set(newValue);

// ...
});

// throws an error!
x.get();
}

Type parameters

Name
T

Table of contents

Constructors

Properties

Methods

Constructors

constructor

Private new Unconstrained\<T>(isSome, value?)

Type parameters

Name
T

Parameters

NameType
isSomeboolean
value?T

Defined in

lib/circuit_value.ts:514

Properties

option

Private option: { isSome: true ; value: T } | { isSome: false ; value: undefined }

Defined in

lib/circuit_value.ts:510


provable

Static provable: Provable\<Unconstrained\<any>> & { toInput: (x: Unconstrained\<any>) => { fields?: Field[] ; packed?: [Field, number][] } }

Defined in

lib/circuit_value.ts:558

Methods

get

get(): T

Read an unconstrained value.

Note: Can only be called outside provable code.

Returns

T

Defined in

lib/circuit_value.ts:523


set

set(value): void

Modify the unconstrained value.

Parameters

NameType
valueT

Returns

void

Defined in

lib/circuit_value.ts:537


from

Static from\<T>(value): Unconstrained\<T>

Create an Unconstrained with the given value.

Type parameters

Name
T

Parameters

NameType
valueT

Returns

Unconstrained\<T>

Defined in

lib/circuit_value.ts:544


witness

Static witness\<T>(compute): Unconstrained\<T>

Create an Unconstrained from a witness computation.

Type parameters

Name
T

Parameters

NameType
compute() => T

Returns

Unconstrained\<T>

Defined in

lib/circuit_value.ts:551