@aztec/foundation 5.0.0-nightly.20260521 → 5.0.0-nightly.20260523
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,15 +15,13 @@ export declare class Point {
|
|
|
15
15
|
* The point's y coordinate
|
|
16
16
|
*/
|
|
17
17
|
readonly y: Fr;
|
|
18
|
-
|
|
19
|
-
* Whether the point is at infinity
|
|
20
|
-
*/
|
|
21
|
-
readonly isInfinite: boolean;
|
|
22
|
-
static ZERO: Point;
|
|
18
|
+
static INFINITY: Point;
|
|
23
19
|
static SIZE_IN_BYTES: number;
|
|
24
20
|
static COMPRESSED_SIZE_IN_BYTES: number;
|
|
25
21
|
/** Used to differentiate this class from AztecAddress */
|
|
26
22
|
readonly kind = "point";
|
|
23
|
+
/** Whether the point is at infinity */
|
|
24
|
+
readonly isInfinite: boolean;
|
|
27
25
|
constructor(
|
|
28
26
|
/**
|
|
29
27
|
* The point's x coordinate
|
|
@@ -32,11 +30,7 @@ export declare class Point {
|
|
|
32
30
|
/**
|
|
33
31
|
* The point's y coordinate
|
|
34
32
|
*/
|
|
35
|
-
y: Fr
|
|
36
|
-
/**
|
|
37
|
-
* Whether the point is at infinity
|
|
38
|
-
*/
|
|
39
|
-
isInfinite: boolean);
|
|
33
|
+
y: Fr);
|
|
40
34
|
toJSON(): `0x${string}`;
|
|
41
35
|
static get schema(): import("zod").ZodType<Point, string, import("zod/v4/core").$ZodTypeInternals<Point, string>>;
|
|
42
36
|
/**
|
|
@@ -80,8 +74,8 @@ export declare class Point {
|
|
|
80
74
|
*/
|
|
81
75
|
static fromString(str: string): Point;
|
|
82
76
|
/**
|
|
83
|
-
* Returns the contents of the point as an array of
|
|
84
|
-
* @returns The point as an array of
|
|
77
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
78
|
+
* @returns The point as an array of 2 fields
|
|
85
79
|
*/
|
|
86
80
|
toFields(): Fr[];
|
|
87
81
|
static fromFields(fields: Fr[] | FieldReader): Point;
|
|
@@ -96,7 +90,8 @@ export declare class Point {
|
|
|
96
90
|
*/
|
|
97
91
|
static fromXAndSign(x: Fr, sign: boolean): Promise<Point>;
|
|
98
92
|
/**
|
|
99
|
-
* @
|
|
93
|
+
* @param x - The x coordinate of the point
|
|
94
|
+
* @returns y^2 such that y^2 = x^3 - 17
|
|
100
95
|
*/
|
|
101
96
|
static YFromX(x: Fr): Promise<Fr | null>;
|
|
102
97
|
/**
|
|
@@ -112,17 +107,11 @@ export declare class Point {
|
|
|
112
107
|
toBigInts(): {
|
|
113
108
|
x: bigint;
|
|
114
109
|
y: bigint;
|
|
115
|
-
isInfinite: bigint;
|
|
116
110
|
};
|
|
117
111
|
/**
|
|
118
112
|
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
119
113
|
* @returns A Buffer representation of the Point instance.
|
|
120
|
-
* @dev Note that toBuffer does not include the isInfinite flag
|
|
121
|
-
* This is because currently when we work with point as bytes we don't want to populate the extra bytes for
|
|
122
|
-
* isInfinite flag because:
|
|
123
|
-
* 1. Our Grumpkin BB API currently does not handle point at infinity,
|
|
124
|
-
* 2. we use toBuffer when serializing notes and events and there we only work with public keys and point at infinity
|
|
125
|
-
* is not considered a valid public key and the extra byte would raise DA cost.
|
|
114
|
+
* @dev Note that toBuffer does not include the isInfinite flag. The point at infinity is serialized as (0, 0).
|
|
126
115
|
*/
|
|
127
116
|
toBuffer(): Buffer<ArrayBufferLike>;
|
|
128
117
|
/**
|
|
@@ -150,13 +139,11 @@ export declare class Point {
|
|
|
150
139
|
toNoirStruct(): {
|
|
151
140
|
x: Fr;
|
|
152
141
|
y: Fr;
|
|
153
|
-
is_infinite: boolean;
|
|
154
142
|
};
|
|
155
143
|
toWrappedNoirStruct(): {
|
|
156
144
|
inner: {
|
|
157
145
|
x: Fr;
|
|
158
146
|
y: Fr;
|
|
159
|
-
is_infinite: boolean;
|
|
160
147
|
};
|
|
161
148
|
};
|
|
162
149
|
/**
|
|
@@ -168,15 +155,14 @@ export declare class Point {
|
|
|
168
155
|
*/
|
|
169
156
|
equals(rhs: Point): boolean;
|
|
170
157
|
isZero(): boolean;
|
|
171
|
-
hash(): Promise<Fr>;
|
|
172
158
|
/**
|
|
173
|
-
*
|
|
174
|
-
*
|
|
159
|
+
* @param x - The x coordinate of the point
|
|
160
|
+
* @param y - The y coordinate of the point
|
|
161
|
+
* @returns Whether the point exists on Grumpkin
|
|
175
162
|
*/
|
|
176
|
-
|
|
177
|
-
isOnGrumpkin(): boolean;
|
|
163
|
+
isOnCurve(): boolean;
|
|
178
164
|
}
|
|
179
165
|
export declare class NotOnCurveError extends Error {
|
|
180
166
|
constructor(x: Fr);
|
|
181
167
|
}
|
|
182
|
-
//# sourceMappingURL=data:application/json;base64,
|
|
168
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicG9pbnQuZC50cyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9jdXJ2ZXMvZ3J1bXBraW4vcG9pbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBR0EsT0FBTyxFQUFFLFlBQVksRUFBRSxXQUFXLEVBQXFCLE1BQU0sMEJBQTBCLENBQUM7QUFFeEYsT0FBTyxFQUFFLEVBQUUsRUFBRSxNQUFNLG1CQUFtQixDQUFDO0FBRXZDOzs7OztHQUtHO0FBQ0gscUJBQWEsS0FBSztJQVlkOztPQUVHO2FBQ2EsQ0FBQyxFQUFFLEVBQUU7SUFDckI7O09BRUc7YUFDYSxDQUFDLEVBQUUsRUFBRTtJQWxCdkIsTUFBTSxDQUFDLFFBQVEsUUFBK0I7SUFDOUMsTUFBTSxDQUFDLGFBQWEsU0FBd0I7SUFDNUMsTUFBTSxDQUFDLHdCQUF3QixTQUFvQjtJQUVuRCx5REFBeUQ7SUFDekQsU0FBZ0IsSUFBSSxXQUFXO0lBRS9CLHVDQUF1QztJQUN2QyxTQUFnQixVQUFVLEVB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U8sQ0FBQyxDQUUxQjtJQUVEOzs7T0FHRztJQUNILFNBQVM7OztNQUtSO0lBRUQ7Ozs7T0FJRztJQUNILFFBQVEsNEJBTVA7SUFFRDs7O09BR0c7SUFDSCxrQkFBa0IsNEJBV2pCO0lBRUQ7Ozs7OztPQU1HO0lBQ0gsUUFBUSxrQkFFUDtJQUVEOzs7Ozs7O09BT0c7SUFDSCxhQUFhLFdBR1o7SUFFRCxZQUFZOzs7TUFFWDtJQUdELG1CQUFtQjs7Ozs7TUFFbEI7SUFFRDs7Ozs7O09BTUc7SUFDSCxNQUFNLENBQUMsR0FBRyxFQUFFLEtBQUssV0FFaEI7SUFFRCxNQUFNLFlBRUw7SUFFRDs7OztPQUlHO0lBQ0gsU0FBUyxZQVVSO0NBQ0Y7QUFFRCxxQkFBYSxlQUFnQixTQUFRLEtBQUs7SUFDeEMsWUFBWSxDQUFDLEVBQUUsRUFBRSxFQUdoQjtDQUNGIn0=
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../src/curves/grumpkin/point.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"point.d.ts","sourceRoot":"","sources":["../../../src/curves/grumpkin/point.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,WAAW,EAAqB,MAAM,0BAA0B,CAAC;AAExF,OAAO,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAEvC;;;;;GAKG;AACH,qBAAa,KAAK;IAYd;;OAEG;aACa,CAAC,EAAE,EAAE;IACrB;;OAEG;aACa,CAAC,EAAE,EAAE;IAlBvB,MAAM,CAAC,QAAQ,QAA+B;IAC9C,MAAM,CAAC,aAAa,SAAwB;IAC5C,MAAM,CAAC,wBAAwB,SAAoB;IAEnD,yDAAyD;IACzD,SAAgB,IAAI,WAAW;IAE/B,uCAAuC;IACvC,SAAgB,UAAU,EAAE,OAAO,CAAC;IAEpC;IACE;;OAEG;IACa,CAAC,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AK;IACxC,YAAY,CAAC,EAAE,EAAE,EAGhB;CACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toBigIntBE } from '../../bigint-buffer/index.js';
|
|
2
|
-
import { poseidon2Hash } from '../../crypto/poseidon/index.js';
|
|
3
2
|
import { randomBoolean } from '../../crypto/random/index.js';
|
|
4
3
|
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
5
4
|
import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
|
|
@@ -13,23 +12,22 @@ import { Fr } from '../bn254/field.js';
|
|
|
13
12
|
*/ export class Point {
|
|
14
13
|
x;
|
|
15
14
|
y;
|
|
16
|
-
|
|
17
|
-
static ZERO = new Point(Fr.ZERO, Fr.ZERO, false);
|
|
15
|
+
static INFINITY = new Point(Fr.ZERO, Fr.ZERO);
|
|
18
16
|
static SIZE_IN_BYTES = Fr.SIZE_IN_BYTES * 2;
|
|
19
17
|
static COMPRESSED_SIZE_IN_BYTES = Fr.SIZE_IN_BYTES;
|
|
20
18
|
/** Used to differentiate this class from AztecAddress */ kind;
|
|
19
|
+
/** Whether the point is at infinity */ isInfinite;
|
|
21
20
|
constructor(/**
|
|
22
21
|
* The point's x coordinate
|
|
23
22
|
*/ x, /**
|
|
24
23
|
* The point's y coordinate
|
|
25
|
-
*/ y
|
|
26
|
-
* Whether the point is at infinity
|
|
27
|
-
*/ isInfinite){
|
|
24
|
+
*/ y){
|
|
28
25
|
this.x = x;
|
|
29
26
|
this.y = y;
|
|
30
|
-
this.isInfinite = isInfinite;
|
|
31
27
|
this.kind = 'point';
|
|
32
|
-
|
|
28
|
+
// TODO(#7386): check if on curve
|
|
29
|
+
// NOTE: now there is no isInfinite in the struct, empty == inf, so an empty class would pass an on-curve check. This may be fine depending on the usage.
|
|
30
|
+
this.isInfinite = x.isZero() && y.isZero();
|
|
33
31
|
}
|
|
34
32
|
toJSON() {
|
|
35
33
|
return this.toString();
|
|
@@ -52,7 +50,7 @@ import { Fr } from '../bn254/field.js';
|
|
|
52
50
|
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
53
51
|
return Point.fromBuffer(obj);
|
|
54
52
|
}
|
|
55
|
-
return new
|
|
53
|
+
return new this(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y));
|
|
56
54
|
}
|
|
57
55
|
/**
|
|
58
56
|
* Generate a random Point instance that is on the curve.
|
|
@@ -78,7 +76,7 @@ import { Fr } from '../bn254/field.js';
|
|
|
78
76
|
* @returns A Point instance.
|
|
79
77
|
*/ static fromBuffer(buffer) {
|
|
80
78
|
const reader = BufferReader.asReader(buffer);
|
|
81
|
-
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader)
|
|
79
|
+
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader));
|
|
82
80
|
}
|
|
83
81
|
/**
|
|
84
82
|
* Create a Point instance from a compressed buffer.
|
|
@@ -104,21 +102,21 @@ import { Fr } from '../bn254/field.js';
|
|
|
104
102
|
return this.fromBuffer(hexToBuffer(str));
|
|
105
103
|
}
|
|
106
104
|
/**
|
|
107
|
-
* Returns the contents of the point as an array of
|
|
108
|
-
* @returns The point as an array of
|
|
109
|
-
*/
|
|
110
|
-
// `noir-projects/noir-protocol-circuits/crates/types/src/point.nr`, revert this to serialize as `[x, y]` (2 fields)
|
|
111
|
-
// and drop the `is_infinite` flag from `fromFields` / `toNoirStruct` below.
|
|
112
|
-
toFields() {
|
|
105
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
106
|
+
* @returns The point as an array of 2 fields
|
|
107
|
+
*/ toFields() {
|
|
113
108
|
return [
|
|
114
109
|
this.x,
|
|
115
|
-
this.y
|
|
116
|
-
new Fr(this.isInfinite)
|
|
110
|
+
this.y
|
|
117
111
|
];
|
|
118
112
|
}
|
|
119
113
|
static fromFields(fields) {
|
|
120
114
|
const reader = FieldReader.asReader(fields);
|
|
121
|
-
|
|
115
|
+
const [x, y] = [
|
|
116
|
+
reader.readField(),
|
|
117
|
+
reader.readField()
|
|
118
|
+
];
|
|
119
|
+
return new this(x, y);
|
|
122
120
|
}
|
|
123
121
|
/**
|
|
124
122
|
* Uses the x coordinate and isPositive flag (+/-) to reconstruct the point.
|
|
@@ -138,10 +136,11 @@ import { Fr } from '../bn254/field.js';
|
|
|
138
136
|
// Choose the positive or negative root based on isPositive
|
|
139
137
|
const finalY = sign ? new Fr(yPositiveBigInt) : new Fr(yNegativeBigInt);
|
|
140
138
|
// Create and return the new Point
|
|
141
|
-
return new this(x, finalY
|
|
139
|
+
return new this(x, finalY);
|
|
142
140
|
}
|
|
143
141
|
/**
|
|
144
|
-
* @
|
|
142
|
+
* @param x - The x coordinate of the point
|
|
143
|
+
* @returns y^2 such that y^2 = x^3 - 17
|
|
145
144
|
*/ static YFromX(x) {
|
|
146
145
|
// Calculate y^2 = x^3 - 17 (i.e. the Grumpkin curve equation)
|
|
147
146
|
const ySquared = x.square().mul(x).sub(new Fr(17));
|
|
@@ -165,23 +164,14 @@ import { Fr } from '../bn254/field.js';
|
|
|
165
164
|
*/ toBigInts() {
|
|
166
165
|
return {
|
|
167
166
|
x: this.x.toBigInt(),
|
|
168
|
-
y: this.y.toBigInt()
|
|
169
|
-
isInfinite: this.isInfinite ? 1n : 0n
|
|
167
|
+
y: this.y.toBigInt()
|
|
170
168
|
};
|
|
171
169
|
}
|
|
172
170
|
/**
|
|
173
171
|
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
174
172
|
* @returns A Buffer representation of the Point instance.
|
|
175
|
-
* @dev Note that toBuffer does not include the isInfinite flag
|
|
176
|
-
* This is because currently when we work with point as bytes we don't want to populate the extra bytes for
|
|
177
|
-
* isInfinite flag because:
|
|
178
|
-
* 1. Our Grumpkin BB API currently does not handle point at infinity,
|
|
179
|
-
* 2. we use toBuffer when serializing notes and events and there we only work with public keys and point at infinity
|
|
180
|
-
* is not considered a valid public key and the extra byte would raise DA cost.
|
|
173
|
+
* @dev Note that toBuffer does not include the isInfinite flag. The point at infinity is serialized as (0, 0).
|
|
181
174
|
*/ toBuffer() {
|
|
182
|
-
if (this.isInfinite) {
|
|
183
|
-
throw new Error('Cannot serialize infinite point with isInfinite flag');
|
|
184
|
-
}
|
|
185
175
|
const buf = serializeToBuffer([
|
|
186
176
|
this.x,
|
|
187
177
|
this.y
|
|
@@ -227,13 +217,12 @@ import { Fr } from '../bn254/field.js';
|
|
|
227
217
|
return `${str.slice(0, 10)}...${str.slice(-4)}`;
|
|
228
218
|
}
|
|
229
219
|
toNoirStruct() {
|
|
230
|
-
|
|
220
|
+
return {
|
|
231
221
|
x: this.x,
|
|
232
|
-
y: this.y
|
|
233
|
-
is_infinite: this.isInfinite
|
|
222
|
+
y: this.y
|
|
234
223
|
};
|
|
235
|
-
|
|
236
|
-
// Used for IvpkM
|
|
224
|
+
}
|
|
225
|
+
// Used for IvpkM. TODO(#8124): Consider removing this method.
|
|
237
226
|
toWrappedNoirStruct() {
|
|
238
227
|
return {
|
|
239
228
|
inner: this.toNoirStruct()
|
|
@@ -251,18 +240,12 @@ import { Fr } from '../bn254/field.js';
|
|
|
251
240
|
isZero() {
|
|
252
241
|
return this.x.isZero() && this.y.isZero();
|
|
253
242
|
}
|
|
254
|
-
hash() {
|
|
255
|
-
return poseidon2Hash(this.toFields());
|
|
256
|
-
}
|
|
257
243
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
isOnGrumpkin() {
|
|
264
|
-
// TODO: Check this against how bb handles curve check and infinity point check
|
|
265
|
-
if (this.inf) {
|
|
244
|
+
* @param x - The x coordinate of the point
|
|
245
|
+
* @param y - The y coordinate of the point
|
|
246
|
+
* @returns Whether the point exists on Grumpkin
|
|
247
|
+
*/ isOnCurve() {
|
|
248
|
+
if (this.isInfinite) {
|
|
266
249
|
return true;
|
|
267
250
|
}
|
|
268
251
|
// The Grumpkin equation is y^2 = x^3 - 17. We could use `YFromX` and then compare to `this.y`, but this would
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aztec/foundation",
|
|
3
|
-
"version": "5.0.0-nightly.
|
|
3
|
+
"version": "5.0.0-nightly.20260523",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dest/index.js",
|
|
6
6
|
"types": "./dest/index.d.ts",
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
"testEnvironment": "../../foundation/src/jest/env.mjs"
|
|
146
146
|
},
|
|
147
147
|
"dependencies": {
|
|
148
|
-
"@aztec/bb.js": "5.0.0-nightly.
|
|
148
|
+
"@aztec/bb.js": "5.0.0-nightly.20260523",
|
|
149
149
|
"@koa/cors": "^5.0.0",
|
|
150
150
|
"@noble/curves": "=1.7.0",
|
|
151
151
|
"@noble/hashes": "^1.6.1",
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { toBigIntBE } from '../../bigint-buffer/index.js';
|
|
2
|
-
import { poseidon2Hash } from '../../crypto/poseidon/index.js';
|
|
3
2
|
import { randomBoolean } from '../../crypto/random/index.js';
|
|
4
3
|
import { hexSchemaFor } from '../../schemas/utils.js';
|
|
5
4
|
import { BufferReader, FieldReader, serializeToBuffer } from '../../serialize/index.js';
|
|
@@ -13,13 +12,16 @@ import { Fr } from '../bn254/field.js';
|
|
|
13
12
|
* TODO(#7386): Clean up this class.
|
|
14
13
|
*/
|
|
15
14
|
export class Point {
|
|
16
|
-
static
|
|
15
|
+
static INFINITY = new Point(Fr.ZERO, Fr.ZERO);
|
|
17
16
|
static SIZE_IN_BYTES = Fr.SIZE_IN_BYTES * 2;
|
|
18
17
|
static COMPRESSED_SIZE_IN_BYTES = Fr.SIZE_IN_BYTES;
|
|
19
18
|
|
|
20
19
|
/** Used to differentiate this class from AztecAddress */
|
|
21
20
|
public readonly kind = 'point';
|
|
22
21
|
|
|
22
|
+
/** Whether the point is at infinity */
|
|
23
|
+
public readonly isInfinite: boolean;
|
|
24
|
+
|
|
23
25
|
constructor(
|
|
24
26
|
/**
|
|
25
27
|
* The point's x coordinate
|
|
@@ -29,12 +31,10 @@ export class Point {
|
|
|
29
31
|
* The point's y coordinate
|
|
30
32
|
*/
|
|
31
33
|
public readonly y: Fr,
|
|
32
|
-
/**
|
|
33
|
-
* Whether the point is at infinity
|
|
34
|
-
*/
|
|
35
|
-
public readonly isInfinite: boolean,
|
|
36
34
|
) {
|
|
37
35
|
// TODO(#7386): check if on curve
|
|
36
|
+
// NOTE: now there is no isInfinite in the struct, empty == inf, so an empty class would pass an on-curve check. This may be fine depending on the usage.
|
|
37
|
+
this.isInfinite = x.isZero() && y.isZero();
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
toJSON() {
|
|
@@ -61,7 +61,7 @@ export class Point {
|
|
|
61
61
|
if (obj instanceof Buffer || Buffer.isBuffer(obj)) {
|
|
62
62
|
return Point.fromBuffer(obj);
|
|
63
63
|
}
|
|
64
|
-
return new
|
|
64
|
+
return new this(Fr.fromPlainObject(obj.x), Fr.fromPlainObject(obj.y));
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -92,7 +92,7 @@ export class Point {
|
|
|
92
92
|
*/
|
|
93
93
|
static fromBuffer(buffer: Buffer | BufferReader) {
|
|
94
94
|
const reader = BufferReader.asReader(buffer);
|
|
95
|
-
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader)
|
|
95
|
+
return new this(Fr.fromBuffer(reader), Fr.fromBuffer(reader));
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -125,19 +125,17 @@ export class Point {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
/**
|
|
128
|
-
* Returns the contents of the point as an array of
|
|
129
|
-
* @returns The point as an array of
|
|
128
|
+
* Returns the contents of the point as an array of 2 fields.
|
|
129
|
+
* @returns The point as an array of 2 fields
|
|
130
130
|
*/
|
|
131
|
-
// TODO(F-553): Once we take the breaking change and drop the custom Noir `Point` wrapper in
|
|
132
|
-
// `noir-projects/noir-protocol-circuits/crates/types/src/point.nr`, revert this to serialize as `[x, y]` (2 fields)
|
|
133
|
-
// and drop the `is_infinite` flag from `fromFields` / `toNoirStruct` below.
|
|
134
131
|
toFields() {
|
|
135
|
-
return [this.x, this.y
|
|
132
|
+
return [this.x, this.y];
|
|
136
133
|
}
|
|
137
134
|
|
|
138
135
|
static fromFields(fields: Fr[] | FieldReader) {
|
|
139
136
|
const reader = FieldReader.asReader(fields);
|
|
140
|
-
|
|
137
|
+
const [x, y] = [reader.readField(), reader.readField()];
|
|
138
|
+
return new this(x, y);
|
|
141
139
|
}
|
|
142
140
|
|
|
143
141
|
/**
|
|
@@ -162,11 +160,12 @@ export class Point {
|
|
|
162
160
|
const finalY = sign ? new Fr(yPositiveBigInt) : new Fr(yNegativeBigInt);
|
|
163
161
|
|
|
164
162
|
// Create and return the new Point
|
|
165
|
-
return new this(x, finalY
|
|
163
|
+
return new this(x, finalY);
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
/**
|
|
169
|
-
* @
|
|
167
|
+
* @param x - The x coordinate of the point
|
|
168
|
+
* @returns y^2 such that y^2 = x^3 - 17
|
|
170
169
|
*/
|
|
171
170
|
static YFromX(x: Fr): Promise<Fr | null> {
|
|
172
171
|
// Calculate y^2 = x^3 - 17 (i.e. the Grumpkin curve equation)
|
|
@@ -194,24 +193,15 @@ export class Point {
|
|
|
194
193
|
return {
|
|
195
194
|
x: this.x.toBigInt(),
|
|
196
195
|
y: this.y.toBigInt(),
|
|
197
|
-
isInfinite: this.isInfinite ? 1n : 0n,
|
|
198
196
|
};
|
|
199
197
|
}
|
|
200
198
|
|
|
201
199
|
/**
|
|
202
200
|
* Converts the Point instance to a Buffer representation of the coordinates.
|
|
203
201
|
* @returns A Buffer representation of the Point instance.
|
|
204
|
-
* @dev Note that toBuffer does not include the isInfinite flag
|
|
205
|
-
* This is because currently when we work with point as bytes we don't want to populate the extra bytes for
|
|
206
|
-
* isInfinite flag because:
|
|
207
|
-
* 1. Our Grumpkin BB API currently does not handle point at infinity,
|
|
208
|
-
* 2. we use toBuffer when serializing notes and events and there we only work with public keys and point at infinity
|
|
209
|
-
* is not considered a valid public key and the extra byte would raise DA cost.
|
|
202
|
+
* @dev Note that toBuffer does not include the isInfinite flag. The point at infinity is serialized as (0, 0).
|
|
210
203
|
*/
|
|
211
204
|
toBuffer() {
|
|
212
|
-
if (this.isInfinite) {
|
|
213
|
-
throw new Error('Cannot serialize infinite point with isInfinite flag');
|
|
214
|
-
}
|
|
215
205
|
const buf = serializeToBuffer([this.x, this.y]);
|
|
216
206
|
if (buf.length !== Point.SIZE_IN_BYTES) {
|
|
217
207
|
throw new Error(`Invalid buffer length for Point: ${buf.length}`);
|
|
@@ -261,12 +251,10 @@ export class Point {
|
|
|
261
251
|
}
|
|
262
252
|
|
|
263
253
|
toNoirStruct() {
|
|
264
|
-
|
|
265
|
-
return { x: this.x, y: this.y, is_infinite: this.isInfinite };
|
|
266
|
-
/* eslint-enable camelcase */
|
|
254
|
+
return { x: this.x, y: this.y };
|
|
267
255
|
}
|
|
268
256
|
|
|
269
|
-
// Used for IvpkM
|
|
257
|
+
// Used for IvpkM. TODO(#8124): Consider removing this method.
|
|
270
258
|
toWrappedNoirStruct() {
|
|
271
259
|
return { inner: this.toNoirStruct() };
|
|
272
260
|
}
|
|
@@ -286,21 +274,13 @@ export class Point {
|
|
|
286
274
|
return this.x.isZero() && this.y.isZero();
|
|
287
275
|
}
|
|
288
276
|
|
|
289
|
-
hash() {
|
|
290
|
-
return poseidon2Hash(this.toFields());
|
|
291
|
-
}
|
|
292
|
-
|
|
293
277
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
278
|
+
* @param x - The x coordinate of the point
|
|
279
|
+
* @param y - The y coordinate of the point
|
|
280
|
+
* @returns Whether the point exists on Grumpkin
|
|
296
281
|
*/
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
isOnGrumpkin() {
|
|
302
|
-
// TODO: Check this against how bb handles curve check and infinity point check
|
|
303
|
-
if (this.inf) {
|
|
282
|
+
isOnCurve() {
|
|
283
|
+
if (this.isInfinite) {
|
|
304
284
|
return true;
|
|
305
285
|
}
|
|
306
286
|
|