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.
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.
- To test, please download the provided G1 and G2 points from DA Resources,
- Specify these files in the
kzg.setup()
function, leave theg2_power_of2_path
empty, and specifysrs_order
to be 3000.
- Follow the setup instructions to download the G1 and G2 powers of 2 points from the Operator Setup Guide
- Specify the files in
kzg.setup()
function, leave theg2_points
empty, and specify thesrs_order
per the guide. - Note that this is process will take a few minutes to load since it is a bit intensive.
Linting can be triggered via running cargo clippy --all --manifest-path Cargo.toml -- -D warnings
.
- Check the test in
test_compute_kzg_proof
function to see the end to end usage of the library for quick start.
- SRS points required are in the same format as provided by the EigenDA.
- Commiting is performed in lagrange format. The required IFFT is done within the function and is not required to be performed separately.
- 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.
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.
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.
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.
The commit
function takes in a polynomial
. It is computed over lagrange
basis by performing the (i)FFT depending on the polynomial
form specified.
The initialize_cache
function takes in a bool force
. If force
is set to true
which delete's files which ends in .cache
in the cache_dir
. It computes the needed cache and writes it to files on disk into cache_dir
.
The commit_with_cache
function takes in a polynomial
and cache_dir
. It computes the commitment over the cached IFFT'd SRS points. The cache has to be already populated.
The compute_kzg_proof_with_roots_of_unity
takes in a Polynomial
and an index
at which it needs to be computed.