Skip to content

Commit

Permalink
chore(ipa-multipoint): switch to LE bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
dragan2234 committed Jan 29, 2024
1 parent dc5d0a9 commit e303b91
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions ipa-multipoint/ipa_multipoint_jni/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,15 @@ pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaM
_class: JClass<'_>,
input: jbyteArray,
) -> jbyteArray {
let mut input = env
let input = env
.convert_byte_array(input)
.expect("Cannot convert jbyteArray to rust array");

let committer = &CONFIG.committer;

reverse_scalars_endian(&mut input);
let commitment = ffi_interface::commit_to_scalars(committer, &input).unwrap();

let mut hash = ffi_interface::hash_commitment(commitment);
// TODO(Big-Endian): The output of `hash_commitment` is a scalar serialized
// TODO(Big-Endian): in little endian. The previous implementation used big endian.
hash.reverse();
let hash = ffi_interface::hash_commitment(commitment);

env.byte_array_from_slice(&hash)
.expect("Couldn't convert to byte array")
Expand All @@ -104,27 +100,15 @@ pub extern "system" fn Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaM
_class: JClass<'_>,
input: jbyteArray,
) -> jbyteArray {
let mut input = env
let input = env
.convert_byte_array(input)
.expect("Cannot convert jbyteArray to rust array");

let committer = &CONFIG.committer;
reverse_scalars_endian(&mut input);

let commitment = ffi_interface::commit_to_scalars(committer, &input).unwrap();
let hash = ffi_interface::deprecated_serialize_commitment(commitment);

env.byte_array_from_slice(&hash)
.expect("Couldn't convert to byte array")
}

// TODO(Big-Endian): rust-verkle now uses Little-Endian for scalars.
// TODO(Big-Endian): We switch the endianness here to match the old implementation.
// TODO(Big-Endian): Doing the switch here allows use to restrict the changes to just this part of the code, until
// TODO(Big-Endian): we are ready to change besu-verkle and other parts of the code to use little endian input.
fn reverse_scalars_endian(scalars: &mut [u8]) {
const SCALAR_SIZE: usize = 32;
for scalar in scalars.chunks_exact_mut(SCALAR_SIZE) {
scalar.reverse();
}
}

0 comments on commit e303b91

Please sign in to comment.