Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constantine backend #251

Merged
merged 17 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .github/workflows/backend-benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-11]
# Excluding mcl for now due to they have different project layout
backend: [blst, zkcrypto, arkworks]
backend: [blst, zkcrypto, arkworks, constantine]
include:
# Setup exec_once_per_backend flag
- os: ubuntu-latest
Expand All @@ -23,6 +23,8 @@ jobs:
support_ckzg: true
- backend: arkworks
support_ckzg: true
- backend: constantine
support_ckzg: true

steps:
- uses: actions/checkout@v2
Expand All @@ -31,6 +33,20 @@ jobs:
distribution: "temurin"
java-version: "11"

- if: matrix.backend == 'constantine'
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '1.6.14'

# Install constantine backend deps
- name: "constantine - install deps"
if: matrix.backend == 'constantine' && matrix.os == 'ubuntu-latest'
run: |
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq \
libgmp-dev \
llvm

- uses: actions/setup-go@v2
with:
go-version: ^1.19
Expand Down
21 changes: 20 additions & 1 deletion .github/workflows/backend-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest, macos-11]
# Excluding mcl for now due to they have different project layout
backend: [blst, zkcrypto, arkworks]
backend: [blst, zkcrypto, arkworks, constantine]
include:
# Set default clippy flag to all-features
- clippy-flag: --all-features
Expand All @@ -36,13 +36,23 @@ jobs:
- backend: arkworks
support_wasm: true
support_ckzg: true
- backend: constantine
# FIXME: Check for wasm support
support_wasm: false
support_ckzg: true

steps:
- uses: actions/checkout@v2
- uses: actions/setup-java@v3
with:
distribution: "temurin"
java-version: "11"

- if: matrix.backend == 'constantine'
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '1.6.14'

- uses: actions/setup-python@v4
with:
python-version: '3.10'
Expand All @@ -55,6 +65,15 @@ jobs:
with:
go-version: ^1.19

# Install constantine backend deps
- name: "constantine - install deps"
if: matrix.backend == 'constantine' && matrix.os == 'ubuntu-latest'
run: |
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq \
libgmp-dev \
llvm

# Check kzg clippy
- name: "kzg clippy"
if: matrix.exec_once_overall
Expand Down
16 changes: 15 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
backend: [blst, zkcrypto, arkworks]
backend: [blst, zkcrypto, arkworks, constantine]
target: [windows, linux]
include:
# Set target-name for target builds
Expand All @@ -30,6 +30,20 @@ jobs:
steps:
- uses: actions/checkout@v2

- if: matrix.backend == 'constantine'
uses: jiro4989/setup-nim-action@v1
with:
nim-version: '1.6.14'

# Install constantine backend deps
- name: "constantine - install deps"
if: matrix.backend == 'constantine' && matrix.os == 'ubuntu-latest'
run: |
sudo DEBIAN_FRONTEND='noninteractive' apt-fast install \
--no-install-recommends -yq \
libgmp-dev \
llvm

- if: matrix.target == 'windows'
name: Install MinGW
run: |
Expand Down
41 changes: 41 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ members = [
"mcl/kzg",
"mcl/kzg-bench",
"zkcrypto",
"constantine"
]


Expand Down
1 change: 1 addition & 0 deletions constantine/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
c-kzg-4844/
93 changes: 93 additions & 0 deletions constantine/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[package]
name = "rust-kzg-constantine"
version = "0.1.0"
edition = "2021"

[dependencies]
blst = "0.3.11"
kzg = { path = "../kzg", default-features = false }
libc = { version = "0.2.148", default-features = false }
once_cell = { version = "1.18.0", features = ["critical-section"], default-features = false }
constantine-ethereum-kzg = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
constantine-sys = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
constantine-core = { 'git' = 'https://github.com/mratsim/constantine.git' , branch='constantine-public-sys' }
rand = { version = "0.8.5", optional = true }
rayon = { version = "1.8.0", optional = true }
smallvec = { version = "1.11.1", features = ["const_generics"] }
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }

[dev-dependencies]
criterion = "0.5.1"
kzg-bench = { path = "../kzg-bench" }
rand = "0.8.5"

[features]
default = [
"std",
"rand",
]
std = [
"hex/std",
"kzg/std",
"libc/std",
"once_cell/std",
]
rand = [
"dep:rand",
"kzg/rand",
]
parallel = [
"dep:rayon",
"kzg/parallel"
]
constantine_msm = []
bgmw = [
"kzg/bgmw"
]
arkmsm = [
"kzg/arkmsm"
]

