Unconstrained
o1js / Exports / 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 be accessed only in auxiliary contexts. - An
Unconstrainedcontainer can be empty when compiling, but never empty when running as the prover. (there is no way to create an emptyUnconstrainedin 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
| Name | Type |
|---|---|
isSome | boolean |
value? | T |
Defined in
Properties
option
• Private option: { isSome: true ; value: T } | { isSome: false ; value: undefined }
Defined in
provable
▪ Static provable: Provable<Unconstrained<any>>
Defined in
Methods
get
▸ get(): T
Read an unconstrained value.
Note: Can only be called outside provable code.
Returns
T
Defined in
set
▸ set(value): void
Modify the unconstrained value.
Parameters
| Name | Type |
|---|---|
value | T |
Returns
void
Defined in
from
▸ Static from<T>(value): Unconstrained<T>
Create an Unconstrained with the given value.
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
value | T |
Returns
Defined in
witness
▸ Static witness<T>(compute): Unconstrained<T>
Create an Unconstrained from a witness computation.
Type parameters
| Name |
|---|
T |
Parameters
| Name | Type |
|---|---|
compute | () => T |