Skip to content

Commit 96d7602

Browse files
committed
chore: clippy
1 parent 8cde032 commit 96d7602

24 files changed

+139
-131
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,6 @@ kzg_multi_open = { package = "crate_crypto_kzg_multi_open_fk20", version = "0.3.
3535
c_peerdas_kzg = { version = "0.3.0", path = "bindings/c" }
3636
hex = "0.4.3"
3737
rayon = "1.10.0"
38+
39+
[profile.release]
40+
lto = true

bindings/c/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ fn main() {
2222
.with_language(cbindgen::Language::C)
2323
.generate()
2424
.unwrap()
25-
.write_to_file(&output_file);
25+
.write_to_file(output_file);
2626
}

bindings/c/src/blob_to_kzg_commitment.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(crate) fn _blob_to_kzg_commitment(
88
blob: *const u8,
99
out: *mut u8,
1010
) -> Result<(), CResult> {
11-
assert!(ctx.is_null() == false, "context pointer is null");
11+
assert!(!ctx.is_null(), "context pointer is null");
1212

1313
// Dereference the input pointers
1414
//
@@ -22,7 +22,7 @@ pub(crate) fn _blob_to_kzg_commitment(
2222
.map_err(|err| CResult::with_error(&format!("{:?}", err)))?;
2323

2424
assert!(
25-
commitment.len() == BYTES_PER_COMMITMENT as usize,
25+
commitment.len() == BYTES_PER_COMMITMENT,
2626
"This is a library bug. commitment.len() != BYTES_PER_COMMITMENT, {} != {}",
2727
commitment.len(),
2828
BYTES_PER_COMMITMENT

bindings/c/src/compute_cells_and_kzg_proofs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub(crate) fn _compute_cells_and_kzg_proofs(
88
out_cells: *mut *mut u8,
99
out_proofs: *mut *mut u8,
1010
) -> Result<(), CResult> {
11-
assert!(ctx.is_null() == false, "context pointer is null");
11+
assert!(!ctx.is_null(), "context pointer is null");
1212

1313
// Pointer checks
1414
//

bindings/c/src/lib.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,16 @@ pub struct PeerDASContext {
5252
verifier_ctx: eip7594_VerifierContext,
5353
}
5454

55-
impl PeerDASContext {
56-
pub fn new() -> Self {
55+
impl Default for PeerDASContext {
56+
fn default() -> Self {
5757
PeerDASContext {
5858
prover_ctx: eip7594_ProverContext::new(),
5959
verifier_ctx: eip7594_VerifierContext::new(),
6060
}
6161
}
62+
}
6263

64+
impl PeerDASContext {
6365
pub fn prover_ctx(&self) -> &eip7594_ProverContext {
6466
&self.prover_ctx
6567
}
@@ -77,7 +79,7 @@ impl PeerDASContext {
7779
/// by calling `peerdas_context_free`.
7880
#[no_mangle]
7981
pub extern "C" fn peerdas_context_new() -> *mut PeerDASContext {
80-
let ctx = Box::new(PeerDASContext::new());
82+
let ctx = Box::<PeerDASContext>::default();
8183
Box::into_raw(ctx)
8284
}
8385

@@ -94,6 +96,7 @@ pub extern "C" fn peerdas_context_new() -> *mut PeerDASContext {
9496
///
9597
/// - Since the `ctx` is created in Rust, we can only get undefined behavior, if the caller passes in
9698
/// a pointer that was not created by `peerdas_context_new`.
99+
#[allow(clippy::not_unsafe_ptr_arg_deref)]
97100
#[no_mangle]
98101
pub extern "C" fn peerdas_context_free(ctx: *mut PeerDASContext) {
99102
if ctx.is_null() {
@@ -156,7 +159,7 @@ impl CResult {
156159
/// - The caller must ensure that the pointer is valid. If the pointer is null, this method will return early.
157160
/// - The caller should also avoid a double-free by setting the pointer to null after calling this method.
158161
#[no_mangle]
159-
pub extern "C" fn free_error_message(c_message: *mut std::os::raw::c_char) {
162+
pub unsafe extern "C" fn free_error_message(c_message: *mut std::os::raw::c_char) {
160163
// check if the pointer is null
161164
if c_message.is_null() {
162165
return;
@@ -190,7 +193,7 @@ pub extern "C" fn blob_to_kzg_commitment(
190193
) -> CResult {
191194
match _blob_to_kzg_commitment(ctx, blob, out) {
192195
Ok(_) => CResult::with_ok(),
193-
Err(err) => return err,
196+
Err(err) => err,
194197
}
195198
}
196199

@@ -220,8 +223,8 @@ pub extern "C" fn compute_cells_and_kzg_proofs(
220223
out_proofs: *mut *mut u8,
221224
) -> CResult {
222225
match _compute_cells_and_kzg_proofs(ctx, blob, out_cells, out_proofs) {
223-
Ok(_) => return CResult::with_ok(),
224-
Err(err) => return err,
226+
Ok(_) => CResult::with_ok(),
227+
Err(err) => err,
225228
}
226229
}
227230

@@ -250,8 +253,8 @@ pub extern "C" fn verify_cell_kzg_proof(
250253
verified: *mut bool,
251254
) -> CResult {
252255
match _verify_cell_kzg_proof(ctx, cell, commitment, cell_id, proof, verified) {
253-
Ok(_) => return CResult::with_ok(),
254-
Err(err) => return err,
256+
Ok(_) => CResult::with_ok(),
257+
Err(err) => err,
255258
}
256259
}
257260

@@ -330,8 +333,8 @@ pub extern "C" fn verify_cell_kzg_proof_batch(
330333
proofs,
331334
verified,
332335
) {
333-
Ok(_) => return CResult::with_ok(),
334-
Err(err) => return err,
336+
Ok(_) => CResult::with_ok(),
337+
Err(err) => err,
335338
}
336339
}
337340

bindings/c/src/pointer_utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub(crate) fn ptr_ptr_to_vec_slice_const<'a>(
3636
let mut result: Vec<&[u8]> = Vec::with_capacity(outer_len);
3737

3838
// Convert each inner pointer to a slice of u8
39-
for ptr in vec_slice.into_iter() {
39+
for ptr in vec_slice.iter() {
4040
result.push(create_slice_view(*ptr, inner_len));
4141
}
4242

@@ -57,7 +57,7 @@ pub(crate) fn write_to_2d_slice<T: Copy, const N: usize>(
5757
) {
5858
let out_cells = ptr_ptr_to_slice_slice_mut(ptr, N);
5959

60-
for (out_cell, result) in out_cells.into_iter().zip(data) {
60+
for (out_cell, result) in out_cells.iter_mut().zip(data) {
6161
write_to_slice(*out_cell, result.as_ref());
6262
}
6363
}

bindings/c/src/recover_cells_and_kzg_proofs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn _recover_all_cells_and_proofs(
1313
out_cells: *mut *mut u8,
1414
out_proofs: *mut *mut u8,
1515
) -> Result<(), CResult> {
16-
assert!(ctx.is_null() == false, "context pointer is null");
16+
assert!(!ctx.is_null(), "context pointer is null");
1717

1818
// Dereference the input pointers
1919
//

bindings/c/src/verify_cells_and_kzg_proofs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn _verify_cell_kzg_proof(
1313
proof: *const u8,
1414
verified: *mut bool,
1515
) -> Result<(), CResult> {
16-
assert!(ctx.is_null() == false, "context pointer is null");
16+
assert!(!ctx.is_null(), "context pointer is null");
1717

1818
// Dereference the input pointers
1919
//

bindings/c/src/verify_cells_and_kzg_proofs_batch.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::pointer_utils::{create_slice_view, deref_const, deref_mut, ptr_ptr_to
22
use crate::{verification_result_to_bool_cresult, CResult, PeerDASContext};
33
use eip7594::constants::{BYTES_PER_CELL, BYTES_PER_COMMITMENT};
44

5+
#[allow(clippy::too_many_arguments)]
56
pub(crate) fn _verify_cell_kzg_proof_batch(
67
ctx: *const PeerDASContext,
78

@@ -22,7 +23,7 @@ pub(crate) fn _verify_cell_kzg_proof_batch(
2223

2324
verified: *mut bool,
2425
) -> Result<(), CResult> {
25-
assert!(ctx.is_null() == false, "context pointer is null");
26+
assert!(!ctx.is_null(), "context pointer is null");
2627

2728
// When the arrays are empty in the caller language, the pointer might be null
2829
// This was witnessed in csharp.

bindings/java/rust_code/src/errors.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#[derive(Debug)]
22
pub enum Error {
33
Jni(jni::errors::Error),
4-
ProverError(eip7594::prover::ProverError),
5-
VerifierError(eip7594::verifier::VerifierError),
4+
Prover(eip7594::prover::ProverError),
5+
Verifier(eip7594::verifier::VerifierError),
66
}
77

88
impl From<jni::errors::Error> for Error {
@@ -13,6 +13,6 @@ impl From<jni::errors::Error> for Error {
1313

1414
impl From<eip7594::prover::ProverError> for Error {
1515
fn from(err: eip7594::prover::ProverError) -> Self {
16-
Error::ProverError(err)
16+
Error::Prover(err)
1717
}
1818
}

bindings/java/rust_code/src/lib.rs

+23-33
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ mod errors;
99
use errors::Error;
1010

1111
#[no_mangle]
12-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_peerDASContextNew(
12+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_peerDASContextNew(
1313
_env: JNIEnv,
1414
_class: JClass,
1515
) -> jlong {
1616
c_peerdas_kzg::peerdas_context_new() as jlong
1717
}
1818

1919
#[no_mangle]
20-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_peerDASContextDestroy(
20+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_peerDASContextDestroy(
2121
_env: JNIEnv,
2222
_class: JClass,
2323
ctx_ptr: jlong,
@@ -26,20 +26,18 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_peerDASCo
2626
}
2727

2828
#[no_mangle]
29-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_computeCellsAndKZGProofs<
30-
'local,
31-
>(
29+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_computeCellsAndKZGProofs<'local>(
3230
mut env: JNIEnv<'local>,
3331
_class: JClass,
3432
ctx_ptr: jlong,
3533
blob: JByteArray<'local>,
3634
) -> JObject<'local> {
37-
let ctx = &*(ctx_ptr as *const PeerDASContext);
35+
let ctx = unsafe { &*(ctx_ptr as *const PeerDASContext) };
3836
match compute_cells_and_kzg_proofs(&mut env, ctx, blob) {
3937
Ok(cells_and_proofs) => cells_and_proofs,
4038
Err(err) => {
4139
throw_on_error(&mut env, err, "computeCellsAndKZGProofs");
42-
return JObject::default();
40+
JObject::default()
4341
}
4442
}
4543
}
@@ -54,20 +52,18 @@ fn compute_cells_and_kzg_proofs<'local>(
5452
}
5553

5654
#[no_mangle]
57-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_blobToKZGCommitment<
58-
'local,
59-
>(
55+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_blobToKZGCommitment<'local>(
6056
mut env: JNIEnv<'local>,
6157
_class: JClass,
6258
ctx_ptr: jlong,
6359
blob: JByteArray<'local>,
6460
) -> JByteArray<'local> {
65-
let ctx = &*(ctx_ptr as *const PeerDASContext);
61+
let ctx = unsafe { &*(ctx_ptr as *const PeerDASContext) };
6662
match blob_to_kzg_commitment(&mut env, ctx, blob) {
6763
Ok(commitment) => commitment,
6864
Err(err) => {
6965
throw_on_error(&mut env, err, "blobToKZGCommitment");
70-
return JByteArray::default();
66+
JByteArray::default()
7167
}
7268
}
7369
}
@@ -82,9 +78,7 @@ fn blob_to_kzg_commitment<'local>(
8278
}
8379

8480
#[no_mangle]
85-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCellKZGProof<
86-
'local,
87-
>(
81+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCellKZGProof<'local>(
8882
mut env: JNIEnv<'local>,
8983
_class: JClass,
9084
ctx_ptr: jlong,
@@ -93,13 +87,13 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCel
9387
cell: JByteArray<'local>,
9488
proof_bytes: JByteArray<'local>,
9589
) -> jboolean {
96-
let ctx = &*(ctx_ptr as *const PeerDASContext);
90+
let ctx = unsafe { &*(ctx_ptr as *const PeerDASContext) };
9791

9892
match verify_cell_kzg_proof(&mut env, ctx, commitment_bytes, cell_id, cell, proof_bytes) {
9993
Ok(result) => result,
10094
Err(err) => {
10195
throw_on_error(&mut env, err, "verifyCellKZGProof");
102-
return jboolean::default();
96+
jboolean::default()
10397
}
10498
}
10599
}
@@ -122,14 +116,12 @@ fn verify_cell_kzg_proof(
122116
{
123117
Ok(_) => Ok(jboolean::from(true)),
124118
Err(VerifierError::InvalidProof) => Ok(jboolean::from(false)),
125-
Err(err) => Err(Error::VerifierError(err)),
119+
Err(err) => Err(Error::Verifier(err)),
126120
}
127121
}
128122

129123
#[no_mangle]
130-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCellKZGProofBatch<
131-
'local,
132-
>(
124+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCellKZGProofBatch<'local>(
133125
mut env: JNIEnv<'local>,
134126
_class: JClass,
135127
ctx_ptr: jlong,
@@ -139,7 +131,7 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCel
139131
cells: JObjectArray<'local>,
140132
proofs: JObjectArray<'local>,
141133
) -> jboolean {
142-
let ctx = &*(ctx_ptr as *const PeerDASContext);
134+
let ctx = unsafe { &*(ctx_ptr as *const PeerDASContext) };
143135

144136
match verify_cell_kzg_proof_batch(
145137
&mut env,
@@ -153,7 +145,7 @@ pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_verifyCel
153145
Ok(result) => result,
154146
Err(err) => {
155147
throw_on_error(&mut env, err, "verifyCellKZGProofBatch");
156-
return jboolean::default();
148+
jboolean::default()
157149
}
158150
}
159151
}
@@ -181,27 +173,25 @@ fn verify_cell_kzg_proof_batch<'local>(
181173
) {
182174
Ok(_) => Ok(jboolean::from(true)),
183175
Err(VerifierError::InvalidProof) => Ok(jboolean::from(false)),
184-
Err(err) => Err(Error::VerifierError(err)),
176+
Err(err) => Err(Error::Verifier(err)),
185177
}
186178
}
187179

188180
#[no_mangle]
189-
pub unsafe extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_recoverCellsAndProof<
190-
'local,
191-
>(
181+
pub extern "system" fn Java_ethereum_cryptography_LibPeerDASKZG_recoverCellsAndProof<'local>(
192182
mut env: JNIEnv<'local>,
193183
_class: JClass,
194184
ctx_ptr: jlong,
195185
cell_ids: JLongArray,
196186
cells: JObjectArray<'local>,
197187
) -> JObject<'local> {
198-
let ctx = &*(ctx_ptr as *const PeerDASContext);
188+
let ctx = unsafe { &*(ctx_ptr as *const PeerDASContext) };
199189

200190
match recover_cells_and_kzg_proofs(&mut env, ctx, cell_ids, cells) {
201191
Ok(cells_and_proofs) => cells_and_proofs,
202192
Err(err) => {
203193
throw_on_error(&mut env, err, "recoverCellsAndProof");
204-
return JObject::default();
194+
JObject::default()
205195
}
206196
}
207197
}
@@ -288,7 +278,7 @@ fn cells_and_proofs_to_jobject<'local>(
288278
env.new_byte_array(0)?,
289279
)?;
290280

291-
for (i, cell) in cells.into_iter().enumerate() {
281+
for (i, cell) in cells.iter().enumerate() {
292282
let cell_array = env.byte_array_from_slice(cell.as_ref())?;
293283
env.set_object_array_element(&cells_array, i as i32, cell_array)?;
294284
}
@@ -300,7 +290,7 @@ fn cells_and_proofs_to_jobject<'local>(
300290
env.new_byte_array(0)?,
301291
)?;
302292

303-
for (i, proof) in proofs.into_iter().enumerate() {
293+
for (i, proof) in proofs.iter().enumerate() {
304294
let proof_array = env.byte_array_from_slice(proof.as_ref())?;
305295
env.set_object_array_element(&proofs_array, i as i32, proof_array)?;
306296
}
@@ -319,8 +309,8 @@ fn cells_and_proofs_to_jobject<'local>(
319309
fn throw_on_error(env: &mut JNIEnv, err: Error, func_name: &'static str) {
320310
let reason = match err {
321311
Error::Jni(err) => format!("{:?}", err),
322-
Error::ProverError(err) => format!("{:?}", err),
323-
Error::VerifierError(err) => format!("{:?}", err),
312+
Error::Prover(err) => format!("{:?}", err),
313+
Error::Verifier(err) => format!("{:?}", err),
324314
};
325315
let msg = format!(
326316
"function {} has thrown an exception, with reason: {}",

bindings/nim/rust_code/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn main() {
2222
.with_crate(path_to_c_crate)
2323
.generate()
2424
.unwrap()
25-
.write_to_file(&output_file);
25+
.write_to_file(output_file);
2626
}
2727

2828
fn path_to_bindings_folder() -> PathBuf {

0 commit comments

Comments
 (0)