Skip to content

Commit bfa6096

Browse files
committed
Update EIP-2537: Remove MUL precompiles
This removes `BLS12_G1MUL` and `BLS12_G2MUL` precompiles because they are trivially replaceable by corresponding MSM precompiles. This reduces the number of precompile's addresses defined in this EIP from 9 to 7. The addresses of remaining 7 precompiles are changed to be continues. The Rationale entry describes why this change make sense. Additionally, the cost of MSM for single input (`k==1`) has been corrected to match the original MUL cost. The specification now suggests how this case should be implemented. Morever, because of the ABI compatibility between MUL and MSM all existing tests for MULs can be easily converted to tests for MSMs. The PoC of MUL and MSM precompiles equivalence is provided in [evmone PR#1042](ipsilon/evmone#1042).
1 parent 9f3b9e9 commit bfa6096

1 file changed

Lines changed: 15 additions & 35 deletions

File tree

EIPS/eip-2537.md

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +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

4038
If `block.timestamp >= FORK_TIMESTAMP` we introduce *nine* 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
47-
- 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
4843
- 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
4944
- BLS12_MAP_FP_TO_G1 - maps base field element into the G1 point with a gas cost of `5500` gas
5045
- BLS12_MAP_FP2_TO_G2 - maps extension field element into the G2 point with a gas cost of `75000` gas
@@ -145,17 +140,6 @@ Note:
145140

146141
There is no subgroup check for the G1 addition precompile.
147142

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-
159143
#### ABI for G1 MSM
160144

161145
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 +165,6 @@ Note:
181165

182166
There is no subgroup check for the G2 addition precompile.
183167

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-
195168
#### ABI for G2 MSM
196169

197170
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).
@@ -277,10 +250,12 @@ MSMs are expected to be performed by Pippenger's algorithm (we can also say that
277250

278251
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.
279252

253+
For `k == 1` (single scalar + point) the cost is exactly `multiplication_cost`. In this case implementations **should** use basic point multiplication algorithm.
254+
280255
Discounts table as a vector of pairs `[k, discount]`:
281256

282257
```
283-
[[1, 1200], [2, 888], [3, 764], [4, 641], [5, 594], [6, 547], [7, 500], [8, 453], [9, 438], [10, 423], [11, 408], [12, 394], [13, 379], [14, 364], [15, 349], [16, 334], [17, 330], [18, 326], [19, 322], [20, 318], [21, 314], [22, 310], [23, 306], [24, 302], [25, 298], [26, 294], [27, 289], [28, 285], [29, 281], [30, 277], [31, 273], [32, 269], [33, 268], [34, 266], [35, 265], [36, 263], [37, 262], [38, 260], [39, 259], [40, 257], [41, 256], [42, 254], [43, 253], [44, 251], [45, 250], [46, 248], [47, 247], [48, 245], [49, 244], [50, 242], [51, 241], [52, 239], [53, 238], [54, 236], [55, 235], [56, 233], [57, 232], [58, 231], [59, 229], [60, 228], [61, 226], [62, 225], [63, 223], [64, 222], [65, 221], [66, 220], [67, 219], [68, 219], [69, 218], [70, 217], [71, 216], [72, 216], [73, 215], [74, 214], [75, 213], [76, 213], [77, 212], [78, 211], [79, 211], [80, 210], [81, 209], [82, 208], [83, 208], [84, 207], [85, 206], [86, 205], [87, 205], [88, 204], [89, 203], [90, 202], [91, 202], [92, 201], [93, 200], [94, 199], [95, 199], [96, 198], [97, 197], [98, 196], [99, 196], [100, 195], [101, 194], [102, 193], [103, 193], [104, 192], [105, 191], [106, 191], [107, 190], [108, 189], [109, 188], [110, 188], [111, 187], [112, 186], [113, 185], [114, 185], [115, 184], [116, 183], [117, 182], [118, 182], [119, 181], [120, 180], [121, 179], [122, 179], [123, 178], [124, 177], [125, 176], [126, 176], [127, 175], [128, 174]]
258+
[[1, 1000], [2, 888], [3, 764], [4, 641], [5, 594], [6, 547], [7, 500], [8, 453], [9, 438], [10, 423], [11, 408], [12, 394], [13, 379], [14, 364], [15, 349], [16, 334], [17, 330], [18, 326], [19, 322], [20, 318], [21, 314], [22, 310], [23, 306], [24, 302], [25, 298], [26, 294], [27, 289], [28, 285], [29, 281], [30, 277], [31, 273], [32, 269], [33, 268], [34, 266], [35, 265], [36, 263], [37, 262], [38, 260], [39, 259], [40, 257], [41, 256], [42, 254], [43, 253], [44, 251], [45, 250], [46, 248], [47, 247], [48, 245], [49, 244], [50, 242], [51, 241], [52, 239], [53, 238], [54, 236], [55, 235], [56, 233], [57, 232], [58, 231], [59, 229], [60, 228], [61, 226], [62, 225], [63, 223], [64, 222], [65, 221], [66, 220], [67, 219], [68, 219], [69, 218], [70, 217], [71, 216], [72, 216], [73, 215], [74, 214], [75, 213], [76, 213], [77, 212], [78, 211], [79, 211], [80, 210], [81, 209], [82, 208], [83, 208], [84, 207], [85, 206], [86, 205], [87, 205], [88, 204], [89, 203], [90, 202], [91, 202], [92, 201], [93, 200], [94, 199], [95, 199], [96, 198], [97, 197], [98, 196], [99, 196], [100, 195], [101, 194], [102, 193], [103, 193], [104, 192], [105, 191], [106, 191], [107, 190], [108, 189], [109, 188], [110, 188], [111, 187], [112, 186], [113, 185], [114, 185], [115, 184], [116, 183], [117, 182], [118, 182], [119, 181], [120, 180], [121, 179], [122, 179], [123, 178], [124, 177], [125, 176], [126, 176], [127, 175], [128, 174]]
284259
```
285260

286261
`max_discount = 174`
@@ -340,13 +315,18 @@ The motivation section covers a total motivation to have operations over the BLS
340315

341316
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).
342317

318+
### No dedicated MUL call
319+
320+
Dedicated MUL precompiles which perform single G1/G2 point by scalar multiplication have exactly the same ABI as MSM with `k == 1`.
321+
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.
322+
343323
## Backwards Compatibility
344324

345325
There are no backward compatibility questions.
346326

347327
### Subgroup checks
348328

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

0 commit comments

Comments
 (0)