Skip to content

Commit b447abc

Browse files
ArtiomTrsauliusgrigaitis
authored andcommitted
Bump c-kzg-4844 commit & update bindings
1 parent 49e6c90 commit b447abc

File tree

15 files changed

+200
-89
lines changed

15 files changed

+200
-89
lines changed

.github/workflows/backend-benchmarks.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: benchmarks
22
on: [push, pull_request, workflow_dispatch]
33
env:
4-
C_KZG_4844_GIT_HASH: 'dffa18ee350aeef38f749ffad24a27c1645fb4f8'
4+
C_KZG_4844_GIT_HASH: '00ae727c21a346ba0bd027eca6e378da0def988f'
55

66
jobs:
77
benchmarks:

.github/workflows/backend-tests.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: tests
22
on: [push, pull_request, workflow_dispatch]
33
env:
4-
C_KZG_4844_GIT_HASH: "dffa18ee350aeef38f749ffad24a27c1645fb4f8"
4+
C_KZG_4844_GIT_HASH: '00ae727c21a346ba0bd027eca6e378da0def988f'
55

66
jobs:
77
kzg_ci:
@@ -133,6 +133,15 @@ jobs:
133133
with:
134134
dotnet-version: "8.x.x"
135135

136+
- name: "install clang-format"
137+
if: matrix.os == 'ubuntu-latest'
138+
run: |
139+
sudo DEBIAN_FRONTEND='noninteractive' apt-get install \
140+
--no-install-recommends -yq \
141+
clang-format-20
142+
sudo update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-20 200
143+
sudo update-alternatives --set clang-format /usr/bin/clang-format-20
144+
136145
# Install constantine backend deps
137146
- name: "constantine - install deps"
138147
if: matrix.backend == 'constantine' && matrix.os == 'ubuntu-latest'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
workflow_dispatch:
88

99
env:
10-
C_KZG_4844_GIT_HASH: 'dffa18ee350aeef38f749ffad24a27c1645fb4f8'
10+
C_KZG_4844_GIT_HASH: '00ae727c21a346ba0bd027eca6e378da0def988f'
1111

1212
jobs:
1313
release-build:

arkworks3/rust.patch

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
From bfa93fbf74ad292e6d0cda71a32574ed54bedf04 Mon Sep 17 00:00:00 2001
1+
From 4827bc7aef00721206d42b2615b5340344e488b3 Mon Sep 17 00:00:00 2001
22
From: sirse <[email protected]>
3-
Date: Tue, 25 Mar 2025 23:34:09 +0200
3+
Date: Thu, 16 Oct 2025 14:51:36 +0300
44
Subject: [PATCH] Patch rust bindings
55

66
---
77
Cargo.toml | 1 +
8-
bindings/rust/build.rs | 51 ++++--------------------------------------
9-
2 files changed, 5 insertions(+), 47 deletions(-)
8+
bindings/rust/build.rs | 50 +++---------------------------------------
9+
2 files changed, 4 insertions(+), 47 deletions(-)
1010

1111
diff --git a/Cargo.toml b/Cargo.toml
12-
index 4c3fea5..9678f0d 100644
12+
index 75784d3..d7e4e94 100644
1313
--- a/Cargo.toml
1414
+++ b/Cargo.toml
1515
@@ -1,3 +1,4 @@
1616
+[workspace]
1717
[package]
1818
name = "c-kzg"
19-
version = "2.1.0"
19+
version = "2.1.5"
2020
diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs
21-
index 2f4170a..f1d3f25 100644
21+
index 2f4170a..14b0963 100644
2222
--- a/bindings/rust/build.rs
2323
+++ b/bindings/rust/build.rs
24-
@@ -3,53 +3,10 @@ use std::{env, path::PathBuf};
24+
@@ -3,53 +3,9 @@ use std::{env, path::PathBuf};
2525
fn main() {
2626
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
2727

@@ -73,7 +73,6 @@ index 2f4170a..f1d3f25 100644
7373
- // Finally, tell cargo this provides ckzg/ckzg_min
7474
- println!("cargo:rustc-link-lib=ckzg");
7575
+ let rust_kzg_target_dir = root_dir.join("lib");
76-
+
7776
+ println!("cargo:rustc-link-search={}", rust_kzg_target_dir.display());
7877
+ println!("cargo:rustc-link-arg=-lrust_kzg_arkworks3");
7978
}

arkworks4/rust.patch

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
From bfa93fbf74ad292e6d0cda71a32574ed54bedf04 Mon Sep 17 00:00:00 2001
1+
From 4827bc7aef00721206d42b2615b5340344e488b3 Mon Sep 17 00:00:00 2001
22
From: sirse <[email protected]>
3-
Date: Tue, 25 Mar 2025 23:34:09 +0200
3+
Date: Thu, 16 Oct 2025 14:51:36 +0300
44
Subject: [PATCH] Patch rust bindings
55

