Skip to content

Commit

Permalink
chore!: remove kzg cache feature (#22)
Browse files Browse the repository at this point in the history
* chore!: remove kzg cache feature

breaking change Kzg::setup now takes 5 arguments instead of 6

* chore: fix lint by removing mention of cache benchmarks in cargo.toml

* docs: remove mentions of cache functions in readme
  • Loading branch information
samlaf authored Jan 4, 2025
1 parent fe0c03c commit 2b43565
Show file tree
Hide file tree
Showing 14 changed files with 21 additions and 346 deletions.
10 changes: 0 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ harness = false
path = "benches/bench_g1_ifft.rs"


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

[[bench]]
name = "bench_kzg_setup"
harness = false
Expand All @@ -81,11 +76,6 @@ name = "bench_kzg_commit_large_blobs"
harness = false
path = "benches/bench_kzg_commit_large_blobs.rs"

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

[[bench]]
name = "bench_kzg_proof"
harness = false
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ The `data_setup_custom` (for testing) or `data_setup_mins` should be used to spe

The `commit` function takes in a `polynomial`. It is computed over `lagrange` basis by performing the (i)FFT depending on the `polynomial` form specified.

### `initialize_cache()`

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`.

### `commit_with_cache()`

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.



### `compute_kzg_proof_with_roots_of_unity()`

Expand Down
1 change: 0 additions & 1 deletion benches/bench_g1_ifft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ fn bench_g1_ifft(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
3000,
3000,
"".to_owned(),
)
.unwrap();
b.iter(|| {
Expand Down
1 change: 0 additions & 1 deletion benches/bench_kzg_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn bench_kzg_commit(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
268435456,
131072,
"".to_owned(),
)
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion benches/bench_kzg_commit_large_blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn bench_kzg_commit(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
268435456,
524288,
"".to_owned(),
)
.unwrap();

Expand Down
57 changes: 0 additions & 57 deletions benches/bench_kzg_commit_with_cache.rs

This file was deleted.

33 changes: 0 additions & 33 deletions benches/bench_kzg_ifft_cache.rs

This file was deleted.

1 change: 0 additions & 1 deletion benches/bench_kzg_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn bench_kzg_proof(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
268435456,
131072,
"".to_owned(),
)
.unwrap();

Expand Down
2 changes: 0 additions & 2 deletions benches/bench_kzg_setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn bench_kzg_setup(c: &mut Criterion) {
"tests/test-files/g2.point.powerOf2",
3000,
3000,
"".to_owned(),
)
.unwrap()
});
Expand All @@ -23,7 +22,6 @@ fn bench_kzg_setup(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
268435456,
131072,
"".to_owned(),
)
.unwrap()
});
Expand Down
1 change: 0 additions & 1 deletion benches/bench_kzg_verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ fn bench_kzg_verify(c: &mut Criterion) {
"tests/test-files/mainnet-data/g2.point.powerOf2",
268435456,
131072,
"".to_owned(),
)
.unwrap();

Expand Down
1 change: 0 additions & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub const BYTES_PER_FIELD_ELEMENT: usize = 32;
pub const SIZE_OF_G1_AFFINE_COMPRESSED: usize = 32; // in bytes
pub const SIZE_OF_G2_AFFINE_COMPRESSED: usize = 64; // in bytes
pub const REQUIRED_FREE_SPACE: u64 = 100 * 1024 * 1024; // 100 MB in bytes
65 changes: 2 additions & 63 deletions src/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
use ark_bn254::{Fq, Fq2, Fr, G1Affine, G1Projective, G2Affine, G2Projective};
use ark_ec::AffineRepr;
use ark_ff::{sbb, BigInt, BigInteger, Field, LegendreSymbol, PrimeField};
use ark_serialize::Write;
use ark_std::{str::FromStr, vec::Vec, One, Zero};
use crossbeam_channel::Receiver;
use std::{
cmp,
fs::{self, OpenOptions},
path::Path,
};
use sys_info::disk_info;
use std::cmp;

use crate::{
arith,
consts::{
BYTES_PER_FIELD_ELEMENT, REQUIRED_FREE_SPACE, SIZE_OF_G1_AFFINE_COMPRESSED,
SIZE_OF_G2_AFFINE_COMPRESSED,
},
consts::{BYTES_PER_FIELD_ELEMENT, SIZE_OF_G1_AFFINE_COMPRESSED, SIZE_OF_G2_AFFINE_COMPRESSED},
traits::ReadPointFromBytes,
};
use ark_ec::AdditiveGroup;
Expand Down Expand Up @@ -376,55 +367,3 @@ pub fn is_on_curve_g2(g2: &G2Projective) -> bool {
right += &tmp;
left == right
}

/// Checks if the directory specified by `path`:
/// 1. can be written to by creating a temporary file, writing to it, and deleting it.
/// 2. has [REQUIRED_FREE_SPACE] to store the required amount of data.
///
/// # Arguments
/// * `path` - The directory path to check
///
/// # Returns
/// * `Ok(true)` if directory is writable and has enough space
/// * `Err(String)` with error description if checks fail
pub fn check_directory<P: AsRef<Path> + std::fmt::Display>(path: P) -> Result<(), String> {
let test_file_path = path.as_ref().join("cache_dir_write_test.tmp");

// Try to create and write to a temporary file
let result = OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(&test_file_path)
.and_then(|mut file| file.write_all(b"test"));

// Clean up the test file
let _ = fs::remove_file(test_file_path);

// Return true if writing was successful, otherwise false
if result.is_err() {
return Err(format!(
"directory {} unable to be modified by kzg program",
path
));
}

// Get disk information
// FIXME: I don't think this works... the directory might actually be on a separate
// disk than the default one disk_info looks at.
let disk = match disk_info() {
Ok(info) => info,
Err(_) => return Err(format!("unable to get disk information for path {}", path)),
};

// Calculate available space in the directory's disk
let free_space = disk.free * 1024; // Convert from KB to bytes

if free_space < REQUIRED_FREE_SPACE {
return Err(format!(
"the cache path {} does not have {} space on disk",
path, REQUIRED_FREE_SPACE
));
}
Ok(())
}
Loading

0 comments on commit 2b43565

Please sign in to comment.