[[bench]]
name = "das"
harness = false

[[bench]]
name = "fft"
harness = false

[[bench]]
name = "poly"
harness = false

[[bench]]
name = "kzg"
harness = false

[[bench]]
name = "fk_20"
harness = false

[[bench]]
name = "recover"
harness = false

[[bench]]
name = "zero_poly"
harness = false

[[bench]]
name = "eip_4844"
harness = false

[[bench]]
name = "eip_4844_constantine"
harness = false

[[bench]]
name = "eip_4844_constantine_no_conv"
harness = false

[[bench]]
name = "lincomb"
harness = false
46 changes: 46 additions & 0 deletions constantine/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# KZG10-BLST
## [BLS12-381 lib](https://github.com/supranational/blst)

Planned functionality:
* Finite field FFT (Fast Fourier Transform);
* G1 group FFT;
* Data availability sampling (data extension, recovery from any 1/2 samples);
* Zero polynomials;
* KZG10 single commit/verify;
* KZG10 multi commit/verify;
* FK20 single proof regular/optimised for DAS;
* FK20 multi proof regular/optimised for DAS.
* Test suite (based on C implementation)
* Benchmarks

## Other implementations
* [C implementation](https://github.com/benjaminion/c-kzg)
* [Go implementation](https://github.com/protolambda/go-kzg)
* [Rust herumi implementation](https://github.com/UndeadRat22/kzg10-rust)

```
.-. .-.
/ \ / \
| _ \ / _ |
; | \ \ / / | ;
\ \ \ \_.._/ / / /
'. '.;' ';,' .'
'./ _ _ \.'
.' a __ a '.
'--./ _, \/ ,_ \.--'
----| \ /\ / |----
.--'\ '-' '-' /'--.
_>.__ -- _.- `;
.' _ __/ _/
/ '.,:".-\ /:,
| \.' `""`'.\\
'-,.__/ _ .-. ;|_
/` `|| _/ `\/_ \_|| `\
| ||/ \-./` \ / || |
\ ||__/__|___|__|| /
\_ |__BLS12-381__| /
.' \ = _= _ = _= /`\
/ `-;----=--;--' \
\ _.-' '. /
`""` Happy Easter `""`
```
16 changes: 16 additions & 0 deletions constantine/benches/das.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use criterion::{criterion_group, criterion_main, Criterion};
use kzg_bench::benches::das::bench_das_extension;
use rust_kzg_constantine::types::fft_settings::CtFFTSettings;
use rust_kzg_constantine::types::fr::CtFr;

fn bench_das_extension_(c: &mut Criterion) {
bench_das_extension::<CtFr, CtFFTSettings>(c)
}

criterion_group! {
name = benches;
config = Criterion::default().sample_size(10);
targets = bench_das_extension_
}

criterion_main!(benches);
36 changes: 36 additions & 0 deletions constantine/benches/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use criterion::{criterion_group, criterion_main, Criterion};
use kzg::eip_4844::{
blob_to_kzg_commitment_rust, bytes_to_blob, compute_blob_kzg_proof_rust,
compute_kzg_proof_rust, verify_blob_kzg_proof_batch_rust, verify_blob_kzg_proof_rust,
verify_kzg_proof_rust,
};
use kzg_bench::benches::eip_4844::bench_eip_4844;
use rust_kzg_constantine::{
eip_4844::load_trusted_setup_filename_rust,
types::{
fft_settings::CtFFTSettings,
fp::CtFp,
fr::CtFr,
g1::{CtG1, CtG1Affine},
g2::CtG2,
kzg_settings::CtKZGSettings,
poly::CtPoly,
},
};

fn bench_eip_4844_(c: &mut Criterion) {
bench_eip_4844::<CtFr, CtG1, CtG2, CtPoly, CtFFTSettings, CtKZGSettings, CtFp, CtG1Affine>(
c,
&load_trusted_setup_filename_rust,
&blob_to_kzg_commitment_rust,
&bytes_to_blob,
&compute_kzg_proof_rust,
&verify_kzg_proof_rust,
&compute_blob_kzg_proof_rust,
&verify_blob_kzg_proof_rust,
&verify_blob_kzg_proof_batch_rust,
);
}

criterion_group!(benches, bench_eip_4844_);
criterion_main!(benches);
Loading
Loading