diff --git a/src/lib/provable/field.ts b/src/lib/provable/field.ts index 4afb787563..6f5398ae02 100644 --- a/src/lib/provable/field.ts +++ b/src/lib/provable/field.ts @@ -565,17 +565,14 @@ class Field { * * @example * ```ts - * Field(2).lessThan(3).assertEquals(Bool(true)); + * let isTrue = Field(2).lessThan(3); * ``` * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * **Warning**: As this method compares the bigint value of a {@link Field}, it can result in unexpected behavior when used with negative inputs or modular division. * * @example * ```ts - * Field(1).div(Field(3)).lessThan(Field(1).div(Field(2))).assertEquals(Bool(true)); // This code will throw an error + * let isFalse = Field(1).div(3).lessThan(Field(1).div(2)); // in fact, 1/3 > 1/2 * ``` * * @param value - the "field-like" value to compare with this {@link Field}. @@ -595,17 +592,14 @@ class Field { * * @example * ```ts - * Field(3).lessThanOrEqual(3).assertEquals(Bool(true)); + * let isTrue = Field(3).lessThanOrEqual(3); * ``` * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * **Warning**: As this method compares the bigint value of a {@link Field}, it can result in unexpected behaviour when used with negative inputs or modular division. * * @example * ```ts - * Field(1).div(Field(3)).lessThanOrEqual(Field(1).div(Field(2))).assertEquals(Bool(true)); // This code will throw an error + * let isFalse = Field(1).div(3).lessThanOrEqual(Field(1).div(2)); // in fact, 1/3 > 1/2 * ``` * * @param value - the "field-like" value to compare with this {@link Field}. @@ -625,17 +619,14 @@ class Field { * * @example * ```ts - * Field(5).greaterThan(3).assertEquals(Bool(true)); + * let isTrue = Field(5).greaterThan(3); * ``` * - * **Warning**: Comparison methods currently only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * **Warning**: As this method compares the bigint value of a {@link Field}, it can result in unexpected behaviour when used with negative inputs or modular division. * * @example * ```ts - * Field(1).div(Field(2)).greaterThan(Field(1).div(Field(3))).assertEquals(Bool(true)); // This code will throw an error + * let isFalse = Field(1).div(2).greaterThan(Field(1).div(3); // in fact, 1/3 > 1/2 * ``` * * @param value - the "field-like" value to compare with this {@link Field}. @@ -652,17 +643,14 @@ class Field { * * @example * ```ts - * Field(3).greaterThanOrEqual(3).assertEquals(Bool(true)); + * let isTrue = Field(3).greaterThanOrEqual(3); * ``` * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * **Warning**: As this method compares the bigint value of a {@link Field}, it can result in unexpected behaviour when used with negative inputs or modular division. * * @example * ```ts - * Field(1).div(Field(2)).greaterThanOrEqual(Field(1).div(Field(3))).assertEquals(Bool(true)); // This code will throw an error + * let isFalse = Field(1).div(2).greaterThanOrEqual(Field(1).div(3); // in fact, 1/3 > 1/2 * ``` * * @param value - the "field-like" value to compare with this {@link Field}. @@ -675,14 +663,12 @@ class Field { /** * Assert that this {@link Field} is less than another "field-like" value. - * Calling this function is equivalent to `Field(...).lessThan(...).assertEquals(Bool(true))`. + * + * Note: This uses fewer constraints than `x.lessThan(y).assertTrue()`. * See {@link Field.lessThan} for more details. * * **Important**: If an assertion fails, the code throws an error. * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * @param value - the "field-like" value to compare & assert with this {@link Field}. * @param message? - a string error message to print if the assertion fails, optional. */ @@ -702,14 +688,12 @@ class Field { /** * Assert that this {@link Field} is less than or equal to another "field-like" value. - * Calling this function is equivalent to `Field(...).lessThanOrEqual(...).assertEquals(Bool(true))`. + * + * Note: This uses fewer constraints than `x.lessThanOrEqual(y).assertTrue()`. * See {@link Field.lessThanOrEqual} for more details. * * **Important**: If an assertion fails, the code throws an error. * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * @param value - the "field-like" value to compare & assert with this {@link Field}. * @param message? - a string error message to print if the assertion fails, optional. */ @@ -729,14 +713,12 @@ class Field { /** * Assert that this {@link Field} is greater than another "field-like" value. - * Calling this function is equivalent to `Field(...).greaterThan(...).assertEquals(Bool(true))`. + * + * Note: This uses fewer constraints than `x.greaterThan(y).assertTrue()`. * See {@link Field.greaterThan} for more details. * * **Important**: If an assertion fails, the code throws an error. * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * @param value - the "field-like" value to compare & assert with this {@link Field}. * @param message? - a string error message to print if the assertion fails, optional. */ @@ -746,14 +728,12 @@ class Field { /** * Assert that this {@link Field} is greater than or equal to another "field-like" value. - * Calling this function is equivalent to `Field(...).greaterThanOrEqual(...).assertEquals(Bool(true))`. + * + * Note: This uses fewer constraints than `x.greaterThanOrEqual(y).assertTrue()`. * See {@link Field.greaterThanOrEqual} for more details. * * **Important**: If an assertion fails, the code throws an error. * - * **Warning**: Comparison methods only support Field elements of size <= 253 bits in provable code. - * The method will throw if one of the inputs exceeds 253 bits. - * * @param value - the "field-like" value to compare & assert with this {@link Field}. * @param message? - a string error message to print if the assertion fails, optional. */ diff --git a/src/lib/provable/test/field.unit-test.ts b/src/lib/provable/test/field.unit-test.ts index 2465df3adb..54c2ae5518 100644 --- a/src/lib/provable/test/field.unit-test.ts +++ b/src/lib/provable/test/field.unit-test.ts @@ -76,8 +76,6 @@ let SmallField = Random.reject( (x) => x.toString(2).length > Fp.sizeInBits - 2 ); let smallField: Spec = { ...field, rng: SmallField }; -let smallBigint: Spec = { ...bigintField, rng: SmallField }; -let smallFieldOrBigint = oneOf(smallField, smallBigint); // arithmetic, both in- and outside provable code let equivalent1 = equivalent({ from: [field], to: field }); @@ -105,11 +103,11 @@ equivalent({ from: [field, fieldOrBigint], to: bool })( (x, y) => x.equals(y) ); -equivalent({ from: [smallField, smallFieldOrBigint], to: bool })( +equivalent({ from: [field, fieldOrBigint], to: bool })( (x, y) => x < y, (x, y) => x.lessThan(y) ); -equivalent({ from: [smallField, smallFieldOrBigint], to: bool })( +equivalent({ from: [field, fieldOrBigint], to: bool })( (x, y) => x <= y, (x, y) => x.lessThanOrEqual(y) ); @@ -121,11 +119,11 @@ equivalent({ from: [field, fieldOrBigint], to: unit })( (x, y) => x !== y || throwError('equal'), (x, y) => x.assertNotEquals(y) ); -equivalent({ from: [smallField, smallFieldOrBigint], to: unit })( +equivalent({ from: [field, fieldOrBigint], to: unit })( (x, y) => x < y || throwError('not less than'), (x, y) => x.assertLessThan(y) ); -equivalent({ from: [smallField, smallFieldOrBigint], to: unit })( +equivalent({ from: [field, fieldOrBigint], to: unit })( (x, y) => x <= y || throwError('not less than or equal'), (x, y) => x.assertLessThanOrEqual(y) );