@@ -16,16 +16,16 @@ const errors = {
16
16
17
17
export type UIntConstructor < BITS extends number > = {
18
18
// new(value: Field | { value: Field }): UIntX<BITS>;
19
- from ( x : UIntX < BITS > | bigint | number | string ) : UIntX < BITS > ;
19
+ from ( x : UInt < BITS > | bigint | number | string ) : UInt < BITS > ;
20
20
check ( x : { value : Field } ) : void ;
21
- get zero ( ) : UIntX < BITS > ;
21
+ get zero ( ) : UInt < BITS > ;
22
22
23
23
Unsafe : {
24
- fromField ( x : Field ) : UIntX < BITS >
25
- }
26
- }
24
+ fromField ( x : Field ) : UInt < BITS > ;
25
+ } ;
26
+ } ;
27
27
28
- export abstract class UIntX < BITS extends number > extends Struct ( {
28
+ export abstract class UInt < BITS extends number > extends Struct ( {
29
29
value : Field ,
30
30
} ) {
31
31
public static readonly assertionFunction : ( bool : Bool , msg ?: string ) => void =
@@ -45,7 +45,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
45
45
}
46
46
47
47
/**
48
- * Creates a {@link UIntX } with a value of 18,446,744,073,709,551,615.
48
+ * Creates a {@link UInt } with a value of 18,446,744,073,709,551,615.
49
49
*/
50
50
public static maxIntField ( numBits : number ) : Field {
51
51
return Field ( ( 1n << BigInt ( numBits ) ) - 1n ) ;
@@ -64,28 +64,28 @@ export abstract class UIntX<BITS extends number> extends Struct({
64
64
}
65
65
}
66
66
67
- public abstract numBits ( ) : BITS
67
+ public abstract numBits ( ) : BITS ;
68
68
69
69
public abstract constructorReference ( ) : UIntConstructor < BITS > ;
70
70
71
- private fromField ( value : Field ) : UIntX < BITS > {
72
- return this . constructorReference ( ) . Unsafe . fromField ( value )
71
+ private fromField ( value : Field ) : UInt < BITS > {
72
+ return this . constructorReference ( ) . Unsafe . fromField ( value ) ;
73
73
}
74
74
75
- private from ( value : UIntX < BITS > | string | number | bigint ) : UIntX < BITS > {
76
- return this . constructorReference ( ) . from ( value )
75
+ private from ( value : UInt < BITS > | string | number | bigint ) : UInt < BITS > {
76
+ return this . constructorReference ( ) . from ( value ) ;
77
77
}
78
78
79
79
/**
80
- * Turns the {@link UIntX } into a string.
80
+ * Turns the {@link UInt } into a string.
81
81
* @returns
82
82
*/
83
83
public toString ( ) {
84
84
return this . value . toString ( ) ;
85
85
}
86
86
87
87
/**
88
- * Turns the {@link UIntX } into a {@link BigInt}.
88
+ * Turns the {@link UInt } into a {@link BigInt}.
89
89
* @returns
90
90
*/
91
91
public toBigInt ( ) {
@@ -97,7 +97,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
97
97
*
98
98
* `x.divMod(y)` returns the quotient and the remainder.
99
99
*/
100
- public divMod ( divisor : UIntX < BITS > | bigint | number | string ) {
100
+ public divMod ( divisor : UInt < BITS > | bigint | number | string ) {
101
101
let x = this . value ;
102
102
let divisor_ = this . from ( divisor ) . value ;
103
103
@@ -114,14 +114,14 @@ export abstract class UIntX<BITS extends number> extends Struct({
114
114
115
115
divisor_ = divisor_ . seal ( ) ;
116
116
117
- UIntX . assertionFunction ( divisor_ . equals ( 0 ) . not ( ) , "Division by 0" ) ;
117
+ UInt . assertionFunction ( divisor_ . equals ( 0 ) . not ( ) , "Division by 0" ) ;
118
118
119
119
let q = Provable . witness ( Field , ( ) => {
120
120
const divisorInt = divisor_ . toBigInt ( ) ;
121
121
return new Field ( x . toBigInt ( ) / ( divisorInt == 0n ? 1n : divisorInt ) ) ;
122
122
} ) ;
123
123
124
- UIntX . assertionFunction (
124
+ UInt . assertionFunction (
125
125
q . rangeCheckHelper ( this . numBits ( ) ) . equals ( q ) ,
126
126
"Divison overflowing"
127
127
) ;
@@ -136,15 +136,15 @@ export abstract class UIntX<BITS extends number> extends Struct({
136
136
// TODO: Could be a bit more efficient
137
137
let r = x . sub ( q . mul ( divisor_ ) ) . seal ( ) ;
138
138
139
- UIntX . assertionFunction (
139
+ UInt . assertionFunction (
140
140
r . rangeCheckHelper ( this . numBits ( ) ) . equals ( r ) ,
141
141
"Divison overflowing, remainder"
142
142
) ;
143
143
144
144
let r_ = this . fromField ( r ) ;
145
145
let q_ = this . fromField ( q ) ;
146
146
147
- UIntX . assertionFunction (
147
+ UInt . assertionFunction (
148
148
r_ . lessThan ( this . fromField ( divisor_ ) ) ,
149
149
"Divison failure, remainder larger than divisor"
150
150
) ;
@@ -159,7 +159,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
159
159
* `z` such that `z * y <= x`.
160
160
*
161
161
*/
162
- public div ( y : UIntX < BITS > | bigint | number ) : UIntX < BITS > {
162
+ public div ( y : UInt < BITS > | bigint | number ) : UInt < BITS > {
163
163
return this . divMod ( y ) . quotient ;
164
164
}
165
165
@@ -178,7 +178,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
178
178
* @returns rest: The remainder indicating how far off the result
179
179
* is from the "real" sqrt
180
180
*/
181
- public sqrtMod ( ) : { sqrt : UIntX < BITS > ; rest : UIntX < BITS > } {
181
+ public sqrtMod ( ) : { sqrt : UInt < BITS > ; rest : UInt < BITS > } {
182
182
let x = this . value ;
183
183
184
184
if ( x . isConstant ( ) ) {
@@ -241,7 +241,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
241
241
/**
242
242
* Wraps sqrtMod() by only returning the sqrt and omitting the rest field.
243
243
*/
244
- public sqrtFloor ( ) : UIntX < BITS > {
244
+ public sqrtFloor ( ) : UInt < BITS > {
245
245
return this . sqrtMod ( ) . sqrt ;
246
246
}
247
247
@@ -251,14 +251,14 @@ export abstract class UIntX<BITS extends number> extends Struct({
251
251
* `x.mod(y)` returns the value `z` such that `0 <= z < y` and
252
252
* `x - z` is divisble by `y`.
253
253
*/
254
- public mod ( y : UIntX < BITS > | bigint | number ) {
254
+ public mod ( y : UInt < BITS > | bigint | number ) {
255
255
return this . divMod ( y ) . rest ;
256
256
}
257
257
258
258
/**
259
259
* Multiplication with overflow checking.
260
260
*/
261
- public mul ( y : UIntX < BITS > | bigint | number ) {
261
+ public mul ( y : UInt < BITS > | bigint | number ) {
262
262
let yField = this . from ( y ) . value ;
263
263
let z = this . value . mul ( yField ) ;
264
264
@@ -267,7 +267,7 @@ export abstract class UIntX<BITS extends number> extends Struct({
267
267
z . assertGreaterThan ( this . value , "Multiplication overflowing" ) ;
268
268
}
269
269
270
- UIntX . assertionFunction (
270
+ UInt . assertionFunction (
271
271
z . rangeCheckHelper ( this . numBits ( ) ) . equals ( z ) ,
272
272
"Multiplication overflowing"
273
273
) ;
@@ -277,9 +277,9 @@ export abstract class UIntX<BITS extends number> extends Struct({
277
277
/**
278
278
* Addition with overflow checking.
279
279
*/
280
- public add ( y : UIntX < BITS > | bigint | number ) {
280
+ public add ( y : UInt < BITS > | bigint | number ) {
281
281
let z = this . value . add ( this . from ( y ) . value ) ;
282
- UIntX . assertionFunction (
282
+ UInt . assertionFunction (
283
283
z . rangeCheckHelper ( this . numBits ( ) ) . equals ( z ) ,
284
284
"Addition overflowing"
285
285
) ;
@@ -289,35 +289,35 @@ export abstract class UIntX<BITS extends number> extends Struct({
289
289
/**
290
290
* Subtraction with underflow checking.
291
291
*/
292
- public sub ( y : UIntX < BITS > | bigint | number ) {
292
+ public sub ( y : UInt < BITS > | bigint | number ) {
293
293
let z = this . value . sub ( this . from ( y ) . value ) ;
294
- UIntX . assertionFunction (
294
+ UInt . assertionFunction (
295
295
z . rangeCheckHelper ( this . numBits ( ) ) . equals ( z ) ,
296
296
"Subtraction overflow"
297
297
) ;
298
298
return this . fromField ( z ) ;
299
299
}
300
300
301
301
/**
302
- * Checks if a {@link UIntX } is less than or equal to another one.
302
+ * Checks if a {@link UInt } is less than or equal to another one.
303
303
*/
304
- public lessThanOrEqual ( y : UIntX < BITS > ) {
304
+ public lessThanOrEqual ( y : UInt < BITS > ) {
305
305
if ( this . value . isConstant ( ) && y . value . isConstant ( ) ) {
306
306
return Bool ( this . value . toBigInt ( ) <= y . value . toBigInt ( ) ) ;
307
307
}
308
308
let xMinusY = this . value . sub ( y . value ) . seal ( ) ;
309
309
let yMinusX = xMinusY . neg ( ) ;
310
310
let yMinusXFits = yMinusX . rangeCheckHelper ( this . numBits ( ) ) . equals ( yMinusX ) ;
311
311
let xMinusYFits = xMinusY . rangeCheckHelper ( this . numBits ( ) ) . equals ( xMinusY ) ;
312
- UIntX . assertionFunction ( xMinusYFits . or ( yMinusXFits ) ) ;
312
+ UInt . assertionFunction ( xMinusYFits . or ( yMinusXFits ) ) ;
313
313
// x <= y if y - x fits in 64 bits
314
314
return yMinusXFits ;
315
315
}
316
316
317
317
/**
318
- * Asserts that a {@link UIntX } is less than or equal to another one.
318
+ * Asserts that a {@link UInt } is less than or equal to another one.
319
319
*/
320
- public assertLessThanOrEqual ( y : UIntX < BITS > , message ?: string ) {
320
+ public assertLessThanOrEqual ( y : UInt < BITS > , message ?: string ) {
321
321
if ( this . value . isConstant ( ) && y . value . isConstant ( ) ) {
322
322
let x0 = this . value . toBigInt ( ) ;
323
323
let y0 = y . value . toBigInt ( ) ;
@@ -330,67 +330,67 @@ export abstract class UIntX<BITS extends number> extends Struct({
330
330
return ;
331
331
}
332
332
let yMinusX = y . value . sub ( this . value ) . seal ( ) ;
333
- UIntX . assertionFunction (
333
+ UInt . assertionFunction (
334
334
yMinusX . rangeCheckHelper ( this . numBits ( ) ) . equals ( yMinusX ) ,
335
335
message
336
336
) ;
337
337
}
338
338
339
339
/**
340
340
*
341
- * Checks if a {@link UIntX } is less than another one.
341
+ * Checks if a {@link UInt } is less than another one.
342
342
*/
343
- public lessThan ( y : UIntX < BITS > ) {
343
+ public lessThan ( y : UInt < BITS > ) {
344
344
return this . lessThanOrEqual ( y ) . and ( this . value . equals ( y . value ) . not ( ) ) ;
345
345
}
346
346
347
347
/**
348
- * Asserts that a {@link UIntX } is less than another one.
348
+ * Asserts that a {@link UInt } is less than another one.
349
349
*/
350
- public assertLessThan ( y : UIntX < BITS > , message ?: string ) {
351
- UIntX . assertionFunction ( this . lessThan ( y ) , message ) ;
350
+ public assertLessThan ( y : UInt < BITS > , message ?: string ) {
351
+ UInt . assertionFunction ( this . lessThan ( y ) , message ) ;
352
352
}
353
353
354
354
/**
355
- * Checks if a {@link UIntX } is greater than another one.
355
+ * Checks if a {@link UInt } is greater than another one.
356
356
*/
357
- public greaterThan ( y : UIntX < BITS > ) {
357
+ public greaterThan ( y : UInt < BITS > ) {
358
358
return y . lessThan ( this ) ;
359
359
}
360
360
361
361
/**
362
- * Asserts that a {@link UIntX } is greater than another one.
362
+ * Asserts that a {@link UInt } is greater than another one.
363
363
*/
364
- public assertGreaterThan ( y : UIntX < BITS > , message ?: string ) {
364
+ public assertGreaterThan ( y : UInt < BITS > , message ?: string ) {
365
365
y . assertLessThan ( this , message ) ;
366
366
}
367
367
368
368
/**
369
- * Checks if a {@link UIntX } is greater than or equal to another one.
369
+ * Checks if a {@link UInt } is greater than or equal to another one.
370
370
*/
371
- public greaterThanOrEqual ( y : UIntX < BITS > ) {
371
+ public greaterThanOrEqual ( y : UInt < BITS > ) {
372
372
return this . lessThan ( y ) . not ( ) ;
373
373
}
374
374
375
375
/**
376
- * Asserts that a {@link UIntX } is greater than or equal to another one.
376
+ * Asserts that a {@link UInt } is greater than or equal to another one.
377
377
*/
378
- public assertGreaterThanOrEqual ( y : UIntX < BITS > , message ?: string ) {
378
+ public assertGreaterThanOrEqual ( y : UInt < BITS > , message ?: string ) {
379
379
y . assertLessThanOrEqual ( this , message ) ;
380
380
}
381
381
382
382
/**
383
- * Checks if a {@link UIntX } is equal to another one.
383
+ * Checks if a {@link UInt } is equal to another one.
384
384
*/
385
- public equals ( y : UIntX < BITS > | bigint | number ) : Bool {
385
+ public equals ( y : UInt < BITS > | bigint | number ) : Bool {
386
386
return this . from ( y ) . value . equals ( this . value ) ;
387
387
}
388
388
389
389
/**
390
- * Asserts that a {@link UIntX } is equal to another one.
390
+ * Asserts that a {@link UInt } is equal to another one.
391
391
*/
392
- public assertEquals ( y : UIntX < BITS > | bigint | number , message ?: string ) {
393
- UIntX . assertionFunction ( this . equals ( y ) , message ) ;
392
+ public assertEquals ( y : UInt < BITS > | bigint | number , message ?: string ) {
393
+ UInt . assertionFunction ( this . equals ( y ) , message ) ;
394
394
}
395
395
396
396
// /**
0 commit comments