Skip to content

Commit

Permalink
Disable c_bindings feature by default
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtiomTr committed Jan 8, 2025
1 parent caeec0e commit 500911c
Show file tree
Hide file tree
Showing 24 changed files with 475 additions and 456 deletions.
1 change: 0 additions & 1 deletion arkworks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ default = [
"std",
"rand",
"bgmw",
"c_bindings"
]
std = [
"ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-std/std",
Expand Down
9 changes: 7 additions & 2 deletions arkworks/src/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
extern crate alloc;

use crate::kzg_proofs::KZGSettings as LKZGSettings;

Check warning on line 3 in arkworks/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks)

unused import: `crate::kzg_proofs::KZGSettings as LKZGSettings`

Check warning on line 3 in arkworks/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks)

unused import: `crate::kzg_proofs::KZGSettings as LKZGSettings`
#[cfg(feature = "c_bindings")]
use crate::utils::PRECOMPUTATION_TABLES;
#[cfg(feature = "c_bindings")]
use kzg::{
eth::{
self,
Expand All @@ -10,13 +12,14 @@ use kzg::{
Fr, G1,
};

#[cfg(feature = "std")]
#[cfg(feature = "c_bindings")]
use core::ptr;
#[cfg(all(feature = "std", feature = "c_bindings"))]
use libc::FILE;
#[cfg(feature = "std")]
use std::fs::File;
#[cfg(feature = "std")]
use std::io::Read;
use std::ptr;

#[cfg(feature = "std")]
use kzg::eip_4844::load_trusted_setup_string;
Expand All @@ -37,6 +40,7 @@ pub fn load_trusted_setup_filename_rust(
load_trusted_setup_rust(&g1_monomial_bytes, &g1_lagrange_bytes, &g2_monomial_bytes)
}

#[cfg(feature = "c_bindings")]
pub(crate) fn kzg_settings_to_c(rust_settings: &LKZGSettings) -> CKZGSettings {
CKZGSettings {
roots_of_unity: Box::leak(
Expand Down Expand Up @@ -119,6 +123,7 @@ pub(crate) fn kzg_settings_to_c(rust_settings: &LKZGSettings) -> CKZGSettings {
}
}

#[cfg(feature = "c_bindings")]
macro_rules! handle_ckzg_badargs {
($x: expr) => {
match $x {
Expand Down
5 changes: 2 additions & 3 deletions arkworks/src/eip_7594.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ extern crate alloc;

use kzg::EcBackend;

use kzg::c_bindings_eip7594;

use crate::kzg_proofs::FFTSettings;
use crate::kzg_proofs::KZGSettings;
use crate::kzg_types::ArkFp;
Expand All @@ -26,4 +24,5 @@ impl EcBackend for ArkBackend {
type KZGSettings = KZGSettings;
}

c_bindings_eip7594!(ArkBackend);
#[cfg(feature = "c_bindings")]
kzg::c_bindings_eip7594!(ArkBackend);
1 change: 0 additions & 1 deletion arkworks3/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ rand = { version = "0.8.5" }
default = [
"std",
"rand",
"c_bindings"
]
std = [
"ark-ff/std", "ark-ec/std", "ark-poly/std", "ark-std/std",
Expand Down
118 changes: 110 additions & 8 deletions arkworks3/src/eip_4844.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
extern crate alloc;

use crate::kzg_proofs::KZGSettings;

Check warning on line 3 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks3)

unused import: `crate::kzg_proofs::KZGSettings`

Check warning on line 3 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks3)

unused import: `crate::kzg_proofs::KZGSettings`
#[cfg(feature = "c_bindings")]
use alloc::boxed::Box;
#[cfg(feature = "c_bindings")]
use core::ptr;
use kzg::eip_4844::{
load_trusted_setup_rust, BYTES_PER_G1, FIELD_ELEMENTS_PER_BLOB, TRUSTED_SETUP_NUM_G1_POINTS,
TRUSTED_SETUP_NUM_G2_POINTS,
};
use kzg::eth::c_bindings::{
Blob, Bytes32, Bytes48, CKZGSettings, CKzgRet, KZGCommitment, KZGProof,
use kzg::eip_4844::load_trusted_setup_rust;

Check warning on line 8 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks3)

unused import: `kzg::eip_4844::load_trusted_setup_rust`

Check warning on line 8 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks3)

unused import: `kzg::eip_4844::load_trusted_setup_rust`
#[cfg(feature = "c_bindings")]
use kzg::{
eip_4844::{
BYTES_PER_G1, FIELD_ELEMENTS_PER_BLOB, TRUSTED_SETUP_NUM_G1_POINTS,
TRUSTED_SETUP_NUM_G2_POINTS,
},
eth::{
self,
c_bindings::{Blob, Bytes32, Bytes48, CKZGSettings, CKzgRet, KZGCommitment, KZGProof},
},
Fr, G1,
};
use kzg::{eth, Fr, G1};

#[cfg(feature = "std")]
#[cfg(all(feature = "std", feature = "c_bindings"))]
use libc::FILE;
#[cfg(feature = "std")]
use std::fs::File;
#[cfg(feature = "std")]
use std::io::Read;

#[cfg(feature = "c_bindings")]
use crate::utils::{handle_ckzg_badargs, kzg_settings_to_c, PRECOMPUTATION_TABLES};

Check failure on line 30 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / benchmarks (ubuntu-latest, arkworks3)

unresolved imports `crate::utils::handle_ckzg_badargs`, `crate::utils::kzg_settings_to_c`

Check failure on line 30 in arkworks3/src/eip_4844.rs

View workflow job for this annotation

GitHub Actions / backend_ci (ubuntu-latest, arkworks3)

unresolved imports `crate::utils::handle_ckzg_badargs`, `crate::utils::kzg_settings_to_c`

#[cfg(feature = "std")]
Expand All @@ -37,6 +46,99 @@ pub fn load_trusted_setup_filename_rust(
load_trusted_setup_rust(&g1_monomial_bytes, &g1_lagrange_bytes, &g2_monomial_bytes)
}

#[cfg(feature = "c_bindings")]
macro_rules! handle_ckzg_badargs {
($x: expr) => {
match $x {
Ok(value) => value,
Err(_) => return kzg::eth::c_bindings::CKzgRet::BadArgs,
}
};
}

#[cfg(feature = "c_bindings")]
fn kzg_settings_to_c(rust_settings: &KZGSettings) -> CKZGSettings {
CKZGSettings {
roots_of_unity: Box::leak(
rust_settings
.fs
.roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
brp_roots_of_unity: Box::leak(
rust_settings
.fs
.brp_roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
reverse_roots_of_unity: Box::leak(
rust_settings
.fs
.reverse_roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g1_values_monomial: Box::leak(
rust_settings
.g1_values_monomial
.iter()
.map(|r| r.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g1_values_lagrange_brp: Box::leak(
rust_settings
.g1_values_lagrange_brp
.iter()
.map(|r| r.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g2_values_monomial: Box::leak(
rust_settings
.g2_values_monomial
.iter()
.map(|r| r.to_blst_p2())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
x_ext_fft_columns: Box::leak(
rust_settings
.x_ext_fft_columns
.iter()
.map(|r| {
Box::leak(
r.iter()
.map(|it| it.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr()
})
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
tables: core::ptr::null_mut(),
wbits: 0,
scratch_size: 0,
}
}

/// # Safety
#[cfg(feature = "c_bindings")]
#[no_mangle]
Expand Down
5 changes: 2 additions & 3 deletions arkworks3/src/eip_7594.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ extern crate alloc;

use kzg::EcBackend;

use kzg::c_bindings_eip7594;

use crate::kzg_proofs::FFTSettings;
use crate::kzg_proofs::KZGSettings;
use crate::kzg_types::ArkFp;
Expand All @@ -26,4 +24,5 @@ impl EcBackend for ArkBackend {
type KZGSettings = KZGSettings;
}

c_bindings_eip7594!(ArkBackend);
#[cfg(feature = "c_bindings")]
kzg::c_bindings_eip7594!(ArkBackend);
97 changes: 1 addition & 96 deletions arkworks3/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
extern crate alloc;

use alloc::boxed::Box;

use kzg::{
eip_4844::PrecomputationTableManager,
eth::{self, c_bindings::CKZGSettings},
};

use crate::kzg_proofs::{FFTSettings as LFFTSettings, KZGSettings as LKZGSettings};
use crate::kzg_proofs::FFTSettings as LFFTSettings;
use crate::kzg_types::{ArkFp, ArkFr, ArkG1, ArkG1Affine};

use super::{Fp, P1};
Expand All @@ -28,17 +26,6 @@ pub struct PolyData {
}
// FIXME: Store just dense poly here

macro_rules! handle_ckzg_badargs {
($x: expr) => {
match $x {
Ok(value) => value,
Err(_) => return kzg::eth::c_bindings::CKzgRet::BadArgs,
}
};
}

pub(crate) use handle_ckzg_badargs;

pub(crate) fn fft_settings_to_rust(
c_settings: *const CKZGSettings,
) -> Result<LFFTSettings, String> {
Expand Down Expand Up @@ -90,88 +77,6 @@ pub(crate) static mut PRECOMPUTATION_TABLES: PrecomputationTableManager<
ArkG1Affine,
> = PrecomputationTableManager::new();

pub(crate) fn kzg_settings_to_c(rust_settings: &LKZGSettings) -> CKZGSettings {
CKZGSettings {
roots_of_unity: Box::leak(
rust_settings
.fs
.roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
brp_roots_of_unity: Box::leak(
rust_settings
.fs
.brp_roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
reverse_roots_of_unity: Box::leak(
rust_settings
.fs
.reverse_roots_of_unity
.iter()
.map(|r| r.to_blst_fr())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g1_values_monomial: Box::leak(
rust_settings
.g1_values_monomial
.iter()
.map(|r| r.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g1_values_lagrange_brp: Box::leak(
rust_settings
.g1_values_lagrange_brp
.iter()
.map(|r| r.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
g2_values_monomial: Box::leak(
rust_settings
.g2_values_monomial
.iter()
.map(|r| r.to_blst_p2())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
x_ext_fft_columns: Box::leak(
rust_settings
.x_ext_fft_columns
.iter()
.map(|r| {
Box::leak(
r.iter()
.map(|it| it.to_blst_p1())
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr()
})
.collect::<Vec<_>>()
.into_boxed_slice(),
)
.as_mut_ptr(),
tables: core::ptr::null_mut(),
wbits: 0,
scratch_size: 0,
}
}

pub fn pc_poly_into_blst_poly(poly: DensePoly<ark_bls12_381::Fr>) -> PolyData {
let mut bls_pol: Vec<ArkFr> = { Vec::new() };
for x in poly.coeffs {
Expand Down
1 change: 0 additions & 1 deletion blst/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ default = [
"std",
"rand",
"bgmw",
"c_bindings",
]
std = [
"hex/std",
Expand Down
Loading

0 comments on commit 500911c

Please sign in to comment.