Rust-Starkware crypto rs: Rust FFI bindings for StarkWare's crypto-cpp library

starkware-crypto-rs

Rust FFI bindings for StarkWare's crypto-cpp library

linting-badge tests-badge crates-badge

There's currently an issue on the official crypto-cpp repository that prevents the library from compiling on macOS. We're using Max Gillett's fork until his PR is merged.

Adding starkware-crypto-rs to your project

To use the crate from crates.io, add the following to your Cargo.toml file:

[dependencies]
starkware-crypto-sys = "0.1"

Running benchmark

To run benchmark:

$ cargo bench

On the author's machine, the results are:

pedersen_hash           time:   [267.08 us 270.36 us 274.40 us]

License

Licensed under either of

at your option.

Comments

  • Unable to build on Windows
    Unable to build on Windows

    Jan 12, 2022

    After the macOS build issue was resolved, it's discovered that the library also fails to build on Windows, for both x86_64-pc-windows-gnu and x86_64-pc-windows-msvc targets.

    Target triples to fix:

    • [ ] x86_64-pc-windows-msvc
    • [x] x86_64-pc-windows-gnu
    Reply
  • ci: add tests for Windows and macOS
    ci: add tests for Windows and macOS

    Jan 12, 2022

    This PR adds Windows and macOS testing to CI pipelines.

    Note that currently x86_64-pc-windows-msvc is not tested as it's not supported yet.

    Reply
  • docs: add note on Windows issues to README
    docs: add note on Windows issues to README

    Jan 12, 2022

    This PR adds a note on the issue currently tracked by #3 so that library users are aware.

    Reply
  • feat: switch to upstream fork without endianess conversion
    feat: switch to upstream fork without endianess conversion

    Jan 12, 2022

    Resolves #4.

                                                                                                                                                                                                           
    Reply
  • Remove upstream endianness conversion?
    Remove upstream endianness conversion?

    Jan 12, 2022

    After inspecting the upstream code, it's found that the library converts between little endian and host endian if they're different. This forces library users to be aware of host endianess.

    I'm gonna simply fork upstream and remove the conversion, and instead specifically document that all function inputs must be little-endian.

    Alternative solutions considered:

    • Explicitly document that function inputs must conform to host endianess

      Not good as it forces users to be aware of host endianess, which is mostly irrelevant today.

    • Use target_endian to convert to big endian first if the host is big-endian

      No need to fork upstream, but has unnecessary performance costs on big-endian systems.

    Reply
  • Switch to maxgillett's fork for fixing macOS build errors
    Switch to maxgillett's fork for fixing macOS build errors

    Jan 12, 2022

    Resolves #1.

                                                                                                                                                                                                           
    Reply
  • Unable to build on macOS
    Unable to build on macOS

    Jan 11, 2022

    When building on macOS in a GitHub Actions workflow with cargo build, an error occurs:

      cargo:warning=lib/starkware-crypto/src/starkware/crypto/ffi/utils.cc:1:10: fatal error: 'endian.h' file not found
      cargo:warning=#include <endian.h>
      cargo:warning=         ^~~~~~~~~~
      exit status: 0
      running: "c++" "-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-m64" "-arch" "x86_64" "-static" "-I" "lib/starkware-crypto/src" "-Wall" "-Wextra" "-std=c++17" "-Werror" "-Wall" "-Wextra" "-fno-strict-aliasing" "-fPIC" "-o" "/Users/runner/repos/starknet-rs/target/debug/build/starkware-crypto-sys-7e7a1853b703c604/out/lib/starkware-crypto/src/starkware/crypto/pedersen_hash.o" "-c" "lib/starkware-crypto/src/starkware/crypto/pedersen_hash.cc"
      cargo:warning=1 error generated.
      exit status: 1
      exit status: 0
      exit status: 0
    
      --- stderr
    
    Reply