Bool
Defined in: lib/provable/bool.ts:29
A boolean value. You can use it like this:
const x = new Bool(true);
You can also combine multiple booleans via [[not
]], [[and
]], [[or
]].
Use [[assertEquals]] to enforce the value of a Bool.
Constructors
new Bool()
new Bool(x: boolean | FieldVar | Bool): Bool
Defined in: lib/provable/bool.ts:32
Parameters
x
boolean
| FieldVar
| Bool
Returns
Properties
value
value: FieldVar;
Defined in: lib/provable/bool.ts:30
sizeInBytes
static sizeInBytes: number = 1;
Defined in: lib/provable/bool.ts:400
Unsafe
static Unsafe: {
fromField: Bool;
};
Defined in: lib/provable/bool.ts:406
fromField()
Converts a Field into a Bool. This is an unsafe operation as it assumes that the field element is either 0 or 1 (which might not be true).
Only use this if you have already constrained the Field element to be 0 or 1.
Parameters
x
a Field
Returns
Methods
and()
and(y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:72
Parameters
y
boolean
| Bool
Returns
a new Bool that is set to true only if
this Bool and y
are also true.
assertEquals()
assertEquals(y: boolean | Bool, message?: string): void
Defined in: lib/provable/bool.ts:113
Proves that this Bool is equal to y
.
Parameters
y
a Bool.
boolean
| Bool
message?
string
Returns
void
assertFalse()
assertFalse(message?: string): void
Defined in: lib/provable/bool.ts:144
Proves that this Bool is false
.
Parameters
message?
string
Returns
void
assertTrue()
assertTrue(message?: string): void
Defined in: lib/provable/bool.ts:130
Proves that this Bool is true
.
Parameters
message?
string
Returns
void
equals()
equals(y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:159
Returns true if this Bool is equal to y
.
Parameters
y
a Bool.
boolean
| Bool
Returns
implies()
implies(y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:105
Whether this Bool implies another Bool y
.
This is the same as x.not().or(y)
: if x
is true, then y
must be true for the implication to be true.
Parameters
y
boolean
| Bool
Returns
Example
let isZero = x.equals(0);
let lessThan10 = x.lessThan(10);
assert(isZero.implies(lessThan10), 'x = 0 implies x < 10');
isConstant()
isConstant(): this is { value: ConstantBoolVar }
Defined in: lib/provable/bool.ts:44
Returns
this is { value: ConstantBoolVar }
not()
not(): Bool
Defined in: lib/provable/bool.ts:58
Returns
a new Bool that is the negation of this Bool.
or()
or(y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:85
Parameters
y
boolean
| Bool
Returns
a new Bool that is set to true if either
this Bool or y
is true.
sizeInFields()
sizeInFields(): number
Defined in: lib/provable/bool.ts:184
Returns the size of this type.
Returns
number
toBoolean()
toBoolean(): boolean
Defined in: lib/provable/bool.ts:215
This converts the Bool to a JS boolean
.
This can only be called on non-witness values.
Returns
boolean
toField()
toField(): Field
Defined in: lib/provable/bool.ts:51
Converts a Bool to a Field. false
becomes 0 and true
becomes 1.
Returns
toFields()
toFields(): Field[]
Defined in: lib/provable/bool.ts:191
Serializes this Bool into Field elements.
Returns
Field
[]
toJSON()
toJSON(): boolean
Defined in: lib/provable/bool.ts:207
Serialize the Bool to a JSON string. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.
Returns
boolean
toString()
toString(): string
Defined in: lib/provable/bool.ts:199
Serialize the Bool to a string, e.g. for printing. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.
Returns
string
allTrue()
static allTrue(list: (boolean | Bool)[]): Bool
Defined in: lib/provable/bool.ts:263
Boolean AND operation across a list of booleans, returns Bool(true)
if all elements in the list are true.
Parameters
list
(boolean
| Bool
)[]
Returns
and()
static and(x: boolean | Bool, y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:243
Boolean AND operation.
Parameters
x
boolean
| Bool
y
boolean
| Bool
Returns
anyTrue()
static anyTrue(list: (boolean | Bool)[]): Bool
Defined in: lib/provable/bool.ts:280
Boolean OR operation across a list of booleans, returns Bool(true)
if any element in the list is true.
Parameters
list
(boolean
| Bool
)[]
Returns
assertEqual()
static assertEqual(x: Bool, y: boolean | Bool): void
Defined in: lib/provable/bool.ts:297
Asserts if both Bool are equal.
Parameters
x
y
boolean
| Bool
Returns
void
check()
static check(x: Bool): void
Defined in: lib/provable/bool.ts:402
Parameters
x
Returns
void
empty()
static empty(): Bool
Defined in: lib/provable/bool.ts:377
Returns
equal()
static equal(x: boolean | Bool, y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:308
Checks two Bool for equality.
Parameters
x
boolean
| Bool
y
boolean
| Bool
Returns
fromBytes()
static fromBytes(bytes: number[]): Bool
Defined in: lib/provable/bool.ts:389
Parameters
bytes
number
[]
Returns
fromFields()
static fromFields(fields: Field[]): Bool
Defined in: lib/provable/bool.ts:332
Creates a data structure from an array of serialized Field elements.
Parameters
fields
Field
[]
Returns
fromJSON()
static fromJSON(b: boolean): Bool
Defined in: lib/provable/bool.ts:366
Deserialize a JSON structure into a Bool. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.
Parameters
b
boolean
Returns
fromValue()
static fromValue(b: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:349
Provable<Bool>.fromValue()
Parameters
b
boolean
| Bool
Returns
not()
static not(x: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:233
Boolean negation.
Parameters
x
boolean
| Bool
Returns
or()
static or(x: boolean | Bool, y: boolean | Bool): Bool
Defined in: lib/provable/bool.ts:253
Boolean OR operation.
Parameters
x
boolean
| Bool
y
boolean
| Bool
Returns
readBytes()
static readBytes<N>(bytes: number[], offset: NonNegativeInteger<N>): [Bool, number]
Defined in: lib/provable/bool.ts:393
Type Parameters
• N extends number
Parameters
bytes
number
[]
offset
NonNegativeInteger
<N
>
Returns
[Bool
, number
]
sizeInFields()
static sizeInFields(): number
Defined in: lib/provable/bool.ts:373
Returns the size of this type.
Returns
number
toAuxiliary()
static toAuxiliary(_?: Bool): []
Defined in: lib/provable/bool.ts:325
Static method to serialize a Bool into its auxiliary data.
Parameters
_?
Returns
[]
toBytes()
static toBytes(b: Bool): number[]
Defined in: lib/provable/bool.ts:385
Parameters
b
Returns
number
[]
toField()
static toField(x: boolean | Bool): Field
Defined in: lib/provable/bool.ts:226
Parameters
x
boolean
| Bool
Returns
toFields()
static toFields(x: Bool): Field[]
Defined in: lib/provable/bool.ts:318
Static method to serialize a Bool into an array of Field elements.
Parameters
x
Returns
Field
[]
toInput()
static toInput(x: Bool): {
packed: [Field, number][];
}
Defined in: lib/provable/bool.ts:381
Parameters
x
Returns
{
packed: [Field, number][];
}
packed
packed: [Field, number][];
toJSON()
static toJSON(x: Bool): boolean
Defined in: lib/provable/bool.ts:358
Serialize a Bool to a JSON string. This operation does not affect the circuit and can't be used to prove anything about the string representation of the Field.
Parameters
x
Returns
boolean
toValue()
static toValue(x: Bool): boolean
Defined in: lib/provable/bool.ts:342
Provable<Bool>.toValue()
Parameters
x
Returns
boolean