Skip to content

Commit eb4715f

Browse files
authored
Update EIP-2537: Remove redundant MUL precompiles
Merged by EIP-Bot.
1 parent 316bfd2 commit eb4715f

File tree

1 file changed

+14
-35
lines changed

1 file changed

+14
-35
lines changed

EIPS/eip-2537.md

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,18 @@ The motivation of this precompile is to add a cryptographic primitive that allow
2828
|---------------------|-------|--------------------|
2929
| `FORK_TIMESTAMP` | *TBD* | Mainnet |
3030
| BLS12_G1ADD | 0x0b | precompile address |
31-
| BLS12_G1MUL | 0x0c | precompile address |
32-
| BLS12_G1MSM | 0x0d | precompile address |
33-
| BLS12_G2ADD | 0x0e | precompile address |
34-
| BLS12_G2MUL | 0x0f | precompile address |
35-
| BLS12_G2MSM | 0x10 | precompile address |
36-
| BLS12_PAIRING_CHECK | 0x11 | precompile address |
37-
| BLS12_MAP_FP_TO_G1 | 0x12 | precompile address |
38-
| BLS12_MAP_FP2_TO_G2 | 0x13 | precompile address |
31+
| BLS12_G1MSM | 0x0c | precompile address |
32+
| BLS12_G2ADD | 0x0d | precompile address |
33+
| BLS12_G2MSM | 0x0e | precompile address |
34+
| BLS12_PAIRING_CHECK | 0x0f | precompile address |
35+
| BLS12_MAP_FP_TO_G1 | 0x10 | precompile address |
36+
| BLS12_MAP_FP2_TO_G2 | 0x11 | precompile address |
3937

40-
If `block.timestamp >= FORK_TIMESTAMP` we introduce *nine* separate precompiles to perform the following operations:
38+
If `block.timestamp >= FORK_TIMESTAMP` we introduce *seven* separate precompiles to perform the following operations:
4139

4240
- BLS12_G1ADD - to perform point addition in G1 (curve over base prime field) with a gas cost of `500` gas
43-
- BLS12_G1MUL - to perform point multiplication in G1 (curve over base prime field) with a gas cost of `12000` gas
4441
- BLS12_G1MSM - to perform multi-scalar-multiplication (MSM) in G1 (curve over base prime field) with a gas cost formula defined in the corresponding section
4542
- BLS12_G2ADD - to perform point addition in G2 (curve over quadratic extension of the base prime field) with a gas cost of `800` gas
46-
- BLS12_G2MUL - to perform point multiplication in G2 (curve over quadratic extension of the base prime field) with a gas cost of `45000` gas
4743
- BLS12_G2MSM - to perform multi-scalar-multiplication (MSM) in G2 (curve over quadratic extension of the base prime field) with a gas cost formula defined in the corresponding section
4844
- BLS12_PAIRING_CHECK - to perform a pairing operations between a set of *pairs* of (G1, G2) points a gas cost formula defined in the corresponding section
4945
- BLS12_MAP_FP_TO_G1 - maps base field element into the G1 point with a gas cost of `5500` gas
@@ -145,17 +141,6 @@ Note:
145141

146142
There is no subgroup check for the G1 addition precompile.
147143

148-
#### ABI for G1 multiplication
149-
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).
151-
152-
Error cases:
153-
154-
- Invalid coordinate encoding
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
157-
- Input has invalid length
158-
159144
#### ABI for G1 MSM
160145

161146
G1 MSM call expects `160*k` (`k` being a **positive** integer) bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of a G1 point (`128` bytes) and encoding of a scalar value (`32` bytes). Output is an encoding of MSM operation result - a single G1 point (`128` bytes).
@@ -181,17 +166,6 @@ Note:
181166

182167
There is no subgroup check for the G2 addition precompile.
183168

184-
#### ABI for G2 multiplication
185-
186-
G2 multiplication call expects `288` bytes as an input that is interpreted as byte concatenation of encoding of G2 point (`256` bytes) and encoding of a scalar value (`32` bytes). Output is an encoding of multiplication operation result - single G2 point (`256` bytes).
187-
188-
Error cases:
189-
190-
- Invalid coordinate encoding
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
194-
195169
#### ABI for G2 MSM
196170

197171
G2 MSM call expects `288*k` (`k` being a **positive** integer) bytes as an input that is interpreted as byte concatenation of `k` slices each of them being a byte concatenation of encoding of G2 point (`256` bytes) and encoding of a scalar value (`32` bytes). Output is an encoding of MSM operation result - a single G2 point (`256` bytes).
@@ -275,7 +249,7 @@ Assuming `EcRecover` precompile as a baseline.
275249

276250
MSMs are expected to be performed by Pippenger's algorithm (we can also say that it **must** be performed by Pippenger's algorithm to have a speedup that results in a discount over naive implementation by multiplying each pair separately and adding the results). For this case there was a table prepared for discount in case of `k <= 128` points in the MSM with a discount cap `max_discount` for `k > 128`.
277251

278-
To avoid non-integer arithmetic, the call cost is calculated as `(k * multiplication_cost * discount) / multiplier` where `multiplier = 1000`, `k` is a number of (scalar, point) pairs for the call, `multiplication_cost` is a corresponding single multiplication call cost for G1/G2.
252+
To avoid non-integer arithmetic, the call cost is calculated as `(k * multiplication_cost * discount) / multiplier` where `multiplier = 1000`, `k` is a number of (scalar, point) pairs for the call, `multiplication_cost` is a corresponding G1/G2 multiplication cost presented above.
279253

280254
G1 and G2 are priced separately, each having their own discount table and `max_discount`.
281255

@@ -354,13 +328,18 @@ The motivation section covers a total motivation to have operations over the BLS
354328

355329
Explicit separate MSM operation that allows one to save execution time (so gas) by both the algorithm used (namely Pippenger's algorithm) and (usually forgotten) by the fact that `CALL` operation in Ethereum is expensive (at the time of writing), so one would have to pay non-negligible overhead if e.g. for MSM of `100` points would have to call the multiplication precompile `100` times and addition for `99` times (roughly `138600` would be saved).
356330

331+
### No dedicated MUL call
332+
333+
Dedicated MUL precompiles which perform single G1/G2 point by scalar multiplication have exactly the same ABI as MSM with `k == 1`.
334+
MSM has to inspect the input length to reject inputs of invalid lengths. Therefore, it should recognize the case of `k == 1` and invoke the underlying implementation of single point multiplication to avoid the overhead of more complex multi-scalar multiplication algorithm.
335+
357336
## Backwards Compatibility
358337

359338
There are no backward compatibility questions.
360339

361340
### Subgroup checks
362341

363-
Scalar multiplications, MSMs and pairings MUST perform a subgroup check.
342+
MSMs and pairings MUST perform a subgroup check.
364343
Implementations SHOULD use the optimized subgroup check method detailed in a dedicated [document](../assets/eip-2537/fast_subgroup_checks.md).
365344
On any input that fails the subgroup check, the precompile MUST return an error.
366345
As endomorphism acceleration requires input on the correct subgroup, implementers MAY use endomorphism acceleration.

0 commit comments

Comments
 (0)