Skip to content

Commit

Permalink
match doc style of other gadgets and tweak function signature
Browse files Browse the repository at this point in the history
  • Loading branch information
mitschabaude committed Nov 3, 2023
1 parent 96c4797 commit 1a666e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/lib/gadgets/gadgets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},

/**
Expand All @@ -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);
},
};
8 changes: 6 additions & 2 deletions src/lib/gadgets/range-check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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) {
Expand Down

0 comments on commit 1a666e8

Please sign in to comment.