Skip to content

Commit

Permalink
modify interop tests to show how to change the java tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevaundray committed Jan 28, 2024
1 parent 6831f35 commit 5fdb652
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions ffi_interface/src/interop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ pub(crate) fn group_to_field(point: &Element) -> Fr {
mod test {
use super::Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_pedersenHash;
use crate::{
commit_to_scalars, deprecated_serialize_commitment, fr_to_be_bytes, get_tree_key_hash,
commit_to_scalars, deprecated_serialize_commitment, fr_to_le_bytes, get_tree_key_hash,
hash_commitment,
interop::{
Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commit,
Expand Down Expand Up @@ -152,42 +152,68 @@ mod test {

#[test]
fn interop_commit() {
let scalars: Vec<_> = (0..256)
let scalars_le: Vec<_> = (0..256)
.map(|i| {
let val = Fr::from((i + 1) as u128);
fr_to_be_bytes(-val)
fr_to_le_bytes(-val)
})
.flatten()
.collect();

let expected_hash =
Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commit(&scalars);
let scalars_be: Vec<_> = (0..256)
.map(|i| {
let val = Fr::from((i + 1) as u128);
let mut arr = fr_to_le_bytes(-val);
arr.reverse();
arr
})
.flatten()
.collect();

// The previous implementation will return the hash in big endian format
// The new implementation will return the hash in little endian format
// however.
let expected_hash_be =
Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commit(&scalars_be);
let expected_hash_le: Vec<_> = expected_hash_be.iter().rev().cloned().collect();

let crs = CRS::default();
let committer = DefaultCommitter::new(&crs.G);

let got_commitment = commit_to_scalars(&committer, &scalars).unwrap();
let got_commitment = commit_to_scalars(&committer, &scalars_le).unwrap();
let got_hash = hash_commitment(got_commitment);
assert_eq!(got_hash.to_vec(), expected_hash)
assert_eq!(got_hash.to_vec(), expected_hash_le)
}

#[test]
fn interop_commit_root() {
let scalars: Vec<_> = (0..256)
let scalars_le: Vec<_> = (0..256)
.map(|i| {
let val = Fr::from((i + 1) as u128);
fr_to_le_bytes(-val)
})
.flatten()
.collect();

let scalars_be: Vec<_> = (0..256)
.map(|i| {
let val = Fr::from((i + 1) as u128);
fr_to_be_bytes(-val)
let mut arr = fr_to_le_bytes(-val);
arr.reverse();
arr
})
.flatten()
.collect();

let expected_hash =
Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commitRoot(&scalars);
Java_org_hyperledger_besu_nativelib_ipamultipoint_LibIpaMultipoint_commitRoot(
&scalars_be,
);

let crs = CRS::default();
let committer = DefaultCommitter::new(&crs.G);

let got_commitment = commit_to_scalars(&committer, &scalars).unwrap();
let got_commitment = commit_to_scalars(&committer, &scalars_le).unwrap();
let got_hash = deprecated_serialize_commitment(got_commitment);
assert_eq!(got_hash.to_vec(), expected_hash)
}
Expand Down

0 comments on commit 5fdb652

Please sign in to comment.