From 8298b6a8f7666a5c2164b6af841126172532713f Mon Sep 17 00:00:00 2001 From: Kevaundray Wedderburn Date: Wed, 9 Oct 2024 15:48:29 +0100 Subject: [PATCH] lint --- bindings/java/rust_code/src/lib.rs | 28 +++++++++++++------------- bindings/java/rust_code/src/parsers.rs | 6 +++--- bindings/java/rust_code/src/utils.rs | 24 +++++++++------------- 3 files changed, 27 insertions(+), 31 deletions(-) diff --git a/bindings/java/rust_code/src/lib.rs b/bindings/java/rust_code/src/lib.rs index 27c1224..6b54a0f 100644 --- a/bindings/java/rust_code/src/lib.rs +++ b/bindings/java/rust_code/src/lib.rs @@ -35,8 +35,9 @@ use verkle_trie::proof::{ExtPresent, VerificationHint, VerkleProof}; pub static CONFIG: Lazy = Lazy::new(ffi_interface::Context::default); /// Commit receives a list of 32 byte scalars and returns a 32 byte scalar -/// Scalar is actually the map_to_field(commitment) because we want to reuse the commitment in parent node. -/// This is ported from rust-verkle. +/// +/// Scalar is actually the map_to_field(commitment) because we want to +/// reuse the commitment in parent node. This is ported from rust-verkle. #[no_mangle] pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_commit<'local>( mut env: JNIEnv<'local>, @@ -351,17 +352,17 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR } let formatted_commitments = - match jobjectarray_to_vec(&mut env, &commitments_by_path, |b| bytes32_to_element(b)) { + match jobjectarray_to_vec(&mut env, &commitments_by_path, bytes32_to_element) { Some(vec) => vec, None => return false, }; - let formatted_cl = match jobjectarray_to_vec(&mut env, &cl, |b| bytes32_to_element(b)) { + let formatted_cl = match jobjectarray_to_vec(&mut env, &cl, bytes32_to_element) { Some(vec) => vec, None => return false, }; - let formatted_cr = match jobjectarray_to_vec(&mut env, &cr, |b| bytes32_to_element(b)) { + let formatted_cr = match jobjectarray_to_vec(&mut env, &cr, bytes32_to_element) { Some(vec) => vec, None => return false, }; @@ -393,7 +394,7 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR R_vec: formatted_cr, a: scalar_final_evaluation, }, - g_x_comm: g_x_comm, + g_x_comm, }; let depths_bytes = match env.convert_byte_array(depths_extension_present_stems) { @@ -402,7 +403,7 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR }; let (formatted_extension_present, depths): (Vec, Vec) = depths_bytes .iter() - .map(|&byte| byte_to_depth_extension_present(byte as u8)) + .map(|&byte| byte_to_depth_extension_present(byte)) .unzip(); let formatted_other_stems = match convert_to_btree_set(&mut env, &other_stems) { @@ -412,7 +413,7 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR let verkle_proof = VerkleProof { verification_hint: VerificationHint { - depths: depths, + depths, extension_present: formatted_extension_present, diff_stem_no_proof: formatted_other_stems, }, @@ -420,12 +421,11 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR proof, }; - let prestate_root_bytes = match convert_byte_array_to_fixed_array(&env, prestate_root) - .and_then(|bytes| bytes32_to_element(bytes)) - { - Some(element) => element, - None => return false, - }; + let prestate_root_bytes = + match convert_byte_array_to_fixed_array(&env, prestate_root).and_then(bytes32_to_element) { + Some(element) => element, + None => return false, + }; let (bool, _update_hint) = verkle_proof.check( formatted_keys, diff --git a/bindings/java/rust_code/src/parsers.rs b/bindings/java/rust_code/src/parsers.rs index 9075dfb..3875a34 100644 --- a/bindings/java/rust_code/src/parsers.rs +++ b/bindings/java/rust_code/src/parsers.rs @@ -13,16 +13,16 @@ pub fn parse_scalars<'a>(env: &'a JNIEnv<'a>, values: JByteArray<'a>) -> Result< Ok(input_elements) } -pub fn parse_indices<'a>(env: &JNIEnv, values: JByteArray<'a>) -> Result, String> { +pub fn parse_indices(env: &JNIEnv, values: JByteArray<'_>) -> Result, String> { let input_elements = env .convert_byte_array(values) .map_err(|_| "could not convert byte array to vector".to_string())?; Ok(input_elements.into_iter().map(|x| x as usize).collect()) } -pub fn parse_commitment<'a>( +pub fn parse_commitment( env: &JNIEnv, - commitment: JByteArray<'a>, + commitment: JByteArray<'_>, ) -> Result { let commitment_bytes = env .convert_byte_array(commitment) diff --git a/bindings/java/rust_code/src/utils.rs b/bindings/java/rust_code/src/utils.rs index c178993..dc563b3 100644 --- a/bindings/java/rust_code/src/utils.rs +++ b/bindings/java/rust_code/src/utils.rs @@ -86,9 +86,9 @@ pub fn byte_to_depth_extension_present(value: u8) -> (ExtPresent, u8) { /// /// An `Option>` which is `Some` containing the converted elements if all conversions /// are successful, otherwise `None`. -pub fn jobjectarray_to_vec<'local, T, F>( +pub fn jobjectarray_to_vec( env: &mut JNIEnv, - array: &JObjectArray<'local>, + array: &JObjectArray<'_>, mut converter: F, ) -> Option> where @@ -117,9 +117,9 @@ where /// /// An `Option<[u8; 32]>` which is `Some` containing the converted byte array if successful, /// otherwise `None`. -pub fn convert_byte_array_to_fixed_array<'local>( +pub fn convert_byte_array_to_fixed_array( env: &JNIEnv, - byte_array: JByteArray<'local>, + byte_array: JByteArray<'_>, ) -> Option<[u8; 32]> { let bytes = env.convert_byte_array(byte_array).ok()?; if bytes.len() != 32 { @@ -145,11 +145,7 @@ pub fn convert_byte_array_to_fixed_array<'local>( /// # Returns /// /// An `Option<[u8; 32]>` which is `Some` containing the byte array if successful, otherwise `None`. -pub fn get_array<'local>( - env: &mut JNIEnv, - array: &JObjectArray<'local>, - index: i32, -) -> Option<[u8; 32]> { +pub fn get_array(env: &mut JNIEnv, array: &JObjectArray<'_>, index: i32) -> Option<[u8; 32]> { let vec_vec = jobject_array_to_2d_byte_array(env, array); let bytes = vec_vec.get(index as usize).cloned()?; if bytes.len() != 32 { @@ -187,9 +183,9 @@ pub fn get_array<'local>( /// /// An `Option>` which is `Some(None)` if the element is `null`, `Some(Some([u8; 32]))` /// if the element is successfully converted, or `None` if the operation fails. -pub fn get_optional_array<'local>( +pub fn get_optional_array( env: &mut JNIEnv, - array: &JObjectArray<'local>, + array: &JObjectArray<'_>, index: i32, ) -> Option> { let vec_of_vec = jobject_array_to_2d_byte_array(env, array); @@ -227,9 +223,9 @@ pub fn get_optional_array<'local>( /// /// An `Option>` which is `Some` containing the converted elements as a set /// if all conversions are successful, otherwise `None`. -pub fn convert_to_btree_set<'local>( +pub fn convert_to_btree_set( env: &mut JNIEnv, - array: &JObjectArray<'local>, + array: &JObjectArray<'_>, ) -> Option> { // jobject_array_to_2d_byte_array(env, array) // .into_iter() @@ -260,7 +256,7 @@ pub(crate) fn jobject_array_to_2d_byte_array( for i in 0..outer_len { // Get each inner array (JByteArray) - let inner_array_obj = env.get_object_array_element(&array, i).unwrap(); + let inner_array_obj = env.get_object_array_element(array, i).unwrap(); let inner_array: JByteArray = JByteArray::from(inner_array_obj); // Get the length of the inner array