Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: balance sanitization #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions csv/entry_16_negative.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
username,balance_ETH_ETH,balance_USDT_ETH
dxGaEAii,-11888,41163
MBlfbBGI,67823,18651
lAhWlEWZ,-18651,2087
nuZweYtO,22073,-55683
gbdSwiuY,34897,83296
RZNneNuP,-83296,16881
YsscHXkp,31699,35479
RkLzkDun,-2087,-79731
HlQlnEYI,30605,11888
RqkZOFYe,16881,-14874
NjCSRAfD,-41163,67823
pHniJMQY,14874,22073
dOGIMzKR,10032,10032
HfMDmNLp,55683,34897
xPLKzCBl,79731,30605
AtwIxZHo,35479,31699
12 changes: 12 additions & 0 deletions zk_prover/src/chips/range/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,18 @@ mod testing {
);
}

/* #[test]
// test converting negative value to Fp for use in range_check chip
fn test_negative_value() {
let a = Fp::from(-1i8);
/*
the trait bound `halo2_proofs::halo2curves::bn256::Fr: From<i8>` is not satisfied
the following other types implement trait `From<T>`:
<halo2_proofs::halo2curves::bn256::Fr as From<bool>>
<halo2_proofs::halo2curves::bn256::Fr as From<u64>>
*/
} */

#[cfg(feature = "dev-graph")]
#[test]
fn print_range_check_test() {
Expand Down
19 changes: 19 additions & 0 deletions zk_prover/src/merkle_sum_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,25 @@ mod test {
assert_eq!(fp_3, 18446744073709551613.into());
}

#[test]
fn test_negative_big_uint_conversion() {
// test that the conversion from a negative big uint to an Fp returns None & panics
let big_uint = (-3).to_biguint();
assert!(big_uint.is_none());
assert!(std::panic::catch_unwind(|| big_uint.unwrap()).is_err());
// cannot convert negative number to big uint
// big uint is being converted to field element using merkle_sum_tree::utils::big_uint_to_fp
// plus field elements are non-negative values so it doesn't seem possible to get a negative value into mst or range_check
}

#[test]
fn test_mst_negative_value_in_csv() {
// create new merkle tree with csv containing negative values
let merkle_tree =
MerkleSumTree::<N_CURRENCIES, N_BYTES>::from_csv("../csv/entry_16_negative.csv");
assert!(merkle_tree.is_err());
}

#[test]
fn get_middle_node_hash_preimage() {
let merkle_tree =
Expand Down
12 changes: 12 additions & 0 deletions zk_prover/src/merkle_sum_tree/utils/csv_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ pub fn parse_csv_to_entries<P: AsRef<Path>, const N_CURRENCIES: usize, const N_B

Ok((cryptocurrencies, entries))
}

#[cfg(test)]
mod test {
use crate::merkle_sum_tree::utils::parse_csv_to_entries;

#[test]
fn test_parse_csv_to_entries() {
// test negative value in csv
let result = parse_csv_to_entries::<&str, 2, 8>("../csv/entry_16_negative.csv");
assert!(result.is_err());
}
}
Loading