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 emptyUnconstrained
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
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
>> & { toInput
: (x
: Unconstrained
\<any
>) => { fields?
: Field
[] ; packed?
: [Field
, number
][] } }
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
Unconstrained
\<T
>
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 |
Returns
Unconstrained
\<T
>