Skip to content

Commit

Permalink
Updated Readme with information about c-kzg-4844 drop-in replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
sauliusgrigaitis committed Jan 24, 2023
1 parent 43ee3ec commit 080f956
Showing 1 changed file with 13 additions and 46 deletions.
59 changes: 13 additions & 46 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,31 @@ The goal is to create a parallelized KZG library for Ethereum Data Sharding (aka

# Backend ECC libraries

Support for multiple backend ECC libraries is implemented via [Traits](https://github.com/sifraitech/kzg/blob/main/kzg/src/lib.rs). Such an approach allows to easily change backend ECC libraries in a way that is done in [benchmarks](https://github.com/sifraitech/kzg/tree/main/kzg-bench/src/benches) and [tests](https://github.com/sifraitech/kzg/tree/main/kzg-bench/src/tests). List of different backend ECC libraries:
Support for multiple backend ECC libraries is implemented via [Traits](https://github.com/sifraitech/kzg/blob/main/kzg/src/lib.rs). Such an approach allows to easy change backend ECC libraries as all the crates shared the same interface (see [benchmarks](https://github.com/sifraitech/kzg/tree/main/kzg-bench/src/benches) and [tests](https://github.com/sifraitech/kzg/tree/main/kzg-bench/src/tests)). The current state of supported backend ECC libraries:

* Arkworks - Rust implementation using [akrworks](https://github.com/arkworks-rs);
* blst-from-scratch - Rust implementation using [blst](https://github.com/supranational/blst);
* ckzg - bindings for [c-kzg](https://github.com/benjaminion/c-kzg) that uses [blst](https://github.com/supranational/blst);
* mcl - Rust implementation using [mcl](https://github.com/herumi/mcl);
* zkcrypto - Rust implementation using [zkcrypto](https://github.com/zkcrypto).
| Backend ECC | FFT/DAS | EIP-4844 (non-parallel) | EIP-4844 (parallel) | [c-kzg-4844](https://github.com/ethereum/c-kzg-4844) drop-in replacement |
| :---: | :---: | :---: | :---: | :---: |
| [blst](https://github.com/supranational/blst) | [x] | [x] | [x] | [x] |
| [mcl](https://github.com/herumi/mcl) | [x] | [x] | [x] | [ ] |
| [arkworks](https://github.com/arkworks-rs/algebra) | [x] | [ ] | [ ] | [ ] |
| [zkcrypto](https://github.com/zkcrypto/bls12_381) | [x] | [ ] | [ ] | [ ] |

# Drop-in replacement for c-kzg-4844

We aim to expose [an identical C interface](https://github.com/sifraitech/rust-kzg/blob/b4de1923a6218ea37021d0f9e3bd375dbf529d34/blst-from-scratch/src/eip_4844.rs#L604:L835) compared to [c-kzg-4844](https://github.com/ethereum/c-kzg-4844) so that `rust-kzg` could work as a drop-in replacement for c-kzg-4844. If you already use [c-kzg-4844 bindings](https://github.com/ethereum/c-kzg-4844/tree/main/bindings) you can try faster paralellized `rust-kzg` without any changes to your code-base by simply replacing the binary. Instructions for C#, Java, Nodejs, Python, Rust bindings are available [here](https://github.com/sifraitech/rust-kzg/blob/main/blst-from-scratch/run-c-kzg-4844-tests.sh)

# Example

The best place to look for examples is [tests](https://github.com/sifraitech/kzg/tree/main/kzg-bench/src/tests) directory.

Currently, the ECC backend is set by pointing Cargo to the corresponding crate:

```
[dependencies]
kzg = { git = "https://github.com/sifraitech/kzg.git", package = "blst_from_scratch" }
kzg_traits = { git = "https://github.com/sifraitech/kzg.git", package = "kzg" }
```

```
use kzg::eip_4844::{bytes_to_bls_field, compute_powers};
use kzg_traits::*;
const EXPECTED_POWERS: [[u64; 4usize]; 11] = [
[1, 0, 0, 0],
[32930439, 0, 0, 0],
[1084413812732721, 0, 0, 0],
[15773128324309817559, 1935, 0, 0],
[17639716667354648417, 63748557064, 0, 0],
[14688837229838358055, 2099267969765560859, 0, 0],
[17806839894568993937, 15217493595388594120, 3747534, 0],
[17407663719861420663, 10645919139951883969, 123407966953127, 0],
[9882663619548185281, 9079722283539367550, 5594831647882181930, 220],
[4160126872399834567, 5941227867469556516, 11658769961926678707, 7254684264],
[4000187329613806065, 4317886535621327299, 17988956659770583631, 238899937640724696]
];
fn main() {
let x: u64 = 32930439;
let n = 11;
let x_bytes: [u8; 32] = u64_to_bytes(x);
let x_bls = bytes_to_bls_field(&x_bytes);
let powers = compute_powers(&x_bls, n);
for (p, expected_p) in powers.iter().zip(EXPECTED_POWERS.iter()) {
assert_eq!(expected_p, &p.to_u64_arr());
}
}
fn u64_to_bytes(x: u64) -> [u8; 32] {
let mut bytes = [0u8; 32];
bytes[0..8].copy_from_slice(&x.to_le_bytes());
bytes
}
```

# Benchmarks

The latest benchmarks on AMD 3900X:
Expand Down

0 comments on commit 080f956

Please sign in to comment.