|
1 |
| -// Constants related to the bls12-381 gas schedule and precompile address |
| 1 | +// Constants specifying the precompile addresses for each precompile |
| 2 | +// in EIP-2537 |
2 | 3 | pub const G1_ADD_ADDRESS: u64 = 0x0b;
|
3 |
| -pub const G1_ADD_BASE_GAS_FEE: u64 = 375; |
4 | 4 | pub const G1_MSM_ADDRESS: u64 = 0x0c;
|
5 |
| -pub const G1_MSM_BASE_GAS_FEE: u64 = 12000; |
| 5 | +pub const G2_ADD_ADDRESS: u64 = 0x0d; |
| 6 | +pub const G2_MSM_ADDRESS: u64 = 0x0e; |
| 7 | +pub const PAIRING_ADDRESS: u64 = 0x0f; |
6 | 8 | pub const MAP_FP_TO_G1_ADDRESS: u64 = 0x10;
|
7 |
| -pub const MAP_FP_TO_G1_BASE_GAS_FEE: u64 = 5500; |
8 | 9 | pub const MAP_FP2_TO_G2_ADDRESS: u64 = 0x11;
|
| 10 | + |
| 11 | +/// G1_ADD_BASE_GAS_FEE specifies the amount of gas needed |
| 12 | +/// to perform the G1_ADD precompile. |
| 13 | +pub const G1_ADD_BASE_GAS_FEE: u64 = 375; |
| 14 | +/// G1_MSM_BASE_GAS_FEE specifies the base amount of gas needed to |
| 15 | +/// perform the G1_MSM precompile. |
| 16 | +/// |
| 17 | +/// The cost to do an MSM is determined by the formula: |
| 18 | +/// (k * G1_MSM_BASE_GAS_FEE * DISCOUNT\[k\]) // MSM_MULTIPLIER |
| 19 | +/// where k is the number of point-scalar pairs. |
| 20 | +/// |
| 21 | +/// Note: If one wants to do a G1 scalar multiplication, they would call |
| 22 | +/// this precompile with a single point and a scalar. |
| 23 | +pub const G1_MSM_BASE_GAS_FEE: u64 = 12000; |
| 24 | +/// MSM_MULTIPLIER specifies the division constant that is used to determine the |
| 25 | +/// gas needed to compute an MSM. |
| 26 | +/// |
| 27 | +/// The cost to do an MSM is determined by the formula: |
| 28 | +/// (k * MSM_BASE_GAS_FEE * DISCOUNT\[k\]) // MSM_MULTIPLIER |
| 29 | +/// where k is the number of point-scalar pairs. |
| 30 | +/// |
| 31 | +/// Note: If `k` is more than the size of the discount table, then |
| 32 | +/// the last value in the discount table is chosen. |
| 33 | +pub const MSM_MULTIPLIER: u64 = 1000; |
| 34 | +/// MAP_FP_TO_G1_BASE_GAS_FEE specifies the amount of gas needed |
| 35 | +/// to perform the MAP_FP_TO_G1 precompile. |
| 36 | +pub const MAP_FP_TO_G1_BASE_GAS_FEE: u64 = 5500; |
| 37 | +/// MAP_FP2_TO_G2_BASE_GAS_FEE specifies the amount of gas needed |
| 38 | +/// to perform the MAP_FP2_TO_G2 precompile. |
9 | 39 | pub const MAP_FP2_TO_G2_BASE_GAS_FEE: u64 = 23800;
|
10 |
| -pub const G2_ADD_ADDRESS: u64 = 0x0d; |
| 40 | +/// G2_ADD_BASE_GAS_FEE specifies the amount of gas needed |
| 41 | +/// to perform the G2_ADD precompile. |
11 | 42 | pub const G2_ADD_BASE_GAS_FEE: u64 = 600;
|
12 |
| -pub const G2_MSM_ADDRESS: u64 = 0x0e; |
| 43 | +/// G2_MSM_BASE_GAS_FEE specifies the base amount of gas needed to |
| 44 | +/// perform the G2_MSM precompile. |
| 45 | +/// |
| 46 | +/// The cost to do an MSM is determined by the formula: |
| 47 | +/// (k * G2_MSM_BASE_GAS_FEE * DISCOUNT\[k\]) // MSM_MULTIPLIER |
| 48 | +/// where k is the number of point-scalar pairs. |
| 49 | +/// |
| 50 | +/// Note: If one wants to do a G2 scalar multiplication, they would call |
| 51 | +/// this precompile with a single point and a scalar. |
13 | 52 | pub const G2_MSM_BASE_GAS_FEE: u64 = 22500;
|
14 |
| -pub const PAIRING_ADDRESS: u64 = 0x0f; |
| 53 | +/// PAIRING_OFFSET_BASE specifies the y-intercept for the linear expression to determine |
| 54 | +/// the amount of gas needed to perform a pairing. |
| 55 | +/// |
| 56 | +/// The cost to do a pairing is determined by the formula: |
| 57 | +/// cost = PAIRING_MULTIPLIER_BASE * number_of_pairs + PAIRING_OFFSET_BASE |
15 | 58 | pub const PAIRING_OFFSET_BASE: u64 = 37700;
|
16 |
| -pub const MSM_MULTIPLIER: u64 = 1000; |
| 59 | +/// PAIRING_MULTIPLIER_BASE specifies the slope/gradient for the linear expression to determine |
| 60 | +/// the amount of gas needed to perform a pairing. |
| 61 | +/// |
| 62 | +/// The cost to do a pairing is determined by the formula: |
| 63 | +/// PAIRING_MULTIPLIER_BASE * number_of_pairs + PAIRING_OFFSET_BASE |
17 | 64 | pub const PAIRING_MULTIPLIER_BASE: u64 = 32600;
|
18 | 65 |
|
19 | 66 | /// Discounts table for G1 MSM as a vector of pairs `[k, discount]`.
|
|
0 commit comments