Skip to content

Commit

Permalink
replace rng fr element, fix patch elements and proof
Browse files Browse the repository at this point in the history
  • Loading branch information
ananas-block committed Jun 25, 2024
1 parent 7a5a721 commit 90d89b9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
},
);
Expand Down
7 changes: 2 additions & 5 deletions merkle-tree/concurrent/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 2 additions & 1 deletion merkle-tree/indexed/src/copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
7 changes: 5 additions & 2 deletions merkle-tree/indexed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions merkle-tree/indexed/src/zero_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();

Expand Down
21 changes: 11 additions & 10 deletions merkle-tree/indexed/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90d89b9

Please sign in to comment.