diff --git a/js/compressed-token/src/instructions/pack-compressed-token-accounts.ts b/js/compressed-token/src/instructions/pack-compressed-token-accounts.ts index 64ab948193..d0d1126f11 100644 --- a/js/compressed-token/src/instructions/pack-compressed-token-accounts.ts +++ b/js/compressed-token/src/instructions/pack-compressed-token-accounts.ts @@ -84,7 +84,9 @@ export function packCompressedTokenAccounts( leafIndex: account.compressedAccount.leafIndex, }, rootIndex: rootIndices[index], - lamports: account.compressedAccount.lamports.eq(bn(0)) ? null : account.compressedAccount.lamports, + lamports: account.compressedAccount.lamports.eq(bn(0)) + ? null + : account.compressedAccount.lamports, }); }, ); diff --git a/merkle-tree/concurrent/src/copy.rs b/merkle-tree/concurrent/src/copy.rs index 9848b352ca..ee586a4a46 100644 --- a/merkle-tree/concurrent/src/copy.rs +++ b/merkle-tree/concurrent/src/copy.rs @@ -191,11 +191,8 @@ mod test { ) .unwrap(); - let leaf: [u8; 32] = Fr::rand(&mut rng) - .into_bigint() - .to_bytes_be() - .try_into() - .unwrap(); + let leaf: [u8; 32] = rng.gen_biguint(248).to_be_bytes().try_into().unwrap(); + mt_1.append(&leaf).unwrap(); mt_2.append(&leaf).unwrap(); diff --git a/merkle-tree/indexed/src/copy.rs b/merkle-tree/indexed/src/copy.rs index 3834d1dd49..553b352144 100644 --- a/merkle-tree/indexed/src/copy.rs +++ b/merkle-tree/indexed/src/copy.rs @@ -101,6 +101,7 @@ where #[cfg(test)] mod test { use light_hasher::Poseidon; + use light_utils::bigint::bigint_to_be_bytes_array; use num_bigint::RandBigInt; use rand::thread_rng; @@ -163,7 +164,7 @@ mod test { ) .unwrap(); - let leaf: [u8; 32] = rng.gen_biguint(256).to_be_bytes().try_into().unwrap(); + let leaf: [u8; 32] = bigint_to_be_bytes_array::<32>(&rng.gen_biguint(248)).unwrap(); mt_1.append(&leaf).unwrap(); mt_2.append(&leaf).unwrap(); diff --git a/merkle-tree/indexed/src/lib.rs b/merkle-tree/indexed/src/lib.rs index d15e60afd4..b4f17d1e95 100644 --- a/merkle-tree/indexed/src/lib.rs +++ b/merkle-tree/indexed/src/lib.rs @@ -261,7 +261,7 @@ where .enumerate() .filter_map(|(index, changelog_entry)| { if changelog_entry.element.index == low_element.index { - Some(indexed_changelog_index + 1 + index) + Some((indexed_changelog_index + 1 + index) % self.indexed_changelog.len()) } else { None } @@ -279,7 +279,10 @@ where // that it should become the low element. // // Save it and break the loop. - new_low_element = Some((next_indexed_changelog_index + 1, next_element_value)); + new_low_element = Some(( + (next_indexed_changelog_index + 1) % self.indexed_changelog.len(), + next_element_value, + )); break; } diff --git a/merkle-tree/indexed/src/zero_copy.rs b/merkle-tree/indexed/src/zero_copy.rs index e4025388c1..7d7d73e7cb 100644 --- a/merkle-tree/indexed/src/zero_copy.rs +++ b/merkle-tree/indexed/src/zero_copy.rs @@ -244,6 +244,7 @@ where #[cfg(test)] mod test { use light_hasher::Poseidon; + use light_utils::bigint::bigint_to_be_bytes_array; use num_bigint::RandBigInt; use rand::thread_rng; @@ -304,8 +305,7 @@ mod test { ) .unwrap(); - let leaf: [u8; 32] = rng.gen_biguint(256).to_be_bytes().try_into().unwrap(); - + let leaf: [u8; 32] = bigint_to_be_bytes_array::<32>(&rng.gen_biguint(248)).unwrap(); mt_1.append(&leaf).unwrap(); mt_2.append(&leaf).unwrap(); diff --git a/merkle-tree/indexed/tests/tests.rs b/merkle-tree/indexed/tests/tests.rs index eb7e766587..2fb4c2b38b 100644 --- a/merkle-tree/indexed/tests/tests.rs +++ b/merkle-tree/indexed/tests/tests.rs @@ -936,16 +936,17 @@ fn functional_changelog_test_random_wrap_around_8_128_512_0_512() { const CANOPY: usize = 0; const INDEXED_CHANGELOG: usize = 128; const N_OPERATIONS: usize = (1 << HEIGHT) / 2; - - functional_changelog_test_random::< - true, - HEIGHT, - CHANGELOG, - ROOTS, - CANOPY, - INDEXED_CHANGELOG, - N_OPERATIONS, - >() + for _ in 0..100 { + functional_changelog_test_random::< + true, + HEIGHT, + CHANGELOG, + ROOTS, + CANOPY, + INDEXED_CHANGELOG, + N_OPERATIONS, + >() + } } /// Performs `N_OPERATIONS` concurrent updates with random elements. All of them without