Giter VIP home page Giter VIP logo

rust-eth-kzg's Introduction

Rust Eth KZG

Overview

What

A cryptographic library that is compatible with the KZG commitment scheme used in the Ethereum blockchain for PeerDAS.

Why

The cryptography implemented in this library is the prerequisite needed for Ethereum's version of Data Availability Sampling(DAS). The library has been implemented in a modular way, so one can also use the underlying polynomial commitment scheme, for a different purpose.

Installation

Rust

cargo add rust_eth_kzg

Node

npm i @crate-crypto/node-eth-kzg

Java

pkg:maven/io.github.crate-crypto/[email protected]

CSharp

dotnet add package EthKZG.Bindings

Nim

Use the github URL for Nim.

Building the source

This library is written in Rust and offers bindings to C, C#, node.js, golang, Java and Nim. These bindings can be found in the bindings folder. The bindings expose an API that is compatible with the API needed for Ethereum.

If you only intend to modify the cryptography, then a Rust compiler will be needed. For the bindings, one should check the respective language's README file to find out additional requirements.

Building everything

To build everything including the artifacts needed for the bindings, you can run:

./scripts/compile.sh

To only build the native Rust code, you can run:

cargo build

Benchmarks

Benchmarks can be run by calling:

cargo bench

Note: This will benchmark the underlying Rust library. It will not account for (if any) discrepancies due to calling the library via a particular language. An example of this is the CGO overhead when calling a foreign language from Golang; in our case, this overhead is negligible compared to the actual computations being performed.

Consensus Specs

This library conforms and is tested against commit 13ac373a2c284dc66b48ddd2ef0a10537e4e0de6.

License

Licensed and distributed under either of

MIT license: LICENSE-MIT or http://opensource.org/licenses/MIT

or

