Skip to content

Commit

Permalink
Splitting to Multiple files and Optimizing (#43)
Browse files Browse the repository at this point in the history
* major changes

* moving to non struct functions

* moving verification functions to separate file, cleanup, optimize

* more optimizations

* bench code changes

* cleanup

* cargo fmt

* moving to workspaces, splitting tests, other things

* cargo fmt

* clippy fixes

* some version updates

* fixing tests

* moving to prover and verifier crates

* removing duplicate functions

* moving process_chunks

* unused deps

* fixing crate name

* fixing package names

---------

Co-authored-by: anupsv <[email protected]>
  • Loading branch information
anupsv and anupsv authored Jan 30, 2025
1 parent ff437c9 commit bdd755e
Show file tree
Hide file tree
Showing 44 changed files with 1,727 additions and 1,670 deletions.
9 changes: 4 additions & 5 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Build
run: cargo build --verbose
- name: Fmt check
run: cargo fmt --all -- --check
- name: Clippy Format test
run: cargo clippy --all --manifest-path Cargo.toml -- -D warnings
- name: Run tests
run: cargo test --verbose
- name: Run tests with mainnet data
run: KZG_ENV=mainnet-data cargo test --verbose
- name: Fmt check
run: cargo fmt --all -- --check


113 changes: 28 additions & 85 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,91 +1,20 @@
[package]
name = "rust-kzg-bn254"
version = "0.2.1"
[workspace]
members = [
"verifier",
"prover",
"primitives",
]
resolver = "2"

[workspace.dependencies]
thiserror = "2.0.11"

[workspace.package]
edition = "2021"
authors = ["Anup Swamy Veena", "Teddy Knox"]
rust-version = "1.81"
description = "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."
readme = "README.md"
repository = "https://github.com/Layr-Labs/rust-kzg-bn254"
homepage = ""
license-file = "LICENSE"
exclude = ["tests/*", "benches/*"]
# TODO: is this needed for the image to show up in the rust docs?
include = ["./kzg_commitment_diagram.png"]

[dependencies]
ark-bn254 = "0.5.0"
ark-ec = { version = "0.5.0", features = ["parallel"] }
ark-ff = { version = "0.5.0", features = ["parallel"] }
ark-serialize = "0.5.0"
ark-std = { version = "0.5.0", features = ["parallel"] }
directories = "5.0.1"
hex-literal = "0.4.1"
rand = "0.8.5"
sha2 = "0.10.8"
ureq = "2.12.1"
num-bigint = "0.4"
rayon = "1.10"
num-traits = "0.2"
byteorder = "1.5"
ark-poly = { version = "0.5.0", features = ["parallel"] }
crossbeam-channel = "0.5"
num_cpus = "1.16.0"
sys-info = "0.9"
itertools = "0.13.0"
thiserror = "2.0.10"

[dev-dependencies]
criterion = "0.5"
lazy_static = "1.5"
tracing = { version = "0.1.41", features = ["log"] }
tracing-subscriber = "0.3.19"

[[test]]
name = "kzg"
path = "tests/kzg_test.rs"

[[test]]
name = "blob"
path = "tests/blob_test.rs"

[[test]]
name = "polynomial"
path = "tests/polynomial_test.rs"

[[test]]
name = "helpers"
path = "tests/helpers_test.rs"

[[bench]]
name = "bench_g1_ifft"
harness = false
path = "benches/bench_g1_ifft.rs"


[[bench]]
name = "bench_kzg_setup"
harness = false
path = "benches/bench_kzg_setup.rs"

[[bench]]
name = "bench_kzg_commit"
harness = false
path = "benches/bench_kzg_commit.rs"

[[bench]]
name = "bench_kzg_commit_large_blobs"
harness = false
path = "benches/bench_kzg_commit_large_blobs.rs"

[[bench]]
name = "bench_kzg_proof"
harness = false
path = "benches/bench_kzg_proof.rs"

[[bench]]
name = "bench_kzg_verify"
harness = false
path = "benches/bench_kzg_verify.rs"

[profile.bench]
opt-level = 3
Expand All @@ -94,7 +23,7 @@ strip = "none"
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
panic = 'abort'
incremental = false
codegen-units = 16
rpath = false
Expand All @@ -106,7 +35,21 @@ strip = "none"
debug-assertions = false
overflow-checks = false
lto = false
panic = 'abort'
incremental = false
codegen-units = 16
rpath = false

[profile.release]
opt-level = 3
debug = false
strip = "none"
debug-assertions = false
overflow-checks = false
lto = true
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false


32 changes: 32 additions & 0 deletions primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "rust-kzg-bn254-primitives"
version = "0.1.0"
edition.workspace = true
repository.workspace = true
license-file.workspace = true

[dependencies]
ark-bn254 = "0.5.0"
ark-ec = { version = "0.5.0", features = ["parallel"] }
ark-ff = { version = "0.5.0", features = ["parallel"] }
ark-serialize = "0.5.0"
ark-std = { version = "0.5.0", features = ["parallel"] }
ark-poly = { version = "0.5.0", features = ["parallel"] }
sha2 = "0.10.8"
num-traits = "0.2"
thiserror = "2.0.11"

[dev-dependencies]
rand = "0.8.5"

[[test]]
name = "blob"
path = "tests/blob_test.rs"

[[test]]
name = "polynomial"
path = "tests/polynomial_test.rs"

[[test]]
name = "helpers"
path = "tests/helpers_test.rs"
9 changes: 9 additions & 0 deletions primitives/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# rust-kzg-bn254-primitives

[![Crate](https://img.shields.io/crates/v/rust-kzg-bn254.svg)](https://crates.io/crates/rust-kzg-bn254-primitives)

This library offers primitive set of structures and functions for generating and interacting with bn254 KZG commitments and proofs in rust.

## 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.
File renamed without changes.
File renamed without changes.
15 changes: 2 additions & 13 deletions src/consts.rs → primitives/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,7 @@ pub const PRIMITIVE_ROOTS_OF_UNITY: [Fr; 29] = [
MontFp!("19103219067921713944291392827692070036145651957329286315305642004821462161904"),
];

pub const G2_TAU_FOR_TEST_SRS_3000: G2Affine = G2Affine::new_unchecked(
Fq2::new(
MontFp!("7912312892787135728292535536655271843828059318189722219035249994421084560563"),
MontFp!("21039730876973405969844107393779063362038454413254731404052240341412356318284"),
),
Fq2::new(
MontFp!("18697407556011630376420900106252341752488547575648825575049647403852275261247"),
MontFp!("7586489485579523767759120334904353546627445333297951253230866312564920951171"),
),
);

pub const G2_TAU_FOR_MAINNET_SRS: G2Affine = G2Affine::new_unchecked(
pub const G2_TAU: G2Affine = G2Affine::new_unchecked(
Fq2::new(
MontFp!("19394299006376106554626551996044114846855237028623244664226757033024550999552"),
MontFp!("10478571113809844268398751534081669357808742555529167819607714577862447855483"),
Expand All @@ -73,5 +62,5 @@ pub const G2_TAU_FOR_MAINNET_SRS: G2Affine = G2Affine::new_unchecked(
),
);

// This is the G2 Tau for the MAINNET SRS points.
// This is the G2 Tau for the EigenDA MAINNET SRS points.
pub const MAINNET_SRS_G1_SIZE: usize = 131072;
File renamed without changes.
Loading

0 comments on commit bdd755e

Please sign in to comment.