Skip to main content

Bool

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

Parameters​

• x: boolean | FieldVar | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:33

Properties​

value​

value: FieldVar;

Source​

lib/provable/bool.ts:31


Unsafe​

static Unsafe: {
"fromField": Bool;
};

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: Field

a Field

Returns​

Bool

Source​

lib/provable/bool.ts:373


sizeInBytes​

static sizeInBytes: number = 1;

Source​

lib/provable/bool.ts:367

Methods​

and()​

and(y: boolean | Bool): Bool

Parameters​

• y: boolean | Bool

A Bool to AND with this Bool.

Returns​

Bool

a new Bool that is set to true only if this Bool and y are also true.

Source​

lib/provable/bool.ts:73


assertEquals()​

assertEquals(y: boolean | Bool, message?: string): void

Proves that this Bool is equal to y.

Parameters​

• y: boolean | Bool

a Bool.

• message?: string

Returns​

void

Source​

lib/provable/bool.ts:114


assertFalse()​

assertFalse(message?: string): void

Proves that this Bool is false.

Parameters​

• message?: string

Returns​

void

Source​

lib/provable/bool.ts:145


assertTrue()​

assertTrue(message?: string): void

Proves that this Bool is true.

Parameters​

• message?: string

Returns​

void

Source​

lib/provable/bool.ts:131


equals()​

equals(y: boolean | Bool): Bool

Returns true if this Bool is equal to y.

Parameters​

• y: boolean | Bool

a Bool.

Returns​

Bool

Source​

lib/provable/bool.ts:160


implies()​

implies(y: boolean | Bool): Bool

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​

Bool

Example​

let isZero = x.equals(0);
let lessThan10 = x.lessThan(10);
assert(isZero.implies(lessThan10), 'x = 0 implies x < 10');

Source​

lib/provable/bool.ts:106


isConstant()​

isConstant(): this is Object

Returns​

this is Object

Source​

lib/provable/bool.ts:45


not()​

not(): Bool

Returns​

Bool

a new Bool that is the negation of this Bool.

Source​

lib/provable/bool.ts:59


or()​

or(y: boolean | Bool): Bool

Parameters​

• y: boolean | Bool

a Bool to OR with this Bool.

Returns​

Bool

a new Bool that is set to true if either this Bool or y is true.

Source​

lib/provable/bool.ts:86


sizeInFields()​

sizeInFields(): number

Returns the size of this type.

Returns​

number

Source​

lib/provable/bool.ts:185


toBoolean()​

toBoolean(): boolean

This converts the Bool to a JS boolean. This can only be called on non-witness values.

Returns​

boolean

Source​

lib/provable/bool.ts:216


toField()​

toField(): Field

Converts a Bool to a Field. false becomes 0 and true becomes 1.

Returns​

Field

Source​

lib/provable/bool.ts:52


toFields()​

toFields(): Field[]

Serializes this Bool into Field elements.

Returns​

Field[]

Source​

lib/provable/bool.ts:192


toJSON()​

toJSON(): boolean

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

Source​

lib/provable/bool.ts:208


toString()​

toString(): string

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

Source​

lib/provable/bool.ts:200


and()​

static and(x: boolean | Bool, y: boolean | Bool): Bool

Boolean AND operation.

Parameters​

• x: boolean | Bool

• y: boolean | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:244


assertEqual()​

static assertEqual(x: Bool, y: boolean | Bool): void

Asserts if both Bool are equal.

Parameters​

• x: Bool

• y: boolean | Bool

Returns​

void

Source​

lib/provable/bool.ts:264


check()​

static check(x: Bool): void

Parameters​

• x: Bool

Returns​

void

Source​

lib/provable/bool.ts:369


empty()​

static empty(): Bool

Returns​

Bool

Source​

lib/provable/bool.ts:344


equal()​

static equal(x: boolean | Bool, y: boolean | Bool): Bool

Checks two Bool for equality.

Parameters​

• x: boolean | Bool

• y: boolean | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:275


fromBytes()​

static fromBytes(bytes: number[]): Bool

Parameters​

• bytes: number[]

Returns​

Bool

Source​

lib/provable/bool.ts:356


fromFields()​

static fromFields(fields: Field[]): Bool

Creates a data structure from an array of serialized Field elements.

Parameters​

• fields: Field[]

Returns​

Bool

Source​

lib/provable/bool.ts:299


fromJSON()​

static fromJSON(b: boolean): Bool

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​

Bool

Source​

lib/provable/bool.ts:333


fromValue()​

static fromValue(b: boolean | Bool): Bool

Provable<Bool>.fromValue()

Parameters​

• b: boolean | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:316


not()​

static not(x: boolean | Bool): Bool

Boolean negation.

Parameters​

• x: boolean | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:234


or()​

static or(x: boolean | Bool, y: boolean | Bool): Bool

Boolean OR operation.

Parameters​

• x: boolean | Bool

• y: boolean | Bool

Returns​

Bool

Source​

lib/provable/bool.ts:254


readBytes()​

static readBytes<N>(bytes: number[], offset: NonNegativeInteger<N>): [Bool, number]

Type parameters​

• N extends number

Parameters​

• bytes: number[]

• offset: NonNegativeInteger\<N>

Returns​

[Bool, number]

Source​

lib/provable/bool.ts:360


sizeInFields()​

static sizeInFields(): number

Returns the size of this type.

Returns​

number

Source​

lib/provable/bool.ts:340


toAuxiliary()​

static toAuxiliary(_?: Bool): []

Static method to serialize a Bool into its auxiliary data.

Parameters​

• _?: Bool

Returns​

[]

Source​

lib/provable/bool.ts:292


toBytes()​

static toBytes(b: Bool): number[]

Parameters​

• b: Bool

Returns​

number[]

Source​

lib/provable/bool.ts:352


toField()​

static toField(x: boolean | Bool): Field

Parameters​

• x: boolean | Bool

Returns​

Field

Source​

lib/provable/bool.ts:227


toFields()​

static toFields(x: Bool): Field[]

Static method to serialize a Bool into an array of Field elements.

Parameters​

• x: Bool

Returns​

Field[]

Source​

lib/provable/bool.ts:285


toInput()​

static toInput(x: Bool): {
"packed": [Field, number][];
}

Parameters​

• x: Bool

Returns​

{
"packed": [Field, number][];
}
packed​
packed: [Field, number][];

Source​

lib/provable/bool.ts:348


toJSON()​

static toJSON(x: Bool): boolean

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: Bool

Returns​

boolean

Source​

lib/provable/bool.ts:325


toValue()​

static toValue(x: Bool): boolean

Provable<Bool>.toValue()

Parameters​

• x: Bool

Returns​

boolean

Source​

lib/provable/bool.ts:309