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

Rust bindings #287

Merged
merged 7 commits into from
Oct 24, 2023
Merged

Rust bindings #287

merged 7 commits into from
Oct 24, 2023

Conversation

mratsim
Copy link
Owner

@mratsim mratsim commented Oct 21, 2023

Most provers are written in Rust, so we need to provide Rust bindings for consumption.

In particular we want to provide a backend to test Halo2 KZG's hardware accel API: privacy-scaling-explorations/halo2#216

@mratsim
Copy link
Owner Author

mratsim commented Oct 24, 2023

The PR adds the following:

  • Add a constantine-sys Rust package that exposes BN254-Snarks, BLS12-381 and the Pasta curves as well as Ethereum BLS signatures protocols.
  • Add a skeleton of high-level curves and protocol package to expose a Rust API on top of the low-level one.
  • Instead of building many libraries we build a single big one, a configuration tool might be provided in the future so that only the required modules are built in. Having multiple libraries would lead to namespacing problem on duplicated functions and status code like serialization or the threadpool.
  • Nim+Rust are optimized together through cross-language ThinLTO
  • The library is now built with --passC:-fmerge-all-constants to help on merging constant arrays that contains things like Montgomery constants.
    The core of duplication problem was addressed by nim-lang/Nim@df7b4bb / Noinline and/or Addressable consts nim-lang/RFCs#257 (comment).
    However, it may be possible for Nim to create temporaries in its codegen
    This might also help ICF (Identical Code Folding / Identical COMDAT folding) in C compiler.
  • Calling NimMain for CPU feature detection / filling globals is not needed anymore. This should work but is not tested with MSVC.
    • x86 features detection has been cleaned up and focused. 319 LOC instead of 779 LOC.

@mratsim mratsim marked this pull request as ready for review October 24, 2023 08:56
@mratsim mratsim merged commit 3e27f1e into master Oct 24, 2023
16 checks passed
@mratsim mratsim deleted the rust-bindings branch October 24, 2023 08:56
@mratsim mratsim restored the rust-bindings branch October 25, 2023 14:03
@mratsim mratsim deleted the rust-bindings branch October 27, 2023 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant