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

Faster TS field inverse #1373

Merged
merged 10 commits into from
Jan 26, 2024
Merged

Faster TS field inverse #1373

merged 10 commits into from
Jan 26, 2024

Conversation

mitschabaude
Copy link
Collaborator

@mitschabaude mitschabaude commented Jan 16, 2024

Closes #1213
bindings: o1-labs/o1js-bindings#235

This adds a faster TS implementation of the field inverse algorithm.

Instead of the classical Extended Euclidian Algorithm, we use the state-of-the-art algorithm from https://eprint.iacr.org/2020/972.pdf. It benefits from doing most of the work in a tight loop which only operates on a few JS numbers with bit shifts and similar small operations, instead of doing lots of costly bigint modulos.

Note: Code changes mostly in the bindings PR

Results

  • The new inverse is 3x faster as shown by a new benchmark:
> ./run src/bindings/crypto/benchmarks/inverse.ts

inverse                  50396ns @   20K ops/s
fast inverse             16785ns @   60K ops/s
  • Contribution of field inverses to the ECDSA proof goes down from 5% to 1.2% and reduces proving time by about 1.5s
./run-debug src/examples/crypto/ecdsa/run.ts

Further work

The inverse could still be sped up a lot by moving to wasm (1000-5000ns are known to be possible). However, I think it has hit diminishing returns at least until we make the Rust/wasm prover much faster.

Copy link
Member

@Trivo25 Trivo25 left a comment

Choose a reason for hiding this comment

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

This could also be a great addition to the changelog 👀

@mitschabaude mitschabaude merged commit f60ef63 into main Jan 26, 2024
11 checks passed
@mitschabaude mitschabaude deleted the perf/field-inverse branch January 26, 2024 11:12
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.

Faster field inversions
2 participants