You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: EIPS/eip-2537.md
+37-18Lines changed: 37 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -91,10 +91,10 @@ One should note that base field modulus `p` is equal to `3 mod 4` that allows an
91
91
92
92
### Fields and Groups
93
93
94
-
Field Fp is defined as the finite field of size `p` with elements represented as integers between 0 and p-1 (both inclusive).
94
+
Field Fp is defined as the finite field of size `p` with elements represented as integers between 0 and p-1 (both inclusive).
95
95
96
96
Field Fp2 is defined as `Fp[X]/(X^2-nr2)` with elements `el = c0 + c1 * v`, where `v` is the formal square root of `nr2` represented as integer pairs `(c0,c1)`.
97
-
97
+
98
98
Group G1 is defined as a set of Fp pairs (points) `(x,y)` such that either `(x,y)` is `(0,0)` or `x,y` satisfy the curve Fp equation.
99
99
100
100
Group G2 is defined as a set of Fp2 pairs (points) `(x',y')` such that either `(x,y)` is `(0,0)` or `(x',y')` satisfy the curve Fp2 equation.
@@ -138,17 +138,22 @@ G1 addition call expects `256` bytes as an input that is interpreted as byte con
138
138
Error cases:
139
139
140
140
- Invalid coordinate encoding
141
-
-Either of points not in G1 (i.e. neither on a curve nor the infinity point)
141
+
-An input is neither a point on the G1 elliptic curve nor the infinity point
142
142
- Input has invalid length
143
143
144
+
Note:
145
+
146
+
There is no subgroup check for the G1 addition precompile.
147
+
144
148
#### ABI for G1 multiplication
145
149
146
150
G1 multiplication call expects `160` bytes as an input that is interpreted as byte concatenation of encoding of a G1 point (`128` bytes) and encoding of a scalar value (`32` bytes). Output is an encoding of the multiplication operation result - a single G1 point (`128` bytes).
147
151
148
152
Error cases:
149
153
150
154
- Invalid coordinate encoding
151
-
- The point not in G1 (i.e. neither on a curve nor the infinity point)
155
+
- An input is neither a point on the G1 elliptic curve nor the infinity point
156
+
- An input is on the G1 elliptic curve but not in the correct subgroup
152
157
- Input has invalid length
153
158
154
159
#### ABI for G1 MSM
@@ -158,8 +163,9 @@ G1 MSM call expects `160*k` (`k` being a **positive** integer) bytes as an input
158
163
Error cases:
159
164
160
165
- Invalid coordinate encoding
161
-
- Any point not in G1 (i.e. neither on a curve nor the infinity point)
162
-
- Input has invalid length
166
+
- An input is neither a point on the G1 elliptic curve nor the infinity point
167
+
- An input is on the G1 elliptic curve but not in the correct subgroup
168
+
- Input has invalid length
163
169
164
170
#### ABI for G2 addition
165
171
@@ -168,8 +174,12 @@ G2 addition call expects `512` bytes as an input that is interpreted as byte con
168
174
Error cases:
169
175
170
176
- Invalid coordinate encoding
171
-
- Either of points not in G2 (i.e. neither on a curve nor the infinity point)
172
-
- Input has invalid length
177
+
- An input is neither a point on the G2 elliptic curve nor the infinity point
178
+
- Input has invalid length
179
+
180
+
Note:
181
+
182
+
There is no subgroup check for the G2 addition precompile.
173
183
174
184
#### ABI for G2 multiplication
175
185
@@ -178,8 +188,9 @@ G2 multiplication call expects `288` bytes as an input that is interpreted as by
178
188
Error cases:
179
189
180
190
- Invalid coordinate encoding
181
-
- Either of points not in G1 (i.e. neither on a curve nor the infinity point)
182
-
- Input has invalid length
191
+
- An input is neither a point on the G2 elliptic curve nor the infinity point
192
+
- An input is on the G2 elliptic curve but not in the correct subgroup
193
+
- Input has invalid length
183
194
184
195
185
196
#### ABI for G2 MSM
@@ -189,8 +200,9 @@ G2 MSM call expects `288*k` (`k` being a **positive** integer) bytes as an input
189
200
Error cases:
190
201
191
202
- Invalid coordinate encoding
192
-
- Any point not in G2 (i.e. neither on a curve nor the infinity point)
193
-
- Input has invalid length
203
+
- An input is neither a point on the G2 elliptic curve nor the infinity point
204
+
- An input is on the G2 elliptic curve but not in the correct subgroup
205
+
- Input has invalid length
194
206
195
207
#### ABI for pairing
196
208
@@ -206,9 +218,13 @@ Output is a `32` bytes where first `31` bytes are equal to `0x00` and the last b
206
218
Error cases:
207
219
208
220
- Invalid coordinate encoding
209
-
- Any of points being not on the respective curve
210
-
- Any of points is not in the correct subgroup
211
-
- Input has invalid length
221
+
- An input is neither a point on its respective elliptic curve nor the infinity point
222
+
- An input is on its respective elliptic curve but not in the correct subgroup
223
+
- Input has invalid length
224
+
225
+
Note:
226
+
227
+
If any input is the infinity point, pairing result will be 1. Protocols may want to check and reject infinity points prior to calling the precompile.
212
228
213
229
#### ABI for mapping Fp element to G1 point
214
230
@@ -217,7 +233,7 @@ Field-to-curve call expects `64` bytes as an input that is interpreted as an ele
217
233
Error cases:
218
234
219
235
- Input has invalid length
220
-
- Input is not correctly encoded
236
+
- Input is not correctly encoded
221
237
222
238
#### ABI for mapping Fp2 element to G2 point
223
239
@@ -226,7 +242,7 @@ Field-to-curve call expects `128` bytes as an input that is interpreted as a an
226
242
Error cases:
227
243
228
244
- Input has invalid length
229
-
- Input is not correctly encoded
245
+
- Input is not correctly encoded
230
246
231
247
232
248
### Gas burning on error
@@ -338,9 +354,12 @@ There are no backward compatibility questions.
338
354
339
355
### Subgroup checks
340
356
341
-
A subgroup check **is mandatory** during the pairing call. Implementations *should* use fast subgroup checks: at the time of writing, multiplication gas cost is based on the `double-and-add` multiplication method that has a clear "worst case" (all bits are equal to one). For pairing operations, it is expected that implementations use faster subgroup checks, e.g. by using the wNAF multiplication method for elliptic curves that is ~ `40%` cheaper with windows size equal to 4. (Tested empirically. Savings are due to lower hamming weight of the group order and even lower hamming weight for wNAF. Concretely, subgroup check for both G1 and G2 points in a pair are around `35000` combined).
357
+
Scalar multiplications, MSMs and pairings MUST perform a subgroup check.
358
+
Implementations SHOULD use the optimized subgroup check method detailed in a dedicated [document](../assets/eip-2537/fast_subgroup_checks.md).
342
359
360
+
On any input that fail the subgroup check, the precompile MUST return an error.
343
361
362
+
As endomorphism acceleration requires input on the correct subgroup, implementers MAY use endomorphism acceleration.
Field Fp is defined as the finite field of size `p` with elements represented as integers between 0 and p-1 (both inclusive).
6
+
7
+
Field Fp2 is defined as `Fp[X]/(X^2-nr2)` with elements `el = c0 + c1 * v`, where `v` is the formal square root of `nr2` represented as integer pairs `(c0,c1)`.
8
+
9
+
Group G1 is defined as a set of Fp pairs (points) `(x,y)` such that either `(x,y)` is `(0,0)` or `x,y` satisfy the curve Fp equation.
10
+
11
+
Group G2 is defined as a set of Fp2 pairs (points) `(x',y')` such that either `(x,y)` is `(0,0)` or `(x',y')` satisfy the curve Fp2 equation.
12
+
13
+
## Curve parameters
14
+
15
+
The set of parameters used by fast subgroup checks:
16
+
17
+
```
18
+
|x| (seed) = 15132376222941642752
19
+
x is negative = true
20
+
Cube root of unity modulo p - Beta = 793479390729215512621379701633421447060886740281060493010456487427281649075476305620758731620350
21
+
r = 4002409555221667392624310435006688643935503118305586438271171395842971157480381377015405980053539358417135540939437 * v
22
+
s = 2973677408986561043442465346520108879172042883009249989176415018091420807192182638567116318576472649347015917690530 + 1028732146235106349975324479215795277384839936929757896155643118032610843298655225875571310552543014690878354869257 * v
23
+
```
24
+
25
+
## Helper function to compute the conjugate over Fp2 - `conjugate`
26
+
27
+
`conjugate(c0 + c1 * v) := c0 - c1 * v`
28
+
29
+
## G1 endomorphism - `phi`
30
+
31
+
The endomorphism `phi` transform the point from `(x,y)` to `(Beta*x,y)` where `Beta` is a precomputed cube root of unity modulo `p` given above in parameters sections:
32
+
33
+
`phi((x,y)) := (Beta*x,y)`
34
+
35
+
## G2 endomorphism - `psi`
36
+
37
+
`psi((x,y)) := (conjugate(x)*r,conjugate(y)*s)`
38
+
39
+
# The G1 case
40
+
41
+
Before accepting a point `P` as input that purports to be a member of G1 subject the input to the following endomorphism test: `phi(P) + x^2*P = 0`
42
+
43
+
44
+
# The G2 case
45
+
46
+
Before accepting a point `P` as input that purports to be a member of G2 subject the input to the following endomorphism test: `psi(P) + x*P = 0`
0 commit comments