66
---
77
Cargo.toml | 1 +
8-
bindings/rust/build.rs | 51 ++++--------------------------------------
9-
2 files changed, 5 insertions(+), 47 deletions(-)
8+
bindings/rust/build.rs | 50 +++---------------------------------------
9+
2 files changed, 4 insertions(+), 47 deletions(-)
1010

1111
diff --git a/Cargo.toml b/Cargo.toml
12-
index 4c3fea5..9678f0d 100644
12+
index 75784d3..d7e4e94 100644
1313
--- a/Cargo.toml
1414
+++ b/Cargo.toml
1515
@@ -1,3 +1,4 @@
1616
+[workspace]
1717
[package]
1818
name = "c-kzg"
19-
version = "2.1.0"
19+
version = "2.1.5"
2020
diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs
21-
index 2f4170a..f1d3f25 100644
21+
index 2f4170a..14b0963 100644
2222
--- a/bindings/rust/build.rs
2323
+++ b/bindings/rust/build.rs
24-
@@ -3,53 +3,10 @@ use std::{env, path::PathBuf};
24+
@@ -3,53 +3,9 @@ use std::{env, path::PathBuf};
2525
fn main() {
2626
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
2727

@@ -73,7 +73,6 @@ index 2f4170a..f1d3f25 100644
7373
- // Finally, tell cargo this provides ckzg/ckzg_min
7474
- println!("cargo:rustc-link-lib=ckzg");
7575
+ let rust_kzg_target_dir = root_dir.join("lib");
76-
+
7776
+ println!("cargo:rustc-link-search={}", rust_kzg_target_dir.display());
7877
+ println!("cargo:rustc-link-arg=-lrust_kzg_arkworks4");
7978
}

arkworks5/rust.patch

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
From bfa93fbf74ad292e6d0cda71a32574ed54bedf04 Mon Sep 17 00:00:00 2001
1+
From 4827bc7aef00721206d42b2615b5340344e488b3 Mon Sep 17 00:00:00 2001
22
From: sirse <[email protected]>
3-
Date: Tue, 25 Mar 2025 23:34:09 +0200
3+
Date: Thu, 16 Oct 2025 14:51:36 +0300
44
Subject: [PATCH] Patch rust bindings
55

66
---
77
Cargo.toml | 1 +
8-
bindings/rust/build.rs | 51 ++++--------------------------------------
9-
2 files changed, 5 insertions(+), 47 deletions(-)
8+
bindings/rust/build.rs | 50 +++---------------------------------------
9+
2 files changed, 4 insertions(+), 47 deletions(-)
1010

1111
diff --git a/Cargo.toml b/Cargo.toml
12-
index 4c3fea5..9678f0d 100644
12+
index 75784d3..d7e4e94 100644
1313
--- a/Cargo.toml
1414
+++ b/Cargo.toml
1515
@@ -1,3 +1,4 @@
1616
+[workspace]
1717
[package]
1818
name = "c-kzg"
19-
version = "2.1.0"
19+
version = "2.1.5"
2020
diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs
21-
index 2f4170a..f1d3f25 100644
21+
index 2f4170a..14b0963 100644
2222
--- a/bindings/rust/build.rs
2323
+++ b/bindings/rust/build.rs
24-
@@ -3,53 +3,10 @@ use std::{env, path::PathBuf};
24+
@@ -3,53 +3,9 @@ use std::{env, path::PathBuf};
2525
fn main() {
2626
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
2727

@@ -73,7 +73,6 @@ index 2f4170a..f1d3f25 100644
7373
- // Finally, tell cargo this provides ckzg/ckzg_min
7474
- println!("cargo:rustc-link-lib=ckzg");
7575
+ let rust_kzg_target_dir = root_dir.join("lib");
76-
+
7776
+ println!("cargo:rustc-link-search={}", rust_kzg_target_dir.display());
7877
+ println!("cargo:rustc-link-arg=-lrust_kzg_arkworks5");
7978
}

blst/rust.patch

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
From bfa93fbf74ad292e6d0cda71a32574ed54bedf04 Mon Sep 17 00:00:00 2001
1+
From 4827bc7aef00721206d42b2615b5340344e488b3 Mon Sep 17 00:00:00 2001
22
From: sirse <[email protected]>
3-
Date: Tue, 25 Mar 2025 23:34:09 +0200
3+
Date: Thu, 16 Oct 2025 14:51:36 +0300
44
Subject: [PATCH] Patch rust bindings
55

66
---
77
Cargo.toml | 1 +
8-
bindings/rust/build.rs | 51 ++++--------------------------------------
9-
2 files changed, 5 insertions(+), 47 deletions(-)
8+
bindings/rust/build.rs | 50 +++---------------------------------------
9+
2 files changed, 4 insertions(+), 47 deletions(-)
1010

1111
diff --git a/Cargo.toml b/Cargo.toml
12-
index 4c3fea5..9678f0d 100644
12+
index 75784d3..d7e4e94 100644
1313
--- a/Cargo.toml
1414
+++ b/Cargo.toml
1515
@@ -1,3 +1,4 @@
1616
+[workspace]
1717
[package]
1818
name = "c-kzg"
19-
version = "2.1.0"
19+
version = "2.1.5"
2020
diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs
21-
index 2f4170a..f1d3f25 100644
21+
index 2f4170a..14b0963 100644
2222
--- a/bindings/rust/build.rs
2323
+++ b/bindings/rust/build.rs
24-
@@ -3,53 +3,10 @@ use std::{env, path::PathBuf};
24+
@@ -3,53 +3,9 @@ use std::{env, path::PathBuf};
2525
fn main() {
2626
let root_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
2727

@@ -73,7 +73,6 @@ index 2f4170a..f1d3f25 100644
7373
- // Finally, tell cargo this provides ckzg/ckzg_min
7474
- println!("cargo:rustc-link-lib=ckzg");
7575
+ let rust_kzg_target_dir = root_dir.join("lib");
76-
+
7776
+ println!("cargo:rustc-link-search={}", rust_kzg_target_dir.display());
7877
+ println!("cargo:rustc-link-arg=-lrust_kzg_blst");
7978
}

blst/src/eip_4844.rs

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ extern crate alloc;
33
#[cfg(feature = "c_bindings")]
44
use alloc::{boxed::Box, vec::Vec};
55
#[cfg(feature = "c_bindings")]
6+
use blst::{blst_fr, blst_p1};
7+
#[cfg(feature = "c_bindings")]
68
use core::ptr;
79
use kzg::eip_4844::load_trusted_setup_rust;
810
#[cfg(feature = "c_bindings")]
@@ -28,7 +30,11 @@ use std::io::Read;
2830
use kzg::eip_4844::load_trusted_setup_string;
2931

3032
#[cfg(feature = "c_bindings")]
31-
use crate::{types::kzg_settings::FsKZGSettings, utils::PRECOMPUTATION_TABLES};
33+
use crate::{
34+
handle_ckzg_badargs,
35+
types::{fr::FsFr, g1::FsG1, kzg_settings::FsKZGSettings},
36+
utils::PRECOMPUTATION_TABLES,
37+
};
3238

3339
#[cfg(feature = "c_bindings")]
3440
fn kzg_settings_to_c(rust_settings: &FsKZGSettings) -> CKZGSettings {
@@ -137,16 +143,6 @@ fn kzg_settings_to_c(rust_settings: &FsKZGSettings) -> CKZGSettings {
137143
}
138144
}
139145

140-
#[cfg(feature = "c_bindings")]
141-
macro_rules! handle_ckzg_badargs {
142-
($x: expr) => {
143-
match $x {
144-
Ok(value) => value,
145-
Err(_) => return kzg::eth::c_bindings::CKzgRet::BadArgs,
146-
}
147-
};
148-
}
149-
150146
#[cfg(feature = "std")]
151147
pub fn load_trusted_setup_filename_rust(
152148
filepath: &str,
@@ -498,3 +494,37 @@ pub unsafe extern "C" fn compute_kzg_proof(
498494
(*y_out).bytes = fry_tmp.to_bytes();
499495
CKzgRet::Ok
500496
}
497+
498+
/// # Safety
499+
#[cfg(feature = "c_bindings")]
500+
#[no_mangle]
501+
pub unsafe extern "C" fn compute_challenge(
502+
eval_challenge_out: *mut blst_fr,
503+
blob: *const Blob,
504+
commitment: *const blst_p1,
505+
) {
506+
use kzg::eip_4844::{bytes_to_blob, compute_challenge_rust};
507+
508+
let output = compute_challenge_rust::<FsFr, FsG1>(
509+
&bytes_to_blob(&(*blob).bytes).unwrap(),
510+
&FsG1(*commitment),
511+
);
512+
513+
*eval_challenge_out = output.0
514+
}
515+
516+
/// # Safety
517+
#[cfg(feature = "c_bindings")]
518+
#[no_mangle]
519+
pub unsafe extern "C" fn bytes_to_kzg_commitment(out: *mut blst_p1, b: *const Bytes48) -> CKzgRet {
520+
*out = handle_ckzg_badargs!(FsG1::from_bytes(&(*b).bytes)).0;
521+
522+
CKzgRet::Ok
523+
}
524+
525+
/// # Safety
526+
#[cfg(feature = "c_bindings")]
527+
#[no_mangle]
528+
pub unsafe extern "C" fn bytes_from_bls_field(out: *mut Bytes32, inp: *const blst_fr) {
529+
(*out).bytes = FsFr(*inp).to_bytes();
530+
}

blst/src/eip_7594.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,69 @@ impl EcBackend for BlstBackend {
2929

3030
#[cfg(feature = "c_bindings")]
3131
kzg::c_bindings_eip7594!(BlstBackend);
32+
33+
#[cfg(feature = "c_bindings")]
34+
#[no_mangle]
35+
pub unsafe extern "C" fn compute_verify_cell_kzg_proof_batch_challenge(
36+
challenge_out: *mut blst::blst_fr,
37+
commitment_bytes: *const kzg::eth::c_bindings::Bytes48,
38+
num_commitments: u64,
39+
commitment_indices: *const u64,
40+
cell_indices: *const u64,
41+
cells: *const kzg::eth::c_bindings::Cell,
42+
proofs_bytes: *const kzg::eth::c_bindings::Bytes48,
43+
num_cells: u64,
44+
) -> kzg::eth::c_bindings::CKzgRet {
45+
use crate::handle_ckzg_badargs;
46+
use kzg::{eip_4844::BYTES_PER_FIELD_ELEMENT, Fr, G1};
47+
48+
*challenge_out = blst::blst_fr::default();
49+
50+
let commitment_bytes =
51+
unsafe { core::slice::from_raw_parts(commitment_bytes, num_commitments as usize) };
52+
let commitments = handle_ckzg_badargs!(commitment_bytes
53+
.iter()
54+
.map(|v| FsG1::from_bytes(&v.bytes))
55+
.collect::<Result<Vec<_>, _>>());
56+
57+
let commitment_indices =
58+
unsafe { core::slice::from_raw_parts(commitment_indices, num_cells as usize) };
59+
let commitment_indices = commitment_indices
60+
.iter()
61+
.map(|v| *v as usize)
62+
.collect::<Vec<_>>();
63+
64+
let cell_indices = unsafe { core::slice::from_raw_parts(cell_indices, num_cells as usize) };
65+
let cell_indices = cell_indices.iter().map(|c| *c as usize).collect::<Vec<_>>();
66+
67+
let cells = unsafe { core::slice::from_raw_parts(cells, num_cells as usize) };
68+
let cells = handle_ckzg_badargs!(cells
69+
.iter()
70+
.flat_map(|c| c
71+
.bytes
72+
.chunks(BYTES_PER_FIELD_ELEMENT)
73+
.map(|bytes| FsFr::from_bytes(&bytes)))
74+
.collect::<Result<Vec<_>, _>>());
75+
76+
let proofs_bytes = unsafe { core::slice::from_raw_parts(proofs_bytes, num_cells as usize) };
77+
let proofs = handle_ckzg_badargs!(proofs_bytes
78+
.iter()
79+
.map(|b| FsG1::from_bytes(&b.bytes))
80+
.collect::<Result<Vec<_>, _>>());
81+
82+
let challenge = handle_ckzg_badargs!(
83+
<FsKZGSettings as kzg::DAS<BlstBackend>>::compute_verify_cell_kzg_proof_batch_challenge(
84+
kzg::eth::FIELD_ELEMENTS_PER_CELL,
85+
&commitments,
86+
&commitment_indices,
87+
&cell_indices,
88+
&cells,
89+
&proofs,
90+
kzg::eth::FIELD_ELEMENTS_PER_BLOB
91+
)
92+
);
93+
94+
*challenge_out = challenge.0;
95+
96+
kzg::eth::c_bindings::CKzgRet::Ok
97+
}

blst/src/utils.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,14 @@ pub(crate) static mut PRECOMPUTATION_TABLES: PrecomputationTableManager<
4343
FsG1Affine,
4444
FsG1ProjAddAffine,
4545
> = PrecomputationTableManager::new();
46+
47+
#[cfg(feature = "c_bindings")]
48+
#[macro_export]
49+
macro_rules! handle_ckzg_badargs {
50+
($x: expr) => {
51+
match $x {
52+
Ok(value) => value,
53+
Err(_) => return kzg::eth::c_bindings::CKzgRet::BadArgs,
54+
}
55+
};
56+
}

0 commit comments

Comments
 (0)