crate-crypto / go-ipa

A Go implementation of cryptographic primitives for Verkle Trees
https://verkle.dev
Apache License 2.0
32 stars 14 forks source link

Use 16-bit window for five first group elements #37

Closed jsign closed 1 year ago

jsign commented 1 year ago

This PR generates a separate precomputed table for the first five elements of the vector to optimize the MSM.

The motivation is optimizing go-ethereum use in Verkle Tries. In this case, we have a reasonable amount of commitment calculations that only have non-zero values for the first five elements. This happens because every trie key calculation falls in this case. Saying it differently, we need to do the MSM only for the first five elements of the vector on every trie access.

A wider table focused on these five elements provides a good tradeoff between extra memory (i.e: making this for the 256 elements would be too costly), and CPU speedup since we avoid half-field multiplications.

This has shown a 1.30x speedup in our go-ethereum Verkle Trie benchmark regarding CommitToPoly(...) CPU usage.


Now we generate two tables:

The serialization and deserialization of the tables were also changed since now we can't make some assumptions about how many points are per table or window size.

I've also improved on some other fronts while being here: