Skip to content

Commit d8f70e7

Browse files
authored
Update EIP-2537: Rephrased subgroup check part
Merged by EIP-Bot.
1 parent 72523ee commit d8f70e7

File tree

2 files changed

+88
-18
lines changed

2 files changed

+88
-18
lines changed

EIPS/eip-2537.md

Lines changed: 37 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ One should note that base field modulus `p` is equal to `3 mod 4` that allows an
9191

9292
### Fields and Groups
9393

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).
9595

9696
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+
9898
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.
9999

100100
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
138138
Error cases:
139139

140140
- 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
142142
- Input has invalid length
143143

144+
Note:
145+
146+
There is no subgroup check for the G1 addition precompile.
147+
144148
#### ABI for G1 multiplication
145149

146150
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).
147151

148152
Error cases:
149153

150154
- 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
152157
- Input has invalid length
153158

154159
#### ABI for G1 MSM
@@ -158,8 +163,9 @@ G1 MSM call expects `160*k` (`k` being a **positive** integer) bytes as an input
158163
Error cases:
159164

160165
- 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
163169

164170
#### ABI for G2 addition
165171

@@ -168,8 +174,12 @@ G2 addition call expects `512` bytes as an input that is interpreted as byte con
168174
Error cases:
169175

170176
- 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.
173183

174184
#### ABI for G2 multiplication
175185

@@ -178,8 +188,9 @@ G2 multiplication call expects `288` bytes as an input that is interpreted as by
178188
Error cases:
179189

180190
- 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
183194

184195

185196
#### ABI for G2 MSM
@@ -189,8 +200,9 @@ G2 MSM call expects `288*k` (`k` being a **positive** integer) bytes as an input
189200
Error cases:
190201

191202
- 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
194206

195207
#### ABI for pairing
196208

@@ -206,9 +218,13 @@ Output is a `32` bytes where first `31` bytes are equal to `0x00` and the last b
206218
Error cases:
207219

208220
- 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.
212228

213229
#### ABI for mapping Fp element to G1 point
214230

@@ -217,7 +233,7 @@ Field-to-curve call expects `64` bytes as an input that is interpreted as an ele
217233
Error cases:
218234

219235
- Input has invalid length
220-
- Input is not correctly encoded
236+
- Input is not correctly encoded
221237

222238
#### ABI for mapping Fp2 element to G2 point
223239

@@ -226,7 +242,7 @@ Field-to-curve call expects `128` bytes as an input that is interpreted as a an
226242
Error cases:
227243

228244
- Input has invalid length
229-
- Input is not correctly encoded
245+
- Input is not correctly encoded
230246

231247

232248
### Gas burning on error
@@ -338,9 +354,12 @@ There are no backward compatibility questions.
338354

339355
### Subgroup checks
340356

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).
342359

360+
On any input that fail the subgroup check, the precompile MUST return an error.
343361

362+
As endomorphism acceleration requires input on the correct subgroup, implementers MAY use endomorphism acceleration.
344363

345364
### Field to curve mapping
346365

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Fast subgroup checks used by EIP-2537
2+
3+
### Fields and Groups
4+
5+
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`
47+
48+
# Resources
49+
50+
* https://eprint.iacr.org/2021/1130.pdf, sec.4
51+
* https://eprint.iacr.org/2022/352.pdf, sec. 4.2

0 commit comments

Comments
 (0)