Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Oct 9, 2024
1 parent e85f2cb commit 8298b6a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 31 deletions.
28 changes: 14 additions & 14 deletions bindings/java/rust_code/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ use verkle_trie::proof::{ExtPresent, VerificationHint, VerkleProof};
pub static CONFIG: Lazy<ffi_interface::Context> = 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>,
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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) {
Expand All @@ -402,7 +403,7 @@ pub extern "system" fn Java_verkle_cryptography_LibIpaMultipoint_verifyPreStateR
};
let (formatted_extension_present, depths): (Vec<ExtPresent>, Vec<u8>) = 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) {
Expand All @@ -412,20 +413,19 @@ 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,
},
comms_sorted: formatted_commitments,
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,
Expand Down
6 changes: 3 additions & 3 deletions bindings/java/rust_code/src/parsers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<usize>, String> {
pub fn parse_indices(env: &JNIEnv, values: JByteArray<'_>) -> Result<Vec<usize>, 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<CommitmentBytes, String> {
let commitment_bytes = env
.convert_byte_array(commitment)
Expand Down
24 changes: 10 additions & 14 deletions bindings/java/rust_code/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ pub fn byte_to_depth_extension_present(value: u8) -> (ExtPresent, u8) {
///
/// An `Option<Vec<T>>` 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<T, F>(
env: &mut JNIEnv,
array: &JObjectArray<'local>,
array: &JObjectArray<'_>,
mut converter: F,
) -> Option<Vec<T>>
where
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -187,9 +183,9 @@ pub fn get_array<'local>(
///
/// An `Option<Option<[u8; 32]>>` 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<Option<[u8; 32]>> {
let vec_of_vec = jobject_array_to_2d_byte_array(env, array);
Expand Down Expand Up @@ -227,9 +223,9 @@ pub fn get_optional_array<'local>(
///
/// An `Option<BTreeSet<[u8; 31]>>` 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<BTreeSet<[u8; 31]>> {
// jobject_array_to_2d_byte_array(env, array)
// .into_iter()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8298b6a

Please sign in to comment.