Apache License, Version 2.0, (LICENSE-APACHEv2 or http://www.apache.org/licenses/LICENSE-2.0) at your option. These files may not be copied, modified, or distributed except according to those terms.

rust-eth-kzg's People

Contributors

kevaundray avatar jtraglia avatar matthewkeil avatar dependabot[bot] avatar

Stargazers

Erhan avatar Mamy Ratsimbazafy avatar Bob Niu avatar zhenfei avatar Agnish Ghosh avatar Sandalots avatar Alexey Shekhirin avatar Shun Kakinoki avatar Dan Cline avatar Chen Kai avatar  avatar

Watchers

 avatar

rust-eth-kzg's Issues

Warnings when building

warning: /Users/jtraglia/Projects/jtraglia/peerdas-kzg/bindings/java/rust_code/Cargo.toml: `crate_type` is deprecated in favor of `crate-type` and will not work in the 2024 edition
(in the `java_peerdas_kzg` library target)
warning: skipping duplicate package `single_crate` found at `/Users/jtraglia/.cargo/git/checkouts/nbindgen-d5c3df89ad9a133d/e80a85f/tests/depfile/single_crate`
warning: skipping duplicate package `single_crate` found at `/Users/jtraglia/.cargo/git/checkouts/nbindgen-d5c3df89ad9a133d/e80a85f/tests/depfile/single_crate_default_config`

Consider using a double pointer, so that the rust code can both free and set the pointer to zero.

See Java code where we check the contextPtr to be 0, free it on the rust side and then set the contextPtr to zero.

On one hand, this is ideally done on the Rust side, then bindings code can avoid keeping a flag to check whether the context has been freed.

On the otherhand, some bindings need to keep track of this because even after the pointer is freed, they can attempt to call a method on the freed context. (We could check this on the Rust side too, ie return an error if the context is null on the rust side)

remove usage of `l` from fk20

l (ell) was copied from the FK20 paper, but its not actually clear what it is. Replace it with num_points_per_coset or something along those lines

Re-evaluate benchmark suite

Check each benchmark suite and re-eveluate whether we need the, or not, and add new benchmarks for things that seem reasonable to performance test

Tracking Issue: PeerDAS-KZG Integration (Consensus Layer)

This will track the main integration PR(s) and also the refactor PRs which may need to be merged before integration.

Lighthouse

Reviewer: @jimmygchen

Integration

Refactor

Teku

Reviewer: @zilm13

Integration

Refactor

None yet

Lodestar

Reviewer: Possibly @matthewkeil / @g11tech

Integration

Refactor

None yet

Prysm

Prysm is integrating go-eth-kzg, its easier to track all clients in one place, so it is included here

Reviewer: @nalepae

Integration

Refactor

Nimbus

Reviewer: Still unclear; tagging relevant nim-kzg folks @tersec, @cheatfate, @jangko, @arnetheduck

Integration

None yet

Refactor

None yet

Fix maven false-negative timeouts

Currently when we publish to maven, JReleaser will try 61 times to publish to maven.

After the first time, Maven central repository picks it up but it then takes about an hour to publish the release.

After the 61st try, the CI will think that it has failed but its just Maven taking a long time to publish the release.

We could increase the timeout to 30 minutes or an hour and or check if there is a config in JReleaser for this seemingly common scenario.

Consider renaming FK20Verifier and FK20Prover

Internally, we have FK20Verifier and FK20Prover. Benedikt Wagner corrrectly noted that this is not enirely a good name once you think about it more.

George (asn) noted further that the verifier can verify proofs that are not created by the FK20 strategy. (They can just use the naive method)

Leaving this issue open, incase we think of a better name.

RIght now, I've exported them in stabilize FK20 branch as Prover, and Verifier. Even though they are internally being referenced as FK20Prover and FK20Verifier. I think FK20Prover likely makes more sense to stay though.

Windows heap pressure

When running cargo test on windows, we seem to be getting a lot of heap pressure causing the CI to fail:

running 19 tests
test fk20::cosets::tests::bit_reverse_fuzz ... ok
test fk20::cosets::tests::check_valid_cosets ... ok
test fk20::cosets::tests::bit_reverse_cosets_equality ... ok
test fk20::cosets::tests::test_data_distribution_bit_reverse_order ... ok
test fk20::h_poly::tests::smoke_test_downsample ... ok
test fk20::naive::tests::check_divide_by_monomial_floor ... ok
test fk20::batch_toeplitz::tests::smoke_aggregated_matrix_vector_mul ... ok
test fk20::cosets::tests::test_data_distribution_original_cosets ... ok
test fk20::prover::tests::show_data_distribution_on_recover_evaluations_in_domain_order ... ok
memory allocation of 75497472 bytes failed
error: test failed, to rerun pass `-p crate_crypto_kzg_multi_open_fk20 --lib`

Caused by:
  process didn't exit successfully: `D:\a\rust-eth-kzg\rust-eth-kzg\target\x86_64-pc-windows-gnu\debug\deps\crate_crypto_kzg_multi_open_fk20-d4b6db1a58f80145.exe` (exit code: 0xc0000409, STATUS_STACK_BUFFER_OVERRUN)
note: test exited abnormally; to see the full output pass --nocapture to the harness.
Error: Process completed with exit code 1.

This was hot-fixed by making the tests run on a single thread. We could figure out what in the fk20 tests are causing the issue and possibly release memory quickly

Add a coherent release story

For PRs, it makes sense to run on stock windows-latest, mac-latest and ubuntu-latest.

For master, we can run the full release-suite with qemu for linux arm (This will be a lot slower which is fine)

Consider using node arm64 docker image

CI code could be made a bit more concise by using the armv64 docker image for testing aarch64-linux-gnu. Something like:

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2

      - name: Run tests in ARM64 container
        uses: addnab/docker-run-action@v3
        with:
          image: arm64v8/node:16-alpine
          options: -v ${{ github.workspace }}:/app
          run: |
            cd /app
            yarn install
            yarn test

Error with `erasure_codes` benchmark

Running benches/benchmark.rs (target/release/deps/benchmark-5e0ad2e17c19d295)
thread 'main' panicked at erasure_codes/benches/benchmark.rs:34:31:
index out of bounds: the len is 8192 but the index is 13184
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: bench failed, to rerun pass `-p crate_crypto_internal_peerdas_erasure_codes --bench benchmark`

Add a better interface for cosets

Currently the domain allows only one coset, which gets pregenerated. We can add a better interface for cosets, allowing multiple cosets to be created from a single domain, or for a single Domain to be able to do multiple coset_ffts on different cosets

Consider removing the language prefix in package names

Currently the released packages have their corresponding language prefix in the package name, ie rust has rust-eth-kzg and node has node-eth-kzg -- consider removing these and simply naming them eth-kzg since the language part is somewhat implied.

Add batch_normalize to bls12-381 crate

Currently bls12_381::G1Projective::batch_normalize seems to be doing an inversion per projective point.

We can move this into the bls12-381 crate and use batch_inversion to speed it up

standardize the comments that reference the consensus-specs

Currently there are functions that reference functions in the specs to let the reader know what function this is supposed to match.

This is a tracking issue to check those comments and ensure that they are standardized for folks who want to grep the codebase

Namespace the c ffi methods

Currently, the c methods are called verify_cell_kzg_proof for example, whereas we want to rename them to rust_eth_kzg_verify_cell_kzg_proof since nim will put all c functions into same namespace.

This will cause issues with methods that have the same name in different c projects like c-kzg

Cleaning up benchmarking code

Currently we benchmark the naive versions of some algorithms. It was used to confirm that the optimized versions indeed did give a noticeable speedup and by how much.

We probably don't need to do this and just benchmarking the optimized versions should be enough

Consider removing node pre-release and publish to a github branch

Leaving this open incase its wanted.

Currently we release pre-release versions to node, we could just release those to a github branch, and possibly have this solution for all bindings, ie just have a branch with precompiled binaries etc, instead of each language having its own prerelease registry

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.