Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Booth encoding #106

Merged
merged 4 commits into from
Nov 29, 2023
Merged

Conversation

kilic
Copy link
Collaborator

@kilic kilic commented Nov 28, 2023

Booth encoding is implemented in line with incremental suggetions of halo2/#187. This is basically signed digit encoding but without preprocessing and extra memory requirements. And signed digit encoding helps us to reduce number of buckets to nearly half. Below there are benchmark results whihc are run on M1 machine. This PR also moves original msm implementation under mod test to keep it as baseline implementation for benchmarking and testing purposes.

w/  booth k=14 ............................................................29.588ms
w/o booth k=14 ............................................................41.151ms

w/  booth k=15 ............................................................47.325ms
w/o booth k=15 ............................................................56.038ms

w/  booth k=16 ............................................................97.727ms
w/o booth k=16 ............................................................104.224ms

w/  booth k=17 ............................................................153.295ms
w/o booth k=17 ............................................................185.561ms

w/  booth k=18 ............................................................297.498ms
w/o booth k=18 ............................................................317.606ms

w/  booth k=19 ............................................................525.640ms
w/o booth k=19 ............................................................561.605ms

w/  booth k=20 ............................................................977.872ms
w/o booth k=20 ............................................................1.037s

w/  booth k=21 ............................................................1.767s
w/o booth k=21 ............................................................2.001s

w/  booth k=22 ............................................................3.458s
w/o booth k=22 ............................................................3.622s```

@han0110 han0110 self-requested a review November 29, 2023 00:30
Copy link
Contributor

@han0110 han0110 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

src/ff_ext/mod.rs Outdated Show resolved Hide resolved
src/msm.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@mratsim mratsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

To give more context:

NAF (what most pippenger/bucket implementation use) provides 2 things:

  • signed digit recoding so the number of buckets (and memory consumption) is reduced by half
  • minimizing the number of additions in the double-and-add algorithm.

But with MSM, for large windows for example 16, the chances of having no addition when input is random is extremely low, unless we have special cases like privacy-scaling-explorations/halo2#202 where all bits are zero.

Now the main issue is that for this benefit, NAF requires preprocessing, which requires extra storage and is also less friendly to GPUs. Booth encoding only provides the first part and can be computed on-the-fly.

Implementation

In Constantine:

In BLST:

Litterature
Booth and bit pair encoding.pdf
Booth encoding.pdf

@kilic kilic added this pull request to the merge queue Nov 29, 2023
Merged via the queue into privacy-scaling-explorations:main with commit a3f15e4 Nov 29, 2023
7 checks passed
jonathanpwang pushed a commit to axiom-crypto/halo2curves that referenced this pull request Nov 29, 2023
* booth encoding baseline

* working msm with booth encoding

* tidy

* apply suggestions & remove leftovers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants