From 1a666e86155275d731d59afd464164e351fc91b3 Mon Sep 17 00:00:00 2001 From: Gregor Date: Fri, 3 Nov 2023 15:50:51 +0100 Subject: [PATCH] match doc style of other gadgets and tweak function signature --- src/lib/gadgets/gadgets.ts | 22 ++++++++++++++++++---- src/lib/gadgets/range-check.ts | 8 ++++++-- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/lib/gadgets/gadgets.ts b/src/lib/gadgets/gadgets.ts index 570cd7b21..ab010921b 100644 --- a/src/lib/gadgets/gadgets.ts +++ b/src/lib/gadgets/gadgets.ts @@ -221,9 +221,16 @@ const Gadgets = { * * In particular, the 3x88-bit range check supports bigints up to 264 bits, which in turn is enough * to support foreign field multiplication with moduli up to 2^259. + * + * @example + * ```ts + * Gadgets.multiRangeCheck([x, y, z]); + * ``` + * + * @throws Throws an error if one of the input values exceeds 88 bits. */ - multiRangeCheck(x: Field, y: Field, z: Field) { - multiRangeCheck(x, y, z); + multiRangeCheck(limbs: [Field, Field, Field]) { + multiRangeCheck(limbs); }, /** @@ -238,8 +245,15 @@ const Gadgets = { * - proves that x, y, z are all in the range [0, 2^88). * * The split form [x, y, z] is returned. + * + * @example + * ```ts + * let [x, y] = Gadgets.compactMultiRangeCheck([xy, z]); + * ``` + * + * @throws Throws an error if `xy` exceeds 2*88 = 176 bits, or if z exceeds 88 bits. */ - compactMultiRangeCheck(xy: Field, z: Field) { - return compactMultiRangeCheck(xy, z); + compactMultiRangeCheck(limbs: [Field, Field]) { + return compactMultiRangeCheck(limbs); }, }; diff --git a/src/lib/gadgets/range-check.ts b/src/lib/gadgets/range-check.ts index d48356d48..bc806f430 100644 --- a/src/lib/gadgets/range-check.ts +++ b/src/lib/gadgets/range-check.ts @@ -57,7 +57,7 @@ const lMask = (1n << L) - 1n; /** * Asserts that x, y, z \in [0, 2^88) */ -function multiRangeCheck(x: Field, y: Field, z: Field) { +function multiRangeCheck([x, y, z]: [Field, Field, Field]) { if (x.isConstant() && y.isConstant() && z.isConstant()) { if (x.toBigInt() >> L || y.toBigInt() >> L || z.toBigInt() >> L) { throw Error(`Expected fields to fit in ${L} bits, got ${x}, ${y}, ${z}`); @@ -77,7 +77,11 @@ function multiRangeCheck(x: Field, y: Field, z: Field) { * * Returns the full limbs x, y, z */ -function compactMultiRangeCheck(xy: Field, z: Field): [Field, Field, Field] { +function compactMultiRangeCheck([xy, z]: [Field, Field]): [ + Field, + Field, + Field +] { // constant case if (xy.isConstant() && z.isConstant()) { if (xy.toBigInt() >> twoL || z.toBigInt() >> L) {