From a9b6f675925d27da07bbd774b452044b74224468 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 21:40:26 -0400 Subject: [PATCH 01/19] refactor --- docs/icicle/primitives/msm.md | 113 +++++++++++++++++++++++------ docs/icicle/primitives/overview.md | 8 -- 2 files changed, 91 insertions(+), 30 deletions(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 534bfdd..d089ee6 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -1,19 +1,87 @@ -# MSM +# MSM - Multi scalar multiplication -MSM (Multi scalar multiplication) is an important primitive in ZK protocols. +MSM stands for Multi scalar multiplication, its defined as: -### Using MSM + + M + S + M + ( + a + , + G + ) + = + + + + j + = + 0 + + + n + + 1 + + + + a + j + + + G + j + + -#### Supported algorithms -Our MSM implementation supports two algorithms. +Where -- Bucket accumulation -- Large triangle accumulation +$G_j \in G$ - points from an Elliptic Curve group. -In most scenarios you should be using Bucket accumulation as its a more parallel friendly algorithm and will yield better performance on larger MSMs. +$a_0, \ldots, a_n$ - Scalars -The exception being a large batch of smaller MSMs. +$MSM(a, G) \in G$ - a single EC (elliptic curve point) point + +Accelerating MSM is crucial to ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. + +You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from this resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). + +# Using MSM + +## Supported curves + +MSM supports all curves; + +`bls12-377`, `bls12-381`, `bn-254`, `bw6-761` + +## Supported algorithms + +Our MSM implementation supports two algorithms `Bucket accumulation` and `Large triangle accumulation`. + +### Bucket accumulation + +The Bucket Accumulation algorithm is a method of dividing the overall MSM task into smaller, more manageable sub-tasks. It involves partitioning scalars and their corresponding points into different "buckets" based on the scalar values. + +Bucket Accumulation can be more parallel-friendly because it involves dividing the computation into smaller, independent tasks, distributing scalar-point pairs into buckets and summing points within each bucket. This division makes it well-suited for parallel processing on GPUs. + +#### When should I use Bucket accumulation? + +In scenarios involving large MSM computations with many scalar-point pairs, the ability to parallelize operations makes Bucket Accumulation more efficient. The larger the MSM task, the more significant the potential gains from parallelization. + +### Large triangle accumulation + +Large Triangle Accumulation is a method for optimizing MSM which focuses on reducing the number of point doublings in the computation. This algorithm is based on the observation that the number of point doublings can be minimized by structuring the computation in a specific manner. + +#### When should I use Large triangle accumulation? + +The Large Triangle Accumulation algorithm is more sequential in nature, as it builds upon each step sequentially (accumulating sums and then performing doubling). This structure can make it less suitable for parallelization but potentially more efficient for a large batch of smaller MSM computations. + + +### How do I toggle between the supported algorithms ? + +When creating your MSM Config you may state which algorithm you wish to use. `is_big_triangle=true` will activate Large triangle accumulation and `is_big_triangle=false` will activate Bucket accumulation. ```rust ... @@ -27,17 +95,22 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ... ``` -`is_big_triangle=true` will activate Large triangle accumulation and `is_big_triangle=false` will activate Bucket accumulation. - -#### MSM Modes +You may reference the rust code [here](https://github.com/ingonyama-zk/icicle/blob/77a7613aa21961030e4e12bf1c9a78a2dadb2518/wrappers/rust/icicle-core/src/msm/mod.rs#L54). -ICICLE MSM also supports two different modes +## MSM Modes -- Batch MSM -- Single MSM +ICICLE MSM also supports two different modes `Batch MSM` and `Single MSM` Batch MSM allows you to run many MSMs with a single API call, Single MSM will launch a single MSM computation. +### Which mode should I use ? + +This decision is highly dependent on your use case and design. However if your design allows for it using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple operations concurrently, leveraging parallel processing capabilities of the GPU. + +Single MSM mode should be used when batching isnt possible or when you have to run a single MSM. + +### How do I toggle between MSM modes? + You don't need to do anything special to toggle between batch or single MSM. ```rust @@ -48,12 +121,12 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ... ``` -You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode. +You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results as the `batch_size`. -#### Extension fields +#### support for G2 group -MSM also supports extension fields (G2). +MSM also supports G2 group. Using MSM in G2 requires a G2 config, and of course your Points should also be G2 Points. @@ -69,7 +142,3 @@ msm::msm(&scalars, &g2_points, &g2_cfg, &mut g2_msm_results).unwrap(); ``` Here you can [find an example](https://github.com/ingonyama-zk/icicle/blob/5a96f9937d0a7176d88c766bd3ef2062b0c26c37/examples/rust/msm/src/main.rs#L114) of MSM on G2 Points. - -### Benchmarks - -TODO \ No newline at end of file diff --git a/docs/icicle/primitives/overview.md b/docs/icicle/primitives/overview.md index 5fbace1..f6a8ef0 100644 --- a/docs/icicle/primitives/overview.md +++ b/docs/icicle/primitives/overview.md @@ -7,11 +7,3 @@ This section of the documentation is dedicated to the ICICLE primitives, we will - [MSM](./msm) -- NTT - - Forward NTT - - Inverse NTT -- ECNTT - - Forward ECNTT - - Inverse NTT -- Scalar Vector Addition/Subtraction/Multiplication -- Point Vector Addition/Subtraction/Multiplication \ No newline at end of file From 00425fc4d0369fc8a50c66439da3125bb8f2c8a0 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 21:47:12 -0400 Subject: [PATCH 02/19] refactor --- docs/icicle/primitives/msm.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index d089ee6..dfca082 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -44,7 +44,7 @@ $a_0, \ldots, a_n$ - Scalars $MSM(a, G) \in G$ - a single EC (elliptic curve point) point -Accelerating MSM is crucial to ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. +Accelerating MSM is crucial to a ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from this resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). @@ -121,7 +121,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ... ``` -You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results as the `batch_size`. +You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results as the `batch_size`, the scalar and points will be split into groups based on `batch_size` and processed in parallel. #### support for G2 group From fd2c1e5e047f4183684973f7fdee9048e60d3fae Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 23:04:53 -0400 Subject: [PATCH 03/19] refactor --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index dfca082..6c075ac 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -105,7 +105,7 @@ Batch MSM allows you to run many MSMs with a single API call, Single MSM will la ### Which mode should I use ? -This decision is highly dependent on your use case and design. However if your design allows for it using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple operations concurrently, leveraging parallel processing capabilities of the GPU. +This decision is highly dependent on your use case and design. However if your design allows for it using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple MSM leveraging parallel processing capabilities of the GPU. Single MSM mode should be used when batching isnt possible or when you have to run a single MSM. From b0bc8ea765d48d06d0222a3785fc6a1322a0b8ad Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 23:06:17 -0400 Subject: [PATCH 04/19] refactor --- docs/icicle/primitives/msm.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 6c075ac..d118dd3 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -107,11 +107,11 @@ Batch MSM allows you to run many MSMs with a single API call, Single MSM will la This decision is highly dependent on your use case and design. However if your design allows for it using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple MSM leveraging parallel processing capabilities of the GPU. -Single MSM mode should be used when batching isnt possible or when you have to run a single MSM. +Single MSM mode should be used when batching isn't possible or when you have to run a single MSM. ### How do I toggle between MSM modes? -You don't need to do anything special to toggle between batch or single MSM. +You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results in `msm_results` as the `batch_size`, the scalars and points will be split into groups based on `batch_size` and processed in parallel. ```rust ... @@ -121,7 +121,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ... ``` -You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results as the `batch_size`, the scalar and points will be split into groups based on `batch_size` and processed in parallel. + #### support for G2 group From ce85dc5b0e9c70e1d28f22642066ffccab6e4352 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 23:07:45 -0400 Subject: [PATCH 05/19] refactor --- docs/icicle/primitives/msm.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index d118dd3..d6bc38b 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -122,9 +122,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ``` - - -#### support for G2 group +## support for G2 group MSM also supports G2 group. @@ -139,6 +137,8 @@ let mut g2_msm_results: HostOrDeviceSlice<'_, G2Projective> = HostOrDeviceSlice: let mut g2_cfg = msm::get_default_msm_config::(); msm::msm(&scalars, &g2_points, &g2_cfg, &mut g2_msm_results).unwrap(); + +... ``` Here you can [find an example](https://github.com/ingonyama-zk/icicle/blob/5a96f9937d0a7176d88c766bd3ef2062b0c26c37/examples/rust/msm/src/main.rs#L114) of MSM on G2 Points. From 904b117495ca992433ac9e714cc9ba1bd5292748 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 23:08:20 -0400 Subject: [PATCH 06/19] refactor --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index d6bc38b..6e0d4d6 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -122,7 +122,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ``` -## support for G2 group +## Support for G2 group MSM also supports G2 group. From c889458b48717e48e8c2360a9e7db405ebd632b9 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Wed, 31 Jan 2024 23:19:31 -0400 Subject: [PATCH 07/19] refactor --- docs/icicle/primitives/msm.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 6e0d4d6..390ad1e 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -35,7 +35,6 @@ MSM stands for Multi scalar multiplication, its defined as: - Where $G_j \in G$ - points from an Elliptic Curve group. @@ -44,6 +43,8 @@ $a_0, \ldots, a_n$ - Scalars $MSM(a, G) \in G$ - a single EC (elliptic curve point) point +Or in more simple terms MSM is the sum of scalar and EC point multiplications, we can learn from this definition as well that the core operations occurring are Modular Multiplication and Elliptic curve point addition. Since each multiplication can be computed independently and then the products need to be summed, this makes MSM inherently extremely parallelizable. + Accelerating MSM is crucial to a ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from this resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). From ef3c45f463c5f66a414694e498cf7d84cb41b706 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:38:51 -0500 Subject: [PATCH 08/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 390ad1e..4227d01 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -47,7 +47,7 @@ Or in more simple terms MSM is the sum of scalar and EC point multiplications, w Accelerating MSM is crucial to a ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. -You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from this resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). +You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from our resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). # Using MSM From d9ec06bf6acf21d9168db3b0430811e06efe9f0c Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:38:57 -0500 Subject: [PATCH 09/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 4227d01..c4697f5 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -65,7 +65,7 @@ Our MSM implementation supports two algorithms `Bucket accumulation` and `Large The Bucket Accumulation algorithm is a method of dividing the overall MSM task into smaller, more manageable sub-tasks. It involves partitioning scalars and their corresponding points into different "buckets" based on the scalar values. -Bucket Accumulation can be more parallel-friendly because it involves dividing the computation into smaller, independent tasks, distributing scalar-point pairs into buckets and summing points within each bucket. This division makes it well-suited for parallel processing on GPUs. +Bucket Accumulation can be more parallel-friendly because it involves dividing the computation into smaller, independent tasks, distributing scalar-point pairs into buckets and summing points within each bucket. This division makes it well suited for parallel processing on GPUs. #### When should I use Bucket accumulation? From d7677a934cb5f592e4da897ecacb5bf1f41b4253 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:02 -0500 Subject: [PATCH 10/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index c4697f5..f40e071 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -106,7 +106,7 @@ Batch MSM allows you to run many MSMs with a single API call, Single MSM will la ### Which mode should I use ? -This decision is highly dependent on your use case and design. However if your design allows for it using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple MSM leveraging parallel processing capabilities of the GPU. +This decision is highly dependent on your use case and design. However, if your design allows for it, using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple MSMs leveraging the parallel processing capabilities of GPUs. Single MSM mode should be used when batching isn't possible or when you have to run a single MSM. From 0b5eb62b47c20a52483207e5e2c3a5b023b451a9 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:29 -0500 Subject: [PATCH 11/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index f40e071..878f8b2 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -104,7 +104,7 @@ ICICLE MSM also supports two different modes `Batch MSM` and `Single MSM` Batch MSM allows you to run many MSMs with a single API call, Single MSM will launch a single MSM computation. -### Which mode should I use ? +### Which mode should I use? This decision is highly dependent on your use case and design. However, if your design allows for it, using batch mode can significantly improve efficiency. Batch processing allows you to perform multiple MSMs leveraging the parallel processing capabilities of GPUs. From 527e50ba6883da83e28d986dccd950051881e6aa Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:34 -0500 Subject: [PATCH 12/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 878f8b2..50bb9f0 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -80,7 +80,7 @@ Large Triangle Accumulation is a method for optimizing MSM which focuses on redu The Large Triangle Accumulation algorithm is more sequential in nature, as it builds upon each step sequentially (accumulating sums and then performing doubling). This structure can make it less suitable for parallelization but potentially more efficient for a large batch of smaller MSM computations. -### How do I toggle between the supported algorithms ? +### How do I toggle between the supported algorithms? When creating your MSM Config you may state which algorithm you wish to use. `is_big_triangle=true` will activate Large triangle accumulation and `is_big_triangle=false` will activate Bucket accumulation. From 83c800547f7462763f1f7dd2b13195c500aa188c Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:39 -0500 Subject: [PATCH 13/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 50bb9f0..f168b92 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -53,7 +53,7 @@ You can learn more about how MSMs work from this [video](https://www.youtube.com ## Supported curves -MSM supports all curves; +MSM supports the following curves: `bls12-377`, `bls12-381`, `bn-254`, `bw6-761` From e0f601778ce2976cc6dd03229b726fa3e7c66b53 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:44 -0500 Subject: [PATCH 14/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index f168b92..9d4fb1a 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -45,7 +45,7 @@ $MSM(a, G) \in G$ - a single EC (elliptic curve point) point Or in more simple terms MSM is the sum of scalar and EC point multiplications, we can learn from this definition as well that the core operations occurring are Modular Multiplication and Elliptic curve point addition. Since each multiplication can be computed independently and then the products need to be summed, this makes MSM inherently extremely parallelizable. -Accelerating MSM is crucial to a ZK protocol performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take up when generating proofs. +Accelerating MSM is crucial to a ZK protocol's performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take when generating proofs. You can learn more about how MSMs work from this [video](https://www.youtube.com/watch?v=Bl5mQA7UL2I) and from our resource list on [Ingopedia](https://www.ingonyama.com/ingopedia/msm). From 280a06812a1c66a0616fd3fd88faf6d086af2e73 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 05:39:50 -0500 Subject: [PATCH 15/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 9d4fb1a..9ad0cf0 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -43,7 +43,7 @@ $a_0, \ldots, a_n$ - Scalars $MSM(a, G) \in G$ - a single EC (elliptic curve point) point -Or in more simple terms MSM is the sum of scalar and EC point multiplications, we can learn from this definition as well that the core operations occurring are Modular Multiplication and Elliptic curve point addition. Since each multiplication can be computed independently and then the products need to be summed, this makes MSM inherently extremely parallelizable. +In words, MSM is the sum of scalar and EC point multiplications. We can see from this definition that the core operations occurring are Modular Multiplication and Elliptic curve point addition. Each multiplication can be computed independently and then the products are summed, making MSM inherently parallelizable. Accelerating MSM is crucial to a ZK protocol's performance due to the [large percent of run time](https://hackmd.io/@0xMonia/SkQ6-oRz3#Hardware-acceleration-in-action) they take when generating proofs. From e05c14eaea7ab4b8e06f9e27a903835eeb49836e Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 07:57:16 -0400 Subject: [PATCH 16/19] refactor --- docs/icicle/primitives/msm.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 390ad1e..bc5edc5 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -112,16 +112,33 @@ Single MSM mode should be used when batching isn't possible or when you have to ### How do I toggle between MSM modes? -You simply call `msm::msm`, if `msm_results` is a single result it will run in single MSM mode, if you are expecting many results MSM will run in batch mode, using the number of expected results in `msm_results` as the `batch_size`, the scalars and points will be split into groups based on `batch_size` and processed in parallel. +Toggling between MSM modes occurrences automatically, based on the number of results you are expecting from the `msm::msm` function. If you are expecting an array of `msm_results` ICICLE will automatically split `scalars` and `points` into equal parts and run them as multiple MSMs in parallel. ```rust ... +let mut msm_result: HostOrDeviceSlice<'_, G1Projective> = HostOrDeviceSlice::cuda_malloc(1).unwrap(); +msm::msm(&scalars, &points, &cfg, &mut msm_result).unwrap(); + +... +``` + +In the example above we allocate a single expected result, the MSM method will interpret this as `batch_size=1` and run it as a single MSM. + + +In the next example we see that we are expecting 10 results, this would set `batch_size=10` and run 10 MSMs in batch. + +```rust +... + +let mut msm_results: HostOrDeviceSlice<'_, G1Projective> = HostOrDeviceSlice::cuda_malloc(10).unwrap(); msm::msm(&scalars, &points, &cfg, &mut msm_results).unwrap(); ... ``` +Here is a [reference](https://github.com/ingonyama-zk/icicle/blob/77a7613aa21961030e4e12bf1c9a78a2dadb2518/wrappers/rust/icicle-core/src/msm/mod.rs#L108) to the code which automatically sets the batch size. For more MSM examples have a look [here](https://github.com/ingonyama-zk/icicle/blob/77a7613aa21961030e4e12bf1c9a78a2dadb2518/examples/rust/msm/src/main.rs#L1). + ## Support for G2 group From c8b812fe5834cd76962662fe852dad007cda317f Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 14:24:20 +0200 Subject: [PATCH 17/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 777c9cf..5010a57 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -123,7 +123,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_result).unwrap(); ... ``` -In the example above we allocate a single expected result, the MSM method will interpret this as `batch_size=1` and run it as a single MSM. +In the example above we allocate a single expected result which the MSM method will interpret as `batch_size=1` and run a single MSM. In the next example we see that we are expecting 10 results, this would set `batch_size=10` and run 10 MSMs in batch. From 0a520e0136a4785d3f65f384cd53948bb017e7c5 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 14:24:27 +0200 Subject: [PATCH 18/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 5010a57..82d6d69 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -112,7 +112,7 @@ Single MSM mode should be used when batching isn't possible or when you have to ### How do I toggle between MSM modes? -Toggling between MSM modes occurrences automatically, based on the number of results you are expecting from the `msm::msm` function. If you are expecting an array of `msm_results` ICICLE will automatically split `scalars` and `points` into equal parts and run them as multiple MSMs in parallel. +Toggling between MSM modes occurs automatically based on the number of results you are expecting from the `msm::msm` function. If you are expecting an array of `msm_results`, ICICLE will automatically split `scalars` and `points` into equal parts and run them as multiple MSMs in parallel. ```rust ... From 78db23d9d0f8d91caff2c4de5ca304a58fdfc438 Mon Sep 17 00:00:00 2001 From: ImmanuelSegol <3ditds@gmail.com> Date: Thu, 1 Feb 2024 14:24:33 +0200 Subject: [PATCH 19/19] Update docs/icicle/primitives/msm.md Co-authored-by: Jeremy Felder --- docs/icicle/primitives/msm.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/icicle/primitives/msm.md b/docs/icicle/primitives/msm.md index 82d6d69..618dbb2 100644 --- a/docs/icicle/primitives/msm.md +++ b/docs/icicle/primitives/msm.md @@ -126,7 +126,7 @@ msm::msm(&scalars, &points, &cfg, &mut msm_result).unwrap(); In the example above we allocate a single expected result which the MSM method will interpret as `batch_size=1` and run a single MSM. -In the next example we see that we are expecting 10 results, this would set `batch_size=10` and run 10 MSMs in batch. +In the next example, we are expecting 10 results which sets `batch_size=10` and runs 10 MSMs in batch mode. ```rust ...