-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style!: issue15 - cleaner polynomial interface (#21)
* style!: issue15 - cleaner polynomial interface Separate Polynomial into PolynomialEvalForm and PolynomialCoefForm to make library type safe when converting between these. Eg: fft can only go from coeff->eval, and ifft can only go from eval->coeff * refactor!: change kzg commit functions to take a specific form Made the internal function take a Polynomial trait (that has len() and elements() fns) to be polymorphic. But public fns are now duplicated, one for each form (foo_coeff_form, foo_eval_form) * test: fix tests after new breaking api changes * style!: rename commit_coef_form -> commit_coeff_form follows renaming done in a previous commit, forgot this fn * test: fix benchmarks following api changes * style: fix lint issues * fix: removed polymorphism on commit function this fixes all the tests and benchmarks that were failing The previous code also had the implicit assumption that it only worked with polys in eval form. So just made that explicit. We can add the function to commit from coeff form (by taking ifft for eg) later if needed, but opted to keep API simple for now. * docs: add README section about kzg commitment * style: cargo fmt * docs: fix commitment explanation in readme * docs: add doc comment for fn convert_by_padding_empty_byte * docs: make read_file_chunks comment more precise * docs: add "monomial" prefix to srs points in comment * style: rename function to_coef_form -> to_coeff_form for consistency * docs: clarify some comments * docs: clean up and make much more precise data type documentation + readme * style: switch poly eval and coeff forms to have eval at top of file Eval is the most important one, so should be prominent and easier to find/look at. * test: add test to check length of polynomials during conversions * docs: move readme docs to lib.rs rust docs * docs: fix doc code that was failing * style: cargo fmt * test: fix cargo doc test
- Loading branch information
Showing
16 changed files
with
473 additions
and
433 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,27 @@ | ||
# rust-kzg-bn254 | ||
|
||
## Description | ||
[](https://docs.rs/rust-kzg-bn254/latest/rust_kzg_bn254/) | ||
[](https://crates.io/crates/rust-kzg-bn254) | ||
|
||
This library offers a set of functions for generating and interacting with bn254 KZG commitments and proofs in rust, with the motivation of supporting fraud and validity proof logic in EigenDA rollup integrations. | ||
|
||
## Warning & Disclaimer | ||
|
||
This code is unaudited and under construction. This is experimental software and is provided on an "as is" and "as available" basis and may not work at all. It should not be used in production. | ||
|
||
## Setup for testing | ||
|
||
1. To test, please download the provided G1 and G2 points from [DA Resources](https://github.com/Layr-Labs/eigenda/tree/master/inabox/resources/kzg), | ||
2. Specify these files in the `kzg.setup()` function, leave the `g2_power_of2_path` empty, and specify `srs_order` to be 3000. | ||
|
||
## Configuring with the EigenDA KZG trusted setup | ||
|
||
1. Follow the setup instructions to download the G1 and G2 powers of 2 points from the [Operator Setup Guide](https://github.com/Layr-Labs/eigenda-operator-setup) | ||
2. Specify the files in `kzg.setup()` function, leave the `g2_points` empty, and specify the `srs_order` per the guide. | ||
3. Note that this is process will take a few minutes to load since it is a bit intensive. | ||
|
||
## Clippy | ||
Linting can be triggered via running `cargo clippy --all --manifest-path Cargo.toml -- -D warnings`. | ||
|
||
## Quick Start | ||
|
||
See the `test_compute_kzg_proof` function in [./tests/kzg_test.rs](./tests/kzg_test.rs#) for an end to end usage of the library. | ||
|
||
## Requirements | ||
|
||
1. SRS points required are in the same format as provided by EigenDA. | ||
2. Committing is performed in Lagrange format. The required IFFT is done within the function and is not required to be performed separately. | ||
3. For proof generation, the data is treated as evaluation of polynomial. The required (I)FFT is performed by the compute function and is not required to be performed separately. | ||
See the `test_compute_kzg_proof` function in [./tests/kzg_test.rs](./tests/kzg_test.rs) for an end to end usage of the library. | ||
|
||
## Function Reference | ||
Also make sure to check out the examples in our [docs](https://docs.rs/rust-kzg-bn254/latest/rust_kzg_bn254/). | ||
|
||
### `from_bytes_and_pad()` | ||
|
||
The `Blob` is loaded with `from_bytes_and_pad` which accepts bytes and "pads" it so that the data fits within the requirements of Eigen DA functioning. It also keeps track of the blob length after padding. | ||
|
||
### `to_polynomial()` | ||
|
||
From the `Blob`, a polynomial can be obtained via calling the `to_polynomial()` function. This converts the Blob to Field elements, then calculates the next power of 2 from this length of field elements and appends `zero` value elements for the remaining length. | ||
|
||
### `data_setup_custom` and `data_setup_mins` parameters | ||
|
||
The `data_setup_custom` (for testing) or `data_setup_mins` should be used to specify the number of chunks and chunk length. These parameters are used to calculate the FFT params required for FFT operations. | ||
|
||
### `commit()` | ||
|
||
The `commit` function takes in a `polynomial`. It is computed over `lagrange` basis by performing the (i)FFT depending on the `polynomial` form specified. | ||
## Setup for testing | ||
|
||
1. To test, please download the provided G1 and G2 points from [DA Resources](https://github.com/Layr-Labs/eigenda/tree/master/inabox/resources/kzg), | ||
2. Specify these files in the `kzg.setup()` function, leave the `g2_power_of2_path` empty, and specify `srs_order` to be 3000. | ||
|
||
### `compute_kzg_proof_with_roots_of_unity()` | ||
## Warning & Disclaimer | ||
|
||
The `compute_kzg_proof_with_roots_of_unity` takes in a `Polynomial` and an `index` at which it needs to be computed. | ||
This code is unaudited and under construction. This is experimental software and is provided on an "as is" and "as available" basis and may not work at all. It should not be used in production. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.