MSM - Multi Scalar Multiplication
Overview
Multi-Scalar Multiplication (MSM) is a fundamental operation in elliptic curve cryptography and zero-knowledge proofs. It is defined as:
Where:
- are points from an elliptic curve group.
- are scalars.
- is the result, a single elliptic curve point.
MSM is inherently parallelizable, making it a critical operation for optimizing performance in cryptographic protocols like zk-SNARKs. Accelerating MSM can significantly reduce the time required for proof generation.
Accelerating MSM is crucial to a ZK protocol's performance due to the large percent of run time they take when generating proofs. You can learn more about how MSMs work from this video and from our resource list on Ingopedia.
C++ API
MSMConfig
Struct
The MSMConfig
struct configures the MSM operation. It allows customization of parameters like the number of precomputed points, the window bitsize (c
), and memory management. Here's the configuration structure:
struct MSMConfig {
icicleStreamHandle stream;
int precompute_factor;
int c;
int bitsize;
int batch_size;
bool are_points_shared_in_batch;
bool are_scalars_on_device;
bool are_scalars_montgomery_form;
bool are_points_on_device;
bool are_points_montgomery_form;
bool are_results_on_device;
bool is_async;
ConfigExtension* ext;
};
Default Configuration
You can obtain a default MSMConfig
using:
static MSMConfig default_msm_config()
{
MSMConfig config = {
nullptr, // stream
1, // precompute_factor
0, // c
0, // bitsize
1, // batch_size
true, // are_points_shared_in_batch
false, // are_scalars_on_device
false, // are_scalars_montgomery_form
false, // are_points_on_device
false, // are_points_montgomery_form
false, // are_results_on_device
false, // is_async
nullptr, // ext
};
return config;
}
msm
Function
The msm
function computes the MSM operation:
template <typename S, typename A, typename P>
eIcicleError msm(const S* scalars, const A* bases, int msm_size, const MSMConfig& config, P* results);
The API is template and can work with all ICICLE curves (if corresponding lib is linked), including G2 groups.
Batched MSM
The MSM supports batch mode - running multiple MSMs in parallel. It's always better to use the batch mode instead of running single msms in serial as long as there is enough memory available. We support running a batch of MSMs that share the same points as well as a batch of MSMs that use different points.
Config fields are_points_shared_in_batch
and batch_size
are used to configure msm for batch mode.
G2 MSM
for G2 MSM, use the same msm api with the G2 types.
Supported curves have types for both G1 and G2.